code wiki / _hdl_build / nx_frame_codec.nx
nx_frame_codec.nx
buildroot/runtime/_hdl_build/nx_frame_codec.nx
about
nx_frame_codec.nx -- TUTOR-AUTHORED SCAFFOLD (Claude), NOT team-emitter output.
2-D LOSSLESS image/video-FRAME codec: JPEG-LS/FFV1-class MED (median) predictor over causal
neighbors + zigzag + Rice residuals. FOUNDED ON nx_nv1_lpc: it REUSES that organ's proven
Rice bit I/O (nv1l_rice_put/get), best-k (nv1l_best_k) and the predict->zigzag->Rice machinery,
lifted from 1-D audio samples to 2-D pixels. Bit-exact (lossless): decode(encode(f)) == f.
Tamper-evident: an out-of-range reconstruction returns -7 (the nv1_lpc doctrine).
This is the lossless-VIDEO fidelity anchor (the bird's video pixel-exact); JPEG/lossy demotes
to a measured fallback tier. main() is the unforgeable self-test: round-trip bit-exact on
gradient/checker/edge/extremes/noise + compression-actual (gradient must shrink) + tamper.
NOT FLOATING (operator law 2026-06-13 "don't build things that hang in the air"): it sits on
nx_nv1_lpc (a GREEN organ). BACK-FILL: the team RE-AUTHORS this from a DATA spec via the
emitter-of-emitters (X-AUT-006c/e/f, spec 2026-06-13-codec-dual-spec-and-kat.md) -- this scaffold
is the sanctioned one-time bootstrap, NOT credited as team self-authoring (meter-integrity).
v1 = single 8-bit plane, single MED predictor; the adaptive predictor library + NFC1 container
are the named follow-ons. No verbatim escape yet (buffers sized 2n so noise cannot overrun).
license_tier: ORIGINAL
dependencies 2 imports · 6 importers
imports: nx_nv1_lpc.nxnx_itoa_lib.nx
imported by: _codec_bench.nx_codec_bench2.nx_codec_bench_med.nx_codec_real_med.nx_fc_rtgate.nx_fc_rtgate_sa.nx
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 22 | const K_MAGIC_2463534242: i64 = 2463534242 |
| 23 | const K_MAGIC_1103515245: i64 = 1103515245 |
| 24 | const K_MAGIC_12345: i64 = 12345 |
| 25 | const K_MAGIC_2147483647: i64 = 2147483647 |
| 26 | const K_MAGIC_65536: i64 = 65536 |
functions
| 28 | func fc_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } |
| 33 | func fc_putn(v: i64) -> i64 { nxi_out(v); return 0 } |
| 36 | func fc_med(a: i64, b: i64, c: i64) -> i64 |
| 45 | func fc_pred(buf: *u8, w: i64, x: i64, y: i64) -> i64 |
| 58 | func fc_encode(buf: *u8, w: i64, h: i64, out: *u8, outcap: i64) -> i64 |
| 96 | func fc_decode(pl: *u8, plen: i64, out: *u8, outcap: i64) -> i64 called by 4: _fc_rtgate_check_fc_rtgate_sa_checkfc_roundtripmain calls 3: nv1_rd_u32nv1l_rice_getfc_pred |
| 129 | func fc_gen_gradient(buf: *u8, w: i64, h: i64) -> i64 |
| 133 | func fc_gen_checker(buf: *u8, w: i64, h: i64) -> i64 |
| 138 | func fc_gen_edge(buf: *u8, w: i64, h: i64) -> i64 |
| 143 | func fc_gen_extremes(buf: *u8, w: i64, h: i64) -> i64 |
| 147 | func fc_gen_noise(buf: *u8, w: i64, h: i64) -> i64 |
| 153 | func fc_roundtrip(name: *u8, buf: *u8, w: i64, h: i64) -> i64 |
| 169 | func main() -> i64 |