mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-22 09:19:03 +00:00
This implements some of basic webp compression: Huffman coding. (The other parts of the basics are backreferences, and color cache entries; and after that there are the four transforms -- predictor, subtract green, color indexing, color.) How much huffman coding helps depends on the input's entropy. Constant-color channels are now encoded in constant space, but otherwise a huffman code always needs at least one bit per symbol. This means just huffman coding can at the very best reduce output size to 1/8th of input size. For three test input files: sunset-retro.png (876K): 2.25M -> 2.02M (helps fairly little; from 2.6x as big as the png input to 2.36x) giphy.gif (184k): 11M -> 4.9M (pretty decent, from 61x as big as the gif input to 27x as big) 7z7c.gif (11K): 775K -> 118K (almost as good as possible an improvement for just huffman coding, from 70x as big as the gif input to 10.7x as big) No measurable encoding perf impact for encoding. The code is pretty similar to Deflate.cpp in LibCompress, with just enough differences that sharing code doesn't look like it's worth it to me. I left comments outlining similarities.