3 * COPYRIGHT: Written by John Cunningham Bowler, 2013.
4 * To the extent possible under law, the author has waived all copyright and
5 * related or neighboring rights to this work. This work is published from:
8 * Utility file; not actually a header, this contains definitions of sRGB
9 * calculation functions for inclusion in those test programs that need them.
11 * All routines take and return a floating point value in the range
12 * 0 to 1.0, doing a calculation according to the sRGB specification
13 * (in fact the source of the numbers is the wikipedia article at
14 * https://en.wikipedia.org/wiki/SRGB).
18 sRGB_from_linear(double l)
24 l = 1.055 * pow(l, 1/2.4) - 0.055;
30 linear_from_sRGB(double s)
36 return pow((s+0.055)/1.055, 2.4);
40 YfromRGB(double r, double g, double b)
42 /* Use the sRGB (rounded) coefficients for Rlinear, Glinear, Blinear to get
43 * the CIE Y value (also linear).
45 return 0.2126 * r + 0.7152 * g + 0.0722 * b;