code wiki / (root) / nx_likeness_lib.nx

nx_likeness_lib.nx

buildroot/runtime/nx_likeness_lib.nx

53971 B1114 linesdepth 11pulls 51 transitivereach 2 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_likeness_lib.nx -- THE IMAGE-LEVEL LIKENESS REFEREE (aesthetictwin AT45, 2026-09-18). The board had no ruler that reads a RENDER against the PHOTOGRAPHS of the person it claims to be, so a render the operator called an ugly ventriloquist dummy was published beside its reference with every gate green. This lib is that ruler, and every layer of the feedback loop above it (fit, morph, texture, hair) is judged by it. It COMPOSES the estate's incumbents and re-implements none of them: nx_photomark_lib decodes a JPEG or PNG through one door (pm_decode_file), places the four canthi and the five mouth landmarks (pm_landmarks_cascade, pm_landmarks), measures the roll-corrected canthal tilts, and parses the OUTSIDE oracle rows (pm_field, pm_span_int) the intake lane already banks per reference still nx_visdesc the grayscale edge-orientation layout descriptor (80 integers) and its L1 distance -- the STRUCTURE axis nx_cosine_similarity the signed Q10 cosine over the same two vectors -- structure read a second way nx_skinsample_lib the skin chroma rule and the linear-light mean converted to CIE L*a*b* -- the TONE axis THE SHAPE OF THE VERDICT. Two images are ALIGNED into one canvas by the similarity that maps each face's two eye centres onto the canvas's two eye centres (the same normalisation on both sides, so a roll or a scale in either still is undone before anything is compared), then SEVEN AXES are measured between the aligned pair and each is published on its own: geom_nme_permil mean landmark distance in the canvas, permil of the canvas eye span (the four canthi, plus the five mouth landmarks when both images carry a mouth); needs both images landmarked by a passing eye pair tilt_delta_deg10 the larger of the two roll-corrected canthal-tilt differences; needs both tilts measured struct_l1 nx_visdesc_l1 between the two aligned crops' descriptors struct_cos_dist NX_COSINE_Q minus the Q10 cosine of the same descriptors (0 = parallel) tone_dl_e3, tone_da_e3, tone_db_e3 the absolute L*, a*, b* differences (x1000) of the skin-masked linear mean of each crop; need skin pixels in both crops THE SAME-PERSON BAND is not a number anyone typed: `lk_band` measures every axis on EVERY PAIR of reference stills of the one person and the band per axis is the WORST (largest) distance any same-person pair reached. A subject passes an axis iff its distance to its NEAREST reference is within that band; the verdict is the count of axes inside, outside and unmeasured, and INSIDE only when no measured axis is outside (the MIN-headline doctrine: no axis may be compensated by another, so there is no weighted sum and no coefficient). The band prints the pair that set it and how many pairs derived it. EVERY NUMBER ANNOUNCES ITS RESOURCE. The canvas side is TWICE THE SMALLEST REFERENCE EYE SPAN, floored to the descriptor's grid (no reference is ever upsampled; a subject smaller than that is announced as upsampled); the eye line sits at 340 permil of the canvas height because on the anchor oracle row (ri_diora_baird_14: brow top 127.8 px, eye line 197.3 px, eye span 103.4 px) the brow top sits 680 permil of the eye span above the eye line, so with a canvas two spans wide the brow top lands on the canvas's top edge and the bottom edge falls 1.32 spans below the eye line -- past the stomion (1.15 spans on the same row) and above the chin (1.65). The smallest canvas is VD_GRID cells of three pixels, the least a Sobel neighbourhood needs. ALIGNMENT SOURCES ARE NAMED, NEVER SILENT. A still with an oracle row (knowledge/refintake/<slug>.oracle, matched by basename) aligns on the oracle's canthi at the oracle's tenth-pixel precision; a subject without one runs the photo ruler's cascade route, then its skin route, and when the skin route REFUSES its eye pair but still holds candidate canthi, those candidates align the crop while the geometry and tilt axes read UNMEASURED (the pair was refused, so its landmarks are not evidence). MEASURED the day this was written: on the rejected render diora_baird_close.png the cascade's face box was the nose tip and no eye pair followed, and the route chooser never reaches the skin route on that refusal -- a subject the ruler cannot align reads UNMEASURED, which is neither INSIDE nor OUTSIDE, so the ladder exists to turn "could not look" into a named, degraded look wherever one is possible. Sides follow the image: R is the image-left eye (the subject's right), as the photo ruler and the oracle rows agree. LIB, no main. license_tier: ORIGINAL No hw writes (Rule 26).

dependencies 4 imports · 2 importers

nx_syscalls.nx nx_photomark_lib.nx nx_visdesc.nx nx_cosine_similarity.nx nx_likeness_lib.nx nx_likeness.nx nx_likeness_gate.nx

imports: nx_syscalls.nxnx_photomark_lib.nxnx_visdesc.nxnx_cosine_similarity.nx

imported by: nx_likeness.nxnx_likeness_gate.nx

structs

none

consts

46const LK_I64: i64 = 8
47const LK_BPP: i64 = 3
48const LK_BYTE: i64 = 255
49const LK_DECI: i64 = 10 // landmarks are carried in tenths of a pixel: the oracle's own unit
50const LK_DECI_HALF: i64 = 5
51const LK_PERMIL: i64 = 1000
52const LK_Q8: i64 = 256 // bilinear weights in 1/256 of a pixel
53const LK_Q8_HALF: i64 = 128
54const LK_NL: i64 = 10
55const LK_CR: i64 = 13
56const LK_SPACE: i64 = 32
57const LK_TAB: i64 = 9
58const LK_HASH: i64 = 35
59const LK_AT: i64 = 64
60const LK_SLASH: i64 = 47
61const LK_PNG_SIG0: i64 = 137
62const LK_JPEG_SIG0: i64 = 255
63const LK_DIRECTIVE_ORACLE: *u8 = "@oracle "
65const LK_EYE_Y_PERMIL: i64 = 340
66const LK_EYE_Y_BASIS_BROW_PERMIL: i64 = 680
67const LK_EYE_Y_BASIS: *u8 = "ri_diora_baird_14"
68const LK_CANVAS_SPANS: i64 = 2
69const LK_CANVAS_QUARTER: i64 = 4 // the eye centres sit a quarter of the width in from each side: two spans wide
70const LK_SOBEL_CELL: i64 = 3 // the least pixels a descriptor cell needs to hold one interior Sobel neighbourhood
72const LK_OF_TILT_R: i64 = 21
73const LK_OF_TILT_L: i64 = 22
75const LK_AL_NONE: i64 = 0
76const LK_AL_ORACLE: i64 = 1
77const LK_AL_CASCADE: i64 = 2
78const LK_AL_SKIN: i64 = 3
79const LK_AL_CANDIDATES: i64 = 4
81const LK_OK: i64 = 0
82const LK_E_READ: i64 = 0 - 1
83const LK_E_DECODE: i64 = 0 - 2
84const LK_E_UNALIGNED: i64 = 0 - 3
86const LK_P_RLAT: i64 = 0
87const LK_P_RMED: i64 = 1
88const LK_P_LMED: i64 = 2
89const LK_P_LLAT: i64 = 3
90const LK_P_LS: i64 = 4
91const LK_P_STO: i64 = 5
92const LK_P_LI: i64 = 6
93const LK_P_CHR: i64 = 7
94const LK_P_CHL: i64 = 8
95const LK_P_CANTHI: i64 = 4
96const LK_P_N: i64 = 9
98const LK_I_RGB: i64 = 0
99const LK_I_W: i64 = 1
100const LK_I_H: i64 = 2
101const LK_I_CODEC: i64 = 3
102const LK_I_ALIGN: i64 = 4
103const LK_I_LM: i64 = 5 // LK_P_N points, x then y, deci-pixels: slots 5..22
104const LK_I_MOUTH: i64 = 23
105const LK_I_TILT_R: i64 = 24
106const LK_I_TILT_L: i64 = 25
107const LK_I_TILT_OK: i64 = 26
108const LK_I_ERX: i64 = 27 // the eye centres (midpoint of each eye's canthi), deci-pixels
109const LK_I_ERY: i64 = 28
110const LK_I_ELX: i64 = 29
111const LK_I_ELY: i64 = 30
112const LK_I_IOD: i64 = 31 // the eye-centre span, deci-pixels
113const LK_I_EYES: i64 = 32 // 1 when the canthi are landmarks (a passing eye pair or an oracle row)
114const LK_I_STATUS: i64 = 33
115const LK_I_ROUTE: i64 = 34
116const LK_I_PAIRFAIL: i64 = 35
117const LK_I_UPSAMPLED: i64 = 36
118const LK_I_N: i64 = 37
120const LK_F_CROP: i64 = 0
121const LK_F_GRAY: i64 = 1
122const LK_F_SKIN_N: i64 = 2
123const LK_F_L: i64 = 3
124const LK_F_A: i64 = 4
125const LK_F_B: i64 = 5
126const LK_F_GRID: i64 = 6 // cells per side of the shading and texture grids
127const LK_F_SHADE: i64 = 7 // pointer: grid*grid cell-mean luminances
128const LK_F_TEX: i64 = 8 // pointer: grid*grid cell gradient energies, normalised to sum LK_PERMIL
129const LK_F_TEXE: i64 = 9 // gradient energy per interior pixel (|gx| + |gy|, Sobel)
130const LK_F_VD: i64 = 10 // nx_visdesc_dim() slots follow
132const LK_AX_GEOM: i64 = 0
133const LK_AX_TILT: i64 = 1
134const LK_AX_SL1: i64 = 2
135const LK_AX_SCOS: i64 = 3
136const LK_AX_TL: i64 = 4
137const LK_AX_TA: i64 = 5
138const LK_AX_TB: i64 = 6
139const LK_AX_SHADE: i64 = 7 // NX_COSINE_Q minus the cosine of the two CENTRED shading grids (Pearson r as a Q10 distance)
140const LK_AX_TEX: i64 = 8 // L1 between the two normalised texture-energy layouts (0..2 * LK_PERMIL)
141const LK_AX_TEXE: i64 = 9 // absolute difference of gradient energy per pixel
142const LK_AX_N: i64 = 10
143const LK_AXR_MEAS: i64 = 10 // LK_AX_N flags: 1 measured, 0 unmeasured (slots 10..19)
144const LK_AXR_GEOM_PTS: i64 = 20
145const LK_AXR_COS: i64 = 21
146const LK_AXR_N: i64 = 22
148const LK_B_MAX: i64 = 0 // LK_AX_N slots each
149const LK_B_MEAN: i64 = 10
150const LK_B_PI: i64 = 20
151const LK_B_PJ: i64 = 30
152const LK_B_PAIRS: i64 = 40
153const LK_B_TOTAL: i64 = 50
154const LK_B_N: i64 = 51
156const LK_S_DIST: i64 = 0 // LK_AX_N slots: the nearest reference's distance per axis
157const LK_S_NEAR: i64 = 10 // LK_AX_N slots: which reference
158const LK_S_STATE: i64 = 20 // LK_AX_N slots: LK_ST_*
159const LK_S_INSIDE: i64 = 30
160const LK_S_OUTSIDE: i64 = 31
161const LK_S_UNMEASURED: i64 = 32
162const LK_S_VERDICT: i64 = 33
163const LK_S_N: i64 = 34
164const LK_ST_UNMEASURED: i64 = 0
165const LK_ST_INSIDE: i64 = 1
166const LK_ST_OUTSIDE: i64 = 2
168const LK_V_INSIDE: i64 = 0
169const LK_V_OUTSIDE: i64 = 1
170const LK_V_UNMEASURED: i64 = 5
171const LK_V_NOBAND: i64 = 6
173const LK_C_FACE: i64 = 0
174const LK_C_EYE: i64 = 1
175const LK_C_OBUF: i64 = 2
176const LK_C_OLEN: i64 = 3
177const LK_C_OPATH: i64 = 4
178const LK_C_FACE_RC: i64 = 5
179const LK_C_EYE_RC: i64 = 6
180const LK_C_N: i64 = 7
982const LK_R_IMGS: i64 = 0
983const LK_R_FEATS: i64 = 1
984const LK_R_PATHS: i64 = 2
985const LK_R_N: i64 = 3
986const LK_R_LISTED: i64 = 4
987const LK_R_UNREADABLE: i64 = 5
988const LK_R_UNDECODABLE: i64 = 6
989const LK_R_UNALIGNED: i64 = 7
990const LK_R_CANVAS: i64 = 8
991const LK_R_MIN_IOD: i64 = 9
992const LK_R_MIN_PATH: i64 = 10
993const LK_R_BAND: i64 = 11
994const LK_R_PAIRS: i64 = 12
995const LK_R_ORACLE_BYTES: i64 = 13
996const LK_R_GRID: i64 = 14
997const LK_R_GEOM_BAND: i64 = 15
998const LK_R_GEOM_PAIRS: i64 = 16
999const LK_R_SLOTS: i64 = 17

functions

182func lk_ruler_version() -> i64 { return 1 }
called by 1: lk_print_canvas
183func lkh_abs(v: i64) -> i64 { if v < 0 { return 0 - v } return v }
184func lkh_max(a: i64, b: i64) -> i64 { if a > b { return a } return b }
called by 1: lk_axes
185func lkh_min(a: i64, b: i64) -> i64 { if a < b { return a } return b }
187func lkh_div_round(num: i64, den: i64) -> i64
192func lkh_div_floor(num: i64, den: i64) -> i64
called by 1: lk_sample
197func lkh_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
198func lkh_streq(a: *u8, b: *u8) -> i64
called by 2: mainlg_find
205func lkh_basename(p: *u8) -> *u8
212func lkh_span_copy(buf: *u8, s: i64, e: i64) -> *u8
called by 1: lk_list_read calls 1: sys_mmap
220func lk_align_name(k: i64) -> *u8
called by 1: lk_print_img
227func lk_axis_name(k: i64) -> *u8
240func lk_state_name(k: i64) -> *u8
called by 1: lk_print_score
245func lk_verdict_name(k: i64) -> *u8
called by 1: lk_print_verdict
253func lk_ctx_new() -> *i64
263func lk_ctx_cascades(ctx: *i64) -> i64
269func lk_ctx_oracle(ctx: *i64, path: *u8) -> i64
281func lk_img_new() -> *i64
287func lk_img_set_rgb(img: *i64, rgb: *u8, w: i64, h: i64) -> i64
called by 2: mainlk_load
293func lk_pt_x(img: *i64, p: i64) -> i64 { return img[LK_I_LM + 2 * p] }
294func lk_pt_y(img: *i64, p: i64) -> i64 { return img[LK_I_LM + 2 * p + 1] }
295func lk_pt_set(img: *i64, p: i64, x: i64, y: i64) -> i64 { img[LK_I_LM + 2 * p] = x; img[LK_I_LM + 2 * p + 1] = y; return 0 }
297func lk_img_finish(img: *i64) -> i64
311func lk_field_xy10(buf: *u8, ls: i64, le: i64, idx: i64, out2: *i64) -> i64
325func lkh_line_end(buf: *u8, ls: i64, n: i64) -> i64
334func lk_oracle_row(ctx: *i64, base: *u8, out2: *i64) -> i64
357func lk_landmarks_from_oracle(buf: *u8, ls: i64, le: i64, img: *i64) -> i64
384func lk_landmarks_from_ruler(res: *i64, img: *i64, align: i64) -> i64
called by 1: lk_align_ruler calls 1: lk_pt_set
411func lk_align_ruler(ctx: *i64, img: *i64) -> i64
442func lk_load(ctx: *i64, path: *u8, img: *i64) -> i64
463func lk_map(aRx: i64, aRy: i64, aLx: i64, aLy: i64, bRx: i64, bRy: i64, bLx: i64, bLy: i64, px: i64, py: i64, out2: *i64) -> i64
480func lk_sample(rgb: *u8, w: i64, h: i64, sx: i64, sy: i64, out3: *i64) -> i64
518func lk_resample(img: *i64, dRx: i64, dRy: i64, dLx: i64, dLy: i64, ow: i64, oh: i64) -> *u8
called by 2: mainlk_crop calls 3: sys_mmaplk_maplk_sample
539func lk_img_map_landmarks(src: *i64, dst: *i64, dRx: i64, dRy: i64, dLx: i64, dLy: i64) -> i64
559func lk_canvas(min_iod_deci: i64) -> i64
called by 2: mainlk_refs_load
566func lk_canvas_eye_rx(c: i64) -> i64 { return (c / LK_CANVAS_QUARTER) * LK_DECI }
567func lk_canvas_eye_lx(c: i64) -> i64 { return (c - c / LK_CANVAS_QUARTER) * LK_DECI }
568func lk_canvas_eye_y(c: i64) -> i64 { return (c * LK_EYE_Y_PERMIL / LK_PERMIL) * LK_DECI }
569func lk_canvas_span(c: i64) -> i64 { return lk_canvas_eye_lx(c) - lk_canvas_eye_rx(c) }
571func lk_crop(img: *i64, c: i64) -> *u8
574func lk_feat_new() -> *i64
581func lk_feat_vd(feat: *i64) -> *i64 { return (feat as i64 + LK_F_VD * LK_I64) as *i64 }
called by 2: lk_featureslk_axes
585func lk_grid_from_band(c: i64, geom_band_permil: i64) -> i64
593func lk_features(img: *i64, c: i64, grid: i64, feat: *i64) -> i64
665func lk_centred_cos(a: *i64, b: *i64, n: i64) -> i64
680func lk_geom_pair(imgA: *i64, imgB: *i64, c: i64, out2: *i64) -> i64
707func lk_band_geometry(imgs: *i64, n: i64, c: i64, pairs_out: *i64) -> i64
called by 1: lk_refs_load calls 2: sys_mmaplk_geom_pair
728func lk_axes(imgA: *i64, featA: *i64, imgB: *i64, featB: *i64, c: i64, ax: *i64) -> i64
781func lk_band(imgs: *i64, feats: *i64, n: i64, c: i64, band: *i64) -> i64
called by 1: lk_refs_load calls 2: sys_mmaplk_axes
815func lk_score_img(sub: *i64, subf: *i64, imgs: *i64, feats: *i64, n: i64, c: i64, band: *i64, sc: *i64) -> i64
called by 1: lk_score_subject calls 2: sys_mmaplk_axes
858func lk_list_read(ctx: *i64, path: *u8, out_n: *i64) -> *i64
918func lk_print_img(label: *u8, path: *u8, img: *i64) -> i64
929func lk_print_feat(path: *u8, feat: *i64) -> i64
936func lk_print_canvas(c: i64, min_iod: i64, min_path: *u8, nrefs: i64) -> i64
946func lk_print_band(band: *i64, paths: *i64) -> i64
960func lk_print_score(path: *u8, sc: *i64, band: *i64, paths: *i64) -> i64
973func lk_print_verdict(path: *u8, sc: *i64) -> i64
1002func lk_refs_load(ctx: *i64, list: *u8, set: *i64) -> i64
1079func lk_score_subject(set: *i64, path: *u8, sub: *i64, sc: *i64) -> i64
1090func lk_score(ctx: *i64, subject: *u8, list: *u8, sc: *i64) -> i64