code wiki / (root) / nx_jpeg_entropy.nx

nx_jpeg_entropy.nx

buildroot/runtime/nx_jpeg_entropy.nx

6712 B174 linesdepth 3pulls 3 transitivereach 80 importersview sourcekind librarytopic jpeg
docsdependenciesstructsconstsfunctions

about

nx_jpeg_entropy.nx -- baseline-JPEG entropy-coded segment decoder. Per ITU-T Rec. T.81 sec F.2. Heaviest brick of JPEG decode. Per-MCU decode shape (baseline sequential, T.81 sec F.2.1.2): for each color component in the scan: -- DC coefficient (T.81 sec F.2.2.1) T = HUFF_DECODE(DC_table) // 0..15 = "category" DIFF = if T == 0 then 0 else RECEIVE(T) extended via EXTEND(...) DC[0] = prev_dc + DIFF prev_dc = DC[0] -- 63 AC coefficients (T.81 sec F.2.2.2) k = 1 while k < 64: RS = HUFF_DECODE(AC_table) // 8-bit: high4=run, low4=size R = RS >> 4 S = RS & 0x0F if S == 0: if R == 15: k = k + 16 // ZRL (zero-run-length=16) else: k = 64 // EOB (end of block) else: k = k + R // skip R zeros AC[k] = RECEIVE(S) extended via EXTEND(...) k = k + 1 EXTEND(v, T) per T.81 sec F.2.2.1: if v < 2^(T-1) then v - (2^T - 1) else v RECEIVE(T) reads T bits MSB-first from the bitstream. Output: zig-zag-ordered 64-entry coefficient block. Consumer dequantizes + un-zigzags + IDCTs. nx_safety_envelope: intended_use: "Entropy decode for baseline JPEG MCUs." sil_target: SIL1 evidence: [t81_section_f_2_canonical_basis,

dependencies 2 imports · 3 importers

nx_syscalls.nx nx_jpeg_dht.nx nx_jpeg_entropy.nx nx_jpeg_entropy_test.nx nx_jpeg_mcu.nx nx_jpeg_progressive.nx

imports: nx_syscalls.nxnx_jpeg_dht.nx

imported by: nx_jpeg_entropy_test.nxnx_jpeg_mcu.nxnx_jpeg_progressive.nx

structs

none

consts

51const NX_JPEG_ENT_OK: i64 = 0
52const NX_JPEG_ENT_EOF: i64 = 1 // ran out of bytes mid-block
53const NX_JPEG_ENT_BAD_HUFF: i64 = 2 // Huffman decode failed
54const NX_JPEG_ENT_BAD_RUN: i64 = 3 // AC run would push k >= 64
55const NX_JPEG_ENT_RESULT_N: i64 = 4

functions

57func nx_jpeg_ent_result_is_valid(v: i64) -> i64
67func nx_jpeg_ent_receive(t_bits: i64,
105func nx_jpeg_ent_extend(v: i64, t_bits: i64) -> i64
124func nx_jpeg_ent_decode_block(dc_table: *NxJpegHTable,