Heatshrink: An Embedded Data Compression Library
spin.atomicobject.com
spin.atomicobject.com
However, I am putting images in my code space. I was thinking about RLEing them, but I'll see if this works better.
IME, it works particularly well on bitmapped images and sparse sensor data. Also, it can be faster to incrementally read and unpack compressed data from slow storage (such as flash memory) than to read the whole uncompressed data set. I'm decompressing from flash memory directly into video RAM.
It doesn't change the fundamental algorithm, just speeds up the compression's pattern detection.
The code is less than 100 lines for both compressor and decompressor, and it compresses fairly well considering the code size.
heatshrink can suspend and resume, working in small increments. That's particularly important in embedded and hard real-time systems -- they typically can't block for long. Microcontrollers rarely have enough memory to store all the compressed and decompressed data at once.
Most of the work went into co-routining LZSS in little memory, not LZSS itself. LZSS is pretty simple.
I did run across that while doing research for my embedded project and forgot to mention it. (It was one I skipped due to blocking for too long. It's a good implementation otherwise.) I added it to the article.
We selected it for our embedded devices based on its small code size and suitable license, and since we use it mostly to compress log data with lots of repetitions it works very well.
It's a good implementation if that isn't an issue, but then there's a couple tiny LZSS/LZW/etc. implementations available.