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 LibCompress: Let BrotliDecompressionStream take a MaybeOwned 2023-08-23 12:03:37 +01:00
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 LibCompress: Implement Brotli decompressor 2022-05-21 22:41:40 +02:00
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 Everywhere: Remove needless trailing semi-colons after functions 2023-07-08 10:32:56 +01:00
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
Lzma2.cpp LibCompress: Avoid overflowing the size of uncompressed LZMA2 chunks 2023-03-30 14:39:31 +02:00
Lzma2.h LibCompress: Add support for LZMA2 2023-03-21 10:25:13 +01:00
Lzma.cpp Everywhere: Remove needless trailing semi-colons after functions 2023-07-08 10:32:56 +01:00
Lzma.h AK: Rename GenericTraits to DefaultTraits 2023-11-09 10:05:51 -05:00
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 LibCompress: Implement the XZ BCJ filter for ARM64 2023-12-14 08:59:23 -07:00
Xz.h LibCompress: Implement the XZ BCJ filter for ARM64 2023-12-14 08:59:23 -07:00
Zlib.cpp LibCompress: Port ZlibDecompressor to AK::Stream 2023-08-23 12:03:37 +01:00
Zlib.h AK: Rename GenericTraits to DefaultTraits 2023-11-09 10:05:51 -05:00