nx_img_resample_gate.nx source
↩ module page · 69 lines · 2516 B
1// nx_img_resample_gate.nx -- KAT gate for the selectable-model resampler.
2//
3// Proves (a) model SELECTION works and changes the output, (b) each model is
4// correct. Same input [0,100] 2->4 through three models gives three DIFFERENT
5// middle values: nearest=0, bilinear=25, bicubic=20 -- so the id genuinely
6// selects the algorithm. Bicubic KATs are hand-derived from Catmull-Rom,
7// exact on both axes; identity is byte-exact. Unknown model + bad args refuse.
8
9import "nx_syscalls.nx"
10import "nx_img_scale.nx"
11import "nx_img_resample.nx"
12
13func main() -> i64 {
14 let s2: *u8 = sys_mmap(16)
15 s2[0] = 0 as u8
16 s2[1] = 100 as u8
17 let d: *u8 = sys_mmap(16)
18
19 // NEAREST [0,100] 2->4 = [0,0,100,100]
20 if nx_img_resample(NX_RS_NEAREST, s2, 2, 1, 1, d, 4, 1) != 0 { return 1 }
21 if d[0] != (0 as u8) { return 2 }
22 if d[1] != (0 as u8) { return 3 }
23 if d[2] != (100 as u8) { return 4 }
24 if d[3] != (100 as u8) { return 5 }
25
26 // BILINEAR via dispatch = [0,25,75,100]
27 if nx_img_resample(NX_RS_BILINEAR, s2, 2, 1, 1, d, 4, 1) != 0 { return 6 }
28 if d[0] != (0 as u8) { return 7 }
29 if d[1] != (25 as u8) { return 8 }
30 if d[2] != (75 as u8) { return 9 }
31 if d[3] != (100 as u8) { return 10 }
32
33 // BICUBIC horizontal = [0,20,80,100] (Catmull-Rom, edge-clamped)
34 if nx_img_resample(NX_RS_BICUBIC, s2, 2, 1, 1, d, 4, 1) != 0 { return 11 }
35 if d[0] != (0 as u8) { return 12 }
36 if d[1] != (20 as u8) { return 13 }
37 if d[2] != (80 as u8) { return 14 }
38 if d[3] != (100 as u8) { return 15 }
39
40 // BICUBIC vertical: column [0;100] 1x2 -> 1x4 = [0,20,80,100] (other axis)
41 if nx_img_resample(NX_RS_BICUBIC, s2, 1, 2, 1, d, 1, 4) != 0 { return 16 }
42 if d[0] != (0 as u8) { return 17 }
43 if d[1] != (20 as u8) { return 18 }
44 if d[2] != (80 as u8) { return 19 }
45 if d[3] != (100 as u8) { return 20 }
46
47 // BICUBIC identity 3x2 -> byte-exact
48 let s3: *u8 = sys_mmap(16)
49 s3[0] = 10 as u8
50 s3[1] = 20 as u8
51 s3[2] = 30 as u8
52 s3[3] = 40 as u8
53 s3[4] = 50 as u8
54 s3[5] = 60 as u8
55 let d3: *u8 = sys_mmap(16)
56 if nx_img_resample(NX_RS_BICUBIC, s3, 3, 2, 1, d3, 3, 2) != 0 { return 21 }
57 var i: i64 = 0
58 while i < 6 {
59 if d3[i] != s3[i] { return 22 }
60 i = i + 1
61 }
62
63 // unknown model -> -1 (selection is fail-closed)
64 if nx_img_resample(99, s2, 2, 1, 1, d, 4, 1) != -1 { return 23 }
65 // bad args -> -1
66 if nx_img_resample(NX_RS_BICUBIC, s2, 2, 1, 1, d, 0, 1) != -1 { return 24 }
67
68 return 0
69}