Explorar el Código

Added GTC_color_encoding

Christophe Riccio hace 9 años
padre
commit
8a54ba3462

+ 50 - 0
glm/gtc/color_encoding.hpp

@@ -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"

+ 65 - 0
glm/gtc/color_encoding.inl

@@ -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

+ 5 - 5
glm/gtc/color_space.hpp

@@ -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);
 

+ 1 - 0
readme.md

@@ -53,6 +53,7 @@ glm::mat4 camera(float Translate, glm::vec2 const & Rotate)
 
 #### [GLM 0.9.9.0](https://github.com/g-truc/glm/releases/latest) - 2017-XX-XX
 ##### Features:
+- Added GLM_GTC_color_encoding extension
 
 ##### Improvements:
 

+ 1 - 0
test/gtc/CMakeLists.txt

@@ -1,4 +1,5 @@
 glmCreateTestGTC(gtc_bitfield)
+glmCreateTestGTC(gtc_color_encoding)
 glmCreateTestGTC(gtc_color_space)
 glmCreateTestGTC(gtc_constants)
 glmCreateTestGTC(gtc_epsilon)

+ 51 - 0
test/gtc/gtc_color_encoding.cpp

@@ -0,0 +1,51 @@
+#include <glm/gtc/color_encoding.hpp>
+#include <glm/gtc/color_space.hpp>
+#include <glm/gtc/epsilon.hpp>
+#include <glm/gtc/constants.hpp>
+
+namespace srgb
+{
+	int test()
+	{
+		int Error(0);
+
+		glm::vec3 const ColorSourceRGB(1.0, 0.5, 0.0);
+
+		{
+			glm::vec3 const ColorSRGB = glm::convertLinearSRGBToD65XYZ(ColorSourceRGB);
+			glm::vec3 const ColorRGB = glm::convertD65XYZToLinearSRGB(ColorSRGB);
+			Error += glm::all(glm::epsilonEqual(ColorSourceRGB, ColorRGB, 0.00001f)) ? 0 : 1;
+		}
+
+		{
+			glm::vec3 const ColorSRGB = glm::convertLinearToSRGB(ColorSourceRGB, 2.8f);
+			glm::vec3 const ColorRGB = glm::convertSRGBToLinear(ColorSRGB, 2.8f);
+			Error += glm::all(glm::epsilonEqual(ColorSourceRGB, ColorRGB, 0.00001f)) ? 0 : 1;
+		}
+
+		glm::vec4 const ColorSourceRGBA(1.0, 0.5, 0.0, 1.0);
+
+		{
+			glm::vec4 const ColorSRGB = glm::convertLinearToSRGB(ColorSourceRGBA);
+			glm::vec4 const ColorRGB = glm::convertSRGBToLinear(ColorSRGB);
+			Error += glm::all(glm::epsilonEqual(ColorSourceRGBA, ColorRGB, 0.00001f)) ? 0 : 1;
+		}
+
+		{
+			glm::vec4 const ColorSRGB = glm::convertLinearToSRGB(ColorSourceRGBA, 2.8f);
+			glm::vec4 const ColorRGB = glm::convertSRGBToLinear(ColorSRGB, 2.8f);
+			Error += glm::all(glm::epsilonEqual(ColorSourceRGBA, ColorRGB, 0.00001f)) ? 0 : 1;
+		}
+
+		return Error;
+	}
+}//namespace srgb
+
+int main()
+{
+	int Error(0);
+
+	Error += srgb::test();
+
+	return Error;
+}