fukasawa e60969
/*-
fukasawa e60969
 * sRGB.h
fukasawa e60969
 *
fukasawa e60969
 * Last changed in libpng 1.6.0 [February 14, 2013]
fukasawa e60969
 *
fukasawa e60969
 * COPYRIGHT: Written by John Cunningham Bowler, 2013.
fukasawa e60969
 * To the extent possible under law, the author has waived all copyright and
fukasawa e60969
 * related or neighboring rights to this work.  This work is published from:
fukasawa e60969
 * United States.
fukasawa e60969
 *
fukasawa e60969
 * Utility file; not actually a header, this contains definitions of sRGB
fukasawa e60969
 * calculation functions for inclusion in those test programs that need them.
fukasawa e60969
 *
fukasawa e60969
 * All routines take and return a floating point value in the range
fukasawa e60969
 * 0 to 1.0, doing a calculation according to the sRGB specification
fukasawa e60969
 * (in fact the source of the numbers is the wikipedia article at
fukasawa e60969
 * http://en.wikipedia.org/wiki/SRGB).
fukasawa e60969
 */
fukasawa e60969
static double
fukasawa e60969
sRGB_from_linear(double l)
fukasawa e60969
{
fukasawa e60969
   if (l <= 0.0031308)
fukasawa e60969
      l *= 12.92;
fukasawa e60969
fukasawa e60969
   else
fukasawa e60969
      l = 1.055 * pow(l, 1/2.4) - 0.055;
fukasawa e60969
fukasawa e60969
   return l;
fukasawa e60969
}
fukasawa e60969
fukasawa e60969
static double
fukasawa e60969
linear_from_sRGB(double s)
fukasawa e60969
{
fukasawa e60969
   if (s <= 0.04045)
fukasawa e60969
      return s / 12.92;
fukasawa e60969
fukasawa e60969
   else
fukasawa e60969
      return pow((s+0.055)/1.055, 2.4);
fukasawa e60969
}
fukasawa e60969
fukasawa e60969
static double
fukasawa e60969
YfromRGB(double r, double g, double b)
fukasawa e60969
{
fukasawa e60969
   /* Use the sRGB (rounded) coefficients for Rlinear, Glinear, Blinear to get
fukasawa e60969
    * the CIE Y value (also linear).
fukasawa e60969
    */
fukasawa e60969
   return 0.2126 * r + 0.7152 * g + 0.0722 * b;
fukasawa e60969
}