nx_jpeg_dht.nx
buildroot/runtime/nx_jpeg_dht.nx
about
nx_jpeg_dht.nx -- JPEG Huffman-table (DHT) parser per ITU-T Rec.
T.81 sec B.2.4.2 + canonical decode-table builder per Annex C.
DHT payload layout (one or more tables packed):
Tc (4 bits) Th (4 bits) -- class (0=DC, 1=AC) + table-id (0..3)
L1..L16 (16 bytes) -- BITS: count of codes of each length
V1..Vn (sum-of-BITS) -- HUFFVAL: symbol assignments in
increasing-code-value order
Canonical decode table (T.81 Annex C, Fig C.1-C.3) consists of three
17-entry arrays (lengths 1..16, index 0 unused):
MINCODE[L] -- smallest code of length L
MAXCODE[L] -- largest code of length L (-1 if no codes of len L)
VALPTR[L] -- index into HUFFVAL where codes of length L begin
Decode algorithm (T.81 Fig F.16) -- DECODE:
read 1 bit -> CODE
for L = 1 to 16:
if CODE <= MAXCODE[L]:
return HUFFVAL[VALPTR[L] + CODE - MINCODE[L]]
read 1 more bit; CODE = (CODE << 1) | bit
error
nx_safety_envelope:
intended_use: "Huffman-table parsing + canonical decode-table
construction for JPEG entropy decode."
sil_target: SIL1
evidence: [t81_section_b_2_4_2_canonical_basis,
t81_annex_c_canonical_table_algorithm,
bounded_iteration]
hazard_register: [bug-tape-dht-huffsize-table-overflow,
bug-tape-dht-malformed-bits-length-sum,
bug-tape-dht-tc-th-out-of-range]
residual_risk: "Decode-table users must bound L<=16 per spec;
substrate emits BAD_LENGTH if BITS sum >256."
verdict: NOT_YET_EVALUATED
dependencies 1 imports · 9 importers
imports: nx_syscalls.nx
imported by: nx_jpeg_decode.nxnx_jpeg_decode_image.nxnx_jpeg_decode_image_test.nxnx_jpeg_dht_test.nxnx_jpeg_entropy.nxnx_jpeg_entropy_test.nxnx_jpeg_mcu.nxnx_jpeg_mcu_test.nxnx_jpeg_progressive.nx
structs
| 57 | struct NxJpegHTable |
consts
| 41 | const NX_JPEG_DHT_OK: i64 = 0 |
| 42 | const NX_JPEG_DHT_TRUNC: i64 = 1 |
| 43 | const NX_JPEG_DHT_BAD_TC: i64 = 2 // Tc > 1 |
| 44 | const NX_JPEG_DHT_BAD_TH: i64 = 3 // Th > 3 |
| 45 | const NX_JPEG_DHT_TOO_MANY_SYM: i64 = 4 // sum-of-BITS > 256 |
| 46 | const NX_JPEG_DHT_OVERFLOW: i64 = 5 // more than 4 tables in payload |
| 47 | const NX_JPEG_DHT_RESULT_N: i64 = 6 |
| 68 | const NX_JPEG_HTABLE_BYTES: i64 = 64 |
functions
| 49 | func nx_jpeg_dht_result_is_valid(v: i64) -> i64 |
| 73 | func nx_jpeg_dht_build_decode_tables(bits: *i64, called by 1: nx_jpeg_dht_parse |
| 122 | func nx_jpeg_dht_parse(payload: *u8, payload_len: i64, called by 6: nx_jpeg_decodemainmainmainmainnx_jpeg_prog_decode calls 1: nx_jpeg_dht_build_decode_tables |
| 200 | func nx_jpeg_huff_decode_symbol(table: *NxJpegHTable, |