code wiki / _hdl_build / nx_image_beauty.nx
nx_image_beauty.nx source
↩ module page · 40 lines · 2823 B
1// nx_image_beauty.nx -- the ImageBeauty MCP tool: score a gallery image (by cid) for bilateral symmetry (Q1000).
2// Thin wrapper over nx_image_symmetry_lib (shared with nx_gen_rank -- one source of truth). Asymmetry is a body-horror
3// signal; use to rank generate-N-keep-best. Object model: companion_arch.md. license_tier: ORIGINAL
4import "nx_syscalls.nx"
5import "nx_image_symmetry_lib.nx"
6
7func main(argc: i64, argv: *i64) -> i64 {
8 if argc < 2 { sys_write(1, "usage: nx_image_beauty <cid> | path <file.png> (bilateral symmetry, Q1000)\n" as *u8, 74); return 1 }
9 // ★★★PATH MODE. A judge locked to ONE STORAGE BACKEND cannot score anything the ecosystem GENERATES --
10 // it could only ever grade gallery blobs, so every render our own generators produce was unjudgeable.
11 // That is the missing plumbing in the beauty loop (generate -> render -> SCORE -> constrain the
12 // parameter space), and it is why `beauty-manifold-scored` sits at GAP with weight 8 on the board.
13 // The lib already exposes go_image_symmetry(png_bytes, len); only cid RESOLUTION was hard-wired.
14 // Additive: `nx_image_beauty <cid>` is untouched, so no existing caller changes.
15 let a1: *u8 = argv[1] as *u8
16 if a1[0] == (112 as u8) { if a1[1] == (97 as u8) { if a1[2] == (116 as u8) { if a1[3] == (104 as u8) {
17 if argc < 3 { sys_write(1, "usage: nx_image_beauty path <file.png>\n" as *u8, 38); return 1 }
18 let pln: *i64 = sys_mmap(16) as *i64
19 let pbuf: *u8 = sys_read_file(argv[2] as *u8, pln)
20 if (pbuf as i64) == 0 { sys_write(1, "{\x22error\x22:\x22cannot read file\x22}\n" as *u8, 33); return 1 }
21 let ps: i64 = go_image_symmetry(pbuf, pln[0])
22 let pout: *u8 = sys_mmap(256); var po: i64 = 0
23 if ps < 0 { po = ib_cat(pout, 0, "{\x22error\x22:\x22could not decode PNG\x22}\n" as *u8); sys_write(1, pout, po); return 1 }
24 po = ib_cat(pout, 0, "{\x22symmetry_q1000\x22:" as *u8); po = ib_itoa(pout, po, ps)
25 po = ib_cat(pout, po, "}\n" as *u8)
26 sys_write(1, pout, po)
27 return 0
28 } } } }
29 let cid: *u8 = argv[1] as *u8
30 let s: i64 = go_score_cid(cid)
31 let out: *u8 = sys_mmap(256); var o: i64 = 0
32 if s == (0 - 3) { o = ib_cat(out, 0, "{\"error\":\"unknown cid (no blob) -- list current cids via nx_gen recent\"}\n" as *u8); sys_write(1, out, o); return 1 }
33 if s < 0 { o = ib_cat(out, 0, "{\"error\":\"could not decode PNG for that cid\"}\n" as *u8); sys_write(1, out, o); return 1 }
34 o = ib_cat(out, 0, "{\"cid\":\"" as *u8)
35 var k: i64 = 0; while cid[k]!=(0 as u8) { let c: i64=cid[k]&0xff; if c!=34 { if c!=92 { out[o]=cid[k]; o=o+1 } } k=k+1 }
36 o = ib_cat(out, o, "\",\"symmetry_q1000\":" as *u8); o = ib_itoa(out, o, s)
37 o = ib_cat(out, o, "}\n" as *u8)
38 sys_write(1, out, o)
39 return 0
40}