code wiki / _hdl_build / nx_rgb_color_gate.nx
nx_rgb_color_gate.nx source
↩ module page · 66 lines · 3831 B
1// nx_rgb_color_gate.nx -- VERDICT gate for CSS rgb()/rgba() functional color notation. Asserts: rgb()
2// background + rgb() text paint the EXACT channels; rgba(...,0) is treated as transparent (NOT painted).
3// LIAR-KILL: an unused color absent. Proves the rgb() path (an IDENT value captured whole by the CSS
4// multi-token fix) decodes channels + alpha. 100% sovereign. license_tier: ORIGINAL
5import "nx_syscalls.nx"
6import "nx_render_html.nx"
7
8func g_w(s: *u8) -> i64 { var k: i64=0; while s[k]!=(0 as u8){k=k+1} sys_write(1,s,k); return 0 }
9func pn(v0: i64) -> i64 { var v: i64=v0; if v<0 { let m: *u8=sys_mmap(8); m[0]=45 as u8; sys_write(1,m,1); v=0-v } let b: *u8=sys_mmap(24); var k: i64=0; if v==0 {b[0]=48;k=1} while v>0 {b[k]=(48+(v%10)) as u8; v=v/10; k=k+1} let o: *u8=sys_mmap(24); var j: i64=0; while j<k {o[j]=b[k-1-j];j=j+1} sys_write(1,o,k); return 0 }
10func u32le(d: *u8, p: i64) -> i64 { return (d[p]&0xff) + ((d[p+1]&0xff)<<8) + ((d[p+2]&0xff)<<16) + ((d[p+3]&0xff)<<24) }
11func col_count(data: *u8, off: i64, w: i64, h: i64, R: i64, G: i64, B: i64) -> i64 {
12 let row3: i64 = w*3
13 let pad: i64 = (4-(row3%4))%4
14 let rowstride: i64 = row3+pad
15 var n: i64 = 0
16 var y: i64 = 0
17 while y < h {
18 var x: i64 = 0
19 let rb: i64 = off + y*rowstride
20 while x < w {
21 let p: i64 = rb + x*3
22 if (data[p]&0xff)==B { if (data[p+1]&0xff)==G { if (data[p+2]&0xff)==R { n=n+1 } } }
23 x = x+1
24 }
25 y = y+1
26 }
27 return n
28}
29func chk(cond: i64, label: *u8, pass: *i64) -> i64 {
30 g_w(" " as *u8); g_w(label); g_w(": " as *u8)
31 if cond==1 { g_w("OK\n" as *u8); pass[0]=pass[0]+1 } else { g_w("FAIL\n" as *u8) }
32 return cond
33}
34
35func main() -> i64 {
36 let pass: *i64 = sys_mmap(8) as *i64; pass[0]=0
37 g_w("=== RGB-COLOR GATE (rgb()/rgba() functional notation, sovereign nx_cc->nxasm) ===\n" as *u8)
38
39 let html: *u8 = "<body><style>.a{background-color:rgb(200, 10, 10);height:30px}.b{color:rgb(10, 10, 200)}.c{background-color:rgba(0, 200, 0, 0);height:20px}</style><div class=\"a\">rgb background</div><p class=\"b\">rgb colored text here</p><div class=\"c\">transparent rgba</div></body>\x00" as *u8
40 var hlen: i64 = 0
41 while html[hlen]!=(0 as u8) { hlen=hlen+1 }
42 nx_render_html_to_bmp(html, hlen, "knowledge/status/rgb_color_gate.bmp\x00" as *u8)
43 nx_render_html_to_png(html, hlen, "knowledge/status/rgb_color_gate.png\x00" as *u8)
44
45 let lp: *i64 = sys_mmap(8) as *i64
46 let bmp: *u8 = sys_read_file("knowledge/status/rgb_color_gate.bmp\x00" as *u8, lp)
47 let blen: i64 = lp[0]
48 chk((blen >= 54) as i64, "bmp rendered\x00" as *u8, pass)
49 if blen < 54 { g_w("RGB-COLOR rows=5 pass=" as *u8); pn(pass[0]); g_w(" verdict=RED (no image)\n" as *u8); sys_exit(1); return 1 }
50 let off: i64 = u32le(bmp,10); let w: i64 = u32le(bmp,18); let h: i64 = u32le(bmp,22)
51
52 let bg: i64 = col_count(bmp, off, w, h, 200,10,10)
53 let tx: i64 = col_count(bmp, off, w, h, 10,10,200)
54 let tr: i64 = col_count(bmp, off, w, h, 0,200,0)
55 let lk: i64 = col_count(bmp, off, w, h, 255,255,0)
56 g_w(" measured: rgb-bg(200,10,10)=" as *u8); pn(bg); g_w(" rgb-text(10,10,200)=" as *u8); pn(tx); g_w(" rgba0(0,200,0)=" as *u8); pn(tr); g_w(" yellow=" as *u8); pn(lk); g_w("\n" as *u8)
57
58 chk((bg > 2000) as i64, "rgb() BACKGROUND painted (200,10,10)\x00" as *u8, pass)
59 chk((tx > 100) as i64, "rgb() TEXT painted (10,10,200)\x00" as *u8, pass)
60 chk((tr == 0) as i64, "rgba(...,0) TRANSPARENT not painted (0,200,0 absent)\x00" as *u8, pass)
61 chk((lk == 0) as i64, "LIAR-KILL: yellow (255,255,0) absent\x00" as *u8, pass)
62
63 g_w("RGB-COLOR rows=5 pass=" as *u8); pn(pass[0])
64 if pass[0]==5 { g_w(" verdict=GREEN\n" as *u8); sys_exit(0); return 0 }
65 g_w(" verdict=RED\n" as *u8); sys_exit(1); return 1
66}