nx_aesthetics_test.nx source
↩ module page · 146 lines · 5248 B
1// nx_aesthetics_test.nx -- smoke for V10 aesthetics composite.
2
3import "syscalls.nx"
4import "nx_image.nx"
5import "nx_aesthetics.nx"
6
7func main() -> i64 {
8 // === Test 1: color harmony on a monochromatic-red image ===
9 // All pixels are the same red. Should be high harmony.
10 let img_red: *Image = nx_image_alloc(16, 16, 3)
11 var y: i64 = 0
12 while y < 16 {
13 var x: i64 = 0
14 while x < 16 {
15 nx_image_set(img_red, x, y, 0, 200)
16 nx_image_set(img_red, x, y, 1, 50)
17 nx_image_set(img_red, x, y, 2, 50)
18 x = x + 1
19 }
20 y = y + 1
21 }
22 let h_red: i64 = nx_aesthetics_color_harmony(img_red)
23 if h_red < 900 { return 1 } // single hue = very harmonious
24
25 // === Test 2: color harmony on a chaotic multi-hue image ===
26 // Many different hues. Should be lower harmony.
27 let img_chaos: *Image = nx_image_alloc(16, 16, 3)
28 var y2: i64 = 0
29 while y2 < 16 {
30 var x2: i64 = 0
31 while x2 < 16 {
32 // Vary RGB to hit many hues
33 nx_image_set(img_chaos, x2, y2, 0, (x2 * 16) - (x2 * 16 / 256) * 256)
34 nx_image_set(img_chaos, x2, y2, 1, (y2 * 16) - (y2 * 16 / 256) * 256)
35 nx_image_set(img_chaos, x2, y2, 2, ((x2 + y2) * 8) - ((x2 + y2) * 8 / 256) * 256)
36 x2 = x2 + 1
37 }
38 y2 = y2 + 1
39 }
40 let h_chaos: i64 = nx_aesthetics_color_harmony(img_chaos)
41 if h_chaos >= h_red { return 2 } // chaos LESS harmonious than monochrome
42
43 // === Test 3: lighting quality on a good image (mean=128, range=255) ===
44 let img_good: *Image = nx_image_alloc(16, 16, 1)
45 var y3: i64 = 0
46 while y3 < 16 {
47 var x3: i64 = 0
48 while x3 < 16 {
49 // Gradient 0..255 across image
50 let v: i64 = (x3 * 16) + y3
51 nx_image_set(img_good, x3, y3, 0, v)
52 x3 = x3 + 1
53 }
54 y3 = y3 + 1
55 }
56 let lq_good: i64 = nx_aesthetics_lighting_quality(img_good)
57 if lq_good < 400 { return 10 } // good lighting > 400
58
59 // === Test 4: lighting quality on underexposed image ===
60 let img_dark: *Image = nx_image_alloc(16, 16, 1)
61 var y4: i64 = 0
62 while y4 < 16 {
63 var x4: i64 = 0
64 while x4 < 16 {
65 nx_image_set(img_dark, x4, y4, 0, 5)
66 x4 = x4 + 1
67 }
68 y4 = y4 + 1
69 }
70 let lq_dark: i64 = nx_aesthetics_lighting_quality(img_dark)
71 if lq_dark >= lq_good { return 11 } // dark worse than good
72 if lq_dark > 300 { return 12 } // dark should be poor
73
74 // === Test 5: sharpness on uniform = 0 ===
75 let img_uni: *Image = nx_image_alloc(16, 16, 1)
76 var y5: i64 = 0
77 while y5 < 16 {
78 var x5: i64 = 0
79 while x5 < 16 {
80 nx_image_set(img_uni, x5, y5, 0, 128)
81 x5 = x5 + 1
82 }
83 y5 = y5 + 1
84 }
85 if nx_aesthetics_sharpness(img_uni) != 0 { return 20 }
86
87 // === Test 6: sharpness on edge image > 0 ===
88 let img_edge: *Image = nx_image_alloc(16, 16, 1)
89 var y6: i64 = 0
90 while y6 < 16 {
91 var x6: i64 = 0
92 while x6 < 16 {
93 var v: i64 = 0
94 if x6 >= 8 { v = 255 }
95 nx_image_set(img_edge, x6, y6, 0, v)
96 x6 = x6 + 1
97 }
98 y6 = y6 + 1
99 }
100 let sh_edge: i64 = nx_aesthetics_sharpness(img_edge)
101 if sh_edge <= 0 { return 21 }
102
103 // === Test 7: full composite on a "good" image ===
104 // gradient image with chromatic red overlay
105 let rgb_good: *Image = nx_image_alloc(16, 16, 3)
106 let gray_good: *Image = nx_image_alloc(16, 16, 1)
107 var y7: i64 = 0
108 while y7 < 16 {
109 var x7: i64 = 0
110 while x7 < 16 {
111 let v: i64 = (x7 * 16) + y7
112 nx_image_set(rgb_good, x7, y7, 0, v)
113 nx_image_set(rgb_good, x7, y7, 1, v / 2)
114 nx_image_set(rgb_good, x7, y7, 2, v / 4)
115 nx_image_set(gray_good, x7, y7, 0, v)
116 x7 = x7 + 1
117 }
118 y7 = y7 + 1
119 }
120 let report: *AestheticsReport = (sys_mmap(48)) as *AestheticsReport
121 nx_aesthetics_compute(rgb_good, gray_good, report)
122 // All five components in [0, 1024]
123 if report.color_harmony < 0 { return 30 }
124 if report.color_harmony > 1024 { return 31 }
125 if report.lighting_quality < 0 { return 32 }
126 if report.lighting_quality > 1024 { return 33 }
127 if report.composition < 0 { return 34 }
128 if report.composition > 1024 { return 35 }
129 if report.subject_clarity < 0 { return 36 }
130 if report.subject_clarity > 1024 { return 37 }
131 if report.sharpness < 0 { return 38 }
132 if report.sharpness > 1024 { return 39 }
133 if report.composite < 0 { return 40 }
134 if report.composite > 1024 { return 41 }
135 // Sanity: composite should be the mean of the five.
136 let expected: i64 = (
137 report.color_harmony +
138 report.lighting_quality +
139 report.composition +
140 report.subject_clarity +
141 report.sharpness
142 ) / 5
143 if report.composite != expected { return 42 }
144
145 return 0
146}