next up previous contents index
Next: Dictionary Based Coder ( Up: Lossless Compression Previous: Prediction by Partial Matching   Contents   Index


Deflation/Inflation Coder ( DeflateCoder )

Definition

The class DeflateCoder encapsulates the algorithms ``deflation'' and ``inflation'' from the zlib-library by J.-L. Gilly and M. Adler (see www.zlib.org).

Both algorithms use two buffers (for encoded and decoded data). The user can control the size of each buffer. In addition he can fine-tune some parameters of the algorithm, which gives him a trade-off between compression rate and speed.
This coder is fast, gives good compression rates and has moderate memory requirements.

#include < LEDA/coding/deflate.h >

Creation

DeflateCoder C(streambuf* src_stream = 0, streambuf* tgt_stream = 0, bool own_streams = false, uint32 enc_buffer_sz = DefaultBufferSize, uint32 dec_buffer_sz = DefaultBufferSize)
    creates an instance C which uses the given source and target streams. If own_streams is set, then C is responsible for the destruction of the streams, otherwise the pointers src_stream and tgt_stream must be valid during the life-time of C. (In addition the sizes of the two buffers may be specified.)

DeflateCoder C(const char* src_file_name, const char* tgt_file_name, uint32 enc_buffer_sz = DefaultBufferSize, uint32 dec_buffer_sz = DefaultBufferSize)
    creates an instance C which uses file-streams for input and output. (In addition the sizes of the two buffers may be specified.)

Operations

Standard Operations

void C.encode() encodes the source stream and writes the output to the target stream.

void C.decode() decodes the source stream and writes the output to the target stream.

uint32 C.encode_memory_chunk(const char* in_buf, uint32 in_len, char* out_buf, uint32 out_len)
    encodes the memory chunk starting at in_buf with size in_len into the buffer starting at out_buf with size out_len. The function returns actual length of the encoded chunk which may be smaller than out_len. If the output buffer is too small for the encoded data the failure flag will be set (see below).

uint32 C.decode_memory_chunk(const char* in_buf, uint32 in_len, char* out_buf, uint32 out_len)
    decodes a memory chunk. The meaning of the parameters and the return value is the same as in the previous function.

streambuf* C.get_src_stream() returns the current source stream.

void C.set_src_stream(streambuf* src_stream, bool own_stream = false)
    sets the source stream (cf. constructor).

void C.set_src_file(const char* file_name)
    sets a file as source stream.

streambuf* C.get_tgt_stream() returns the current target stream.

void C.set_tgt_stream(streambuf* tgt_stream, bool own_Stream = false)
    sets the target stream (cf. constructor).

void C.set_tgt_file(const char* file_name)
    sets a file as target stream.

void C.reset(bool keep_parameters = true)
    puts C in the same state as the default constructor. If keep_parameters is false the parameters are set to their default values.

bool C.failed() returns true if an error occured.

bool C.finished() returns true if the coding is finished.

string C.get_description() provides a description for C.

Additional Operations

int C.get_compression_level() returns the current compression level.

void C.set_compression_level(int level)
    sets the compression level (between 0 and 9), whereas 0 means no compression, 1 gives the best speed and 9 yields the highest compression.

int C.get_window_size() returns the base two logarithm of the size of the sliding window used by the deflation algorithm.

void C.set_window_size(int log2_of_sz)
    sets the window size (log2_of_sz must be between 8 and 15).

int C.get_memory_level() returns the current memory level.

void C.set_memory_level(int level)
    sets the memory level (between 1 and 9). The higher this number, the higher the memory consumption.

int C.get_strategy() returns the current strategy for the deflation algorithm.

void C.set_strategy(int strategy)
    sets the compression strategy (between 0 and 3): 0=default, 1=optimization for filtered data, i.e. small values with random distribution, 2=Huffman only (no string matching), 3=RLE (for image data).

void C.get_memory_consumption(uint32& mem_for_enc, uint32& mem_for_dec)
    returns the (approximate) memory consumption (in bytes) needed for encoding and decoding repectively.

uint32 C.get_enc_buffer_size() returns the size of the buffer for encoded data.

void C.set_enc_buffer_size(uint32 buffer_size)
    sets the size of the buffer for encoded data.

uint32 C.get_dec_buffer_size() returns the size of the buffer for decoded data.

void C.set_dec_buffer_size(uint32 buffer_size)
    sets the size of the buffer for decoded data.


next up previous contents index
Next: Dictionary Based Coder ( Up: Lossless Compression Previous: Prediction by Partial Matching   Contents   Index
Christian Uhrig 2017-04-07