code wiki / (root) / nx_webp_huff.nx

nx_webp_huff.nx

buildroot/runtime/nx_webp_huff.nx

9114 B241 linesdepth 5pulls 5 transitivereach 42 importersview sourcekind librarytopic webp
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nx_bitstream.nx nx_huffman.nx nx_webp_huff.nx nx_webp.nx nx_webp_huff_gate.nx nx_webp_vp8l.nx nx_webp_vp8l_gate.nx

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

45struct NxWlTree

consts

33const NX_WL_CODE_LENGTH_CODES: i64 = 19
34const NX_WL_CODE_LEN_LITERALS: i64 = 16
35const NX_WL_DEFAULT_CODE_LEN: i64 = 8
36const NX_WL_TREE_BYTES: i64 = 24

functions

56func wl_code_order(out: *i64) -> i64
called by 2: wl_read_normalmain
66func wl_repeat_extra_bits(slot: i64) -> i64
called by 1: wl_read_normal
72func wl_repeat_offset(slot: i64) -> i64
called by 1: wl_read_normal
85func wl_tree_from_lengths(lengths: *i64, n_symbols: i64) -> *NxWlTree
115func wl_decode_symbol(t: *NxWlTree, bs: *NxBitStream) -> i64
124func wl_read_simple(bs: *NxBitStream, lengths: *i64, n_symbols: i64) -> i64
152func wl_read_normal(bs: *NxBitStream, lengths: *i64, n_symbols: i64) -> i64
226func wl_read_huffman_code(bs: *NxBitStream, n_symbols: i64) -> *NxWlTree