HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
color_space.hpp
1// Copyright Take Vos 2021.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include "../numeric_array.hpp"
8#include "../geometry/matrix.hpp"
9#include "../geometry/scale.hpp"
10
11namespace tt {
12
13[[nodiscard]] constexpr matrix3
14color_primaries_to_RGBtoXYZ(float wx, float wy, float rx, float ry, float gx, float gy, float bx, float by) noexcept
15{
16 ttlet w = f32x4{wx, wy, 1.0f - wx - wy};
17 ttlet r = f32x4{rx, ry, 1.0f - rx - ry};
18 ttlet g = f32x4{gx, gy, 1.0f - gx - gy};
19 ttlet b = f32x4{bx, by, 1.0f - bx - by};
20
21 // Calculate whitepoint's tristimulus values from coordinates
22 ttlet W = f32x4{1.0f * (w.x() / w.y()), 1.0f, 1.0f * (w.z() / w.y())};
23
24 // C is the chromaticity matrix.
25 ttlet C = matrix3{r, g, b};
26
27 // solve tristimulus sums.
28 ttlet S = scale3{(~C * W).xyz1()};
29
30 return C * S;
31}
32
33} // namespace tt