Leptonica 1.85.0
Image processing and image analysis suite
Loading...
Searching...
No Matches
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.

Macro Definition Documentation

◆ DEBUG

#define DEBUG   0

Definition at line 66 of 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 L_BUF_SIZE, and L_ByteBuffer::n.

◆ 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 193 of file zlibmem.c.

References L_BUF_SIZE.

Variable Documentation

◆ L_BUF_SIZE

const l_int32 L_BUF_SIZE = 32768
static

Definition at line 62 of file zlibmem.c.

◆ ZLIB_COMPRESSION_LEVEL

const l_int32 ZLIB_COMPRESSION_LEVEL = 6
static

Definition at line 63 of file zlibmem.c.