Skip to content

Commit

Permalink
Added vec3 variants and removed approx functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
robertosfield committed Jan 17, 2025
1 parent 7fbb176 commit 1ff39e5
Showing 1 changed file with 15 additions and 24 deletions.
39 changes: 15 additions & 24 deletions include/vsg/utils/ColorSpace.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,55 +53,46 @@ namespace vsg
}

template<typename T>
constexpr t_vec4<T> linear_to_sRGB(const t_vec4<T>& src)
{
return t_vec4<T>(linear_to_sRGB_component(src.r), linear_to_sRGB_component(src.g), linear_to_sRGB_component(src.b), src.a);
}

template<typename T>
constexpr t_vec4<T> linear_to_sRGB(T r, T g, T b, T a)
constexpr t_vec3<T> linear_to_sRGB(const t_vec3<T>& src)
{
return t_vec4<T>(linear_to_sRGB_component(r), linear_to_sRGB_component(g), linear_to_sRGB_component(b), a);
return t_vec3<T>(linear_to_sRGB_component(src.r), linear_to_sRGB_component(src.g), linear_to_sRGB_component(src.b));
}

template<typename T>
constexpr t_vec4<T> sRGB_to_linear(const t_vec4<T>& src)
constexpr t_vec4<T> linear_to_sRGB(const t_vec4<T>& src)
{
return t_vec4<T>(sRGB_to_linear_component(src.r), sRGB_to_linear_component(src.g), sRGB_to_linear_component(src.b), src.a);
return t_vec4<T>(linear_to_sRGB_component(src.r), linear_to_sRGB_component(src.g), linear_to_sRGB_component(src.b), src.a);
}

template<typename T>
constexpr t_vec4<T> sRGB_to_linear(T r, T g, T b, T a)
constexpr t_vec4<T> linear_to_sRGB(T r, T g, T b, T a)
{
return t_vec4<T>(sRGB_to_linear_component(r), sRGB_to_linear_component(g), sRGB_to_linear_component(b), a);
return t_vec4<T>(linear_to_sRGB_component(r), linear_to_sRGB_component(g), linear_to_sRGB_component(b), a);
}

template<typename T>
constexpr t_vec4<T> linear_to_sRGB_approx(const t_vec4<T>& src)
constexpr t_vec3<T> sRGB_to_linear(const t_vec3<T>& src)
{
const T exponent = static_cast<T>(1.0 / 2.2);
return t_vec4<T>(std::pow(src.r, exponent), std::pow(src.g, exponent), std::pow(src.b, exponent), src.a);
return t_vec3<T>(sRGB_to_linear_component(src.r), sRGB_to_linear_component(src.g), sRGB_to_linear_component(src.b));
}

template<typename T>
constexpr t_vec4<T> linear_to_sRGB_approx(T r, T g, T b, T a)
constexpr t_vec4<T> sRGB_to_linear(const t_vec4<T>& src)
{
const T exponent = static_cast<T>(1.0 / 2.2);
return t_vec4<T>(std::pow(r, exponent), std::pow(g, exponent), std::pow(b, exponent), a);
return t_vec4<T>(sRGB_to_linear_component(src.r), sRGB_to_linear_component(src.g), sRGB_to_linear_component(src.b), src.a);
}

template<typename T>
constexpr t_vec4<T> sRGB_to_linear_approx(const t_vec4<T>& src)
constexpr t_vec4<T> sRGB_to_linear(T r, T g, T b, T a)
{
const T exponent = static_cast<T>(2.2);
return t_vec4<T>(std::pow(src.r, exponent), std::pow(src.g, exponent), std::pow(src.b, exponent), src.a);
return t_vec4<T>(sRGB_to_linear_component(r), sRGB_to_linear_component(g), sRGB_to_linear_component(b), a);
}

template<typename T>
constexpr t_vec4<T> 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<T>(2.2);
return t_vec4<T>(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<typename T>
Expand Down

0 comments on commit 1ff39e5

Please sign in to comment.