code wiki / (root) / nx_likeness.nx

nx_likeness.nx source

↩ module page · 89 lines · 5014 B

1// nx_likeness.nx -- CLI over nx_likeness_lib (aesthetictwin AT45, 2026-09-18): the image-level likeness referee. A render (or any 2// still) is read against the reference stills of the one person it claims to be; every axis is published on its own line, the 3// same-person band per axis is derived from the reference pairs and printed with the pair that set it, and the verdict is LAST. 4// nx_likeness score <subject.png|jpg> <ref-list|ref-image> [oracle-file] 5// -> the reference receipts, the canvas derivation, the band per axis, the subject's receipt, one line per axis 6// (dist, band, nearest reference, INSIDE|OUTSIDE|UNMEASURED) and the verdict line 7// nx_likeness band <ref-list> [oracle-file] 8// -> the same without a subject: how far apart two photographs of the same person read on every axis 9// nx_likeness crop <image> <out.png> [oracle-file] 10// -> the aligned face crop written as a PNG (the canvas is the image's own two eye spans), so an alignment can be LOOKED AT 11// The reference list is one path per line, comment lines start with the hash byte, and a `@oracle <path>` line names the outside 12// oracle rows (the CLI argument wins when both are given); a list file that opens with a PNG or JPEG signature is a list of one. 13// A list, never a directory: the clothed-only curation of a reference set is a decision the list carries and a directory walk cannot. 14// exit: 0 INSIDE | 1 OUTSIDE | 2 usage | 3 unreadable | 4 decode failed | 5 UNMEASURED (the subject could not be aligned) | 6 NO-BAND 15// license_tier: ORIGINAL No hw writes (Rule 26). 16import "nx_syscalls.nx" 17import "nx_likeness_lib.nx" 18import "nx_png.nx" 19 20const LKC_ARGC_BAND: i64 = 3 21const LKC_ARGC_SCORE: i64 = 4 22const LKC_ARGC_CROP: i64 = 4 23const LKC_ARGC_BAND_ORACLE: i64 = 4 24const LKC_ARGC_SCORE_ORACLE: i64 = 5 25const LKC_ARGC_CROP_ORACLE: i64 = 5 26const LKC_EXIT_USAGE: i64 = 2 27const LKC_EXIT_READ: i64 = 3 28const LKC_EXIT_DECODE: i64 = 4 29const LKC_I64: i64 = 8 30const LKC_BPP: i64 = 3 31const LKC_BYTE: i64 = 255 32const LKC_SHIFT_G: i64 = 8 33const LKC_SHIFT_B: i64 = 16 34 35func lkc_usage() -> i64 { 36 pm_puts("usage: nx_likeness score <subject.png|jpg> <ref-list|ref-image> [oracle-file] | band <ref-list> [oracle-file] | crop <image> <out.png> [oracle-file]\n" as *u8) 37 return LKC_EXIT_USAGE 38} 39func main(argc: i64, argv: **u8) -> i64 { 40 if argc < LKC_ARGC_BAND { return lkc_usage() } 41 let verb: *u8 = argv[1] 42 let ctx: *i64 = lk_ctx_new() 43 if lkh_streq(verb, "score" as *u8) == 1 { 44 if argc < LKC_ARGC_SCORE { return lkc_usage() } 45 if argc >= LKC_ARGC_SCORE_ORACLE { lk_ctx_oracle(ctx, argv[4]) } 46 let sc: *i64 = sys_mmap(LK_S_N * LKC_I64) as *i64 47 let v: i64 = lk_score(ctx, argv[2], argv[3], sc) 48 if v == LK_E_READ { return LKC_EXIT_READ } 49 if v == LK_E_DECODE { return LKC_EXIT_DECODE } 50 if v == LK_E_UNALIGNED { return LK_V_UNMEASURED } 51 return v 52 } 53 if lkh_streq(verb, "band" as *u8) == 1 { 54 if argc >= LKC_ARGC_BAND_ORACLE { lk_ctx_oracle(ctx, argv[3]) } 55 let set: *i64 = sys_mmap(LK_R_SLOTS * LKC_I64) as *i64 56 let n: i64 = lk_refs_load(ctx, argv[2], set) 57 if n < 0 { return LKC_EXIT_READ } 58 pm_puts("LIKENESS band" as *u8); pm_kv(" references_aligned=" as *u8, n); pm_kv(" pairs=" as *u8, set[LK_R_PAIRS]) 59 if set[LK_R_PAIRS] == 0 { pm_puts(" verdict=NO-BAND\n" as *u8); return LK_V_NOBAND } 60 pm_puts(" verdict=DERIVED\n" as *u8) 61 return 0 62 } 63 if lkh_streq(verb, "crop" as *u8) == 1 { 64 if argc < LKC_ARGC_CROP { return lkc_usage() } 65 if argc >= LKC_ARGC_CROP_ORACLE { lk_ctx_oracle(ctx, argv[4]) } 66 let img: *i64 = lk_img_new() 67 let rc: i64 = lk_load(ctx, argv[2], img) 68 if rc == LK_E_READ { pm_puts("LIKENESS crop status=UNREADABLE\n" as *u8); return LKC_EXIT_READ } 69 if rc == LK_E_DECODE { pm_puts("LIKENESS crop status=UNDECODABLE\n" as *u8); return LKC_EXIT_DECODE } 70 if rc != LK_OK { lk_print_img("crop" as *u8, argv[2], img); pm_puts("LIKENESS crop status=UNALIGNED verdict=UNMEASURED\n" as *u8); return LK_V_UNMEASURED } 71 let c: i64 = lk_canvas(img[LK_I_IOD]) 72 let crop: *u8 = lk_crop(img, c) 73 let fb: *i64 = sys_mmap(c * c * LKC_I64) as *i64 74 var i: i64 = 0 75 while i < c * c { 76 let o: i64 = i * LKC_BPP 77 fb[i] = ((crop[o] as i64) & LKC_BYTE) | (((crop[o + 1] as i64) & LKC_BYTE) << LKC_SHIFT_G) | (((crop[o + 2] as i64) & LKC_BYTE) << LKC_SHIFT_B) 78 i = i + 1 79 } 80 let wr: i64 = write_png(fb, c, c, argv[3]) 81 lk_print_img("crop" as *u8, argv[2], img) 82 lk_print_canvas(c, img[LK_I_IOD], argv[2], 1) 83 pm_puts("LIKENESS crop out=" as *u8); pm_puts(argv[3]); pm_kv(" side_px=" as *u8, c); pm_kv(" write_rc=" as *u8, wr) 84 if wr == 0 { pm_puts(" verdict=WRITTEN\n" as *u8); return 0 } 85 pm_puts(" verdict=WRITE-FAILED\n" as *u8) 86 return LKC_EXIT_READ 87 } 88 return lkc_usage() 89}