Add gfx::to_srgb/to_linear for colors
This commit is contained in:
parent
3de591394d
commit
565ab68682
1 changed files with 27 additions and 0 deletions
|
|
@ -75,6 +75,33 @@ namespace psemek::gfx
|
|||
return to_coloru8(geom::lerp(to_colorf(c0), to_colorf(c1), t));
|
||||
}
|
||||
|
||||
template <std::size_t N>
|
||||
auto to_srgb(geom::vector<float, N> const & c, float g = 1.f / 2.2f)
|
||||
{
|
||||
geom::vector<float, N> r = c;
|
||||
for (std::size_t i = 0; i < std::min<std::size_t>(3, N); ++i)
|
||||
r[i] = std::pow(r[i], g);
|
||||
return r;
|
||||
}
|
||||
|
||||
template <std::size_t N>
|
||||
auto to_srgb(geom::vector<std::uint8_t, N> const & c, float g = 1.f / 2.2f)
|
||||
{
|
||||
return to_coloru8(to_srgb(to_colorf(c), g));
|
||||
}
|
||||
|
||||
template <std::size_t N>
|
||||
auto to_srgb(geom::vector<std::uint16_t, N> const & c, float g = 1.f / 2.2f)
|
||||
{
|
||||
return to_coloru16(to_srgb(to_colorf(c), g));
|
||||
}
|
||||
|
||||
template <typename T, std::size_t N>
|
||||
auto to_linear(geom::vector<T, N> const & c, float g = 1.f / 2.2f)
|
||||
{
|
||||
return to_srgb(c, 1.f / g);
|
||||
}
|
||||
|
||||
struct generic_color
|
||||
{
|
||||
color_4f c;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue