code wiki / (root) / nx_transition_gate.nx

nx_transition_gate.nx source

↩ module page · 120 lines · 5174 B

1// nx_transition_gate.nx -- REFEREE for R4 (nx_transition). 2// Solid frames A=(200,40,0), B=(0,80,200), 8x8x3. Asserts: 3// xfade@0 == A exactly (pure A end) 4// xfade@Q == B exactly (pure B end) 5// xfade@Q/2 LINEAR == midpoint (100,60,100) 6// xfade@Q/2 SMOOTHSTEP == midpoint too (smoothstep(0.5)=0.5) 7// xfade@Q/4 LINEAR != xfade@Q/4 SMOOTHSTEP (the easing curve actually bends) 8// fade@0 == black (0,0,0) ; fade@Q == A (fade-in endpoints) 9// Every value PRINTED. stdout + knowledge/status/transition_gate.log. Exit 0/1. 10// Sovereign: nx_syscalls + nx_image + nx_gradient_blend + nx_transition. 11// license_tier: ORIGINAL 12import "nx_syscalls.nx" 13import "nx_image.nx" 14import "nx_gradient_blend.nx" 15import "nx_transition.nx" 16 17func gp(logfd: i64, s: *u8) -> i64 { 18 var n: i64 = 0 19 while s[n] != (0 as u8) { n = n + 1 } 20 sys_write(1, s, n) 21 if logfd > 0 { sys_write(logfd, s, n) } 22 return 0 23} 24func gn(logfd: i64, v: i64) -> i64 { 25 let bb: *u8 = sys_mmap(28) 26 var m: i64 = v 27 if m < 0 { sys_write(1, "-\x00" as *u8, 1); if logfd > 0 { sys_write(logfd, "-\x00" as *u8, 1) } m = 0 - m } 28 let t: *u8 = sys_mmap(28) 29 var k: i64 = 0 30 if m == 0 { t[0] = 48 as u8; k = 1 } 31 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 32 var i: i64 = 0 33 while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } 34 sys_write(1, bb, k) 35 if logfd > 0 { sys_write(logfd, bb, k) } 36 return 0 37} 38func fill(img: *Image, r: i64, g: i64, b: i64) -> i64 { 39 var y: i64 = 0 40 while y < 8 { 41 var x: i64 = 0 42 while x < 8 { nx_image_set(img, x, y, 0, r); nx_image_set(img, x, y, 1, g); nx_image_set(img, x, y, 2, b); x = x + 1 } 43 y = y + 1 44 } 45 return 0 46} 47 48func main() -> i64 { 49 let logfd: i64 = sys_openat_append("knowledge/status/transition_gate.log\x00" as *u8, 0x1a4) 50 gp(logfd, "TRANSITION-GATE R4 (xfade/fade) frame=8x8\n\x00" as *u8) 51 let Q: i64 = NX_GB_Q 52 53 let a: *Image = nx_image_alloc(8, 8, 3) 54 let b: *Image = nx_image_alloc(8, 8, 3) 55 let o: *Image = nx_image_alloc(8, 8, 3) 56 fill(a, 200, 40, 0) 57 fill(b, 0, 80, 200) 58 59 nx_xfade_frame(a, b, 0, NX_GB_CURVE_LINEAR, o) 60 let z0: i64 = nx_image_get(o, 3, 3, 0) 61 let z1: i64 = nx_image_get(o, 3, 3, 1) 62 let z2: i64 = nx_image_get(o, 3, 3, 2) 63 gp(logfd, " xfade@0 =(\x00" as *u8); gn(logfd, z0); gp(logfd, ",\x00" as *u8); gn(logfd, z1); gp(logfd, ",\x00" as *u8); gn(logfd, z2); gp(logfd, ")\n\x00" as *u8) 64 65 nx_xfade_frame(a, b, Q, NX_GB_CURVE_LINEAR, o) 66 let q0: i64 = nx_image_get(o, 3, 3, 0) 67 let q1: i64 = nx_image_get(o, 3, 3, 1) 68 let q2: i64 = nx_image_get(o, 3, 3, 2) 69 gp(logfd, " xfade@Q =(\x00" as *u8); gn(logfd, q0); gp(logfd, ",\x00" as *u8); gn(logfd, q1); gp(logfd, ",\x00" as *u8); gn(logfd, q2); gp(logfd, ")\n\x00" as *u8) 70 71 nx_xfade_frame(a, b, Q / 2, NX_GB_CURVE_LINEAR, o) 72 let h0: i64 = nx_image_get(o, 3, 3, 0) 73 let h1: i64 = nx_image_get(o, 3, 3, 1) 74 let h2: i64 = nx_image_get(o, 3, 3, 2) 75 gp(logfd, " xfade@Q/2 LIN=(\x00" as *u8); gn(logfd, h0); gp(logfd, ",\x00" as *u8); gn(logfd, h1); gp(logfd, ",\x00" as *u8); gn(logfd, h2); gp(logfd, ")\n\x00" as *u8) 76 77 nx_xfade_frame(a, b, Q / 2, NX_GB_CURVE_SMOOTHSTEP, o) 78 let s0: i64 = nx_image_get(o, 3, 3, 0) 79 gp(logfd, " xfade@Q/2 SMOOTH ch0=\x00" as *u8); gn(logfd, s0); gp(logfd, "\n\x00" as *u8) 80 81 nx_xfade_frame(a, b, Q / 4, NX_GB_CURVE_LINEAR, o) 82 let lq: i64 = nx_image_get(o, 3, 3, 0) 83 nx_xfade_frame(a, b, Q / 4, NX_GB_CURVE_SMOOTHSTEP, o) 84 let sq: i64 = nx_image_get(o, 3, 3, 0) 85 gp(logfd, " xfade@Q/4 ch0: linear=\x00" as *u8); gn(logfd, lq); gp(logfd, " smoothstep=\x00" as *u8); gn(logfd, sq); gp(logfd, "\n\x00" as *u8) 86 87 nx_fade_frame(a, 0, NX_GB_CURVE_LINEAR, o) 88 let fb0: i64 = nx_image_get(o, 3, 3, 0) 89 let fb1: i64 = nx_image_get(o, 3, 3, 1) 90 nx_fade_frame(a, Q, NX_GB_CURVE_LINEAR, o) 91 let ff0: i64 = nx_image_get(o, 3, 3, 0) 92 gp(logfd, " fade@0 ch0=\x00" as *u8); gn(logfd, fb0); gp(logfd, " ch1=\x00" as *u8); gn(logfd, fb1); gp(logfd, " ; fade@Q ch0=\x00" as *u8); gn(logfd, ff0); gp(logfd, "\n\x00" as *u8) 93 94 var ok: i64 = 1 95 if z0 != 200 { ok = 0 } 96 if z1 != 40 { ok = 0 } 97 if z2 != 0 { ok = 0 } // xfade@0 == A 98 if q0 != 0 { ok = 0 } 99 if q1 != 80 { ok = 0 } 100 if q2 != 200 { ok = 0 } // xfade@Q == B 101 if h0 != 100 { ok = 0 } 102 if h1 != 60 { ok = 0 } 103 if h2 != 100 { ok = 0 } // linear midpoint 104 if s0 != 100 { ok = 0 } // smoothstep(0.5) == midpoint 105 if lq == sq { ok = 0 } // easing curve must bend (differ at Q/4) 106 if fb0 != 0 { ok = 0 } 107 if fb1 != 0 { ok = 0 } // fade@0 == black 108 if ff0 != 200 { ok = 0 } // fade@Q == A 109 110 if ok == 1 { 111 gp(logfd, "TRANSITION-GATE result=ALL-PASS verdict=GREEN\n\x00" as *u8) 112 if logfd > 0 { sys_close(logfd) } 113 sys_exit(0) 114 return 0 115 } 116 gp(logfd, "TRANSITION-GATE result=FAIL verdict=RED\n\x00" as *u8) 117 if logfd > 0 { sys_close(logfd) } 118 sys_exit(1) 119 return 1 120}