i need to transmit 20k Files containing a lot of repetitive data to a cobra. I’d like to compress them to save bandwidth over a serial connection. Does anyone have a library for some simple compression/decompression?
search for eazylib http://opentransactions.net/OTLib/easyzlib.c
Note that this is not a simple library but a a decent one for embedded devices. You may want to look into simpler options.
For image files, especially ones that have a lot of color data, RLE can actually increase the size of the picture rather than compress it. The same can be said about text and binary data that’s widely dispersed. RLE hasn’t been a very good compression algorithm for years. Depending on what kind of data it is, you may want to look at a dictionary style compression or if you are using one of the more powerful processors, zip compression like Gus said.
I am compressing/decompressing 1bpp bitmaps. I thought a simple rle would work well. They have a lot of white space.
Best thing to do is try to see on sample data how much compression you get.
The RLE algorithm is very simple, the format of the file records will be:
You can encode this into a single byte if you want to have RLE’s no longer than 128 pixels. For example you can use the high bit to signify that the run is either a black pixel (1) or a white pixel (0), and then the lower 7 bits to determine the length (up to 128).
For true black/white the 1:128 rle should be fine. If you use moire to fake grayscale, you might be better of with a 4bit pattern + 4bit RL (first pass). After that you could run a second rle pass that takes 1 byte as RL followed by 1 byte encoded in first pass.