55 const double cube = value * value * value;
75 static constexpr std::string_view
TYPE =
"CIELab";
90 constexpr CIELab(
const float l,
const float a,
const float b,
const float alpha = 1.0f)
106 [[nodiscard]]
constexpr float a() const noexcept {
return _ch2; }
112 [[nodiscard]]
constexpr float b() const noexcept {
return _ch3; }
128 static constexpr std::string_view
TYPE =
"CIELCH";
143 constexpr CIELCH(
const float l,
const float c,
const float h,
const float alpha = 1.0f)
159 [[nodiscard]]
constexpr float chroma() const noexcept {
return _ch2; }
165 [[nodiscard]]
constexpr float hue() const noexcept {
return _ch3; }
202 return CIELab{
static_cast<float>(116 * fy - 16),
static_cast<float>(500 * (fx - fy)),
203 static_cast<float>(200 * (fy - fz)), color.
alpha()};
219 const double lightness = color.
lightness();
220 const double fy = (lightness + 16) / 116;
221 const double fx = fy + color.
a() / 500.0;
222 const double fz = fy - color.
b() / 200.0;
229 return XYZ{
static_cast<float>(xyz[0]),
static_cast<float>(xyz[1]),
230 static_cast<float>(xyz[2]), color.
alpha()};
246 const double a = color.
a();
247 const double b = color.
b();
265 const double chroma = color.
chroma();
267 return CIELab{color.
lightness(),
static_cast<float>(chroma * std::cos(angle)),
268 static_cast<float>(chroma * std::sin(angle)), color.
alpha()};
constexpr double LAB_KAPPA
CIE κ, 24389 / 27: the slope of the line near black.
double lab_compress(const double ratio)
The CIELab compression of a ratio to the white: a cube root, with a line near black.
constexpr Matrix3 D50_TO_D65
Matrix adapting XYZ, D50, to XYZ, D65, with the Bradford transform.
constexpr Matrix3 D65_TO_D50
Matrix adapting XYZ, D65, to XYZ, D50, with the Bradford transform.
constexpr Vector3 D50_WHITE
XYZ of the D50 white at luminance Y = 1, the reference white of CIELab.
constexpr double LAB_EPSILON
CIE ε, 216 / 24389: below it, CIELab follows a line instead of the cube root.
constexpr double lab_expand(const double value)
Inverse of lab_compress() for the X and Z ratios.
constexpr float wrap_hue(const float hue)
Wrap a hue angle to the [0, 360) range.
constexpr float non_negative(const float value)
Clamp a floating-point value to be non-negative, leaving it unbounded above.
constexpr double DEGREES_PER_RADIAN
Degrees in a radian.
constexpr Chromaticity D50
Chromaticity of the D50 white point, as CSS Color 4 and the ICC profile connection space define it: t...
constexpr Matrix3 bradford_to_d65(const Chromaticity &white)
Derives the Bradford matrix that adapts XYZ colors from a white point to D65.
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.
blas::Matrix< double, 3, 3 > Matrix3
A 3x3 matrix, stored as three rows.
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, 3, 3 > inverse(const Matrix< T, 3, 3 > &matrix)
Inverts a 3x3 matrix through its adjugate.
A color in CIELCH: CIELab in polar form, as lightness, chroma and hue.
static constexpr std::string_view TYPE
Color space name, used by the std::formatter specialization.
constexpr float lightness() const noexcept
Get the lightness, 100 being D50 white.
constexpr float chroma() const noexcept
Get the chroma, the distance from gray.
constexpr float hue() const noexcept
Get the hue angle in the 0-360 range.
constexpr CIELCH(const float l, const float c, const float h, const float alpha=1.0f)
Construct a color from CIELCH values and alpha.
constexpr CIELCH()
Default constructor initializes the color to opaque black (0, 0, 0, 1).
A color in CIELab, the CIE 1976 L*a*b* space, relative to D50.
static constexpr std::string_view TYPE
Color space name, used by the std::formatter specialization.
constexpr CIELab()
Default constructor initializes the color to opaque black (0, 0, 0, 1).
constexpr CIELab(const float l, const float a, const float b, const float alpha=1.0f)
Construct a color from CIELab values and alpha.
constexpr float lightness() const noexcept
Get the lightness, 100 being D50 white.
constexpr float b() const noexcept
Get the blue-yellow axis, negative toward blue.
constexpr float a() const noexcept
Get the green-red axis, negative toward green.
A color in the CIE 1931 XYZ color space, relative to the D65 white point.
constexpr float x() const noexcept
Get the X tristimulus value.
constexpr float z() const noexcept
Get the Z tristimulus value.
constexpr float y() const noexcept
Get the Y tristimulus value, the relative luminance.
constexpr ColorBase(const float alpha, const float channel1, const float channel2, const float channel3)
constexpr float alpha() const noexcept
static CIELCH convert(const CIELab &color)
Converts color to CIELCH.
static CIELab convert(const CIELCH &color)
Converts color to CIELab.
static CIELab convert(const XYZ &color)
Converts color to CIELab: Bradford to D50, then the CIELab compression of each ratio to the white.
static constexpr XYZ convert(const CIELab &color)
Converts color to XYZ: the inverse compression, then Bradford back to D65.
Converts colors from one color space to another.
CIELab type
The parent space.
XYZ type
The parent space.
Names the color space a space converts through, joining every space in one tree.