46export template <
typename T>
48 { T::NAME } -> std::convertible_to<std::string_view>;
49 { T::RED } -> std::convertible_to<Chromaticity>;
50 { T::GREEN } -> std::convertible_to<Chromaticity>;
51 { T::BLUE } -> std::convertible_to<Chromaticity>;
52 { T::WHITE } -> std::convertible_to<Chromaticity>;
64 static constexpr std::string_view
NAME =
"SRGB";
77 static constexpr std::string_view
NAME =
"DisplayP3";
90 static constexpr std::string_view
NAME =
"Rec2020";
104 static constexpr std::string_view
NAME =
"AP1";
120 {0.8951, 0.2664, -0.1614},
121 {-0.7502, 1.7135, 0.0367},
122 {0.0389, -0.0685, 1.0296},
132 const double x = chromaticity[0];
133 const double y = chromaticity[1];
134 return {x / y, 1, (1 - x - y) / y};
171 const Vector3 ratios = {target[0] / source[0], target[1] / source[1], target[2] / source[2]};
181template <RGBGamut Gamut>
184 const Matrix3 native =
rgb_to_xyz(Gamut::RED, Gamut::GREEN, Gamut::BLUE, Gamut::WHITE);
185 const bool isD65 = Gamut::WHITE[0] ==
D65[0] && Gamut::WHITE[1] ==
D65[1];
193template <RGBGamut Gamut>
200template <RGBGamut Gamut>
209template <RGBGamut Gamut, TransferFunction Transfer>
211 join_names<Transfer::PREFIX.size() + Gamut::NAME.size()>({Transfer::PREFIX, Gamut::NAME});
223export template <RGBGamut Gamut, TransferFunction Transfer>
236 static constexpr std::string_view
VALUE =
"ACEScg";
244 static constexpr std::string_view
VALUE =
"Rec709";
252 static constexpr std::string_view
VALUE =
"Rec2020";
260 static constexpr std::string_view
VALUE =
"Rec2100PQ";
268 static constexpr std::string_view
VALUE =
"Rec2100HLG";
291export template <RGBGamut Gamut, TransferFunction Transfer>
293 public std::conditional_t<std::same_as<Transfer, tf::Linear>,
294 ColorArithmetic<BasicRGB<Gamut, Transfer>>,
314 constexpr BasicRGB(
const float r,
const float g,
const float b,
const float a = 1.0f)
324 [[nodiscard]]
constexpr float red() const noexcept {
return this->
_ch1; }
330 [[nodiscard]]
constexpr float green() const noexcept {
return this->
_ch2; }
336 [[nodiscard]]
constexpr float blue() const noexcept {
return this->
_ch3; }
354template <RGBGamut Gamut, TransferFunction Transfer>
362export namespace aest::colors
constexpr float clamp(const float value)
Clamp a floating-point value to the 0-1 range.
constexpr std::array< char, Size > join_names(const std::initializer_list< std::string_view > parts)
Concatenate names into a character array, for a color space name built at compile time.
constexpr Chromaticity D50
Chromaticity of the D50 white point, as CSS Color 4 and the ICC profile connection space define it: t...
constexpr Matrix3 gamut_to_xyz()
Derives the matrix from linear RGB of a gamut to XYZ relative to D65.
constexpr auto RGB_NAME_CHARS
The characters of the default BasicRGB name: the transfer prefix, then the gamut name.
BasicRGB< gamut::Rec2020, tf::PQ > Rec2100PQ
Rec.2100 PQ: Rec. 2020 primaries with the PQ signal of HDR10, linear 1.0 at 203 cd/m²
constexpr Chromaticity D65
Chromaticity of the D65 white point, as sRGB defines it: the white of XYZ.
BasicRGB< gamut::SRGB, tf::Rec709 > Rec709
Rec. 709: the sRGB primaries with the Rec. 709 OETF, the encoding of HD video.
BasicRGB< gamut::SRGB, tf::SRGB > SRGB
sRGB with gamma-encoded channels: the encoding of hex codes, 8-bit channels and CSS colors.
std::array< double, 2 > Chromaticity
CIE 1931 xy chromaticity coordinates of a primary or white point.
constexpr Matrix3 bradford_to_d65(const Chromaticity &white)
Derives the Bradford matrix that adapts XYZ colors from a white point to D65.
constexpr Matrix3 BRADFORD
The Bradford cone response matrix, used to adapt a white point.
constexpr Matrix3 rgb_to_xyz(const Chromaticity &red, const Chromaticity &green, const Chromaticity &blue, const Chromaticity &white)
Derives the matrix from linear RGB to XYZ for a set of primaries.
constexpr Vector3 xyz_of(const Chromaticity &chromaticity)
The XYZ of a chromaticity at luminance Y = 1.
blas::Vector< double, 3 > Vector3
A column of three values, such as XYZ or linear RGB channels.
constexpr Matrix3 XYZ_TO_RGB
Matrix from XYZ, D65, to linear RGB of Gamut.
BasicRGB< gamut::DisplayP3, tf::Linear > LinDisplayP3
Linear Display P3.
blas::Matrix< double, 3, 3 > Matrix3
A 3x3 matrix, stored as three rows.
BasicRGB< gamut::AP1, tf::Linear > ACEScg
ACEScg: linear AP1, the working space of ACES rendering and compositing.
BasicRGB< gamut::Rec2020, tf::Rec709 > Rec2020
Rec. 2020: the Rec. 2020 primaries with the Rec. 709 OETF, the encoding of SDR UHD video.
BasicRGB< gamut::Rec2020, tf::HLG > Rec2100HLG
Rec.2100 HLG: Rec. 2020 primaries with the HLG signal, linear 1.0 at 75%.
constexpr Matrix3 RGB_TO_XYZ
Matrix from linear RGB of Gamut to XYZ, D65.
BasicRGB< gamut::DisplayP3, tf::SRGB > DisplayP3
Display P3: the P3 primaries with the sRGB transfer function, as on Apple displays and in CSS.
BasicRGB< gamut::SRGB, tf::Linear > LinSRGB
Linear sRGB: the sRGB primaries without the gamma encoding, so channels are proportional to light and...
BasicRGB< gamut::Rec2020, tf::Linear > LinRec2020
Linear Rec. 2020, the gamut of UHD and HDR video.
constexpr Vector< T, Rows > multiply(const Matrix< T, Rows, Columns > &matrix, const Vector< T, Columns > &vector)
Multiplies a matrix by a column vector.
constexpr Matrix< T, Columns, Rows > transpose(const Matrix< T, Rows, Columns > &matrix)
Swaps the rows and columns of a matrix.
constexpr Matrix< T, 3, 3 > inverse(const Matrix< T, 3, 3 > &matrix)
Inverts a 3x3 matrix through its adjugate.
std::array< Vector< T, Columns >, Rows > Matrix
A matrix of fixed size, stored as an array of rows.
constexpr Matrix< T, Size, Size > diagonal(const Vector< T, Size > &vector)
Builds a square matrix with a vector on its diagonal and 0 elsewhere.
std::array< T, Size > Vector
A column vector of fixed size.
A color in an RGB color space: the primaries and white point of Gamut, with channels encoded by Trans...
constexpr float green() const noexcept
Get the green channel value.
constexpr float red() const noexcept
Get the red channel value.
constexpr BasicRGB()
Default constructor initializes the color to opaque black (0, 0, 0, 1).
constexpr BasicRGB(const float r, const float g, const float b, const float a=1.0f)
Construct a color from floating-point RGBA values.
static constexpr std::string_view TYPE
constexpr float blue() const noexcept
Get the blue channel value.
A BasicRGB space with an SDR encoding: channels in the 0-1 range, relative to the display's white....
A transfer function for HDR signals, such as PQ or HLG: a tag with a static IS_HDR set to true....
A BasicRGB space with linear channels, tf::Linear.
A gamut tag, the first parameter of BasicRGB.
Any BasicRGB color space.
Gamut tags, the first parameter of BasicRGB.
constexpr ColorBase(const float alpha, const float channel1, const float channel2, const float channel3)
Empty base standing in for ColorArithmetic in encoded RGB spaces.
static constexpr std::string_view VALUE
The name.
static constexpr std::string_view VALUE
The name.
static constexpr std::string_view VALUE
The name.
static constexpr std::string_view VALUE
The name.
static constexpr std::string_view VALUE
The name.
Name of the BasicRGB space of a gamut and a transfer function, printed by std::format.
static constexpr std::string_view VALUE
The name.
Gamut GamutTag
The gamut tag.
Transfer TransferTag
The transfer function tag.
The gamut and transfer function of a BasicRGB space; empty for other types.
The ACES AP1 primaries with the ACES white point (about D60), from SMPTE ST 2065-1,...
static constexpr std::string_view NAME
Color space name.
static constexpr Chromaticity BLUE
Blue primary.
static constexpr Chromaticity WHITE
White point.
static constexpr Chromaticity GREEN
Green primary.
static constexpr Chromaticity RED
Red primary.
The DCI-P3 primaries with D65 white, from SMPTE EG 432-1.
static constexpr std::string_view NAME
Color space name.
static constexpr Chromaticity WHITE
White point.
static constexpr Chromaticity BLUE
Blue primary.
static constexpr Chromaticity GREEN
Green primary.
static constexpr Chromaticity RED
Red primary.
The Rec. 2020 / Rec. 2100 primaries, D65 white, from ITU-R BT.2020.
static constexpr Chromaticity GREEN
Green primary.
static constexpr Chromaticity WHITE
White point.
static constexpr Chromaticity BLUE
Blue primary.
static constexpr Chromaticity RED
Red primary.
static constexpr std::string_view NAME
Color space name.
The sRGB and Rec. 709 primaries, D65 white, from IEC 61966-2-1.
static constexpr Chromaticity WHITE
White point.
static constexpr std::string_view NAME
Color space name.
static constexpr Chromaticity GREEN
Green primary.
static constexpr Chromaticity RED
Red primary.
static constexpr Chromaticity BLUE
Blue primary.
The Hybrid Log-Gamma OETF of ITU-R BT.2100 and ARIB STD-B67, the relative HDR transfer function of br...
No transfer function: channel values are proportional to light.
The Perceptual Quantizer of SMPTE ST 2084 and ITU-R BT.2100, the absolute HDR transfer function of HD...
The OETF of ITU-R BT.709, which BT.2020 shares for SDR: a linear segment near black,...