code wiki / (root) / nx_skinsample.nx

nx_skinsample.nx source

↩ module page · 76 lines · 4141 B

1// nx_skinsample.nx -- CLI over nx_skinsample_lib (aesthetictwin AT23, 2026-09-16): skin colour measured from a mirrored 2// photograph and written onto a twin card as MEASURED rows. 3// nx_skinsample measure <jpeg> -> decode, mask, print L a b (x1e3), ITA (deg10), mask count and coverage 4// nx_skinsample card <slug> <refkey> <jpeg> <when> -> measure, then append skin_L skin_a skin_b ita rows to knowledge/twincard/<slug>.card 5// (refused when any of those rows already exists: retire the observed row first) 6// exit: 0 ok | 2 usage | 3 unreadable | 4 decode failed (not a baseline or progressive JPEG the estate decodes) | 5 UNMEASURED 7// (no pixel passed the skin mask) | 6 rows exist 8// license_tier: ORIGINAL No hw writes (Rule 26). 9import "nx_syscalls.nx" 10import "nx_skinsample_lib.nx" 11 12const SKC_EXIT_USAGE: i64 = 2 13const SKC_EXIT_READ: i64 = 3 14const SKC_EXIT_DECODE: i64 = 4 15const SKC_EXIT_UNMEASURED: i64 = 5 16const SKC_EXIT_EXISTS: i64 = 6 17const SKC_ARGC_MEASURE: i64 = 3 18const SKC_ARGC_CARD: i64 = 6 19const SKC_PERMIL: i64 = 1000 20 21func skc_usage() -> i64 { 22 ri_puts("usage: nx_skinsample measure <jpeg> | card <slug> <refkey> <jpeg> <when>\n" as *u8) 23 return SKC_EXIT_USAGE 24} 25func skc_report(path: *u8, res: *i64) -> i64 { 26 ri_puts("SKINSAMPLE file=" as *u8); ri_puts(path) 27 ri_puts(" pixels=" as *u8); ri_putn(res[SKS_R_TOTAL]) 28 ri_puts(" skin_pixels=" as *u8); ri_putn(res[SKS_R_COUNT]) 29 var permil: i64 = 0 30 if res[SKS_R_TOTAL] > 0 { permil = res[SKS_R_COUNT] * SKC_PERMIL / res[SKS_R_TOTAL] } 31 ri_puts(" mask_permil=" as *u8); ri_putn(permil) 32 ri_puts(" L_e3=" as *u8); ri_putn(res[SKS_R_L]) 33 ri_puts(" a_e3=" as *u8); ri_putn(res[SKS_R_A]) 34 ri_puts(" b_e3=" as *u8); ri_putn(res[SKS_R_B]) 35 ri_puts(" ita_deg10=" as *u8); ri_putn(res[SKS_R_ITA]) 36 ri_puts(" (mean of the skin-masked pixels in linear light; the mask is the YCbCr chroma rule and admits skin-coloured backgrounds too, so read the mask share beside the value)\n" as *u8) 37 return 0 38} 39func skc_rc(rc: i64) -> i64 { 40 if rc == SKS_E_READ { ri_puts("SKINSAMPLE verdict=UNREADABLE\n" as *u8); return SKC_EXIT_READ } 41 if rc == SKS_E_DECODE { ri_puts("SKINSAMPLE verdict=DECODE-FAILED (not a JPEG the sovereign decoder reads: baseline and progressive only)\n" as *u8); return SKC_EXIT_DECODE } 42 if rc == SKS_E_UNMEASURED { ri_puts("SKINSAMPLE verdict=UNMEASURED no pixel passed the skin mask; no colour is reported\n" as *u8); return SKC_EXIT_UNMEASURED } 43 return 0 44} 45 46func main(argc: i64, argv: *i64) -> i64 { 47 if argc < SKC_ARGC_MEASURE { return skc_usage() } 48 let verb: *u8 = argv[1] as *u8 49 let res: *i64 = sys_mmap(SKS_R_N * RI_I64) as *i64 50 if ri_streq(verb, "measure" as *u8) == 1 { 51 let path: *u8 = argv[2] as *u8 52 let rc: i64 = sks_measure_file(path, res) 53 skc_report(path, res) 54 if rc != SKS_OK { return skc_rc(rc) } 55 ri_puts("SKINSAMPLE verdict=MEASURED\n" as *u8) 56 return 0 57 } 58 if ri_streq(verb, "card" as *u8) == 1 { 59 if argc < SKC_ARGC_CARD { return skc_usage() } 60 let slug: *u8 = argv[2] as *u8 61 let refkey: *u8 = argv[3] as *u8 62 let path: *u8 = argv[4] as *u8 63 let when: *u8 = argv[5] as *u8 64 let rc: i64 = sks_measure_file(path, res) 65 skc_report(path, res) 66 if rc != SKS_OK { return skc_rc(rc) } 67 let w: i64 = sks_card_write(slug, refkey, when, res) 68 if w == SKS_E_EXISTS { ri_puts("SKINSAMPLE verdict=ROWS-EXIST a skin_L, skin_a, skin_b or ita row already sits on the card; retire it before writing a measured one\n" as *u8); return SKC_EXIT_EXISTS } 69 if w < 0 { ri_puts("SKINSAMPLE verdict=CARD-UNREADABLE\n" as *u8); return SKC_EXIT_READ } 70 ri_puts("SKINSAMPLE card=" as *u8); ri_puts(slug) 71 ri_puts(" rows_appended=" as *u8); ri_putn(w) 72 ri_puts(" verdict=MEASURED-AND-WRITTEN (skin_L skin_a skin_b in lab10, ita in deg10, method measured, source " as *u8); ri_puts(refkey); ri_puts(")\n" as *u8) 73 return 0 74 } 75 return skc_usage() 76}