code wiki / _hdl_build / nx_clarity_test.nx
nx_clarity_test.nx source
↩ module page · 61 lines · 1739 B
1// nx_clarity_test.nx -- smoke for clarity detector.
2
3import "nx_syscalls.nx"
4import "nx_image.nx"
5import "nx_clarity.nx"
6
7func fill_const(img: *Image, value: i64) -> i64 {
8 var y: i64 = 0
9 while y < img.height {
10 var x: i64 = 0
11 while x < img.width {
12 nx_image_set(img, x, y, 0, value)
13 x = x + 1
14 }
15 y = y + 1
16 }
17 return 0
18}
19
20func fill_checker(img: *Image, x0: i64, y0: i64, x1: i64, y1: i64) -> i64 {
21 var y: i64 = y0
22 while y < y1 {
23 var x: i64 = x0
24 while x < x1 {
25 var v: i64 = 0
26 let bx: i64 = x / 2
27 let by: i64 = y / 2
28 let parity: i64 = (bx + by) - ((bx + by) / 2) * 2
29 if parity == 1 { v = 255 }
30 nx_image_set(img, x, y, 0, v)
31 x = x + 1
32 }
33 y = y + 1
34 }
35 return 0
36}
37
38func main() -> i64 {
39 let v: *ClarityVerdict = (sys_mmap(128)) as *ClarityVerdict
40
41 // T1: all-black 64x64 -> NONE
42 let g1: *Image = nx_image_alloc(64, 64, 1)
43 fill_const(g1, 0)
44 nx_clarity_compute(g1, v)
45 if v.kind != NX_CLARITY_NONE { return 1 }
46
47 // T2: full checkerboard -> IMAGE_LEVEL (ratio ~ 1.0)
48 let g2: *Image = nx_image_alloc(64, 64, 1)
49 fill_checker(g2, 0, 0, 64, 64)
50 nx_clarity_compute(g2, v)
51 if v.kind != NX_CLARITY_IMAGE_LEVEL { return 10 }
52
53 // T3: checkerboard center + uniform outside -> PHOTOGRAPHIC
54 let g3: *Image = nx_image_alloc(64, 64, 1)
55 fill_const(g3, 128)
56 fill_checker(g3, 22, 22, 42, 42)
57 nx_clarity_compute(g3, v)
58 if v.kind != NX_CLARITY_PHOTOGRAPHIC { return 20 }
59
60 return 0
61}