code wiki / (root) / nx_colorspace.nx

nx_colorspace.nx

buildroot/runtime/nx_colorspace.nx

3219 B69 linesdepth 0pulls 0 transitivereach 1 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_colorspace.nx -- sovereign RGB <-> YCbCr (JFIF/BT.601 full-range) + 4:2:0 chroma subsample. The video codec (nx_vmotion/vtransform/ventropy) is per-plane 8bpp; real video is colour, so the sender converts the browser's RGB to Y (full res) + Cb,Cr (half res = 4:2:0, since the eye is far less sensitive to chroma) and codes each plane; the receiver upsamples + converts back. Integer-only (no FPU). The browser only extracts RGB from the canvas (last mile); ALL colour math is here. license_tier: ORIGINAL

dependencies 0 imports · 1 importers

nx_colorspace.nx nx_colorspace_gate.nx

imports: none

imported by: nx_colorspace_gate.nx

structs

none

consts

none

functions

7func cs_clamp(v: i64) -> i64 { if v < 0 { return 0 } if v > 255 { return 255 } return v }
11func cs_y(r: i64, g: i64, b: i64) -> i64 { return cs_clamp((77*r + 150*g + 29*b) / 256) }
called by 2: cs_rgb_to_yuvmain calls 1: cs_clamp
12func cs_cb(r: i64, g: i64, b: i64) -> i64 { return cs_clamp(((0-43)*r - 85*g + 128*b) / 256 + 128) }
called by 2: cs_rgb_to_yuvmain calls 1: cs_clamp
13func cs_cr(r: i64, g: i64, b: i64) -> i64 { return cs_clamp((128*r - 107*g - 21*b) / 256 + 128) }
called by 2: cs_rgb_to_yuvmain calls 1: cs_clamp
15func cs_r(y: i64, cb: i64, cr: i64) -> i64 { return cs_clamp(y + (359*(cr-128)) / 256) }
called by 1: cs_yuv_to_rgb calls 1: cs_clamp
16func cs_g(y: i64, cb: i64, cr: i64) -> i64 { return cs_clamp(y - (88*(cb-128)) / 256 - (183*(cr-128)) / 256) }
called by 1: cs_yuv_to_rgb calls 1: cs_clamp
17func cs_b(y: i64, cb: i64, cr: i64) -> i64 { return cs_clamp(y + (454*(cb-128)) / 256) }
called by 1: cs_yuv_to_rgb calls 1: cs_clamp
20func cs_rgb_to_yuv(r: *u8, g: *u8, b: *u8, n: i64, y: *u8, cb: *u8, cr: *u8) -> i64
called by 1: main calls 3: cs_ycs_cbcs_cr
31func cs_yuv_to_rgb(y: *u8, cb: *u8, cr: *u8, n: i64, r: *u8, g: *u8, b: *u8) -> i64
called by 1: main calls 3: cs_rcs_gcs_b
43func cs_subsample(full: *u8, W: i64, H: i64, half: *u8) -> i64
called by 1: main
60func cs_upsample(half: *u8, W: i64, H: i64, full: *u8) -> i64
called by 1: main