Leptonica  1.82.0
Image processing and image analysis suite
zlibmem.c File Reference
#include "allheaders.h"
#include "zlib.h"

Go to the source code of this file.

Macros

#define DEBUG   0
 

Functions

l_uint8 * zlibCompress (const l_uint8 *datain, size_t nin, size_t *pnout)
 
l_uint8 * zlibUncompress (const l_uint8 *datain, size_t nin, size_t *pnout)
 

Variables

static const l_int32 L_BUF_SIZE = 32768
 
static const l_int32 ZLIB_COMPRESSION_LEVEL = 6
 

Detailed Description

     zlib operations in memory, using bbuffer
         l_uint8   *zlibCompress()
         l_uint8   *zlibUncompress()
   This provides an example use of the byte buffer utility
   (see bbuffer.c for details of how the bbuffer works internally).
   We use zlib to compress and decompress a byte array from
   one memory buffer to another.  The standard method uses streams,
   but here we use the bbuffer as an expandable queue of pixels
   for both the reading and writing sides of each operation.
   With memory mapping, one should be able to compress between
   memory buffers by using the file system to buffer everything in
   the background, but the bbuffer implementation is more portable.

Definition in file zlibmem.c.

Function Documentation

◆ zlibCompress()

l_uint8* zlibCompress ( const l_uint8 *  datain,
size_t  nin,
size_t *  pnout 
)

zlibCompress()

Parameters
[in]datainbyte buffer with input data
[in]ninnumber of bytes of input data
[out]pnoutnumber of bytes of output data
Returns
dataout compressed data, or NULL on error
Notes:
     (1) We repeatedly read in and fill up an input buffer,
         compress the data, and read it back out.  zlib
         uses two byte buffers internally in the z_stream
         data structure.  We use the bbuffers to feed data
         into the fixed bufferin, and feed it out of bufferout,
         in the same way that a pair of streams would normally
         be used if the data were being read from one file
         and written to another.  This is done iteratively,
         compressing L_BUF_SIZE bytes of input data at a time.

Definition at line 92 of file zlibmem.c.

References bbufferCreate(), and L_BUF_SIZE.

Referenced by l_genDataString().

◆ zlibUncompress()

l_uint8* zlibUncompress ( const l_uint8 *  datain,
size_t  nin,
size_t *  pnout 
)

zlibUncompress()

Parameters
[in]datainbyte buffer with compressed input data
[in]ninnumber of bytes of input data
[out]pnoutnumber of bytes of output data
Returns
dataout uncompressed data, or NULL on error
Notes:
     (1) See zlibCompress().

Definition at line 196 of file zlibmem.c.

References bbufferCreate(), bbufferDestroy(), bbufferDestroyAndSaveData(), bbufferRead(), bbufferWrite(), L_BUF_SIZE, and lept_stderr().

Referenced by ccbaReadStream().