Debian Codegraph @

gtk/gtkcolorutils.c

raw symbols SCIP
1 /* Color utilities
2 *
3 * Copyright (C) 1999 The Free Software Foundation
4 *
5 * Authors: Simon Budig <[email protected]> (original code)
6 * Federico Mena-Quintero <[email protected]> (cleanup for GTK+)
7 * Jonathan Blandford <[email protected]> (cleanup for GTK+)
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23 /*
24 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
25 * file for a list of people on the GTK+ Team. See the ChangeLog
26 * files for a list of changes. These files are distributed with
27 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
28 */
29
30 #include "config.h"cxx . . $ `<file>/build/config.h`/
31
32 #include <math.h>
33 #include <string.h>
34
35 #include "gtkcolorutilsprivate.h"cxx . . $ `<file>/gtk/gtkcolorutilsprivate.h`/
36 #include "gdkhslaprivate.h"cxx . . $ `<file>/gdk/gdkhslaprivate.h`/
37 #include <math.h>
38
39 /* Converts from RGB to HSV */
40 static void
41 rgb_to_hsvcxx . . $ rgb_to_hsv(c003fa00de8cf887). (float *r,
42 float *g,
43 float *b)
44 {
45 float red, green, blue;
46 float h, s, v;
47 float min, max;
48 float delta;
49
50 red = *r;
51 green = *g;
52 blue = *b;
53
54 h = 0.0;
55
56 if (red > green)
57 {
58 if (red > blue)
59 max = red;
60 else
61 max = blue;
62
63 if (green < blue)
64 min = green;
65 else
66 min = blue;
67 }
68 else
69 {
70 if (green > blue)
71 max = green;
72 else
73 max = blue;
74
75 if (red < blue)
76 min = red;
77 else
78 min = blue;
79 }
80
81 v = max;
82
83 if (max != 0.0)
84 s = (max - min) / max;
85 else
86 s = 0.0;
87
88 if (s == 0.0)
89 h = 0.0;
90 else
91 {
92 delta = max - min;
93
94 if (red == max)
95 h = (green - blue) / delta;
96 else if (green == max)
97 h = 2 + (blue - red) / delta;
98 else if (blue == max)
99 h = 4 + (red - green) / delta;
100
101 h /= 6.0;
102
103 if (h < 0.0)
104 h += 1.0;
105 else if (h > 1.0)
106 h -= 1.0;
107 }
108
109 *r = h;
110 *g = s;
111 *b = v;
112 }
113
114 /**
115 * gtk_hsv_to_rgb:
116 * @h: Hue
117 * @s: Saturation
118 * @v: Value
119 * @r: (out): Return value for the red component
120 * @g: (out): Return value for the green component
121 * @b: (out): Return value for the blue component
122 *
123 * Converts a color from HSV space to RGB.
124 *
125 * Input values must be in the [0.0, 1.0] range;
126 * output values will be in the same range.
127 */
128 void
129 gtk_hsv_to_rgbcxx . . $ gtk_hsv_to_rgb(7348b25d00bc3e4f). (float h, float s, float v,
130 float *r, float *g, float *b)
131 {
132 float hue;
133 float f, p;
134 int ihue;
135
136 g_return_if_failcxx . . $ `<external>/5169755362661750954/gmessages.h:652:9`! (h >= 0.0 && h <= 1.0);
137 g_return_if_failcxx . . $ `<external>/5169755362661750954/gmessages.h:652:9`! (s >= 0.0 && s <= 1.0);
138 g_return_if_failcxx . . $ `<external>/5169755362661750954/gmessages.h:652:9`! (v >= 0.0 && v <= 1.0);
139 g_return_if_failcxx . . $ `<external>/5169755362661750954/gmessages.h:652:9`! (r);
140 g_return_if_failcxx . . $ `<external>/5169755362661750954/gmessages.h:652:9`! (g);
141 g_return_if_failcxx . . $ `<external>/5169755362661750954/gmessages.h:652:9`! (b);
142
143 if (s == 0.0)
144 {
145 *r = v;
146 *g = v;
147 *b = v;
148 return;
149 }
150
151 hue = h * 6.0;
152
153 if (hue == 6.0)
154 hue = 0.0;
155
156 ihue = (int)hue;
157 f = hue - ihue;
158 p = v * (1.0 - s);
159
160 if (ihue == 0)
161 {
162 *r = v;
163 *g = v * (1.0 - s * (1.0 - f));
164 *b = p;
165 }
166 else if (ihue == 1)
167 {
168 *r = v * (1.0 - s * f);
169 *g = v;
170 *b = p;
171 }
172 else if (ihue == 2)
173 {
174 *r = p;
175 *g = v;
176 *b = v * (1.0 - s * (1.0 - f));
177 }
178 else if (ihue == 3)
179 {
180 *r = p;
181 *g = v * (1.0 - s * f);
182 *b = v;
183 }
184 else if (ihue == 4)
185 {
186 *r = v * (1.0 - s * (1.0 - f));
187 *g = p;
188 *b = v;
189 }
190 else if (ihue == 5)
191 {
192 *r = v;
193 *g = p;
194 *b = v * (1.0 - s * f);
195 }
196 }
197
198 /**
199 * gtk_rgb_to_hsv:
200 * @r: Red
201 * @g: Green
202 * @b: Blue
203 * @h: (out): Return value for the hue component
204 * @s: (out): Return value for the saturation component
205 * @v: (out): Return value for the value component
206 *
207 * Converts a color from RGB space to HSV.
208 *
209 * Input values must be in the [0.0, 1.0] range;
210 * output values will be in the same range.
211 */
212 void
213 gtk_rgb_to_hsvcxx . . $ gtk_rgb_to_hsv(7348b25d00bc3e4f). (float r, float g, float b,
214 float *h, float *s, float *v)
215 {
216 g_return_if_failcxx . . $ `<external>/5169755362661750954/gmessages.h:652:9`! (r >= 0.0 && r <= 1.0);
217 g_return_if_failcxx . . $ `<external>/5169755362661750954/gmessages.h:652:9`! (g >= 0.0 && g <= 1.0);
218 g_return_if_failcxx . . $ `<external>/5169755362661750954/gmessages.h:652:9`! (b >= 0.0 && b <= 1.0);
219
220 rgb_to_hsvcxx . . $ rgb_to_hsv(c003fa00de8cf887). (&r, &g, &b);
221
222 if (h)
223 *h = r;
224
225 if (s)
226 *s = g;
227
228 if (v)
229 *v = b;
230 }
231
232 void
233 gtk_rgb_to_hslcxx . . $ gtk_rgb_to_hsl(7348b25d00bc3e4f). (float red, float green, float blue,
234 float *hue, float *saturation, float *lightness)
235 {
236 GdkHSLAcxx . . $ GdkHSLA# hsla;
237
238 _gdk_hsla_init_from_rgbacxx . . $ _gdk_hsla_init_from_rgba(7d66a32a373782a7). (&hsla, &(GdkRGBAcxx . . $ GdkRGBA#) { red, green, blue, 1.0 });
239
240 *hue = hsla.huecxx . . $ _GdkHSLA#hue.;
241 *saturation = hsla.saturationcxx . . $ _GdkHSLA#saturation.;
242 *lightness = hsla.lightnesscxx . . $ _GdkHSLA#lightness.;
243 }
244
245 void
246 gtk_hsl_to_rgbcxx . . $ gtk_hsl_to_rgb(7348b25d00bc3e4f). (float hue, float saturation, float lightness,
247 float *red, float *green, float *blue)
248 {
249 GdkRGBAcxx . . $ GdkRGBA# rgba;
250
251 _gdk_rgba_init_from_hslacxx . . $ _gdk_rgba_init_from_hsla(b072ddcf0f286f14). (&rgba, &(GdkHSLAcxx . . $ GdkHSLA#) { hue, saturation, lightness, 1.0 });
252
253 *red = rgba.redcxx . . $ _GdkRGBA#red.;
254 *green = rgba.greencxx . . $ _GdkRGBA#green.;
255 *blue = rgba.bluecxx . . $ _GdkRGBA#blue.;
256 }
257
258 void
259 gtk_rgb_to_hwbcxx . . $ gtk_rgb_to_hwb(7348b25d00bc3e4f). (float red, float green, float blue,
260 float *hue, float *white, float *black)
261 {
262 GdkRGBAcxx . . $ GdkRGBA# rgba = (GdkRGBAcxx . . $ GdkRGBA#) { red, green, blue, 1 };
263 GdkHSLAcxx . . $ GdkHSLA# hsla;
264
265 _gdk_hsla_init_from_rgbacxx . . $ _gdk_hsla_init_from_rgba(7d66a32a373782a7). (&hsla, &rgba);
266
267 *hue = hsla.huecxx . . $ _GdkHSLA#hue.;
268 *white = MINcxx . . $ `<external>/12741050725406041920/gmacros.h:978:9`! (MINcxx . . $ `<external>/12741050725406041920/gmacros.h:978:9`! (red, green), blue);
269 *black = (1 - MAXcxx . . $ `<external>/12741050725406041920/gmacros.h:975:9`! (MAXcxx . . $ `<external>/12741050725406041920/gmacros.h:975:9`! (red, green), blue));
270 }
271
272 void
273 gtk_hwb_to_rgbcxx . . $ gtk_hwb_to_rgb(7348b25d00bc3e4f). (float hue, float white, float black,
274 float *red, float *green, float *blue)
275 {
276 GdkHSLAcxx . . $ GdkHSLA# hsla;
277 GdkRGBAcxx . . $ GdkRGBA# rgba;
278
279 if (white + black >= 1)
280 {
281 float gray = white / (white + black);
282
283 *red = gray;
284 *green = gray;
285 *blue = gray;
286
287 return;
288 }
289
290 hsla.huecxx . . $ _GdkHSLA#hue. = hue;
291 hsla.saturationcxx . . $ _GdkHSLA#saturation. = 1.0;
292 hsla.lightnesscxx . . $ _GdkHSLA#lightness. = 0.5;
293
294 _gdk_rgba_init_from_hslacxx . . $ _gdk_rgba_init_from_hsla(b072ddcf0f286f14). (&rgba, &hsla);
295
296 *red = rgba.redcxx . . $ _GdkRGBA#red. * (1 - white - black) + white;
297 *green = rgba.greencxx . . $ _GdkRGBA#green. * (1 - white - black) + white;
298 *blue = rgba.bluecxx . . $ _GdkRGBA#blue. * (1 - white - black) + white;
299 }
300
301 #define DEG_TO_RADcxx . . $ `gtk/gtkcolorutils.c:301:9`!(x) ((x) * G_PIcxx . . $ `<external>/10787549987161854489/gtypes.h:201:9`! / 180)
302 #define RAD_TO_DEGcxx . . $ `gtk/gtkcolorutils.c:302:9`!(x) ((x) * 180 / G_PIcxx . . $ `<external>/10787549987161854489/gtypes.h:201:9`!)
303
304 static inline void
305 _sincosfcxx . . $ _sincosf(118562ebef133905). (float angle,
306 float *out_s,
307 float *out_c)
308 {
309 #ifdef HAVE_SINCOSFcxx . . $ `build/config.h:80:9`!
310 sincosf (angle, out_s, out_c);
311 #else
312 *out_s = sinf (angle);
313 *out_c = cosf (angle);
314 #endif
315 }
316
317 void
318 gtk_oklab_to_oklchcxx . . $ gtk_oklab_to_oklch(7348b25d00bc3e4f). (float L, float a, float b,
319 float *L2, float *C, float *H)
320 {
321 *L2 = L;
322 *C = hypotf (a, b);
323 *H = RAD_TO_DEGcxx . . $ `gtk/gtkcolorutils.c:302:9`! (atan2 (b, a));
324 *H = fmod (*H, 360);
325 if (*H < 0)
326 *H += 360;
327 }
328
329 void
330 gtk_oklch_to_oklabcxx . . $ gtk_oklch_to_oklab(7348b25d00bc3e4f). (float L, float C, float H,
331 float *L2, float *a, float *b)
332 {
333 *L2 = L;
334 _sincosfcxx . . $ _sincosf(118562ebef133905). (DEG_TO_RADcxx . . $ `gtk/gtkcolorutils.c:301:9`! (H), b, a);
335 *a *= C;
336 *b *= C;
337 }
338
339 static float
340 apply_gammacxx . . $ apply_gamma(fbcf3211dfe1bfd1). (float v)
341 {
342 if (v > 0.0031308)
343 return 1.055 * pow (v, 1/2.4) - 0.055;
344 else
345 return 12.92 * v;
346 }
347
348 static float
349 unapply_gammacxx . . $ unapply_gamma(fbcf3211dfe1bfd1). (float v)
350 {
351 if (v >= 0.04045)
352 return pow (((v + 0.055)/(1 + 0.055)), 2.4);
353 else
354 return v / 12.92;
355 }
356
357 void
358 gtk_oklab_to_linear_srgbcxx . . $ gtk_oklab_to_linear_srgb(7348b25d00bc3e4f). (float L, float a, float b,
359 float *red, float *green, float *blue)
360 {
361 float l = L + 0.3963377774f * a + 0.2158037573f * b;
362 float m = L - 0.1055613458f * a - 0.0638541728f * b;
363 float s = L - 0.0894841775f * a - 1.2914855480f * b;
364
365 l = powf (l, 3);
366 m = powf (m, 3);
367 s = powf (s, 3);
368
369 *red = +4.0767416621f * l - 3.3077115913f * m + 0.2309699292f * s;
370 *green = -1.2684380046f * l + 2.6097574011f * m - 0.3413193965f * s;
371 *blue = -0.0041960863f * l - 0.7034186147f * m + 1.7076147010f * s;
372 }
373
374 void
375 gtk_oklab_to_rgbcxx . . $ gtk_oklab_to_rgb(7348b25d00bc3e4f). (float L, float a, float b,
376 float *red, float *green, float *blue)
377 {
378 float linear_red, linear_green, linear_blue;
379 gtk_oklab_to_linear_srgbcxx . . $ gtk_oklab_to_linear_srgb(7348b25d00bc3e4f). (L, a, b, &linear_red, &linear_green, &linear_blue);
380 gtk_linear_srgb_to_rgbcxx . . $ gtk_linear_srgb_to_rgb(7348b25d00bc3e4f). (linear_red, linear_green, linear_blue, red, green, blue);
381 }
382
383 void
384 gtk_linear_srgb_to_oklabcxx . . $ gtk_linear_srgb_to_oklab(7348b25d00bc3e4f). (float red, float green, float blue,
385 float *L, float *a, float *b)
386 {
387 float l = 0.4122214708f * red + 0.5363325363f * green + 0.0514459929f * blue;
388 float m = 0.2119034982f * red + 0.6806995451f * green + 0.1073969566f * blue;
389 float s = 0.0883024619f * red + 0.2817188376f * green + 0.6299787005f * blue;
390
391 l = cbrtf (l);
392 m = cbrtf (m);
393 s = cbrtf (s);
394
395 *L = 0.2104542553f*l + 0.7936177850f*m - 0.0040720468f*s;
396 *a = 1.9779984951f*l - 2.4285922050f*m + 0.4505937099f*s;
397 *b = 0.0259040371f*l + 0.7827717662f*m - 0.8086757660f*s;
398 }
399
400 void
401 gtk_rgb_to_oklabcxx . . $ gtk_rgb_to_oklab(7348b25d00bc3e4f). (float red, float green, float blue,
402 float *L, float *a, float *b)
403 {
404 float linear_red, linear_green, linear_blue;
405 gtk_rgb_to_linear_srgbcxx . . $ gtk_rgb_to_linear_srgb(7348b25d00bc3e4f). (red, green, blue, &linear_red, &linear_green, &linear_blue);
406 gtk_linear_srgb_to_oklabcxx . . $ gtk_linear_srgb_to_oklab(7348b25d00bc3e4f). (linear_red, linear_green, linear_blue, L, a, b);
407 }
408
409 void
410 gtk_rgb_to_linear_srgbcxx . . $ gtk_rgb_to_linear_srgb(7348b25d00bc3e4f). (float red, float green, float blue,
411 float *linear_red, float *linear_green, float *linear_blue)
412 {
413 *linear_red = unapply_gammacxx . . $ unapply_gamma(fbcf3211dfe1bfd1). (red);
414 *linear_green = unapply_gammacxx . . $ unapply_gamma(fbcf3211dfe1bfd1). (green);
415 *linear_blue = unapply_gammacxx . . $ unapply_gamma(fbcf3211dfe1bfd1). (blue);
416 }
417
418 void
419 gtk_linear_srgb_to_rgbcxx . . $ gtk_linear_srgb_to_rgb(7348b25d00bc3e4f). (float linear_red, float linear_green, float linear_blue,
420 float *red, float *green, float *blue)
421 {
422 *red = apply_gammacxx . . $ apply_gamma(fbcf3211dfe1bfd1). (linear_red);
423 *green = apply_gammacxx . . $ apply_gamma(fbcf3211dfe1bfd1). (linear_green);
424 *blue = apply_gammacxx . . $ apply_gamma(fbcf3211dfe1bfd1). (linear_blue);
425 }
426
427 void
428 gtk_linear_srgb_to_xyzcxx . . $ gtk_linear_srgb_to_xyz(7348b25d00bc3e4f). (float r, float g, float b,
429 float *x, float *y, float *z)
430 {
431 *x = (506752.0 / 1228815.0) * r + (87881.0 / 245763.0) * g + (12673.0 / 70218.0) * b;
432 *y = (87098.0 / 409605.0) * r + (175762.0 / 245763.0) * g + (12673.0 / 175545.0) * b;
433 *z = ( 7918.0 / 409605.0) * r + (87881.0 / 737289.0) * g + (1001167.0 / 1053270.0) * b;
434 }
435
436 void
437 gtk_xyz_to_linear_srgbcxx . . $ gtk_xyz_to_linear_srgb(7348b25d00bc3e4f). (float x, float y, float z,
438 float *r, float *g, float *b)
439 {
440 *r = (12831.0 / 3959.0) * x - (329.0 / 214.0) * y - (1974.0 / 3959.0) * z;
441 *g = - (851781.0 / 878810.0) * x + (1648619.0 / 878810.0) * y + (36519.0 / 878810.0) * z;
442 *b = (705.0 / 12673.0) * x - (2585.0 / 12673.0) * y + (705.0 / 667.0) * z;
443 }
444
445 static void
446 gtk_lin_p3_to_xyzcxx . . $ gtk_lin_p3_to_xyz(7348b25d00bc3e4f). (float r, float g, float b,
447 float *x, float *y, float *z)
448 {
449 *x = (608311.0 / 1250200.0) * r + (189793.0 / 714400.0) * g + (198249.0 / 1000160.0) * b;
450 *y = (35783.0 / 156275.0) * r + (247089.0 / 357200.0) * g + (198249.0 / 2500400.0) * b;
451 *z = ( 0 / 1) * r + (32229.0 / 714400.0) * g + (5220557.0 / 5000800.0) * b;
452 }
453
454 static void
455 gtk_xyz_to_lin_p3cxx . . $ gtk_xyz_to_lin_p3(7348b25d00bc3e4f). (float x, float y, float z,
456 float *r, float *g, float *b)
457 {
458 *r = (446124.0 / 178915.0) * x - (333277.0 / 357830.0) * y - (72051.0 / 178915.0) * z;
459 *g = - (14852.0 / 17905.0) * x + (63121.0 / 35810.0) * y + (423.0 / 17905.0) * z;
460 *b = (11844.0 / 330415.0) * x - (50337.0 / 660830.0) * y + (316169.0 / 330415.0) * z;
461 }
462
463 void gtk_rgb_to_p3cxx . . $ gtk_rgb_to_p3(7348b25d00bc3e4f). (float red, float green, float blue,
464 float *pr, float *pg, float *pb)
465 {
466 float r, g, b;
467 float x, y, z;
468
469 gtk_rgb_to_linear_srgbcxx . . $ gtk_rgb_to_linear_srgb(7348b25d00bc3e4f). (red, green, blue, &r, &g, &b);
470 gtk_linear_srgb_to_xyzcxx . . $ gtk_linear_srgb_to_xyz(7348b25d00bc3e4f). (r, g, b, &x, &y, &z);
471 gtk_xyz_to_lin_p3cxx . . $ gtk_xyz_to_lin_p3(7348b25d00bc3e4f). (x, y, z, &r, &g, &b);
472 gtk_linear_srgb_to_rgbcxx . . $ gtk_linear_srgb_to_rgb(7348b25d00bc3e4f). (r, g, b, pr, pg, pb);
473 }
474
475 void
476 gtk_p3_to_rgbcxx . . $ gtk_p3_to_rgb(7348b25d00bc3e4f). (float pr, float pg, float pb,
477 float *red, float *green, float *blue)
478 {
479 float r, g, b;
480 float x, y, z;
481
482 gtk_rgb_to_linear_srgbcxx . . $ gtk_rgb_to_linear_srgb(7348b25d00bc3e4f). (pr, pg, pb, &r, &g, &b);
483 gtk_lin_p3_to_xyzcxx . . $ gtk_lin_p3_to_xyz(7348b25d00bc3e4f). (r, g, b, &x, &y, &z);
484 gtk_xyz_to_linear_srgbcxx . . $ gtk_xyz_to_linear_srgb(7348b25d00bc3e4f). (x, y, z, &r, &g, &b);
485 gtk_linear_srgb_to_rgbcxx . . $ gtk_linear_srgb_to_rgb(7348b25d00bc3e4f). (r, g, b, red, green, blue);
486 }
487
488 static inline float
489 linearize_onecxx . . $ linearize_one(fbcf3211dfe1bfd1). (float val)
490 {
491 float alpha = 1.09929682680944 ;
492 float beta = 0.018053968510807;
493
494 int sign = val < 0 ? -1 : 1;
495 float abs = fabs (val);
496
497 if (abs < beta * 4.5 )
498 return val / 4.5;
499 else
500 return sign * powf ((abs + alpha - 1) / alpha, 1.0 / 0.45);
501 }
502
503 void
504 gtk_rec2020_to_rec2020_linearcxx . . $ gtk_rec2020_to_rec2020_linear(7348b25d00bc3e4f). (float r, float g , float b,
505 float *rr, float *gg, float *bb)
506 {
507 *rr = linearize_onecxx . . $ linearize_one(fbcf3211dfe1bfd1). (r);
508 *gg = linearize_onecxx . . $ linearize_one(fbcf3211dfe1bfd1). (g);
509 *bb = linearize_onecxx . . $ linearize_one(fbcf3211dfe1bfd1). (b);
510 }
511
512 void
513 gtk_rec2020_linear_to_xyzcxx . . $ gtk_rec2020_linear_to_xyz(7348b25d00bc3e4f). (float r, float g, float b,
514 float *x, float *y, float *z)
515 {
516 *x = (63426534.0 / 99577255.0) * r + (20160776.0 / 139408157.0) * g + (47086771.0 / 278816314.0) * b;
517 *y = (26158966.0 / 99577255.0) * r + (472592308.0 / 697040785.0) * g + (8267143.0 / 139408157.0) * b;
518 *z = ( 0 / 1) * r + (19567812.0 / 697040785.0) * g + (295819943.0 / 278816314.0) * b;
519 }
520
521 void
522 gtk_rec2020_to_xyzcxx . . $ gtk_rec2020_to_xyz(7348b25d00bc3e4f). (float r, float g, float b,
523 float *x, float *y, float *z)
524 {
525 gtk_rec2020_to_rec2020_linearcxx . . $ gtk_rec2020_to_rec2020_linear(7348b25d00bc3e4f). (r, g, b, &r, &g, &b);
526 gtk_rec2020_linear_to_xyzcxx . . $ gtk_rec2020_linear_to_xyz(7348b25d00bc3e4f). (r, g, b, x, y, z);
527 }
528
529 static inline float
530 delinearize_onecxx . . $ delinearize_one(fbcf3211dfe1bfd1). (float val)
531 {
532 float alpha = 1.09929682680944;
533 float beta = 0.018053968510807;
534 int sign = val < 0 ? -1 : 1;
535 float abs = fabsf (val);
536
537 if (abs > beta)
538 return sign * (alpha * powf (abs, 0.45) - (alpha - 1));
539 else
540 return 4.5 * val;
541 }
542
543 void
544 gtk_rec2020_linear_to_rec2020cxx . . $ gtk_rec2020_linear_to_rec2020(7348b25d00bc3e4f). (float r, float g, float b,
545 float *rr, float *gg, float *bb)
546 {
547 *rr = delinearize_onecxx . . $ delinearize_one(fbcf3211dfe1bfd1). (r);
548 *gg = delinearize_onecxx . . $ delinearize_one(fbcf3211dfe1bfd1). (g);
549 *bb = delinearize_onecxx . . $ delinearize_one(fbcf3211dfe1bfd1). (b);
550 }
551
552 void
553 gtk_xyz_to_rec2020_linearcxx . . $ gtk_xyz_to_rec2020_linear(7348b25d00bc3e4f). (float x, float y, float z,
554 float *r, float *g, float *b)
555 {
556 *r = (30757411.0 / 17917100.0) * x - (6372589.0 / 17917100.0) * y - (4539589.0 / 17917100.0) * z;
557 *g = - (19765991.0 / 29648200.0) * x + (47925759.0 / 29648200.0) * y + (467509.0 / 29648200.0) *z;
558 *b = (792561.0 / 44930125.0) * x - (1921689.0 / 44930125.0) * y + (42328811.0 / 44930125.0) * z;
559 }
560
561 void
562 gtk_xyz_to_rec2020cxx . . $ gtk_xyz_to_rec2020(7348b25d00bc3e4f). (float x, float y, float z,
563 float *r, float *g, float *b)
564 {
565 gtk_xyz_to_rec2020_linearcxx . . $ gtk_xyz_to_rec2020_linear(7348b25d00bc3e4f). (x, y, z, r, g, b);
566 gtk_rec2020_linear_to_rec2020cxx . . $ gtk_rec2020_linear_to_rec2020(7348b25d00bc3e4f). (*r, *g, *b, r, g, b);
567 }
568
569 /* maps [0, 1] to [0, 70] */
570 static inline float
571 pq_to_linearcxx . . $ pq_to_linear(fbcf3211dfe1bfd1). (float v)
572 {
573 float ninv = (1 << 14) / 2610.0;
574 float minv = (1 << 5) / 2523.0;
575 float c1 = 3424.0 / (1 << 12);
576 float c2 = 2413.0 / (1 << 7);
577 float c3 = 2392.0 / (1 << 7);
578
579 float x = powf (MAXcxx . . $ `<external>/12741050725406041920/gmacros.h:975:9`! ((powf (v, minv) - c1), 0) / (c2 - (c3 * (powf (v, minv)))), ninv);
580 return x * 10000 / 203.0;
581 }
582
583 /* maps [0, 70] to [0, 1] */
584 void
585 gtk_rec2100_pq_to_rec2100_linearcxx . . $ gtk_rec2100_pq_to_rec2100_linear(7348b25d00bc3e4f). (float r, float g, float b,
586 float *rr, float *gg, float *bb)
587 {
588 *rr = pq_to_linearcxx . . $ pq_to_linear(fbcf3211dfe1bfd1). (r);
589 *gg = pq_to_linearcxx . . $ pq_to_linear(fbcf3211dfe1bfd1). (g);
590 *bb = pq_to_linearcxx . . $ pq_to_linear(fbcf3211dfe1bfd1). (b);
591 }
592
593 static inline float
594 linear_to_pqcxx . . $ linear_to_pq(fbcf3211dfe1bfd1). (float v)
595 {
596 float x = v * 203.0 / 10000.0;
597 float n = 2610.0 / (1 << 14);
598 float m = 2523.0 / (1 << 5);
599 float c1 = 3424.0 / (1 << 12);
600 float c2 = 2413.0 / (1 << 7);
601 float c3 = 2392.0 / (1 << 7);
602
603 return powf (((c1 + (c2 * powf (x, n))) / (1 + (c3 * powf (x, n)))), m);
604 }
605
606 void
607 gtk_rec2100_linear_to_rec2100_pqcxx . . $ gtk_rec2100_linear_to_rec2100_pq(7348b25d00bc3e4f). (float r, float g, float b,
608 float *rr, float *gg, float *bb)
609 {
610 *rr = linear_to_pqcxx . . $ linear_to_pq(fbcf3211dfe1bfd1). (r);
611 *gg = linear_to_pqcxx . . $ linear_to_pq(fbcf3211dfe1bfd1). (g);
612 *bb = linear_to_pqcxx . . $ linear_to_pq(fbcf3211dfe1bfd1). (b);
613 }
614
615 void
616 gtk_rec2100_linear_to_rec2020_linearcxx . . $ gtk_rec2100_linear_to_rec2020_linear(7348b25d00bc3e4f). (float r, float g, float b,
617 float *rr, float *gg, float *bb)
618 {
619 *rr = r;
620 *gg = g;
621 *bb = b;
622 }
623
624 void
625 gtk_rec2020_linear_to_rec2100_linearcxx . . $ gtk_rec2020_linear_to_rec2100_linear(7348b25d00bc3e4f). (float r, float g, float b,
626 float *rr, float *gg, float *bb)
627 {
628 *rr = r;
629 *gg = g;
630 *bb = b;
631 }