nx_jpeg_upsample.nx
buildroot/runtime/nx_jpeg_upsample.nx
about
nx_jpeg_upsample.nx -- chroma upsampling for JPEG decode.
JPEG with sub-sampled chroma (4:2:2, 4:2:0) stores Cb/Cr at a
lower resolution than Y. Before YCbCr->RGB conversion the
chroma planes must be upsampled to match Y dimensions.
This primitive implements nearest-neighbor (sample-replicate)
upsampling per T.81 Annex A.1.1:
Each source pixel at (sx, sy) is written into a (max_h/Hi) x
(max_v/Vi) rectangle of the destination starting at
(sx * max_h/Hi, sy * max_v/Vi).
Sampling combinations:
4:4:4 (Hi=Vi=max_h=max_v=1) -> identity copy
4:2:2 (Y H=2 V=1; Cb/Cr H=V=1, max_h=2 max_v=1) -> 2x1 replicate for chroma
4:2:0 (Y H=V=2; Cb/Cr H=V=1, max_h=max_v=2) -> 2x2 replicate for chroma
Substrate-honest MVP: nearest-neighbor only. Bilinear
upsampling per JFIF Annex F.1.1.3 is a sibling stone for
quality-critical decode paths; it adds smoother chroma edges
but costs ~3x more arithmetic per pixel.
nx_safety_envelope:
intended_use: "Chroma-plane upsampling for JPEG decode."
sil_target: SIL1
evidence: [t81_annex_a_1_1_canonical_basis,
sample_replicate_no_arithmetic,
bounded_iteration]
hazard_register: [bug-tape-upsample-stride-overflow,
bug-tape-edge-clipping-wrong-on-non-multiple-dims]
residual_risk: "Nearest-neighbor produces blocky chroma
boundaries vs bilinear; acceptable for
substrate's first pass."
verdict: NOT_YET_EVALUATED
dependencies 1 imports · 2 importers
imports: nx_syscalls.nx
imported by: nx_jpeg_ascii.nxnx_jpeg_upsample_test.nx
structs
| none |
consts
| 39 | const NX_JPEG_UPSAMPLE_OK: i64 = 0 |
| 40 | const NX_JPEG_UPSAMPLE_BAD_FACTOR: i64 = 1 // Hi > max_h or Vi > max_v |
| 41 | const NX_JPEG_UPSAMPLE_RESULT_N: i64 = 2 |
functions
| 57 | func nx_jpeg_upsample_nearest(src: *u8, src_w: i64, src_h: i64, |