Leptonica 1.68
C Image Processing Library
|
Compresses and decompresses a byte array from one memory buffer to another. More...
Go to the source code of this file.
Functions | |
l_uint8 * | zlibCompress (l_uint8 *datain, size_t nin, size_t *pnout) |
l_uint8 * | zlibUncompress (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 |
Compresses and decompresses a byte array from one memory buffer to another.
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.
Input: datain (byte buffer with input data) nin (number of bytes of input data) &nout (<return> number of bytes of output data) Return: 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 73 of file zlibmem.c.
References bbufferCreate(), bbufferDestroy(), bbufferDestroyAndSaveData(), bbufferRead(), bbufferWrite(), CALLOC, ERROR_PTR, FREE, L_BUF_SIZE, NULL, PROCNAME, and ZLIB_COMPRESSION_LEVEL.
Referenced by ccbaWriteStream(), main(), and pixGenerateFlateData().
Input: datain (byte buffer with compressed input data) nin (number of bytes of input data) &nout (<return> number of bytes of output data) Return: dataout (uncompressed data), or null on error
Notes: (1) See zlibCompress().
Definition at line 156 of file zlibmem.c.
References bbufferCreate(), bbufferDestroy(), bbufferDestroyAndSaveData(), bbufferRead(), bbufferWrite(), CALLOC, ERROR_PTR, FREE, L_BUF_SIZE, NULL, and PROCNAME.
Referenced by ccbaReadStream(), and main().
const l_int32 L_BUF_SIZE = 32768 [static] |
Definition at line 49 of file zlibmem.c.
Referenced by zlibCompress(), and zlibUncompress().
const l_int32 ZLIB_COMPRESSION_LEVEL = 6 [static] |
Definition at line 50 of file zlibmem.c.
Referenced by zlibCompress().