Compressors, Part 2: S H R I N K E R
Unlike delta compression, the shrinker is just as simply structured and works just as well, but unlike delta, it is much more widespread.
Years ago, a screen shrinker appeared in the type-in listing section of Your Sinclair and impressed me with its included demo, where three pixel spheres rotated around two axes — all extremely smooth and colorful, though only a third of the screen was used.
There are shrinkers for graphics and for program code/data; the two methods differ only slightly from each other. In an image compressor, it first looks for an unused flag byte that does not appear in the picture. If none is found, some compressors abort the operation, or they take a byte that occurs only once and alter it to obtain a flag byte. It goes without saying that doing something like this with program code would lead to crashes!
Program compressors, on the other hand, either use a 2-byte flag (math wizards take note: Spectrum RAM = 49,152 bytes, 2-byte combination possibilities = 65,536, and in practice even less RAM is compressed) or process memory in 255-byte chunks.
Once the shrinker detects a sequence of repeated bytes, it writes the flag byte into memory, followed by the byte count, usually as an 8-bit number to save space. Naturally, this is not worthwhile if only two identical bytes occur, so such edge cases are filtered out during compression.
Decompression is then very simple: as long as no flag byte is encountered, copy everything; otherwise, use LDIR (or LDDR if packed from the back) to replicate the byte that follows the flag.
Shrinkers offer the advantage of very fast compression, making them well-suited as pre-compressors. In Turbo Imploder as well as in PK Lite and many other packers, they can be enabled to save both time and space.
Tiger's Claw
There are many other compression methods such as Imploding (LHZ), Huffman (bit compressor), or fractal packers — unfortunately, I am not familiar with all of these methods...
Share your thoughts about the article