Antkeeper  0.0.1
cat.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_CAT_HPP
21 #define ANTKEEPER_COLOR_CAT_HPP
22 
23 #include <engine/math/matrix.hpp>
24 #include <engine/math/vector.hpp>
25 
26 namespace color {
27 
30 
37 template <class T>
39 {
40  T{ 0.8951}, T{-0.7502}, T{ 0.0389},
41  T{ 0.2664}, T{ 1.7135}, T{-0.0685},
42  T{-0.1614}, T{ 0.0367}, T{ 1.0296}
43 };
44 
50 template <class T>
52 {
53  T{ 0.40024}, T{-0.22630}, T{0.00000},
54  T{ 0.70760}, T{ 1.16532}, T{0.00000},
55  T{-0.08081}, T{ 0.04570}, T{0.91822}
56 };
57 
63 template <class T>
65 
78 template <class T>
79 [[nodiscard]] constexpr math::mat3<T> cat_matrix(const math::vec2<T>& w0, const math::vec2<T>& w1, const math::mat3<T>& cone_response = bradford_cone_response<T>) noexcept
80 {
81  // Convert CIE xy chromaticity coordinates to CIE XYZ colors
82  const math::vec3<T> w0_xyz = {w0[0] / w0[1], T{1}, (T{1} - w0[0] - w0[1]) / w0[1]};
83  const math::vec3<T> w1_xyz = {w1[0] / w1[1], T{1}, (T{1} - w1[0] - w1[1]) / w1[1]};
84 
85  // Calculate cone response of CIE XYZ colors
86  const math::vec3<T> w0_cone_response = cone_response * w0_xyz;
87  const math::vec3<T> w1_cone_response = cone_response * w1_xyz;
88 
89  const math::mat3<T> scale =
90  {
91  w1_cone_response[0] / w0_cone_response[0], T{0}, T{0},
92  T{0}, w1_cone_response[1] / w0_cone_response[1], T{0},
93  T{0}, T{0}, w1_cone_response[2] / w0_cone_response[2],
94  };
95 
96  return math::inverse(cone_response) * scale * cone_response;
97 }
98 
100 
101 } // namespace color
102 
103 #endif // ANTKEEPER_COLOR_CAT_HPP
Color science.
Definition: aces.hpp:27
constexpr math::mat3< T > xyz_scaling_cone_response
XYZ scaling cone response matrix.
Definition: cat.hpp:64
constexpr math::mat3< T > bradford_cone_response
Bradford cone response matrix.
Definition: cat.hpp:38
constexpr math::mat3< T > cat_matrix(const math::vec2< T > &w0, const math::vec2< T > &w1, const math::mat3< T > &cone_response=bradford_cone_response< T >) noexcept
Constructs a chromatic adaptation transform (CAT) matrix.
Definition: cat.hpp:79
constexpr math::mat3< T > von_kries_cone_response
von Kries cone response matrix.
Definition: cat.hpp:51
constexpr mat4< T > scale(const vec3< T > &v)
Constructs a scale matrix.
constexpr matrix< T, N, N > inverse(const matrix< T, N, N > &m) noexcept
Calculates the inverse of a square matrix.
n by m column-major matrix.
Definition: math/matrix.hpp:44
static constexpr matrix identity() noexcept
Returns an identity matrix, with ones on the main diagonal and zeros elsewhere.
n-dimensional vector.
Definition: vector.hpp:44