diff --git a/include/vsg/utils/ColorSpace.h b/include/vsg/utils/ColorSpace.h index 32e9db5a6..132c96058 100644 --- a/include/vsg/utils/ColorSpace.h +++ b/include/vsg/utils/ColorSpace.h @@ -53,55 +53,46 @@ namespace vsg } template - constexpr t_vec4 linear_to_sRGB(const t_vec4& src) - { - return t_vec4(linear_to_sRGB_component(src.r), linear_to_sRGB_component(src.g), linear_to_sRGB_component(src.b), src.a); - } - - template - constexpr t_vec4 linear_to_sRGB(T r, T g, T b, T a) + constexpr t_vec3 linear_to_sRGB(const t_vec3& src) { - return t_vec4(linear_to_sRGB_component(r), linear_to_sRGB_component(g), linear_to_sRGB_component(b), a); + return t_vec3(linear_to_sRGB_component(src.r), linear_to_sRGB_component(src.g), linear_to_sRGB_component(src.b)); } template - constexpr t_vec4 sRGB_to_linear(const t_vec4& src) + constexpr t_vec4 linear_to_sRGB(const t_vec4& src) { - return t_vec4(sRGB_to_linear_component(src.r), sRGB_to_linear_component(src.g), sRGB_to_linear_component(src.b), src.a); + return t_vec4(linear_to_sRGB_component(src.r), linear_to_sRGB_component(src.g), linear_to_sRGB_component(src.b), src.a); } template - constexpr t_vec4 sRGB_to_linear(T r, T g, T b, T a) + constexpr t_vec4 linear_to_sRGB(T r, T g, T b, T a) { - return t_vec4(sRGB_to_linear_component(r), sRGB_to_linear_component(g), sRGB_to_linear_component(b), a); + return t_vec4(linear_to_sRGB_component(r), linear_to_sRGB_component(g), linear_to_sRGB_component(b), a); } template - constexpr t_vec4 linear_to_sRGB_approx(const t_vec4& src) + constexpr t_vec3 sRGB_to_linear(const t_vec3& src) { - const T exponent = static_cast(1.0 / 2.2); - return t_vec4(std::pow(src.r, exponent), std::pow(src.g, exponent), std::pow(src.b, exponent), src.a); + return t_vec3(sRGB_to_linear_component(src.r), sRGB_to_linear_component(src.g), sRGB_to_linear_component(src.b)); } template - constexpr t_vec4 linear_to_sRGB_approx(T r, T g, T b, T a) + constexpr t_vec4 sRGB_to_linear(const t_vec4& src) { - const T exponent = static_cast(1.0 / 2.2); - return t_vec4(std::pow(r, exponent), std::pow(g, exponent), std::pow(b, exponent), a); + return t_vec4(sRGB_to_linear_component(src.r), sRGB_to_linear_component(src.g), sRGB_to_linear_component(src.b), src.a); } template - constexpr t_vec4 sRGB_to_linear_approx(const t_vec4& src) + constexpr t_vec4 sRGB_to_linear(T r, T g, T b, T a) { - const T exponent = static_cast(2.2); - return t_vec4(std::pow(src.r, exponent), std::pow(src.g, exponent), std::pow(src.b, exponent), src.a); + return t_vec4(sRGB_to_linear_component(r), sRGB_to_linear_component(g), sRGB_to_linear_component(b), a); } template - constexpr t_vec4 sRGB_to_linear_approx(T r, T g, T b, T a) + void convert(T& data, ColorSpace source, ColorSpace target) { - const T exponent = static_cast(2.2); - return t_vec4(std::pow(r, exponent), std::pow(g, exponent), std::pow(b, exponent), a); + if (source==sRGB && target==linearRGB) data = sRGB_to_linear(data); + else if (source==linearRGB && target==sRGB) data = linear_to_sRGB(data); } template