nx_img_scale.nx
buildroot/runtime/nx_img_scale.nx
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
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
| 27 | const NX_IMG_Q: i64 = 65536 // Q16.16 one |
| 28 | const NX_IMG_HALF: i64 = 32768 // 0.5 in Q16.16 |
| 29 | const NX_IMG_Q2: i64 = 4294967296 // 2^32 (Q16 * Q16) |
| 30 | const NX_IMG_RND: i64 = 2147483648 // 2^31 (round-to-nearest for the 2^32 divide) |
functions
| 32 | func _img_clamp(v: i64, lo: i64, hi: i64) -> i64 |
| 41 | func _img_srccoord(d: i64, ssize: i64, dsize: i64) -> i64 |
| 50 | func nx_img_scale_bilinear(src: *u8, sw: i64, sh: i64, nc: i64, called by 8: mainup_onenx_img_convert_rgb_to_pngmainnx_img_resamplemain+2 calls 2: _img_srccoord_img_clamp |