ladybird/Userland/Libraries/LibCompress
Nico Weber 1a9d8e8fbe LibCompress: When limiting huffman tree depth, sacrifice bottom of tree
Deflate and WebP can store at most 15 bits per symbol, meaning their
huffman trees can be at most 15 levels deep.

During construction, when we hit this level, we used to try again
with an ever lower frequency cap per symbol. This had the effect
of giving the symbols with the highest frequency lower frequencies
first, causing the most-frequent symbols to be merged. For example,
maybe the most-frequent symbol had 1 bit, and the 2nd-frequent
two bits (and everything else at least 3). With the cap, the two
most frequent symbols might both have 2 symbols, freeing up bits
for the lower levels of the tree.

This has the effect of making the most-frequent symbols longer at
first, which isn't great for file size.

Instead of using a frequency cap, ignore ever more of the low
bits of the frequency. This sacrifices resolution where it hurts
the lower levels of the tree first, and those are stored less
frequently.

For deflate, the 64 kiB block size means this doesn't have a big
effect, but for WebP it can have a big effect:

sunset-retro.png (876K): 2.02M -> 1.73M -- now (very slightly) smaller
than twice the input size! Maybe we'll be competitive one day.

(For wow.webp and 7z7c.webp, it has no effect, since we don't hit
the "tree too deep" case there, since those have relatively few
colors.)

No behavior change other than smaller file size. (No performance
cost either, and it's less code too.)
2024-05-26 21:00:55 +02:00
..
Brotli.cpp LibCompress/Brotli: Update the lookback buffer with uncompressed data 2024-01-03 17:54:36 +01:00
Brotli.h
BrotliDictionary.cpp AK+Lagom: Make it possible to build for iOS 2024-03-03 13:13:42 -07:00
BrotliDictionary.cpp.dict.bin LibCompress: Use a __FILE__-relative path for the brotli dictionary file 2024-01-10 09:40:51 +01:00
BrotliDictionary.h
CMakeLists.txt LibCompress: Add a PackBits decoder 2023-12-27 17:40:11 +01:00
Deflate.cpp LibCompress: Use named EndOfBlock constant 2024-05-26 19:02:49 +02:00
Deflate.h LibCompress: Pass ReadonlyBytes to encode_huffman_lengths() 2024-05-26 19:02:49 +02:00
DeflateTables.h
Gzip.cpp LibCompress: Remove Gzip compress_file & decompress_file methods 2024-05-14 12:35:25 -06:00
Gzip.h LibCompress: Remove Gzip compress_file & decompress_file methods 2024-05-14 12:35:25 -06:00
Huffman.h LibCompress: When limiting huffman tree depth, sacrifice bottom of tree 2024-05-26 21:00:55 +02:00
Lzma.cpp
Lzma.h
Lzma2.cpp
Lzma2.h
Lzw.h LibCompress: Add an LZW compressor 2024-05-14 12:33:53 -06:00
PackBitsDecoder.cpp LibCompress: Add a PackBits decoder 2023-12-27 17:40:11 +01:00
PackBitsDecoder.h LibCompress: Add a PackBits decoder 2023-12-27 17:40:11 +01:00
Xz.cpp
Xz.h
Zlib.cpp
Zlib.h