code wiki / (root) / nx_jpeg_upsample.nx

nx_jpeg_upsample.nx

buildroot/runtime/nx_jpeg_upsample.nx

3575 B87 linesdepth 2pulls 2 transitivereach 73 importersview sourcekind librarytopic jpeg
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nx_jpeg_upsample.nx nx_jpeg_ascii.nx nx_jpeg_upsample_test.nx

imports: nx_syscalls.nx

imported by: nx_jpeg_ascii.nxnx_jpeg_upsample_test.nx

structs

none

consts

39const NX_JPEG_UPSAMPLE_OK: i64 = 0
40const NX_JPEG_UPSAMPLE_BAD_FACTOR: i64 = 1 // Hi > max_h or Vi > max_v
41const NX_JPEG_UPSAMPLE_RESULT_N: i64 = 2

functions

57func nx_jpeg_upsample_nearest(src: *u8, src_w: i64, src_h: i64,