code wiki / _hdl_build / nx_face_r2.nx

nx_face_r2.nx source

↩ module page · 85 lines · 4258 B

1// nx_face_r2.nx -- photoreal ladder R2: a HEAD close-up with sculpted facial features (sdf_head), scored by 2// the SAME critic axes as the body so movement is MEASURED, not eyeballed (operator: the critic drives the 3// climb). Reports fine_detail + structure + chroma + head-region-detail (the face_structure proxy) + overall 4// MIN verdict, and compares to the body's 62/1000 CLAY. Writes knowledge/nx_face.png. GREEN = it renders + 5// scores (NOT that it's photoreal). license_tier: ORIGINAL expect_exit: 0 6import "nx_syscalls.nx" 7import "nx_png.nx" 8import "nx_sdfrender.nx" 9 10func hw(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 11func pn(v: i64) -> i64 { 12 let b: *u8 = sys_mmap(32) as *u8 13 var x: i64 = v 14 var i: i64 = 31 15 if x == 0 { b[i] = 48 as u8; i = i - 1 } 16 while x > 0 { b[i] = (48 + x % 10) as u8; x = x / 10; i = i - 1 } 17 sys_write(1, (b as i64 + i + 1) as *u8, 31 - i) 18 return 0 19} 20func fclamp(v: i64) -> i64 { if v < 0 { return 0 } if v > 1000 { return 1000 } return v } 21func fabsi(v: i64) -> i64 { if v < 0 { return 0 - v } return v } 22func flum(g: i64) -> i64 { return ((g & 255) + ((g >> 8) & 255) + ((g >> 16) & 255)) / 3 } 23func ffg(g: i64) -> i64 { let r: i64 = g & 255; let b: i64 = (g >> 16) & 255; if r >= b { return 1 } return 0 } 24func fchroma(g: i64) -> i64 { 25 let r: i64 = g & 255; let gg: i64 = (g >> 8) & 255; let b: i64 = (g >> 16) & 255 26 var mx: i64 = r; if gg > mx { mx = gg } if b > mx { mx = b } 27 var mn: i64 = r; if gg < mn { mn = gg } if b < mn { mn = b } 28 return mx - mn 29} 30func f_fine(fb: *i64, w: i64, h: i64) -> i64 { 31 var fg: i64 = 0; var s: i64 = 0 32 var y: i64 = 1 33 while y < h - 1 { 34 var x: i64 = 1 35 while x < w - 1 { 36 let c: i64 = fb[y * w + x] 37 if ffg(c) == 1 { 38 let nb: i64 = (flum(fb[y * w + x - 1]) + flum(fb[y * w + x + 1]) + flum(fb[(y - 1) * w + x]) + flum(fb[(y + 1) * w + x])) / 4 39 s = s + fabsi(flum(c) - nb); fg = fg + 1 40 } 41 x = x + 1 42 } 43 y = y + 1 44 } 45 if fg < 1 { fg = 1 } 46 return s / fg 47} 48func f_chroma(fb: *i64, w: i64, h: i64) -> i64 { 49 var fg: i64 = 0; var s: i64 = 0 50 var i: i64 = 0 51 while i < w * h { if ffg(fb[i]) == 1 { s = s + fchroma(fb[i]); fg = fg + 1 } i = i + 1 } 52 if fg < 1 { fg = 1 } 53 let cm: i64 = s / fg 54 var mad: i64 = 0; i = 0 55 while i < w * h { if ffg(fb[i]) == 1 { mad = mad + fabsi(fchroma(fb[i]) - cm) } i = i + 1 } 56 return mad / fg 57} 58 59func main() -> i64 { 60 let W: i64 = ww() 61 let H: i64 = hh() 62 hw("=== nx_face_r2 -- head close-up with facial features, scored by the critic (vs body 62/1000 CLAY) ===\n" as *u8) 63 let base: i64 = sys_mmap(sdf_bytes()) as i64 64 sdf_head(base) 65 sdf_render(base, 40, 4, 238, 180, 156) 66 let fb: *i64 = (base + fb_off()) as *i64 67 write_png(fb, W, H, "knowledge/nx_face.png" as *u8) 68 69 let d: i64 = f_fine(fb, W, H) 70 let ch: i64 = f_chroma(fb, W, H) 71 let ds: i64 = fclamp(d * 1000 / 32) 72 let chs: i64 = fclamp(ch * 1000 / 16) 73 // for a head close-up the WHOLE frame is the face -> fine_detail IS the face_structure signal 74 var overall: i64 = ds 75 if chs < overall { overall = chs } 76 hw(" raw fine_detail="); pn(d); hw(" chroma="); pn(ch); hw("\n" as *u8) 77 hw(" axes/1000: fine_detail/face_structure="); pn(ds); hw(" chroma="); pn(chs); hw("\n" as *u8) 78 hw(" OVERALL "); pn(overall); hw("/1000 -- verdict "); if overall >= 700 { hw("PHOTOREAL" as *u8) } else { if overall >= 400 { hw("STYLIZED-CG" as *u8) } else { hw("CLAY" as *u8) } } hw("\n" as *u8) 79 hw(" COMPARE: body render fine_detail scored 62/1000; a face close-up should raise head-region detail.\n" as *u8) 80 hw(" HONEST: the critic's face axis is still the head-region-detail PROXY (it flagged its own face metric\n" as *u8) 81 hw(" REFUTED). A real feature detector (eyes/nose/mouth locator) is the critic's queued growth; this rung\n" as *u8) 82 hw(" gives it real STRUCTURE to detect. PNG knowledge/nx_face.png -- eyeball it, do not trust my words.\n" as *u8) 83 hw("GATE GREEN: head renders + is critic-scored (photoreal NOT claimed; the number is the number).\n" as *u8) 84 return 0 85}