Antkeeper  0.0.1
srgb.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2023 Christopher J. Howard
3  *
4  * This file is part of Antkeeper source code.
5  *
6  * Antkeeper source code is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Antkeeper source code is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef ANTKEEPER_COLOR_SRGB_HPP
21 #define ANTKEEPER_COLOR_SRGB_HPP
22 
23 #include <engine/color/rgb.hpp>
25 #include <engine/math/vector.hpp>
26 #include <cmath>
27 
28 namespace color {
29 
32 
42 template <class T>
43 [[nodiscard]] math::vec3<T> srgb_oetf(const math::vec3<T>& x)
44 {
45  auto f = [](T x) -> T
46  {
47  return x > T{0.0031308} ? std::pow(x, T{1.0 / 2.4}) * T{1.055} - T{0.055} : x * T{12.92};
48  };
49 
50  return {f(x[0]), f(x[1]), f(x[2])};
51 }
52 
62 template <class T>
63 [[nodiscard]] math::vec3<T> srgb_eotf(const math::vec3<T>& x)
64 {
65  auto f = [](T x) -> T
66  {
67  return x > T{0.0031308 * 12.92} ? std::pow((x + T{0.055}) / T{1.055}, T{2.4}) : x / T{12.92};
68  };
69 
70  return {f(x[0]), f(x[1]), f(x[2])};
71 }
72 
74 template <class T>
76 (
77  {T{0.64}, T{0.33}},
78  {T{0.30}, T{0.60}},
79  {T{0.15}, T{0.06}},
80  deg2_d65<T>,
81  &srgb_eotf<T>,
82  &srgb_oetf<T>
83 );
84 
86 
87 } // namespace color
88 
89 #endif // ANTKEEPER_COLOR_SRGB_HPP
Color science.
Definition: aces.hpp:27
constexpr rgb_color_space< T > srgb({T{0.64}, T{0.33}}, {T{0.30}, T{0.60}}, {T{0.15}, T{0.06}}, deg2_d65< T >, &srgb_eotf< T >, &srgb_oetf< T >)
sRGB color space.
math::vec3< T > srgb_eotf(const math::vec3< T > &x)
sRGB electro-optical transfer function (EOTF).
Definition: srgb.hpp:63
math::vec3< T > srgb_oetf(const math::vec3< T > &x)
sRGB opto-electronic transfer function (OETF).
Definition: srgb.hpp:43
consteval T pow(T x, T e) noexcept
Compile-time pow for unsigned integrals.
Definition: compile.hpp:65
RGB color space.
Definition: rgb.hpp:70
n-dimensional vector.
Definition: vector.hpp:44