code wiki / _hdl_build / nx_face_vs_target.nx

nx_face_vs_target.nx source

↩ module page · 125 lines · 6755 B

1// nx_face_vs_target.nx -- THE HARD BENCHMARK (typography-workstream discipline: measure against the real 2// target on the same ruler). Decodes the operator's synthetic Elara target (their own Z-Image asset, 3// knowledge/elara_ref.jpg) to RGB via our sovereign JPEG decoder, runs the SAME critic axes on it AND on our 4// SDF face render, and prints the gap. No flattery -- if we are clay, the numbers say clay. expect_exit: 0 5import "nx_syscalls.nx" 6import "nx_jpeg_ascii.nx" 7import "nx_critic_axes.nx" 8import "nx_natstat.nx" 9import "nx_sdfrender.nx" 10const K_MAGIC_65536: i64 = 65536 11 12func w(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 13func pn(v: i64) -> i64 { 14 let b: *u8 = sys_mmap(32) as *u8 15 var x: i64 = v; var neg: i64 = 0 16 if x < 0 { neg = 1; x = 0 - x } 17 var i: i64 = 31 18 if x == 0 { b[i] = 48 as u8; i = i - 1 } 19 while x > 0 { b[i] = (48 + x % 10) as u8; x = x / 10; i = i - 1 } 20 if neg == 1 { b[i] = 45 as u8; i = i - 1 } 21 sys_write(1, (b as i64 + i + 1) as *u8, 31 - i) 22 return 0 23} 24func row(label: *u8, det: i64, str: i64, chr: i64, score: i64) -> i64 { 25 w(label); w(" fine_detail=" as *u8); pn(det); w(" structure=" as *u8); pn(str) 26 w(" chroma=" as *u8); pn(chr); w(" -> SCORE=" as *u8); pn(score); w("/1000 " as *u8); w(ca_verdict(score)); w("\n" as *u8) 27 return 0 28} 29func axisrow(label: *u8, tv: i64, ov: i64) -> i64 { 30 w(label); pn(tv); w(" " as *u8); pn(ov); w(" " as *u8) 31 let g: i64 = tv - ov 32 if g > 0 { w("-" as *u8); pn(g) } else { w("ok" as *u8) } 33 w("\n" as *u8) 34 return 0 35} 36 37func main() -> i64 { 38 w("=== HARD BENCHMARK: our SDF face vs the synthetic-Elara TARGET, same critic ruler (no flattery) ===\n" as *u8) 39 // --- decode the target --- 40 let szp: *i64 = sys_mmap(16) as *i64 41 let jpeg: *u8 = sys_read_file("knowledge/elara_ref.jpg" as *u8, szp) 42 if (jpeg as i64) == 0 { w("no target jpeg (run nx_elara_ref_fetch)\n" as *u8); return 1 } 43 let jlen: i64 = szp[0] 44 let rgbp: *i64 = sys_mmap(8) as *i64 45 let twp: *i64 = sys_mmap(8) as *i64 46 let thp: *i64 = sys_mmap(8) as *i64 47 let rc: i64 = nx_jpeg_decode_rgb(jpeg, jlen, rgbp, twp, thp) 48 if rc != NX_JPEG_ASCII_OK { w("JPEG decode failed rc=" as *u8); pn(rc); w(" (progressive/unsupported?)\n" as *u8); return 1 } 49 let rgb: *u8 = rgbp[0] as *u8 50 let tw: i64 = twp[0] 51 let th: i64 = thp[0] 52 let tfb: *i64 = sys_mmap(tw * th * 8) as *i64 53 var i: i64 = 0 54 while i < tw * th { 55 let r: i64 = (rgb[i * 3] as i64) & 255 56 let g: i64 = (rgb[i * 3 + 1] as i64) & 255 57 let b: i64 = (rgb[i * 3 + 2] as i64) & 255 58 tfb[i] = r + g * 256 + b * K_MAGIC_65536 59 i = i + 1 60 } 61 w(" target decoded " as *u8); pn(tw); w("x" as *u8); pn(th); w("\n" as *u8) 62 let tdet: i64 = ca_fine_detail(tfb, tw, th) 63 let tstr: i64 = ca_structure(tfb, tw, th) 64 let tchr: i64 = ca_chroma_mad(tfb, tw, th) 65 let tscore: i64 = ca_score(tfb, tw, th) 66 67 // --- our SDF face render --- 68 let W: i64 = ww() 69 let H: i64 = hh() 70 let base: i64 = sys_mmap(sdf_bytes()) as i64 71 sdf_face(base) 72 sdf_render(base, 200, 4, 236, 180, 156) 73 let ofb: *i64 = (base + fb_off()) as *i64 74 let odet: i64 = ca_fine_detail(ofb, W, H) 75 let ostr: i64 = ca_structure(ofb, W, H) 76 let ochr: i64 = ca_chroma_mad(ofb, W, H) 77 let oscore: i64 = ca_score(ofb, W, H) 78 79 w("\n" as *u8) 80 row(" TARGET (Z-Image photoreal):" as *u8, tdet, tstr, tchr, tscore) 81 row(" OURS (SDF ellipsoid face):" as *u8, odet, ostr, ochr, oscore) 82 w("\n" as *u8) 83 // ★THE FINDING: a real photoreal target should score HIGHER than our clay. If it does NOT, the CRITIC is 84 // broken -- it is not measuring photorealism (its fine_detail axis rewards our procedural grain; a smooth 85 // photoreal face has LOW local micro-contrast at this scale). Measuring vs the real target caught the RULER. 86 if tscore <= oscore { 87 w(" ★CRITIC INADEQUATE: the photoreal TARGET scored " as *u8); pn(tscore) 88 w(" but OUR CLAY scored " as *u8); pn(oscore); w(" -- the critic PREFERS our clay to a real photo.\n" as *u8) 89 w(" The axes (local micro-contrast / block variance / chroma spread) do NOT correlate with photorealism.\n" as *u8) 90 w(" VERDICT: build a REAL photoreal metric (natural-image statistics: power spectrum, multi-scale\n" as *u8) 91 w(" gradient distributions, colour naturalness) so the benchmark measures the true gap. The ruler is wrong.\n" as *u8) 92 } else { 93 w(" target scores above ours by " as *u8); pn(tscore - oscore); w(" -- the critic ranks photoreal over clay (sane).\n" as *u8) 94 } 95 96 // ★★THE REVERSE-JUDGE METRIC (nx_natstat) -- must rank the photoreal target ABOVE our clay (the old critic 97 // did the opposite). This is the graded PHOTOREAL LEVEL: maximise it to steer Z-Image; treat-as-photoreal- 98 // to-level for AI images. 99 let cap: i64 = 512 * 512 * 8 100 let buf1: *i64 = sys_mmap(cap) as *i64 101 let buf2: *i64 = sys_mmap(cap) as *i64 102 w(" [raw subject-kurtosis x100 (natural band 700..3200): target=" as *u8); pn(ns_grad_kurt(tfb, tw, th)); w(" ours=" as *u8); pn(ns_grad_kurt(ofb, W, H)); w("]\n" as *u8) 103 let tout: *i64 = sys_mmap(64) as *i64 104 let oout: *i64 = sys_mmap(64) as *i64 105 let tlevel: i64 = ns_assess(tfb, tw, th, buf1, buf2, tout) 106 let olevel: i64 = ns_assess(ofb, W, H, buf1, buf2, oout) 107 w("\n === ★COMPREHENSIVE PHOTOREAL ASSESSMENT (per-axis; AI-fingerprint = 1 of 5) -- also our engine's GAP MAP ===\n" as *u8) 108 w(" axis TARGET OURS gap\n" as *u8) 109 axisrow(" 0 scale-invariance " as *u8, tout[0], oout[0]) 110 axisrow(" 1 mscn GGD-ratio " as *u8, tout[1], oout[1]) 111 axisrow(" 2 gradient-kurtosis " as *u8, tout[2], oout[2]) 112 axisrow(" 3 colour-naturalness " as *u8, tout[3], oout[3]) 113 axisrow(" 4 ai-fingerprint " as *u8, tout[4], oout[4]) 114 w(" ------------------------------------------------\n" as *u8) 115 w(" OVERALL LEVEL: target=" as *u8); pn(tlevel); w(" " as *u8); w(ns_verdict(tlevel)); w(" ours=" as *u8); pn(olevel); w(" " as *u8); w(ns_verdict(olevel)); w("\n" as *u8) 116 var wk: i64 = 0 117 var wv: i64 = oout[0] 118 var ai: i64 = 1 119 while ai < 5 { if oout[ai] < wv { wv = oout[ai]; wk = ai } ai = ai + 1 } 120 w(" ★OUR ENGINE'S #1 GAP = axis " as *u8); pn(wk); w(" (" as *u8); pn(wv); w("/1000): " as *u8); w(ns_axisname(wk)); w("\n" as *u8) 121 if tlevel > olevel { 122 w(" ✓ SOTA-grounded NSS ruler ranks PHOTOREAL above ours by " as *u8); pn(tlevel - olevel); w(" -- drives BOTH Z-Image (maximise) AND our render (close the weak axis).\n" as *u8) 123 } 124 return 0 125}