code wiki / _hdl_build / nx_named_color_gate.nx

nx_named_color_gate.nx source

↩ module page · 69 lines · 4154 B

1// nx_named_color_gate.nx -- VERDICT gate for CSS NAMED colors (red/blue/green/...). Before this rung the 2// paint paths only decoded #hex and SILENTLY IGNORED named colors (an IDENT value). Renders a page using 3// named colors for background, text, and border, then asserts the exact RGB pixels are present: red bg 4// (255,0,0), blue text (0,0,255), green border (0,128,0). LIAR-KILL: lime (0,255,0) -- a color we DON'T 5// use (green != lime) -- must be ABSENT, proving the scanner has teeth + that "green" decoded to 0,128,0 6// not 0,255,0. 100% sovereign. license_tier: ORIGINAL 7import "nx_syscalls.nx" 8import "nx_render_html.nx" 9 10func 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 } 11func 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 } 12func 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) } 13func col_count(data: *u8, off: i64, w: i64, h: i64, R: i64, G: i64, B: i64) -> i64 { 14 let row3: i64 = w*3 15 let pad: i64 = (4-(row3%4))%4 16 let rowstride: i64 = row3+pad 17 var n: i64 = 0 18 var y: i64 = 0 19 while y < h { 20 var x: i64 = 0 21 let rb: i64 = off + y*rowstride 22 while x < w { 23 let p: i64 = rb + x*3 24 if (data[p]&0xff)==B { if (data[p+1]&0xff)==G { if (data[p+2]&0xff)==R { n=n+1 } } } 25 x = x+1 26 } 27 y = y+1 28 } 29 return n 30} 31func chk(cond: i64, label: *u8, pass: *i64) -> i64 { 32 g_w(" " as *u8); g_w(label); g_w(": " as *u8) 33 if cond==1 { g_w("OK\n" as *u8); pass[0]=pass[0]+1 } else { g_w("FAIL\n" as *u8) } 34 return cond 35} 36 37func main() -> i64 { 38 let pass: *i64 = sys_mmap(8) as *i64; pass[0]=0 39 g_w("=== NAMED-COLOR GATE (CSS named colors paint, sovereign nx_cc->nxasm) ===\n" as *u8) 40 41 let html: *u8 = "<body><style>.rb{background-color:red;height:30px}.bt{color:blue}.gb{border:3px solid green;background-color:white;height:24px;width:200px}</style><div class=\"rb\">red background</div><p class=\"bt\">blue named text rendered here</p><div class=\"gb\">green bordered</div></body>\x00" as *u8 42 var hlen: i64 = 0 43 while html[hlen]!=(0 as u8) { hlen=hlen+1 } 44 let nb: i64 = nx_render_html_to_bmp(html, hlen, "knowledge/status/named_color_gate.bmp\x00" as *u8) 45 nx_render_html_to_png(html, hlen, "knowledge/status/named_color_gate.png\x00" as *u8) 46 47 let lp: *i64 = sys_mmap(8) as *i64 48 let bmp: *u8 = sys_read_file("knowledge/status/named_color_gate.bmp\x00" as *u8, lp) 49 let blen: i64 = lp[0] 50 chk((blen >= 54) as i64, "bmp rendered\x00" as *u8, pass) 51 if blen < 54 { g_w("NAMED-COLOR rows=6 pass=" as *u8); pn(pass[0]); g_w(" verdict=RED (no image)\n" as *u8); sys_exit(1); return 1 } 52 let off: i64 = u32le(bmp,10); let w: i64 = u32le(bmp,18); let h: i64 = u32le(bmp,22) 53 54 let red: i64 = col_count(bmp, off, w, h, 255,0,0) 55 let blue: i64 = col_count(bmp, off, w, h, 0,0,255) 56 let green: i64 = col_count(bmp, off, w, h, 0,128,0) 57 let lime: i64 = col_count(bmp, off, w, h, 0,255,0) 58 g_w(" measured: red(bg)=" as *u8); pn(red); g_w(" blue(text)=" as *u8); pn(blue); g_w(" green(border)=" as *u8); pn(green); g_w(" lime=" as *u8); pn(lime); g_w("\n" as *u8) 59 60 chk((red > 2000) as i64, "red BACKGROUND painted (named bg-color)\x00" as *u8, pass) 61 chk((blue > 100) as i64, "blue TEXT painted (named color)\x00" as *u8, pass) 62 chk((green > 300) as i64, "green BORDER painted (named border color)\x00" as *u8, pass) 63 chk((green < 8000) as i64, "green border is an OUTLINE not a fill\x00" as *u8, pass) 64 chk((lime == 0) as i64, "LIAR-KILL: lime #00ff00 absent (green decoded as 0,128,0 NOT 0,255,0)\x00" as *u8, pass) 65 66 g_w("NAMED-COLOR rows=6 pass=" as *u8); pn(pass[0]) 67 if pass[0]==6 { g_w(" verdict=GREEN\n" as *u8); sys_exit(0); return 0 } 68 g_w(" verdict=RED\n" as *u8); sys_exit(1); return 1 69}