code wiki / (root) / nx_fb_perceptual_test.nx

nx_fb_perceptual_test.nx source

↩ module page · 77 lines · 3280 B

1// nx_fb_perceptual_test.nx -- KAT for nx_fb_perceptual.nx. 2// 3// Verifies the per-profile parametricism is real, not cosmetic: 4// the SAME RGBA input produces DIFFERENT packed bytes per profile. 5// If any two profiles produce identical packed bytes for the same 6// input, the gate fails loud (cardinal anti-cosmetic check from 7// [[feedback-no-false-ok-substrate-honesty-audit]]). 8 9import "nx_syscalls.nx" 10import "nx_perceptual_profile.nx" 11import "nx_fb_perceptual.nx" 12 13func main() -> i64 { 14 let r: i64 = 200 15 let g: i64 = 100 16 let b: i64 = 50 17 let a: i64 = 255 18 19 let p_human: i64 = nx_fb_pack_for_profile(NX_PERCEPT_HUMAN_NORMAL, r, g, b, a) 20 let p_dog: i64 = nx_fb_pack_for_profile(NX_PERCEPT_DOG_VIZSLA, r, g, b, a) 21 let p_bee: i64 = nx_fb_pack_for_profile(NX_PERCEPT_HONEYBEE, r, g, b, a) 22 let p_av: i64 = nx_fb_pack_for_profile(NX_PERCEPT_CHICKEN, r, g, b, a) 23 let p_pres: i64 = nx_fb_pack_for_profile(NX_PERCEPT_PRESERVE_ALL, r, g, b, a) 24 25 // T1: HUMAN exact bytes. RGBA -> R + G*256 + B*65536 + A*16777216 26 let expect_human: i64 = 200 + 100 * 256 + 50 * 65536 + 255 * 16777216 27 if p_human != expect_human { return 1 } 28 29 // T2: DOG dichromat Y = (77*200 + 150*100 + 29*50 + 128) / 256 30 // = (15400 + 15000 + 1450 + 128) / 256 = 31978 / 256 = 124 31 // packed = Y + B*256 = 124 + 50*256 = 124 + 12800 = 12924 32 if p_dog != 12924 { return 2 } 33 34 // T3: HONEYBEE: G + B*256 + (255-R)*65536 + A*16777216 35 // = 100 + 50*256 + 55*65536 + 255*16777216 36 // = 100 + 12800 + 3604480 + 4278190080 = 4281807460 37 if p_bee != 4281807460 { return 3 } 38 39 // T4: AVIAN: R + G*256 + B*65536 + (255-R)*16777216 40 // = 200 + 100*256 + 50*65536 + 55*16777216 41 // = 200 + 25600 + 3276800 + 922746880 = 926049480 42 if p_av != 926049480 { return 4 } 43 44 // T5: PRESERVE_ALL: bytes per channel doubled into 16-bit pair. 45 // R16 = 200*256+200 = 51400 46 // G16 = 100*256+100 = 25700 47 // B16 = 50*256+50 = 12850 48 // A16 = 255*256+255 = 65535 49 // bits 0..15 = R16; 16..31 = G16; 32..47 = B16; 48..63 = A16 50 let expect_pres: i64 = 51400 + 25700 * 65536 + 12850 * 4294967296 + 65535 * 281474976710656 51 if p_pres != expect_pres { return 5 } 52 53 // T6: Cross-profile differentiation -- the cardinal anti-cosmetic 54 // gate. All five outputs must differ pairwise. If any two 55 // match, the per-profile parametricism is fake. 56 if p_human == p_dog { return 10 } 57 if p_human == p_bee { return 11 } 58 if p_human == p_av { return 12 } 59 if p_human == p_pres { return 13 } 60 if p_dog == p_bee { return 14 } 61 if p_dog == p_av { return 15 } 62 if p_dog == p_pres { return 16 } 63 if p_bee == p_av { return 17 } 64 if p_bee == p_pres { return 18 } 65 if p_av == p_pres { return 19 } 66 67 // T7: Unknown profile fallback is deterministic and equals HUMAN_NORMAL. 68 let p_unknown: i64 = nx_fb_pack_for_profile(9998, r, g, b, a) 69 if p_unknown != p_human { return 30 } 70 71 // T8: Out-of-range channel clamp on HUMAN packer. 72 let p_clamped: i64 = nx_fb_pack_human_normal(-50, 300, 1000, 50) 73 let expect_clamped: i64 = 0 + 255 * 256 + 255 * 65536 + 50 * 16777216 74 if p_clamped != expect_clamped { return 40 } 75 76 return 0 77}