code wiki / _hdl_build / nx_nishi_font_gate.nx
nx_nishi_font_gate.nx source
↩ module page · 65 lines · 3483 B
1// nx_nishi_font_gate.nx -- VERDICT gate for the sovereign Nishi stroke font. Renders glyphs to a white RGB
2// buffer and asserts: (1) ink is drawn (black px present); (2) it is ANTI-ALIASED (gray edge px present,
3// not just hard black/white); (3) glyph SHAPE is correct -- an 'H' has a WHITE gap in the top-center
4// (between the two verticals, above the crossbar), proving strokes are placed (not a filled blob); (4)
5// space renders BLANK. LIAR-KILL: the white-gap + blank-space assertions reject a draw-everywhere bug.
6// 100% sovereign. license_tier: ORIGINAL
7import "nx_syscalls.nx"
8import "nx_png_write.nx"
9import "nx_nishi_font.nx"
10
11func 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 }
12func 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 }
13// count pixels in [x0,x1)x[y0,y1) whose gray value is in [lo,hi]
14func count_gray(rgb: *u8, iw: i64, x0: i64, y0: i64, x1: i64, y1: i64, lo: i64, hi: i64) -> i64 {
15 var n: i64 = 0
16 var y: i64 = y0
17 while y < y1 {
18 var x: i64 = x0
19 while x < x1 {
20 let g: i64 = rgb[(y*iw+x)*3] & 0xff
21 if g >= lo { if g <= hi { n = n + 1 } }
22 x = x + 1
23 }
24 y = y + 1
25 }
26 return n
27}
28func chk(cond: i64, label: *u8, pass: *i64) -> i64 {
29 g_w(" " as *u8); g_w(label); g_w(": " as *u8)
30 if cond==1 { g_w("OK\n" as *u8); pass[0]=pass[0]+1 } else { g_w("FAIL\n" as *u8) }
31 return cond
32}
33
34func main() -> i64 {
35 let pass: *i64 = sys_mmap(8) as *i64; pass[0]=0
36 g_w("=== NISHI-FONT GATE (sovereign anti-aliased stroke font) ===\n" as *u8)
37 let iw: i64 = 64
38 let ih: i64 = 64
39 let rgb: *u8 = sys_mmap(iw*ih*3 + 16)
40 var i: i64 = 0
41 while i < iw*ih*3 { rgb[i] = 255 as u8; i = i + 1 }
42 let ch: i64 = 40
43 nf_render_glyph(rgb, iw, ih, 0, 0, ch, 72) // 'H'
44
45 let black: i64 = count_gray(rgb, iw, 0, 0, 30, ch, 0, 40)
46 let aa: i64 = count_gray(rgb, iw, 0, 0, 30, ch, 60, 200) // mid-grays => anti-aliased edges
47 // 'H' top-center gap: between the verticals (out x ~4..21) and above the crossbar (out y ~18): x 9..16, y 4..14
48 let gap: i64 = count_gray(rgb, iw, 9, 4, 16, 14, 0, 120) // dark px in the gap -> should be ~0
49 g_w(" measured: H black=" as *u8); pn(black); g_w(" aa-gray=" as *u8); pn(aa); g_w(" gap-dark=" as *u8); pn(gap); g_w("\n" as *u8)
50 chk((black > 30) as i64, "'H' has ink (strokes drawn)\x00" as *u8, pass)
51 chk((aa > 5) as i64, "ANTI-ALIASED (mid-gray edge pixels present)\x00" as *u8, pass)
52 chk((gap < 4) as i64, "'H' shape correct: WHITE gap top-center (not a blob)\x00" as *u8, pass)
53
54 // space renders blank
55 var j: i64 = 0
56 while j < iw*ih*3 { rgb[j] = 255 as u8; j = j + 1 }
57 nf_render_glyph(rgb, iw, ih, 0, 0, ch, 32) // space
58 let sp: i64 = count_gray(rgb, iw, 0, 0, 40, ch, 0, 200)
59 g_w(" space dark px=" as *u8); pn(sp); g_w("\n" as *u8)
60 chk((sp == 0) as i64, "LIAR-KILL: space renders BLANK (no ink)\x00" as *u8, pass)
61
62 g_w("NISHI-FONT rows=4 pass=" as *u8); pn(pass[0])
63 if pass[0]==4 { g_w(" verdict=GREEN\n" as *u8); sys_exit(0); return 0 }
64 g_w(" verdict=RED\n" as *u8); sys_exit(1); return 1
65}