code wiki / _hdl_build / nx_makeup_gate.nx
nx_makeup_gate.nx source
↩ module page · 45 lines · 2586 B
1// nx_makeup_gate.nx -- MAKEUP as a face-region layer proven: the detailed sdf_face rendered bare vs with makeup,
2// and the lips go BERRY (lipstick material) + cheeks warm (blush) -- pixels the bare face doesn't have. Emits
3// knowledge/face_bare.png + knowledge/face_makeup.png (close-ups). expect_exit:0 license_tier: ORIGINAL
4import "nx_syscalls.nx"
5import "nx_sdfrender.nx"
6import "nx_makeup.nx"
7import "nx_png.nx"
8
9func hw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
10func pn(v: i64) -> i64 { let b: *u8=sys_mmap(32) as *u8; var x: i64=v; var ng: i64=0; if x<0{ng=1;x=0-x} var i: i64=31; if x==0{b[i]=48 as u8;i=i-1} while x>0{b[i]=(48+x%10) as u8;x=x/10;i=i-1} if ng==1{b[i]=45 as u8;i=i-1} sys_write(1,(b as i64+i+1) as *u8,31-i); return 0 }
11// berry-lipstick pixels: strongly red-dominant (skin r-g~56, blush ~64; lipstick r-g~110) and mid-bright
12func count_berry(fb: *i64, n: i64) -> i64 {
13 var c: i64=0; var i: i64=0
14 while i<n { let col: i64=fb[i]; let r: i64=col&255; let g: i64=(col>>8)&255; let b: i64=(col>>16)&255
15 if r > g+78 { if r > b+40 { if r > 100 { c=c+1 } } } i=i+1 }
16 return c
17}
18
19func main() -> i64 {
20 hw("=== nx_makeup_gate -- makeup as a face-region layer (lipstick + blush on sdf_face) ===\n" as *u8)
21 let base: i64 = sys_mmap(sdf_bytes()) as i64
22 var fails: i64 = 0
23
24 // bare face
25 sdf_face(base)
26 sdf_render(base, 0, 4, 236, 180, 156)
27 write_png(base as *i64, W, H, "knowledge/face_bare.png" as *u8)
28 let bare: i64 = count_berry(base as *i64, W*H)
29 hw(" bare face: berry(lipstick) pixels="); pn(bare); hw("\n" as *u8)
30
31 // with makeup (rebuild face so materials reset, then apply cosmetics)
32 sdf_face(base)
33 makeup_style(base, MKUP_GLAM)
34 sdf_render(base, 0, 4, 236, 180, 156)
35 write_png(base as *i64, W, H, "knowledge/face_makeup.png" as *u8)
36 let made: i64 = count_berry(base as *i64, W*H)
37 hw(" made-up face: berry(lipstick) pixels="); pn(made); hw("\n" as *u8)
38
39 if made > bare + 120 { if made > 200 { hw("T1 PASS lipstick renders on the lips (berry pixels appear with makeup, not on the bare face)\n" as *u8) } else { fails=fails+1; hw("T1 FAIL too few lipstick pixels\n" as *u8) } }
40 else { fails=fails+1; hw("T1 FAIL makeup not distinct from bare\n" as *u8) }
41
42 if fails == 0 { hw("MAKEUP-GATE GREEN -- makeup layer paints face regions (lipstick+blush) on the detailed face; the LT_MAKEUP layer is real\n" as *u8); sys_exit(0); return 0 }
43 hw("MAKEUP-GATE RED fails="); pn(fails); hw("\n" as *u8)
44 sys_exit(1); return 1
45}