diff --git a/glm/gtc/color.hpp b/glm/gtc/color.hpp new file mode 100644 index 00000000..1d3872ca --- /dev/null +++ b/glm/gtc/color.hpp @@ -0,0 +1,77 @@ +/////////////////////////////////////////////////////////////////////////////////// +/// OpenGL Mathematics (glm.g-truc.net) +/// +/// Copyright (c) 2005 - 2015 G-Truc Creation (www.g-truc.net) +/// Permission is hereby granted, free of charge, to any person obtaining a copy +/// of this software and associated documentation files (the "Software"), to deal +/// in the Software without restriction, including without limitation the rights +/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +/// copies of the Software, and to permit persons to whom the Software is +/// furnished to do so, subject to the following conditions: +/// +/// The above copyright notice and this permission notice shall be included in +/// all copies or substantial portions of the Software. +/// +/// Restrictions: +/// By making use of the Software for military purposes, you choose to make +/// a Bunny unhappy. +/// +/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +/// THE SOFTWARE. +/// +/// @ref gtc_color +/// @file glm/gtc/color.hpp +/// @date 2015-02-10 / 2015-02-10 +/// @author Christophe Riccio +/// +/// @see core (dependence) +/// @see gtc_color (dependence) +/// +/// @defgroup gtc_color GLM_GTC_color +/// @ingroup gtc +/// +/// @brief Allow to perform bit operations on integer values +/// +/// need to be included to use these functionalities. +/////////////////////////////////////////////////////////////////////////////////// + +#pragma once + +// Dependencies +#include "../detail/setup.hpp" +#include "../detail/precision.hpp" +#include "../exponential.hpp" +#include "../vec3.hpp" +#include "../vec4.hpp" +#include + +#if(defined(GLM_MESSAGES) && !defined(GLM_EXT_INCLUDED)) +# pragma message("GLM: GLM_GTC_color extension included") +#endif + +namespace glm +{ + /// @addtogroup gtc_color + /// @{ + + template class vecType> + GLM_FUNC_DECL vecType rgbToSrgb(vecType const & ColorRGB); + + template class vecType> + GLM_FUNC_DECL vecType rgbToSrgb(vecType const & ColorRGB, T Gamma); + + template class vecType> + GLM_FUNC_DECL vecType srgbToRgb(vecType const & ColorSRGB); + + template class vecType> + GLM_FUNC_DECL vecType srgbToRgb(vecType const & ColorSRGB, T Gamma); + + /// @} +} //namespace glm + +#include "color.inl" diff --git a/glm/gtc/color.inl b/glm/gtc/color.inl new file mode 100644 index 00000000..69df4296 --- /dev/null +++ b/glm/gtc/color.inl @@ -0,0 +1,104 @@ +///////////////////////////////////////////////////////////////////////////////////////// +/// OpenGL Mathematics (glm.g-truc.net) +/// +/// Copyright (c) 2005 - 2015 G-Truc Creation (www.g-truc.net) +/// Permission is hereby granted, free of charge, to any person obtaining a copy +/// of this software and associated documentation files (the "Software"), to deal +/// in the Software without restriction, including without limitation the rights +/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +/// copies of the Software, and to permit persons to whom the Software is +/// furnished to do so, subject to the following conditions: +/// +/// The above copyright notice and this permission notice shall be included in +/// all copies or substantial portions of the Software. +/// +/// Restrictions: +/// By making use of the Software for military purposes, you choose to make +/// a Bunny unhappy. +/// +/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +/// THE SOFTWARE. +/// +/// @ref gtc_color +/// @file glm/gtc/color.inl +/// @date 2015-02-10 / 2015-02-10 +/// @author Christophe Riccio +/////////////////////////////////////////////////////////////////////////////////////////////////// + +namespace glm{ +namespace detail +{ + template class vecType> + struct compute_rgbToSrgb + { + GLM_FUNC_QUALIFIER static vecType call(vecType const & ColorRGB, T InverseGamma) + { + vecType const ClampedColor(clamp(ColorRGB, static_cast(0), static_cast(1))); + + return mix( + pow(ClampedColor, vecType(InverseGamma)) * static_cast(1.055) - static_cast(0.055), + ClampedColor * static_cast(12.92), + lessThan(ClampedColor, vecType(static_cast(0.0031308)))); + } + }; + + template + struct compute_rgbToSrgb + { + GLM_FUNC_QUALIFIER static tvec4 call(tvec4 const & ColorRGB, T InverseGamma) + { + return tvec4(compute_rgbToSrgb::call(tvec3(ColorRGB), InverseGamma), ColorRGB.a); + } + }; + + template class vecType> + struct compute_srgbToRgb + { + GLM_FUNC_QUALIFIER static vecType call(vecType const & ColorSRGB, T Gamma) + { + return mix( + pow((ColorSRGB + static_cast(0.055)) * static_cast(0.94786729857819905213270142180095), vecType(Gamma)), + ColorSRGB * static_cast(0.07739938080495356037151702786378), + lessThanEqual(ColorSRGB, vecType(static_cast(0.04045)))); + } + }; + + template + struct compute_srgbToRgb + { + GLM_FUNC_QUALIFIER static tvec4 call(tvec4 const & ColorSRGB, T Gamma) + { + return tvec4(compute_srgbToRgb::call(tvec3(ColorSRGB), Gamma), ColorSRGB.a); + } + }; +}//namespace detail + + template class vecType> + GLM_FUNC_QUALIFIER vecType rgbToSrgb(vecType const & ColorRGB) + { + return detail::compute_rgbToSrgb::call(ColorRGB, static_cast(0.41666)); + } + + template class vecType> + GLM_FUNC_QUALIFIER vecType rgbToSrgb(vecType const & ColorRGB, T Gamma) + { + return detail::compute_rgbToSrgb::call(ColorRGB, static_cast(1) / Gamma); + } + + template class vecType> + GLM_FUNC_QUALIFIER vecType srgbToRgb(vecType const & ColorSRGB) + { + return detail::compute_srgbToRgb::call(ColorSRGB, static_cast(2.4)); + } + + template class vecType> + GLM_FUNC_QUALIFIER vecType srgbToRgb(vecType const & ColorSRGB, T Gamma) + { + return detail::compute_srgbToRgb::call(ColorSRGB, Gamma); + } +}//namespace glm diff --git a/readme.txt b/readme.txt index d256a537..f2d613a4 100644 --- a/readme.txt +++ b/readme.txt @@ -66,6 +66,9 @@ http://glm.g-truc.net/glm.pdf ================================================================================ GLM 0.9.7.0: 2015-XX-XX -------------------------------------------------------------------------------- +Features: +- Added GTC_color: rgbToSrgb and srgbToRgb functions + Improvements: - Changed usage of __has_include to support Intel compiler #307 diff --git a/test/gtc/CMakeLists.txt b/test/gtc/CMakeLists.txt index 224b8eb5..f7ea5779 100644 --- a/test/gtc/CMakeLists.txt +++ b/test/gtc/CMakeLists.txt @@ -1,4 +1,5 @@ glmCreateTestGTC(gtc_bitfield) +glmCreateTestGTC(gtc_color) glmCreateTestGTC(gtc_constants) glmCreateTestGTC(gtc_epsilon) glmCreateTestGTC(gtc_integer) diff --git a/test/gtc/gtc_color.cpp b/test/gtc/gtc_color.cpp new file mode 100644 index 00000000..5b191a0c --- /dev/null +++ b/test/gtc/gtc_color.cpp @@ -0,0 +1,67 @@ +/////////////////////////////////////////////////////////////////////////////////// +/// OpenGL Mathematics (glm.g-truc.net) +/// +/// Copyright (c) 2005 - 2015 G-Truc Creation (www.g-truc.net) +/// Permission is hereby granted, free of charge, to any person obtaining a copy +/// of this software and associated documentation files (the "Software"), to deal +/// in the Software without restriction, including without limitation the rights +/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +/// copies of the Software, and to permit persons to whom the Software is +/// furnished to do so, subject to the following conditions: +/// +/// The above copyright notice and this permission notice shall be included in +/// all copies or substantial portions of the Software. +/// +/// Restrictions: +/// By making use of the Software for military purposes, you choose to make +/// a Bunny unhappy. +/// +/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +/// THE SOFTWARE. +/// +/// @file test/gtc/gtc_color.cpp +/// @date 2015-02-10 / 2015-02-10 +/// @author Christophe Riccio +/////////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include + +namespace srgb +{ + int test() + { + int Error(0); + + glm::vec4 const ColorSourceRGB(1.0, 0.5, 0.0, 1.0); + + { + glm::vec4 const ColorSRGB = glm::rgbToSrgb(ColorSourceRGB); + glm::vec4 const ColorRGB = glm::srgbToRgb(ColorSRGB); + Error += glm::all(glm::epsilonEqual(ColorSourceRGB, ColorRGB, 0.00001f)) ? 0 : 1; + } + + { + glm::vec4 const ColorSRGB = glm::rgbToSrgb(ColorSourceRGB, 2.8f); + glm::vec4 const ColorRGB = glm::srgbToRgb(ColorSRGB, 2.8f); + Error += glm::all(glm::epsilonEqual(ColorSourceRGB, ColorRGB, 0.00001f)) ? 0 : 1; + } + + return Error; + } +}//namespace srgb + +int main() +{ + int Error(0); + + Error += srgb::test(); + + return Error; +}