nx_view_transform_lib.nx
buildroot/runtime/nx_view_transform_lib.nx
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
imports: nx_syscalls.nxnx_fixq30_lib.nx
imported by: nx_view_transform.nxnx_view_transform_gate.nx
structs
| none |
consts
| 63 | const VT_ANCHOR_MICRO: i64 = 940000 // k: p95 of the operator frame -> the fixed point |
| 64 | const VT_SRC_MEDIAN_MICRO: i64 = 790000 // V p50 measured on that frame |
| 65 | const VT_REF_HI_MICRO: i64 = 660000 // reference band, upper edge |
| 66 | const VT_REF_LO_MICRO: i64 = 590000 // reference band, lower edge |
| 67 | const VT_APPROACH_NUM: i64 = 1 // move HALF of the way to the band near edge |
| 68 | const VT_APPROACH_DEN: i64 = 2 |
| 70 | const VT_LUMA_R_MICRO: i64 = 212600 |
| 71 | const VT_LUMA_G_MICRO: i64 = 715200 |
| 72 | const VT_LUMA_B_MICRO: i64 = 72200 |
| 74 | const VT_CODE_LEVELS: i64 = 255 |
| 75 | const VT_LUT_MIN_N: i64 = 2 |
| 76 | const VT_LUT_MAX_N: i64 = 4096 // a search that has not converged here is being misused |
| 77 | const VT_LUT_PROBES: i64 = 16 // interior probes per interval when measuring interp error |
| 78 | const VT_SLOT_BYTES: i64 = 8 |
| 79 | const VT_RGB_SLOTS: i64 = 3 |
functions
| 81 | func 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 |
| 82 | func vt_puts(s: *u8) -> i64 { sys_write(1, s, vt_slen(s)); return 0 } |
| 84 | func vt_pn(v: i64) -> i64 |
| 99 | func vt_pq(x: i64) -> i64 |
| 111 | func vt_target_median() -> i64 |
| 118 | func vt_exponent(ctx: *i64) -> i64 |
| 126 | func vt_curve(ctx: *i64, g: i64, x: i64) -> i64 called by 6: mainvg_perchannelmainvt_lut_worst_errvt_lut_fillvt_apply calls 4: fq_from_microfq_mulfq_powfq_div |
| 138 | func vt_lut_worst_err(ctx: *i64, g: i64, n: i64) -> i64 |
| 160 | func vt_lut_size(ctx: *i64, g: i64) -> i64 |
| 170 | func vt_lut_fill(ctx: *i64, g: i64, out: *i64, n: i64) -> i64 |
| 177 | func vt_luma(r: i64, g: i64, b: i64) -> i64 |
| 185 | func vt_apply(ctx: *i64, gx: i64, rgb: *i64) -> i64 |
| 200 | func vt_emit_lut_body(lut: *i64, n: i64) -> i64 |
| 210 | func vt_emit_luma_triple() -> i64 |
| 217 | func vt_emit(ctx: *i64, wgsl: i64) -> i64 |
| 247 | func vt_streq(a: *u8, b: *u8) -> i64 called by 1: main |