Debian Codegraph @

testsuite/gdk/colorstate-internal.c

raw symbols SCIP
1 #cxx . . $ `<file>/testsuite/gdk/colorstate-internal.c`/include <gdk/gdk.h>cxx . . $ `<file>/gdk/gdk.h`/
2 #include "gdkcolorstateprivate.h"cxx . . $ `<file>/gdk/gdkcolorstateprivate.h`/
3 #include "gdkcolorprivate.h"cxx . . $ `<file>/gdk/gdkcolorprivate.h`/
4 #include <math.h>
5
6 #include "gdkcolordefs.h"cxx . . $ `<file>/gdk/gdkcolordefs.h`/
7
8 typedef float (* TransferFunccxx . . $ TransferFunc#) (float v);
9
10 typedef structcxx . . $ $anonymous_type_d5da46d8536681c8_0#
11 {
12 const char *namecxx . . $ $anonymous_type_d5da46d8536681c8_0#name.;
13 TransferFunccxx . . $ TransferFunc# oetfcxx . . $ $anonymous_type_d5da46d8536681c8_0#oetf.;
14 TransferFunccxx . . $ TransferFunc# eotfcxx . . $ $anonymous_type_d5da46d8536681c8_0#eotf.;
15 float o_rangecxx . . $ $anonymous_type_d5da46d8536681c8_0#o_range.[2];
16 float e_rangecxx . . $ $anonymous_type_d5da46d8536681c8_0#e_range.[2];
17 } TransferTestcxx . . $ TransferTest#;
18
19 TransferTestcxx . . $ TransferTest# transferscxx . . $ transfers.[] = {
20 { "srgb", srgb_oetfcxx . . $ srgb_oetf(fbcf3211dfe1bfd1)., srgb_eotfcxx . . $ srgb_eotf(fbcf3211dfe1bfd1)., { 0, 1 }, { 0, 1} },
21 { "pq", pq_oetfcxx . . $ pq_oetf(fbcf3211dfe1bfd1)., pq_eotfcxx . . $ pq_eotf(fbcf3211dfe1bfd1)., { 0, 49.2610855 }, { 0, 1 } },
22 { "bt709", bt709_oetfcxx . . $ bt709_oetf(fbcf3211dfe1bfd1)., bt709_eotfcxx . . $ bt709_eotf(fbcf3211dfe1bfd1)., { 0, 1 }, { 0, 1 } },
23 { "hlg", hlg_oetfcxx . . $ hlg_oetf(fbcf3211dfe1bfd1)., hlg_eotfcxx . . $ hlg_eotf(fbcf3211dfe1bfd1)., { 0, 1}, { 0, 1} },
24 { "gamma22", gamma22_oetfcxx . . $ gamma22_oetf(fbcf3211dfe1bfd1)., gamma22_eotfcxx . . $ gamma22_eotf(fbcf3211dfe1bfd1)., { 0, 1 }, { 0, 1 } },
25 { "gamma28", gamma28_oetfcxx . . $ gamma28_oetf(fbcf3211dfe1bfd1)., gamma28_eotfcxx . . $ gamma28_eotf(fbcf3211dfe1bfd1)., { 0, 1 }, { 0, 1 } },
26 { "oklab", to_oklab_nlcxx . . $ to_oklab_nl(fbcf3211dfe1bfd1)., from_oklab_nlcxx . . $ from_oklab_nl(fbcf3211dfe1bfd1).,{ 0, 1 }, { 0, 1 } },
27 };
28
29 #define LERPcxx . . $ `testsuite/gdk/colorstate-internal.c:29:9`!(t, a, b) ((a) + (t) * ((b) - (a)))
30
31 #define ASSERT_IN_RANGEcxx . . $ `testsuite/gdk/colorstate-internal.c:31:9`!(v, a, b, epsilon) \
32 g_assert_cmpfloat_with_epsiloncxx . . $ `<external>/15287032793271088244/gtestutils.h:97:9`! (MINcxx . . $ `<external>/12741050725406041920/gmacros.h:978:9`!(v,a), a, epsilon); \
33 g_assert_cmpfloat_with_epsiloncxx . . $ `<external>/15287032793271088244/gtestutils.h:97:9`! (MAXcxx . . $ `<external>/12741050725406041920/gmacros.h:975:9`!(v,b), b, epsilon); \
34
35 static void
36 test_transfercxx . . $ test_transfer(e4289f82fef2c2f9). (gconstpointercxx . . $ gconstpointer# data)
37 {
38 TransferTestcxx . . $ TransferTest# *transfer = (TransferTestcxx . . $ TransferTest# *) data;
39 float v, v1, v2;
40
41 for (int i = 0; i < 1001; i++)
42 {
43 v = LERPcxx . . $ `testsuite/gdk/colorstate-internal.c:29:9`! (i/1000.0, transfer->e_range[0], transfer->e_range[1]);
44
45 v1 = transfer->eotfcxx . . $ $anonymous_type_d5da46d8536681c8_0#eotf. (v);
46
47 ASSERT_IN_RANGEcxx . . $ `testsuite/gdk/colorstate-internal.c:31:9`! (v1, transfer->o_range[0], transfer->o_range[1], 0.0001);
48
49 v2 = transfer->oetfcxx . . $ $anonymous_type_d5da46d8536681c8_0#oetf. (v1);
50
51 g_assert_cmpfloat_with_epsiloncxx . . $ `<external>/15287032793271088244/gtestutils.h:97:9`! (v, v2, 0.05);
52 }
53
54 for (int i = 0; i < 1001; i++)
55 {
56 v = LERPcxx . . $ `testsuite/gdk/colorstate-internal.c:29:9`! (i/1000.0, transfer->o_range[0], transfer->o_range[1]);
57
58 v1 = transfer->oetfcxx . . $ $anonymous_type_d5da46d8536681c8_0#oetf. (v);
59
60 ASSERT_IN_RANGEcxx . . $ `testsuite/gdk/colorstate-internal.c:31:9`! (v1, transfer->e_range[0], transfer->e_range[1], 0.0001);
61
62 v2 = transfer->eotfcxx . . $ $anonymous_type_d5da46d8536681c8_0#eotf. (v1);
63
64 g_assert_cmpfloat_with_epsiloncxx . . $ `<external>/15287032793271088244/gtestutils.h:97:9`! (v, v2, 0.05);
65 }
66 }
67
68 static void
69 test_transfer_symmetrycxx . . $ test_transfer_symmetry(e4289f82fef2c2f9). (gconstpointercxx . . $ gconstpointer# data)
70 {
71 TransferTestcxx . . $ TransferTest# *transfer = (TransferTestcxx . . $ TransferTest# *) data;
72 float v, v1, v2;
73
74 for (int i = 0; i < 11; i++)
75 {
76 v = LERPcxx . . $ `testsuite/gdk/colorstate-internal.c:29:9`! (i/10.0, transfer->e_range[0], transfer->e_range[1]);
77
78 v1 = transfer->eotfcxx . . $ $anonymous_type_d5da46d8536681c8_0#eotf. (v);
79 v2 = -transfer->eotfcxx . . $ $anonymous_type_d5da46d8536681c8_0#eotf. (-v);
80
81 g_assert_cmpfloat_with_epsiloncxx . . $ `<external>/15287032793271088244/gtestutils.h:97:9`! (v1, v2, 0.05);
82 }
83
84 for (int i = 0; i < 11; i++)
85 {
86 v = LERPcxx . . $ `testsuite/gdk/colorstate-internal.c:29:9`! (i/10.0, transfer->o_range[0], transfer->o_range[1]);
87
88 v1 = transfer->oetfcxx . . $ $anonymous_type_d5da46d8536681c8_0#oetf. (v);
89 v2 = -transfer->oetfcxx . . $ $anonymous_type_d5da46d8536681c8_0#oetf. (-v);
90
91 g_assert_cmpfloat_with_epsiloncxx . . $ `<external>/15287032793271088244/gtestutils.h:97:9`! (v1, v2, 0.05);
92 }
93 }
94 typedef structcxx . . $ $anonymous_type_d5da46d8536681c8_1#
95 {
96 const char *namecxx . . $ $anonymous_type_d5da46d8536681c8_1#name.;
97 const float *to_xyzcxx . . $ $anonymous_type_d5da46d8536681c8_1#to_xyz.;
98 const float *from_xyzcxx . . $ $anonymous_type_d5da46d8536681c8_1#from_xyz.;
99 } MatrixTestcxx . . $ MatrixTest#;
100 static MatrixTestcxx . . $ MatrixTest# matricescxx . . $ matrices.[] = {
101 { "srgb", srgb_to_xyzcxx . . $ srgb_to_xyz., xyz_to_srgbcxx . . $ xyz_to_srgb. },
102 { "rec2020", rec2020_to_xyzcxx . . $ rec2020_to_xyz., xyz_to_rec2020cxx . . $ xyz_to_rec2020. },
103 { "pal", pal_to_xyzcxx . . $ pal_to_xyz., xyz_to_palcxx . . $ xyz_to_pal. },
104 { "ntsc", ntsc_to_xyzcxx . . $ ntsc_to_xyz., xyz_to_ntsccxx . . $ xyz_to_ntsc. },
105 { "p3", p3_to_xyzcxx . . $ p3_to_xyz., xyz_to_p3cxx . . $ xyz_to_p3. },
106 { "srgb<>rec2020", rec2020_to_srgbcxx . . $ rec2020_to_srgb., srgb_to_rec2020cxx . . $ srgb_to_rec2020. },
107 { "oklab<>lms", oklab_to_lmscxx . . $ oklab_to_lms., lms_to_oklabcxx . . $ lms_to_oklab. },
108 { "lms<>srgb", lms_to_srgbcxx . . $ lms_to_srgb., srgb_to_lmscxx . . $ srgb_to_lms. },
109 { "bt601", bt601_to_rgbcxx . . $ bt601_to_rgb., rgb_to_bt601cxx . . $ rgb_to_bt601. },
110 { "bt709", bt709_to_rgbcxx . . $ bt709_to_rgb., rgb_to_bt709cxx . . $ rgb_to_bt709. },
111 { "bt2020", bt2020_to_rgbcxx . . $ bt2020_to_rgb., rgb_to_bt2020cxx . . $ rgb_to_bt2020. },
112 };
113
114 #define IDXcxx . . $ `testsuite/gdk/colorstate-internal.c:114:9`!(i,j) 3*i+j
115 static inline void
116 multiplycxx . . $ multiply(b1a62cf36a497246). (float res[9],
117 const float m1[9],
118 const float m2[9])
119 {
120 for (int i = 0; i < 3; i++)
121 for (int j = 0; j < 3; j++)
122 res[IDXcxx . . $ `testsuite/gdk/colorstate-internal.c:114:9`!(i,j)] = m1[IDXcxx . . $ `testsuite/gdk/colorstate-internal.c:114:9`!(i,0)] * m2[IDXcxx . . $ `testsuite/gdk/colorstate-internal.c:114:9`!(0,j)]
123 + m1[IDXcxx . . $ `testsuite/gdk/colorstate-internal.c:114:9`!(i,1)] * m2[IDXcxx . . $ `testsuite/gdk/colorstate-internal.c:114:9`!(1,j)]
124 + m1[IDXcxx . . $ `testsuite/gdk/colorstate-internal.c:114:9`!(i,2)] * m2[IDXcxx . . $ `testsuite/gdk/colorstate-internal.c:114:9`!(2,j)];
125 }
126
127 static inline void
128 differencecxx . . $ difference(b1a62cf36a497246). (float res[9],
129 const float m1[9],
130 const float m2[9])
131 {
132 for (int i = 0; i < 9; i++)
133 res[i] = m1[i] - m2[i];
134 }
135
136 static float
137 normcxx . . $ norm(bdb257eee332afa4). (const float m[9])
138 {
139 float sum = 0;
140
141 for (int i = 0; i < 9; i++)
142 sum += m[i] * m[i];
143
144 return sqrtf (sum);
145 }
146
147 static void
148 print_matrixcxx . . $ print_matrix(de58861cad56015a). (const float m[9])
149 {
150 g_printcxx . . $ g_print(326aeb464d16410c). ("%f %f %f\n%f %f %f\n%f %f %f\n",
151 m[0], m[1], m[2],
152 m[3], m[4], m[5],
153 m[6], m[7], m[8]);
154 }
155
156 static void
157 test_matrixcxx . . $ test_matrix(e4289f82fef2c2f9). (gconstpointercxx . . $ gconstpointer# data)
158 {
159 MatrixTestcxx . . $ MatrixTest# *matrix = (MatrixTestcxx . . $ MatrixTest# *) data;
160 float res[9];
161 float res2[9];
162
163 multiplycxx . . $ multiply(b1a62cf36a497246). (res, matrix->to_xyzcxx . . $ $anonymous_type_d5da46d8536681c8_1#to_xyz., matrix->from_xyzcxx . . $ $anonymous_type_d5da46d8536681c8_1#from_xyz.);
164
165 if (g_test_verbosecxx . . $ `<external>/15287032793271088244/gtestutils.h:388:9`! ())
166 print_matrixcxx . . $ print_matrix(de58861cad56015a). (res);
167
168 differencecxx . . $ difference(b1a62cf36a497246). (res2, res, identitycxx . . $ identity.);
169
170 if (g_test_verbosecxx . . $ `<external>/15287032793271088244/gtestutils.h:388:9`! ())
171 g_printcxx . . $ g_print(326aeb464d16410c). ("distance: %f\n", normcxx . . $ norm(bdb257eee332afa4). (res2));
172
173 g_assert_cmpfloat_with_epsiloncxx . . $ `<external>/15287032793271088244/gtestutils.h:97:9`! (norm (res2), 0, 0.001);
174 }
175
176 static void
177 test_srgb_to_rec2020cxx . . $ test_srgb_to_rec2020(49f6e7a06ebc5aa8). (void)
178 {
179 float m[9], res[9];
180
181 multiplycxx . . $ multiply(b1a62cf36a497246). (m, xyz_to_rec2020cxx . . $ xyz_to_rec2020., srgb_to_xyzcxx . . $ srgb_to_xyz.);
182 differencecxx . . $ difference(b1a62cf36a497246). (res, m, srgb_to_rec2020cxx . . $ srgb_to_rec2020.);
183
184 g_assert_cmpfloat_with_epsiloncxx . . $ `<external>/15287032793271088244/gtestutils.h:97:9`! (norm (res), 0, 0.001);
185 }
186
187 static void
188 test_rec2020_to_srgbcxx . . $ test_rec2020_to_srgb(49f6e7a06ebc5aa8). (void)
189 {
190 float m[9], res[9];
191
192 multiplycxx . . $ multiply(b1a62cf36a497246). (m, xyz_to_srgbcxx . . $ xyz_to_srgb., rec2020_to_xyzcxx . . $ rec2020_to_xyz.);
193 differencecxx . . $ difference(b1a62cf36a497246). (res, m, rec2020_to_srgbcxx . . $ rec2020_to_srgb.);
194
195 g_assert_cmpfloat_with_epsiloncxx . . $ `<external>/15287032793271088244/gtestutils.h:97:9`! (norm (res), 0, 0.001);
196 }
197
198 /* Verify that this color is different enough in srgb-linear and srgb
199 * to be detected.
200 */
201 static void
202 test_color_mislabelcxx . . $ test_color_mislabel(49f6e7a06ebc5aa8). (void)
203 {
204 GdkColorcxx . . $ GdkColor# color;
205 GdkColorcxx . . $ GdkColor# color1;
206 GdkColorcxx . . $ GdkColor# color2;
207 guintcxx . . $ guint# red1, red2;
208
209 gdk_color_initcxx . . $ `gdk/gdkcolorimpl.h:26:9`! (&color, gdk_color_state_get_srgb_linear (), (float[]) { 0.604, 0, 0, 1 });
210 gdk_color_convertcxx . . $ `gdk/gdkcolorimpl.h:93:9`! (&color1, gdk_color_state_get_srgb (), &color);
211 gdk_color_initcxx . . $ `gdk/gdkcolorimpl.h:26:9`! (&color2, gdk_color_state_get_srgb (), (float[]) { 0.604, 0, 0, 1 });
212
213 g_assert_truecxx . . $ `<external>/15287032793271088244/gtestutils.h:227:9`! (!gdk_color_equalcxx . . $ `gdk/gdkcolorimpl.h:67:9`! (&color1, &color2));
214
215 red1 = round (color1.redcxx . . $ _GdkColor#$anonymous_type_0#$anonymous_type_2#red. * 255.0);
216 red2 = round (color2.redcxx . . $ _GdkColor#$anonymous_type_0#$anonymous_type_2#red. * 255.0);
217
218 g_assert_truecxx . . $ `<external>/15287032793271088244/gtestutils.h:227:9`! (red1 != red2);
219 }
220
221 int
222 maincxx . . $ main(afcd3168fc1188a4). (int argc, char *argv[])
223 {
224 (g_test_initcxx . . $ g_test_init(b91bcc5cc1349d78).) (&argc, &argv, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
225
226 for (guintcxx . . $ guint# i = 0; i < G_N_ELEMENTScxx . . $ `<external>/12741050725406041920/gmacros.h:993:9`! (transfers); i++)
227 {
228 TransferTestcxx . . $ TransferTest# *test = &transferscxx . . $ transfers.[i];
229 char *path = g_strdup_printfcxx . . $ g_strdup_printf(a849077ff1b8d812). ("/colorstate/transfer/%s", test->namecxx . . $ $anonymous_type_d5da46d8536681c8_0#name.);
230 g_test_add_data_funccxx . . $ g_test_add_data_func(a7326f7e8f3610af). (path, test, test_transfercxx . . $ test_transfer(e4289f82fef2c2f9).);
231 g_freecxx . . $ g_free(5d22bdacc48458e8). (path);
232 }
233
234 for (guintcxx . . $ guint# i = 0; i < G_N_ELEMENTScxx . . $ `<external>/12741050725406041920/gmacros.h:993:9`! (transfers); i++)
235 {
236 TransferTestcxx . . $ TransferTest# *test = &transferscxx . . $ transfers.[i];
237 char *path = g_strdup_printfcxx . . $ g_strdup_printf(a849077ff1b8d812). ("/colorstate/transfer-symmetry/%s", test->namecxx . . $ $anonymous_type_d5da46d8536681c8_0#name.);
238 g_test_add_data_funccxx . . $ g_test_add_data_func(a7326f7e8f3610af). (path, test, test_transfer_symmetrycxx . . $ test_transfer_symmetry(e4289f82fef2c2f9).);
239 g_freecxx . . $ g_free(5d22bdacc48458e8). (path);
240 }
241
242 for (guintcxx . . $ guint# i = 0; i < G_N_ELEMENTScxx . . $ `<external>/12741050725406041920/gmacros.h:993:9`! (matrices); i++)
243 {
244 MatrixTestcxx . . $ MatrixTest# *test = &matricescxx . . $ matrices.[i];
245 char *path = g_strdup_printfcxx . . $ g_strdup_printf(a849077ff1b8d812). ("/colorstate/matrix/%s", test->namecxx . . $ $anonymous_type_d5da46d8536681c8_1#name.);
246 g_test_add_data_funccxx . . $ g_test_add_data_func(a7326f7e8f3610af). (path, test, test_matrixcxx . . $ test_matrix(e4289f82fef2c2f9).);
247 g_freecxx . . $ g_free(5d22bdacc48458e8). (path);
248 }
249
250 g_test_add_funccxx . . $ g_test_add_func(18fee6cbb4bb18a4). ("/colorstate/matrix/srgb_to_rec2020", test_srgb_to_rec2020cxx . . $ test_srgb_to_rec2020(49f6e7a06ebc5aa8).);
251 g_test_add_funccxx . . $ g_test_add_func(18fee6cbb4bb18a4). ("/colorstate/matrix/rec2020_to_srgb", test_rec2020_to_srgbcxx . . $ test_rec2020_to_srgb(49f6e7a06ebc5aa8).);
252 g_test_add_funccxx . . $ g_test_add_func(18fee6cbb4bb18a4). ("/color/mislabel", test_color_mislabelcxx . . $ test_color_mislabel(49f6e7a06ebc5aa8).);
253
254 return g_test_runcxx . . $ g_test_run(b126dc7c1de90089). ();
255 }