mirror of
https://github.com/love2d/love.git
synced 2026-08-13 00:50:51 +02:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user