开发者

Array Compression Algorithm

开发者 https://www.devze.com 2023-01-10 21:44 出处:网络
I have an array of 10345 bytes, I want to compress the array and then decompress, kindly suggest me the 开发者_高级运维compression algorithm which can reduce the size of array. I am using c language,

I have an array of 10345 bytes, I want to compress the array and then decompress, kindly suggest me the 开发者_高级运维compression algorithm which can reduce the size of array. I am using c language, and the array is of unsigned char type.

Rephrased: Can someone suggest a general-purpose compression algorithm (or library) for C/C++?


zlib
Lossless Compression Algorithms


This post's a community wiki. I don't want any points for this -- I've already voted to close the question.

The number of bytes to compress has very little to do with choice of compression algorithm, although it does affect the implementation. For example, when you have fewer than 2^15 bytes to compress, if you are using ZLib, you will want to specify a compression-level of less than 15. The compression-level in Zlib (one of the two such parameters) controls the depth of the "look-back" dictionary. If your file is shorter than 16k bytes, then a 32k look-back dictionary will never half-fill; in that case, use one less bit of pointer into the look-back for a 1/15th edge on the compression compared to setting ZLib to "max."

The content of the data is what matters. If you are sending images with mostly background, then you might want Run Length Encoding (used by Windows .BMP, for example).

If you are sending mostly English text, than you wish you could use something like ZLib, which implements Huffman encoding and LZW-style look-back dictionary compression.

If your data has been encrypted, then attempting to compress it will not succeed.

If your data is a particular type of signal, and you can tolerate some loss of detail, then you may want to transform it into frequency space and send only the principal components. (e.g., JPEG, MP3)

0

精彩评论

暂无评论...
验证码 换一张
取 消