https://github.com/recp/huff
canonical huffman coding
https://github.com/recp/huff
canonical-huffman compression deflate huffman huffman-coding png
Last synced: 4 months ago
JSON representation
canonical huffman coding
- Host: GitHub
- URL: https://github.com/recp/huff
- Owner: recp
- Created: 2024-12-29T20:35:14.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2025-01-28T11:19:21.000Z (5 months ago)
- Last Synced: 2025-03-09T08:47:40.504Z (4 months ago)
- Topics: canonical-huffman, compression, deflate, huffman, huffman-coding, png
- Language: C
- Homepage:
- Size: 46.9 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 🗜️ Huffman Coding (In Progress)
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
## 🔧 Usage
### Initializing a Huffman Table
The library provides two initialization functions:
- `huff_init_lsb()` for LSB-first bitstreams.
- `huff_init_msb()` for MSB-first bitstreams.```c
// 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);
```## Decoding a Symbol
```c
// 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);
```## TODO
- [x] lsb
- [ ] sub tables?
- [ ] msb
- [ ] tests
- [ ] build
- [ ] documentation