This library is designed to make Huffman coding easy to use, while providing optimized and reusable utilities. It aims to simplify the integration of Huffman coding into projects, improve maintainability, and ensure robust testing.
Huffman coding is a cornerstone of many compression algorithms and formats, widely used in:
- πΌοΈ Images: JPEG, PNG, WebP, GIF.
- π₯ Video: MPEG, H.264, HEVC (H.265).
- π΅ Audio: MP3, AAC, Opus.
- π¦ Compression: ZIP, DEFLATE, Brotli.
- π Networking: HTTP/2, HTTP/3 (QUIC) header compression.
This library seeks to serve as a shared foundation for these and other applications, offering standardized, high-performance tools for encoding and decoding Huffman streams.
π¨ Don't use this in production until tests are ready
The library provides two initialization functions:
huff_init_lsb()
for LSB-first bitstreams.huff_init_msb()
for MSB-first bitstreams.
// Example: Initializing a Huffman table for LSB-first bitstreams (e.g., DEFLATE)
huff_table_t table;
uint8_t lengths[] = {3, 3, 3, 3}; // Bit lengths for each symbol
uint16_t symbols[] = {0, 1, 2, 3}; // Corresponding symbols
huff_init_lsb(&table, lengths, symbols, 4);
// LSB-first decoding
bitstream_t bitstream = 0b10110010; // Example LSB-first bitstream
uint8_t bit_length = 8; // Number of valid bits
uint8_t used_bits;
uint_fast16_t symbol = huff_decode_lsb(&table, bitstream, bit_length, &used_bits);
- lsb
- sub tables?
- msb
- tests
- build
- documentation