code wiki / (root) / nx_view_transform_lib.nx

nx_view_transform_lib.nx

buildroot/runtime/nx_view_transform_lib.nx

12494 B258 linesdepth 3pulls 5 transitivereach 2 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_view_transform_lib.nx -- THE ONE OWNER OF THE ESTATE VIEW TRANSFORM (GR23, 2026-08-28). license_tier: ORIGINAL No hw writes (Rule 26). WHY THIS EXISTS. The shipped beach page carries the value-structure grade INLINED FOUR TIMES (world FS, figures, hair, WGSL) as a hand-typed .94*(x/.94)^1.45, derived offline in Python and reproducible by nothing. Operator directive 2026-08-28: "we dont want webgl2 and other 3rd party unless we are recreating ourselves the capabilities". So the curve is DERIVED HERE, in NishiLang, from recorded measurements, and BOTH execution surfaces are emitted from ONE generated LUT so they cannot diverge. AgX and ACES are ORACLES we check ourselves against, never a dependency -- borrow the rulers, not the runtime. Neither appears in this file as code. NOTHING BELOW IS TYPED FROM A CALCULATOR. The only numbers are (a) the measurements, declared as data with their provenance, and (b) values DERIVED at runtime. The exponent is computed, not typed; the LUT size is searched, not chosen. THE MEASUREMENT (PIL over the operator own 20:19 frame vs the reference photographs, 2026-08-28): saturation is NOT the gap (S mean .29 against a reference band .27-.32, lift x1.01); the gaps are HUE MONOCULTURE and HIGH-KEY MIDS (V p50 .79 against a reference band .59-.66). THE CURVE. A p95-anchored power pivot: out = k*(x/k)^g, k the frame own p95 so the white point is an exact fixed point. g is fixed by requiring the median to move a declared fraction of the way from where it is to the reference band near edge: m_tgt = m_src - (m_src - band_hi) * num/den g = ln(m_tgt/k) / ln(m_src/k) HALF-way (num/den = 1/2) is the declared choice, because sand content legitimately differs from the reference scenes. MEASURED RESIDUAL: this yields g = 1.4939, while the shipped page carries a hand-typed 1.45, which moves the median 45.7% -- not the "half" its own comment claims. A constant that has drifted from the rule written beside it is exactly what a generator removes. THE APPLICATION IS LUMINANCE-SCALED, AND THAT IS THE FIX, NOT A REFINEMENT. Applying a power per-channel raises saturation BY CONSTRUCTION: with r = min/max, HSV S = 1 - r becomes 1 - r^g, and g > 1 forces r^g < r, so S rises for every non-grey pixel, monotonically in g. Measured on the live frame the shipped per-channel form drove S mean .313 -> .411, i.e. OUT of the .27-.32 band it was told saturation already sat inside. Scaling the triple by the ratio the curve applies to its LUMINANCE leaves min/max untouched, so S is preserved EXACTLY, for every pixel, by construction. Measured: V p50 .729 -> .616 (inside .59-.66) with S mean .313 -> .313 (unchanged). Both bands held. DECLARED EXPOSURE, NOT HIDDEN. The curve crushes deep shadow: over inputs 0..0.10, 26 distinct 8-bit levels collapse to 10 (38.5% survive), and 5 of 256 input levels map above 1.0 and clip. That is invisible on a noon beach and is where a night or interior frame will show banding. It is

dependencies 2 imports · 2 importers

nx_syscalls.nx nx_fixq30_lib.nx nx_view_transform_lib.nx nx_view_transform.nx nx_view_transform_gate.nx

imports: nx_syscalls.nxnx_fixq30_lib.nx

imported by: nx_view_transform.nxnx_view_transform_gate.nx

structs

none

consts

63const VT_ANCHOR_MICRO: i64 = 940000 // k: p95 of the operator frame -> the fixed point
64const VT_SRC_MEDIAN_MICRO: i64 = 790000 // V p50 measured on that frame
65const VT_REF_HI_MICRO: i64 = 660000 // reference band, upper edge
66const VT_REF_LO_MICRO: i64 = 590000 // reference band, lower edge
67const VT_APPROACH_NUM: i64 = 1 // move HALF of the way to the band near edge
68const VT_APPROACH_DEN: i64 = 2
70const VT_LUMA_R_MICRO: i64 = 212600
71const VT_LUMA_G_MICRO: i64 = 715200
72const VT_LUMA_B_MICRO: i64 = 72200
74const VT_CODE_LEVELS: i64 = 255
75const VT_LUT_MIN_N: i64 = 2
76const VT_LUT_MAX_N: i64 = 4096 // a search that has not converged here is being misused
77const VT_LUT_PROBES: i64 = 16 // interior probes per interval when measuring interp error
78const VT_SLOT_BYTES: i64 = 8
79const VT_RGB_SLOTS: i64 = 3

functions

81func vt_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
called by 1: vt_puts
82func vt_puts(s: *u8) -> i64 { sys_write(1, s, vt_slen(s)); return 0 }
84func vt_pn(v: i64) -> i64
called by 3: mainvt_pqvt_emit calls 2: sys_writesys_mmap
99func vt_pq(x: i64) -> i64
111func vt_target_median() -> i64
called by 3: mainmainvt_exponent calls 1: fq_from_micro
118func vt_exponent(ctx: *i64) -> i64
126func vt_curve(ctx: *i64, g: i64, x: i64) -> i64
138func vt_lut_worst_err(ctx: *i64, g: i64, n: i64) -> i64
called by 2: mainvt_lut_size calls 1: vt_curve
160func vt_lut_size(ctx: *i64, g: i64) -> i64
called by 3: mainmainvt_emit calls 1: vt_lut_worst_err
170func vt_lut_fill(ctx: *i64, g: i64, out: *i64, n: i64) -> i64
called by 3: mainmainvt_emit calls 1: vt_curve
177func vt_luma(r: i64, g: i64, b: i64) -> i64
called by 2: mainvt_apply calls 2: fq_mulfq_from_micro
185func vt_apply(ctx: *i64, gx: i64, rgb: *i64) -> i64
200func vt_emit_lut_body(lut: *i64, n: i64) -> i64
called by 2: mainvt_emit calls 2: vt_putsvt_pq
210func vt_emit_luma_triple() -> i64
called by 1: vt_emit calls 3: vt_pqfq_from_microvt_puts
217func vt_emit(ctx: *i64, wgsl: i64) -> i64
247func vt_streq(a: *u8, b: *u8) -> i64
called by 1: main