QuickLZ

When I was searching compression library which is available with C/C++, I have met QuickLZ library. In sample directory, there are two simple sample codes, first is compression, the other one is decompression. After some researching time, I decided to use it in order to compress and decompress my audio data. There are a lot of audio codec libraries for this work but many are old, no documentation or hard to link in Windows environment. I have tried FFMPeg, FLAC, vorbis but QuickLZ is easier than them. It is highly successfull in compression and decompression processes and also full open source (.c file is open) so you don't have to link as dynamic or static. I downloaded its 1.50.32 version and used. Here is compression sample code :


// Sample demo for QuickLZ 1.5.x
// Remember to define QLZ_COMPRESSION_LEVEL and QLZ_STREAMING_MODE to the same values for the compressor and decompressor

source code : src


As you see, it is so simple. There is just qlz_compress function and its argument, qlz_state_compress. I don't like magic number is 400 but it is general rule of library :) Although you allocate len + 400, len2 is generally smaller than it. I debugged quicklz.c file. It has standart libraries, no state which needs any dependency. You can change compression level from inside of quicklz.c. There is 3 level and tread off between speed and compression amount. 

#ifndef QLZ_COMPRESSION_LEVEL

// 1 gives fastest compression speed. 3 gives fastest decompression speed and best

// compression ratio. 
#define QLZ_COMPRESSION_LEVEL 1
//#define QLZ_COMPRESSION_LEVEL 2
//#define QLZ_COMPRESSION_LEVEL 3

// If > 0, zero out both states prior to first call to qlz_compress() or qlz_decompress() 

// and decompress packets in the same order as they were compressed
#define QLZ_STREAMING_BUFFER 0
//#define QLZ_STREAMING_BUFFER 100000
//#define QLZ_STREAMING_BUFFER 1000000

// Guarantees that decompression of corrupted data cannot crash. Decreases decompression

// speed 10-20%. Compression speed not affected.
//#define QLZ_MEMORY_SAFE

#endif


This is decompression sample :

// Sample demo for QuickLZ 1.5.x
// Remember to define QLZ_COMPRESSION_LEVEL and QLZ_STREAMING_MODE to the same values for the compressor and decompressor

source code : src


Difference from compression sample, compress words just become decompress. By algorithm, if you have repeat datum in file, it can compress highly. Sometimes, it may increase size of file is compressed but generally library is so succesfull and easy.

Finally, the library has dynamic link file for C/C++ and JAVA, C# version and command-line tool. Its website has a benchmark table that shows compression details. it is free for one user.

Popular posts from this blog

Polya’nın Problem Çözme Teknikleri

Mikroislemci Temelleri