nx_webp_huff.nx
buildroot/runtime/nx_webp_huff.nx
about
nx_webp_huff.nx -- VP8L Huffman code-group reader (WebP lossless).
VP8L transmits every Huffman tree in one of two forms:
SIMPLE -- 1 or 2 symbols written literally, no code-length layer
NORMAL -- a 19-symbol code-length alphabet (3 bits each, sent in a
fixed permuted order) which then codes the real symbol
lengths, with run-length symbols 16/17/18
Both forms resolve to a canonical Huffman table, so both compose onto
the existing nx_huffman primitive: VP8L reads bits LSB-first out of the
byte stream and sends each code MSB-of-code first, which is exactly what
nx_huffman_decode_lsb implements (contract re-verified against
nx_bitstream.nx and nx_huffman.nx on 2026-07-31, not assumed from docs).
THE ZERO-BIT CASE. A tree carrying exactly one symbol must decode that
symbol while consuming NO bits. nx_huffman_decode_lsb always consumes at
least one bit, so a bare canonical table is wrong here and would desync
the whole stream. NxWlTree carries the single-symbol case explicitly
rather than leaving it to the table -- this is the defect that silently
corrupts every VP8L image whose alpha or red channel is constant, which
is most synthetic images.
genealogy_id: webp_lossless_bitstream_spec_2012
lineage_id: nx_webp_huff_v1
license_tier: ORIGINAL
dependencies 3 imports · 4 importers
imports: nx_syscalls.nxnx_bitstream.nxnx_huffman.nx
imported by: nx_webp.nxnx_webp_huff_gate.nxnx_webp_vp8l.nxnx_webp_vp8l_gate.nx
structs
| 45 | struct NxWlTree |
consts
| 33 | const NX_WL_CODE_LENGTH_CODES: i64 = 19 |
| 34 | const NX_WL_CODE_LEN_LITERALS: i64 = 16 |
| 35 | const NX_WL_DEFAULT_CODE_LEN: i64 = 8 |
| 36 | const NX_WL_TREE_BYTES: i64 = 24 |
functions
| 56 | func wl_code_order(out: *i64) -> i64 |
| 66 | func wl_repeat_extra_bits(slot: i64) -> i64 called by 1: wl_read_normal |
| 72 | func wl_repeat_offset(slot: i64) -> i64 called by 1: wl_read_normal |
| 85 | func wl_tree_from_lengths(lengths: *i64, n_symbols: i64) -> *NxWlTree |
| 115 | func wl_decode_symbol(t: *NxWlTree, bs: *NxBitStream) -> i64 |
| 124 | func wl_read_simple(bs: *NxBitStream, lengths: *i64, n_symbols: i64) -> i64 |
| 152 | func wl_read_normal(bs: *NxBitStream, lengths: *i64, n_symbols: i64) -> i64 |
| 226 | func wl_read_huffman_code(bs: *NxBitStream, n_symbols: i64) -> *NxWlTree |