code wiki / (root) / nx_img_scale.nx

nx_img_scale.nx

buildroot/runtime/nx_img_scale.nx

3864 B91 linesdepth 2pulls 2 transitivereach 14 importersview sourcekind librarytopic img
docsdependenciesstructsconstsfunctions

about

nx_img_scale.nx -- sovereign image resampler, hardware-rung-up. Bilinear resize of an N-channel u8 image: ANY src WxH -> ANY dst WxH (both UP- and DOWN-scale, the general "convert to size Y" primitive). Built from the hardware rung UP: pure i64 Q16.16 fixed-point -- no float, no libc, no SIMD dependency, only integer multiply / add / divide-by-power-of-two. All intermediates are kept NON-NEGATIVE (source coord clamped into range) so the code never relies on signed-shift semantics. Convention: half-pixel centers, sx = (x+0.5)*sw/dw - 0.5, edge pixels repeated -- the SAME convention OpenCV INTER_LINEAR / Pillow / ffmpeg-swscale use, so the planned differential gate can prove byte-parity vs a 3rd-party reference (non-novel-capability proving doctrine). nx_scale.nx is Gaussian-pyramid DOWN-scale only; this is the general up/down resampler the media convert path needs. RUNG 1 (this file): bilinear, correctness via KAT (hand-computed from the standard formula = the independent oracle). NEXT: (a) differential gate vs swscale/Pillow; (b) bicubic / Lanczos as selectable vtable transforms; (c) wire into nx_uxf_negotiate's convert path; (d) MEASURED S-class exceed census (organ-graded, never self-scored). license_tier: ORIGINAL

dependencies 1 imports · 9 importers

nx_syscalls.nx nx_img_scale.nx nx_galx_thumb_oneshot.nx nx_galx_upscale.nx nx_img_convert.nx nx_img_convert_loop_gate.nx nx_img_resample.nx nx_img_resample_gate.nx nx_img_scale_emit.nx nx_img_scale_gate.nx nx_reader_tile.nx

imports: nx_syscalls.nx

imported by: nx_galx_thumb_oneshot.nxnx_galx_upscale.nxnx_img_convert.nxnx_img_convert_loop_gate.nxnx_img_resample.nxnx_img_resample_gate.nxnx_img_scale_emit.nxnx_img_scale_gate.nxnx_reader_tile.nx

structs

none

consts

27const NX_IMG_Q: i64 = 65536 // Q16.16 one
28const NX_IMG_HALF: i64 = 32768 // 0.5 in Q16.16
29const NX_IMG_Q2: i64 = 4294967296 // 2^32 (Q16 * Q16)
30const NX_IMG_RND: i64 = 2147483648 // 2^31 (round-to-nearest for the 2^32 divide)

functions

32func _img_clamp(v: i64, lo: i64, hi: i64) -> i64
41func _img_srccoord(d: i64, ssize: i64, dsize: i64) -> i64
50func nx_img_scale_bilinear(src: *u8, sw: i64, sh: i64, nc: i64,