code wiki / (root) / nx_jpeg_dqt.nx

nx_jpeg_dqt.nx

buildroot/runtime/nx_jpeg_dqt.nx

4827 B113 linesdepth 2pulls 2 transitivereach 77 importersview sourcekind librarytopic jpeg
docsdependenciesstructsconstsfunctions

about

nx_jpeg_dqt.nx -- JPEG quantization-table (DQT) parser per ITU-T Rec. T.81 sec B.2.4.1. DQT payload layout (one or more tables, packed): Pq (4 bits) Tq (4 bits) -- precision + table-id Qk[64] -- table values in zig-zag scan order Pq = 0 means each Qk is an 8-bit unsigned value (64 bytes total). Pq = 1 means each Qk is a 16-bit unsigned big-endian value (128 bytes total). Pq=1 is only legal for sample precision > 8 (T.81 sec B.2.4.1); baseline JPEG (SOF0) is 8-bit so 99% of real-world DQTs are Pq=0. Tq is 0..3. Multiple DQT segments may be concatenated within a single payload; this parser walks the payload and emits each table separately. CRITICAL: JPEG quantization tables are stored in ZIG-ZAG order. Decode pipeline must un-zigzag before dequantization or the IDCT will produce garbage. This parser preserves the on-wire zig-zag order; un-zigzag is the consumer's responsibility (it's a 64-byte permutation lookup -- shipped as nx_jpeg_zigzag.nx in a follow-on stone). nx_safety_envelope: intended_use: "Quantization-table parsing for JPEG decode." sil_target: SIL1 evidence: [t81_section_b_2_4_1_canonical_basis, sealed_precision_pq_2_state, bounded_iteration, substrate_honest_truncation_signal] hazard_register: [bug-tape-dqt-precision-confusion, bug-tape-multi-table-payload-overrun, bug-tape-dqt-zero-coefficient-divide-by-zero] residual_risk: "Caller must validate that Qk[*] != 0 before using as divisor; substrate stores values verbatim including zero." verdict: NOT_YET_EVALUATED

dependencies 1 imports · 4 importers

nx_syscalls.nx nx_jpeg_dqt.nx nx_jpeg_decode.nx nx_jpeg_decode_image_test.nx nx_jpeg_dqt_test.nx nx_jpeg_progressive.nx

imports: nx_syscalls.nx

imported by: nx_jpeg_decode.nxnx_jpeg_decode_image_test.nxnx_jpeg_dqt_test.nxnx_jpeg_progressive.nx

structs

54struct NxJpegQTable

consts

39const NX_JPEG_DQT_OK: i64 = 0
40const NX_JPEG_DQT_TRUNC: i64 = 1 // payload too short for declared precision
41const NX_JPEG_DQT_BAD_TQ: i64 = 2 // Tq > 3
42const NX_JPEG_DQT_BAD_PQ: i64 = 3 // Pq > 1
43const NX_JPEG_DQT_OVERFLOW: i64 = 4 // more than 4 tables in payload
44const NX_JPEG_DQT_RESULT_N: i64 = 5
60const NX_JPEG_QTABLE_BYTES: i64 = 24

functions

46func nx_jpeg_dqt_result_is_valid(v: i64) -> i64
71func nx_jpeg_dqt_parse(payload: *u8, payload_len: i64,