Added GTC_color_encoding

This commit is contained in:
Christophe Riccio
2016-09-11 02:50:08 +02:00
parent 2fd6a9eeee
commit 8a54ba3462
6 changed files with 173 additions and 5 deletions

View File

@@ -0,0 +1,50 @@
/// @ref gtc_color_encoding
/// @file glm/gtc/color_encoding.hpp
///
/// @see core (dependence)
/// @see gtc_color_encoding (dependence)
///
/// @defgroup gtc_color_encoding GLM_GTC_color_encoding
/// @ingroup gtc
///
/// @brief Allow to perform bit operations on integer values
///
/// <glm/gtc/color_encoding.hpp> need to be included to use these functionalities.
#pragma once
// Dependencies
#include "../detail/setup.hpp"
#include "../detail/precision.hpp"
#include "../vec3.hpp"
#include <limits>
#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED)
# pragma message("GLM: GLM_GTC_color_encoding extension included")
#endif
namespace glm
{
/// @addtogroup gtc_color_encoding
/// @{
/// Convert a linear sRGB color to D65 YUV.
template <typename T, precision P>
GLM_FUNC_DECL tvec3<T, P> convertLinearSRGBToD65XYZ(tvec3<T, P> const& ColorLinearSRGB);
/// Convert a D65 YUV color to linear sRGB.
template <typename T, precision P>
GLM_FUNC_DECL tvec3<T, P> convertD65XYZToLinearSRGB(tvec3<T, P> const& ColorD65XYZ);
/// Convert a D50 YUV color to D65 YUV.
template <typename T, precision P>
GLM_FUNC_DECL tvec3<T, P> convertD50XYZToD65XYZ(tvec3<T, P> const& ColorD50XYZ);
/// Convert a D65 YUV color to D50 YUV.
template <typename T, precision P>
GLM_FUNC_DECL tvec3<T, P> convertD65XYZToD50XYZ(tvec3<T, P> const& ColorD65XYZ);
/// @}
} //namespace glm
#include "color_encoding.inl"

View File

@@ -0,0 +1,65 @@
/// @ref gtc_color_encoding
/// @file glm/gtc/color_encoding.inl
namespace glm
{
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec3<T, P> convertLinearSRGBToD65XYZ(tvec3<T, P> const& ColorLinearSRGB)
{
static const tvec3<T, P> M(0.490f, 0.17697f, 0.2f);
static const tvec3<T, P> N(0.31f, 0.8124f, 0.01063f);
static const tvec3<T, P> O(0.490f, 0.01f, 0.99f);
return (M * ColorLinearSRGB + N * ColorLinearSRGB + O * ColorLinearSRGB) * static_cast<T>(5.650675255693055f);
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec3<T, P> convertD65XYZToLinearSRGB(tvec3<T, P> const& ColorD65XYZ)
{
static const tvec3<T, P> M(0.41847f, -0.091169f, 0.0009209f);
static const tvec3<T, P> N(-0.15866f, 0.25243f, 0.015708f);
static const tvec3<T, P> O(0.0009209f, -0.0025498f, 0.1786f);
return M * ColorD65XYZ + N * ColorD65XYZ + O * ColorD65XYZ;
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec3<T, P> convertLinearSRGBToD50XYZ(tvec3<T, P> const& ColorLinearSRGB)
{
static const tvec3<T, P> M(0.436030342570117f, 0.222438466210245f, 0.013897440074263f);
static const tvec3<T, P> N(0.385101860087134f, 0.716942745571917f, 0.097076381494207f);
static const tvec3<T, P> O(0.143067806654203f, 0.060618777416563f, 0.713926257896652f);
return M * ColorLinearSRGB + N * ColorLinearSRGB + O * ColorLinearSRGB;
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec3<T, P> convertD50XYZToLinearSRGB(tvec3<T, P> const& ColorD50XYZ)
{
static const tvec3<T, P> M();
static const tvec3<T, P> N();
static const tvec3<T, P> O();
return M * ColorD65XYZ + N * ColorD65XYZ + O * ColorD65XYZ;
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec3<T, P> convertD65XYZToD50XYZ(tvec3<T, P> const& ColorD65XYZ)
{
static const tvec3<T, P> M(+1.047844353856414f, +0.029549007606644f, -0.009250984365223f);
static const tvec3<T, P> N(+0.022898981050086f, +0.990508028941971f, +0.015072338237051f);
static const tvec3<T, P> O(-0.050206647741605f, -0.017074711360960f, +0.751717835079977f);
return M * ColorD65XYZ + N * ColorD65XYZ + O * ColorD65XYZ;
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec3<T, P> convertD50XYZToD65XYZ(tvec3<T, P> const& ColorD50XYZ)
{
static const tvec3<T, P> M();
static const tvec3<T, P> N();
static const tvec3<T, P> O();
return M * ColorD50XYZ + N * ColorD50XYZ + O * ColorD50XYZ;
}
}//namespace glm

View File

@@ -9,7 +9,7 @@
///
/// @brief Allow to perform bit operations on integer values
///
/// <glm/gtc/color.hpp> need to be included to use these functionalities.
/// <glm/gtc/color_space.hpp> need to be included to use these functionalities.
#pragma once
@@ -31,22 +31,22 @@ namespace glm
/// @{
/// Convert a linear color to sRGB color using a standard gamma correction.
/// IEC 61966-2-1:1999 specification https://www.w3.org/Graphics/Color/srgb
/// IEC 61966-2-1:1999 / Rec. 709 specification https://www.w3.org/Graphics/Color/srgb
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<T, P> convertLinearToSRGB(vecType<T, P> const & ColorLinear);
/// Convert a linear color to sRGB color using a custom gamma correction.
/// IEC 61966-2-1:1999 specification https://www.w3.org/Graphics/Color/srgb
/// IEC 61966-2-1:1999 / Rec. 709 specification https://www.w3.org/Graphics/Color/srgb
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<T, P> convertLinearToSRGB(vecType<T, P> const & ColorLinear, T Gamma);
/// Convert a sRGB color to linear color using a standard gamma correction.
/// IEC 61966-2-1:1999 specification https://www.w3.org/Graphics/Color/srgb
/// IEC 61966-2-1:1999 / Rec. 709 specification https://www.w3.org/Graphics/Color/srgb
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<T, P> convertSRGBToLinear(vecType<T, P> const & ColorSRGB);
/// Convert a sRGB color to linear color using a custom gamma correction.
// IEC 61966-2-1:1999 specification https://www.w3.org/Graphics/Color/srgb
// IEC 61966-2-1:1999 / Rec. 709 specification https://www.w3.org/Graphics/Color/srgb
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<T, P> convertSRGBToLinear(vecType<T, P> const & ColorSRGB, T Gamma);