nx_jpeg_decoder.nx
buildroot/runtime/nx_jpeg_decoder.nx
about
nx_jpeg_decoder.nx -- JPEG baseline (SOF0) 8-bit decoder.
CAPABILITY_COMPLETENESS: PARTIAL
MISSING_CAPABILITIES:
- SOF1 extended sequential (rare; most encoders use baseline)
- SOF2 progressive: queued; widely deployed but needs spectral-
selection + successive-approximation decoder
- SOFn arithmetic-coded variants (SOF9-SOF15): essentially
never seen in the wild
- 12-bit sample precision: ITU-T T.81 allows it; almost no
real-world content uses it
- hierarchical mode (SOF5-SOF7): rare
- lossless JPEG (SOF3, SOF7, SOF11): different algorithm
entirely; queued as a separate primitive
- CMYK / YCCK 4-component output: substrate v1 emits RGB only
COVERED:
- SOF0 baseline DCT 8-bit (the >99% case)
- 1-component (grayscale) and 3-component (YCbCr) frames
- Chroma subsampling 4:4:4, 4:2:2, 4:2:0 (and 4:1:1 by
virtue of the generalised H/V sampling-factor loop)
- DC + AC Huffman entropy decoding
- Restart markers RST0..RST7 (DRI segment defines interval)
- Byte stuffing (FF 00 sequences in entropy data)
- APPn / COM segment skipping
- 8x8 inverse DCT via nx_dct8 (already shipped)
- YCbCr -> RGB conversion (BT.601 in Q10 fixed-point)
Composes: nx_bitstream (MSB-first bit reader), nx_huffman
(DC + AC table decode), nx_dct8 (inverse 2D DCT 8x8),
nx_jpeg_header (existing marker-walk helpers; used for the
initial SOI + structure validation -- this brick implements
the full marker walk inline for self-containment).
genealogy_id: itu_t_t81_jpeg_baseline_1992
lineage_id: nx_jpeg_decoder_v1_baseline
dependencies 6 imports · 4 importers
imports: nx_syscalls.nxnx_runtime.nxnx_tier.nxnx_bitstream.nxnx_huffman.nxnx_dct8.nx
imported by: nx_arousal_body.nxnx_image_grade_v0.nxnx_image_grade_v1.nxnx_image_grade_v2.nx
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| 193 | struct NxJpgComponent |
| 207 | struct NxJpgQTable |
| 214 | struct NxJpgHTable |
| 223 | struct NxJpgResult |
consts
| 53 | const NX_JPG_OK: nx_int = 0 |
| 54 | const NX_JPG_ERR_TOO_SHORT: nx_int = 1 |
| 55 | const NX_JPG_ERR_BAD_SOI: nx_int = 2 |
| 56 | const NX_JPG_ERR_UNSUPPORTED_SOF: nx_int = 3 |
| 57 | const NX_JPG_ERR_UNSUPPORTED_PRECISION: nx_int = 4 |
| 58 | const NX_JPG_ERR_UNSUPPORTED_NCOMP: nx_int = 5 |
| 59 | const NX_JPG_ERR_BAD_MARKER: nx_int = 6 |
| 60 | const NX_JPG_ERR_BAD_DQT: nx_int = 7 |
| 61 | const NX_JPG_ERR_BAD_DHT: nx_int = 8 |
| 62 | const NX_JPG_ERR_BAD_SOS: nx_int = 9 |
| 63 | const NX_JPG_ERR_HUFFMAN: nx_int = 10 |
| 64 | const NX_JPG_ERR_OUT_OF_DATA: nx_int = 11 |
| 65 | const NX_JPG_ERR_NO_EOI: nx_int = 12 |
| 69 | const NX_JPG_MK_SOI: nx_int = 216 // 0xD8 |
| 70 | const NX_JPG_MK_EOI: nx_int = 217 // 0xD9 |
| 71 | const NX_JPG_MK_SOS: nx_int = 218 // 0xDA |
| 72 | const NX_JPG_MK_DQT: nx_int = 219 // 0xDB |
| 73 | const NX_JPG_MK_DHT: nx_int = 196 // 0xC4 |
| 74 | const NX_JPG_MK_DRI: nx_int = 221 // 0xDD |
| 75 | const NX_JPG_MK_SOF0: nx_int = 192 // 0xC0 baseline DCT |
| 79 | const NX_JPG_MAX_COMPS: nx_int = 4 |
| 80 | const NX_JPG_MAX_QTABLES: nx_int = 4 |
| 81 | const NX_JPG_MAX_HTABLES: nx_int = 4 |
| 82 | const NX_JPG_MAX_WIDTH: nx_int = 16384 |
| 83 | const NX_JPG_MAX_HEIGHT: nx_int = 16384 |
| 203 | const NX_JPG_COMP_BYTES: nx_size = 56 |
| 212 | const NX_JPG_QTABLE_BYTES: nx_size = 16 |
| 219 | const NX_JPG_HTABLE_BYTES: nx_size = 16 |
| 232 | const NX_JPG_RESULT_BYTES: nx_size = 48 |
functions
| 90 | func _jpg_zigzag(i: nx_int) -> nx_int |
| 162 | func _jpg_extend(value: nx_int, n_bits: nx_int) -> nx_int |
| 172 | func _jpg_clamp_u8(v: nx_int) -> nx_int |
| 178 | func _jpg_ycbcr_to_rgb(y: nx_int, cb: nx_int, cr: nx_int, |
| 236 | func _jpg_read_u16_be(buf: *u8, off: nx_int) -> nx_int called by 1: nx_jpeg_decode |
| 258 | func _jpg_destuff_entropy( |
| 300 | func _jpg_decode_block( called by 1: nx_jpeg_decode calls 4: nx_huffman_decode_msbnx_bitstream_read_msb_jpg_extend_jpg_zigzag |
| 378 | func nx_jpeg_decode(input: *u8, input_size: nx_int) -> *NxJpgResult |
| 853 | func main() -> nx_int |