Added love.math.gammaToLinear and love.math.linearToGamma for converting RGB color values from the sRGB color-space to linear and vice-versa.

This commit is contained in:
Alex Szpakowski
2014-02-04 19:45:50 -04:00
parent 823b1babc8
commit e54d771be4
4 changed files with 108 additions and 0 deletions
+30
View File
@@ -193,5 +193,35 @@ bool Math::isConvex(const std::vector<Vertex> &polygon)
return true;
}
/**
* http://en.wikipedia.org/wiki/SRGB#The_reverse_transformation
**/
float Math::gammaToLinear(float c) const
{
if (c > 1.0)
return 1.0;
else if (c < 0.0)
return 0.0;
else if (c <= 0.04045)
return c / 12.92;
else
return powf((c + 0.055) / 1.055, 2.4);
}
/**
* http://en.wikipedia.org/wiki/SRGB#The_forward_transformation_.28CIE_xyY_or_CIE_XYZ_to_sRGB.29
**/
float Math::linearToGamma(float c) const
{
if (c > 1.0)
return 1.0;
else if (c < 0.0)
return 0.0;
else if (c < 0.0031308)
return c * 12.92;
else
return 1.055 * powf(c, 0.41666) - 0.055;
}
} // math
} // love