code wiki / (root) / nx_vcodec_color.nx

nx_vcodec_color.nx source

↩ module page · 39 lines · 1802 B

1// nx_vcodec_color.nx -- sovereign COLOR foundation for the s-class video codec (operator 2026-06-23: 2// "s class exceed no matter the investment, from the hardware rung up, no third-party"). The luma-128 3// codec is grayscale; s-class is COLOR. Color starts here: integer BT.601 RGB<->YCbCr (no float, built 4// straight on the ALU/integer hardware rung). The codec encodes the Y/Cb/Cr planes; the camera gives RGB, 5// the display wants RGB, so this is the gateway both ways. Pure integer, sovereign, our own. license_tier: ORIGINAL 6import "nx_syscalls.nx" 7 8func clamp8(v: i64) -> i64 { if v < 0 { return 0 } if v > 255 { return 255 } return v } 9 10// RGB -> YCbCr (full-range BT.601, integer fixed-point /256). out[0]=Y, out[1]=Cb, out[2]=Cr (0..255). 11func rgb_to_ycbcr(r: i64, g: i64, b: i64, out: *i64) -> i64 { 12 out[0] = clamp8((77*r + 150*g + 29*b) >> 8) 13 out[1] = clamp8(((128*b - 43*r - 85*g) >> 8) + 128) 14 out[2] = clamp8(((128*r - 107*g - 21*b) >> 8) + 128) 15 return 0 16} 17// YCbCr -> RGB (inverse BT.601, integer). out[0]=R, out[1]=G, out[2]=B (0..255). 18func ycbcr_to_rgb(y: i64, cb: i64, cr: i64, out: *i64) -> i64 { 19 let d: i64 = cb - 128 20 let e: i64 = cr - 128 21 out[0] = clamp8(y + ((359*e) >> 8)) 22 out[1] = clamp8(y - ((88*d + 183*e) >> 8)) 23 out[2] = clamp8(y + ((454*d) >> 8)) 24 return 0 25} 26 27// plane conversion: an RGB frame (rgb[3*n], interleaved) -> separate Y/Cb/Cr planes (each n bytes). 28func rgb_frame_to_yuv(rgb: *u8, n: i64, yp: *u8, up: *u8, vp: *u8) -> i64 { 29 let t: *i64 = sys_mmap(8*3) as *i64 30 var i: i64 = 0 31 while i < n { 32 rgb_to_ycbcr(rgb[i*3] as i64, rgb[i*3+1] as i64, rgb[i*3+2] as i64, t) 33 yp[i] = t[0] as u8; up[i] = t[1] as u8; vp[i] = t[2] as u8 34 i = i + 1 35 } 36 return 0 37} 38 39func main() -> i64 { return 0 }