Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
Inkscape::Colors::Space Namespace Reference

Classes

class  AnySpace
 
class  CMS
 
struct  Component
 
class  Components
 
class  DeviceCMYK
 This sRGB based DeviceCMYK space is uncalibrated and fixed to the sRGB icc profile. More...
 
class  Gray
 
class  HSL
 
class  HSLuv
 
class  HSV
 
class  Lab
 
class  Lch
 
class  LinearRGB
 
class  Luv
 
class  NamedColor
 A named color is still a purely RGB color, it's just formatted so it can be written back out as a named color faithfully. More...
 
class  OkHsl
 
class  OkHsv
 
class  OkLab
 
class  OkLch
 
class  RGB
 
class  XYZ
 

Typedefs

using Matrix = const double[3][3]
 Two-dimensional array to store a constant 3x3 matrix.
 

Enumerations

enum class  Traits { None = 0 , Picker = 1 , Internal = 2 , CMS = 4 }
 
enum class  Unit {
  EightBit , Percent , Degree , Linear1024 ,
  Chroma40
}
 
enum class  Type {
  NONE , Gray , RGB , linearRGB ,
  HSL , HSV , HWB , CMYK ,
  CMY , XYZ , YXY , LUV ,
  LCH , LAB , HSLUV , OKHSL ,
  OKHSV , OKLCH , OKLAB , YCbCr ,
  CSSNAME , CMS
}
 

Functions

static const std::vector< Componentsget_color_spaces ()
 
std::map< Type, Components_build (bool alpha)
 
Traits operator& (const Traits lhs, const Traits rhs)
 
Traits operator| (const Traits lhs, const Traits rhs)
 
static float hue_2_rgb (float v1, float v2, float h)
 
static double max_chroma_for_lh (double l, double h)
 Calculate the maximum in gamut chromaticity for the given luminance and hue.
 
double from_linear (double c)
 Convenience function used for RGB conversions.
 
double to_linear (double c)
 Convenience function used for RGB conversions.
 
static double y2l (double y)
 Utility function used to convert from the XYZ colorspace to CIELuv.
 
static double l2y (double l)
 Utility function used to convert from CIELuv colorspace to XYZ.
 
template<typename A1 , typename A2 >
constexpr double dot3 (const A1 &a1, const A2 &a2)
 Compute the dot-product between two 3D-vectors.
 
static std::array< double, 4 > component_coefficients (unsigned index, ConstraintMonomials const &m)
 Find the coefficients of the cubic polynomial expressing the linear R, G or B component as a function of OKLch chroma.
 
uint8_t const * render_hue_scale (double s, double l, std::array< uint8_t, 4 *1024 > *map)
 
uint8_t const * render_saturation_scale (double h, double l, std::array< uint8_t, 4 *1024 > *map)
 
uint8_t const * render_lightness_scale (double h, double s, std::array< uint8_t, 4 *1024 > *map)
 
static double dot_product (std::vector< double > const &t1, std::vector< double > const &t2)
 Calculate the dot product of the given arrays.
 

Variables

static cmsUInt32Number customSigOKLabData = 0x4f4b4c42
 
static std::map< cmsUInt32Number, Space::Type_lcmssig_to_space
 
constexpr double LUMA_SCALE = 100
 
constexpr double MIN_SCALE = -128
 
constexpr double MAX_SCALE = 128
 
constexpr double MIN_CSS_SCALE = -125
 
constexpr double MAX_CSS_SCALE = 125
 
constexpr double CHROMA_SCALE = 150
 
constexpr double HUE_SCALE = 360
 
constexpr double REF_U = 0.19783000664283680764
 
constexpr double REF_V = 0.46831999493879100370
 
constexpr double MIN_U = -100
 
constexpr double MAX_U = 200
 
constexpr double MIN_V = -200
 
constexpr double MAX_V = 120
 
constexpr double KAPPA = 903.29629629629629629630
 
constexpr double EPSILON = 0.00885645167903563082
 
Matrix LRGB2CONE
 Matrix of the linear transformation from linear RGB space to linear cone responses, used in the first step of RGB to OKLab conversion.
 
Matrix CONE2LRGB
 The inverse of the matrix LRGB2CONE.
 
Matrix M2
 The matrix M2 used in the second step of RGB to OKLab conversion.
 
Matrix M2_INVERSE
 The inverse of the matrix M2.
 
ChromaLineCoefficients const LAB_BOUNDS []
 
unsigned const COLOR_SCALE_INTERVALS = 32
 How many intervals a color scale should be subdivided into for the chroma bounds probing.
 
const std::vector< double > illuminant_d65 = {0.9504, 1.0000, 1.0888}
 
const std::vector< double > d65 [3]
 
const std::vector< double > d65_inv [3]
 

Typedef Documentation

◆ Matrix

using Inkscape::Colors::Space::Matrix = typedef const double[3][3]

Two-dimensional array to store a constant 3x3 matrix.

Definition at line 42 of file oklab.cpp.

Enumeration Type Documentation

◆ Traits

Enumerator
None 
Picker 
Internal 
CMS 

Definition at line 26 of file components.h.

◆ Type

enum class Inkscape::Colors::Space::Type
strong
Enumerator
NONE 
Gray 
RGB 
linearRGB 
HSL 
HSV 
HWB 
CMYK 
CMY 
XYZ 
YXY 
LUV 
LCH 
LAB 
HSLUV 
OKHSL 
OKHSV 
OKLCH 
OKLAB 
YCbCr 
CSSNAME 
CMS 

Definition at line 47 of file enum.h.

◆ Unit

enum class Inkscape::Colors::Space::Unit
strong
Enumerator
EightBit 
Percent 
Degree 
Linear1024 
Chroma40 

Definition at line 42 of file components.h.

Function Documentation

◆ _build()

std::map< Type, Components > Inkscape::Colors::Space::_build ( bool  alpha)

◆ component_coefficients()

static std::array< double, 4 > Inkscape::Colors::Space::component_coefficients ( unsigned  index,
ConstraintMonomials const &  m 
)
static

Find the coefficients of the cubic polynomial expressing the linear R, G or B component as a function of OKLch chroma.

The returned polynomial gives R(c), G(c) or B(c) for all values of c and fixed values of luminance and hue.

Parameters
indexThe index of the component to evaluate (0 for R, 1 for G, 2 for B).
mThe monomials in L, cos(hue) and sin(hue) needed for the calculation.
Returns
an array whose i-th element is the coefficient of c^i in the polynomial.

Definition at line 173 of file oklch.cpp.

References index, LAB_BOUNDS, and result.

Referenced by Inkscape::Colors::Space::OkLch::max_chroma().

◆ dot3()

template<typename A1 , typename A2 >
constexpr double Inkscape::Colors::Space::dot3 ( const A1 &  a1,
const A2 &  a2 
)
inlineconstexpr

Compute the dot-product between two 3D-vectors.

Definition at line 77 of file oklab.cpp.

Referenced by Inkscape::Colors::Space::OkLab::fromLinearRGB(), and Inkscape::Colors::Space::OkLab::toLinearRGB().

◆ dot_product()

static double Inkscape::Colors::Space::dot_product ( std::vector< double > const &  t1,
std::vector< double > const &  t2 
)
static

Calculate the dot product of the given arrays.

Parameters
t1The first array.
t2The second array.
Returns
The resulting dot product.

Definition at line 30 of file xyz.cpp.

Referenced by Inkscape::Colors::Space::XYZ::fromLinearRGB(), and Inkscape::Colors::Space::XYZ::toLinearRGB().

◆ from_linear()

double Inkscape::Colors::Space::from_linear ( double  c)

Convenience function used for RGB conversions.

Parameters
cValue.
Returns
RGB color component.

Definition at line 26 of file linear-rgb.cpp.

References c.

Referenced by Inkscape::Colors::Space::LinearRGB::toRGB().

◆ get_color_spaces()

static const std::vector< Components > Inkscape::Colors::Space::get_color_spaces ( )
static

Definition at line 25 of file components.cpp.

References Chroma40, CMS, CMY, CMYK, Degree, EightBit, Gray, HSL, HSLUV, HSV, Internal, LAB, LCH, Linear1024, linearRGB, LUV, NONE, OKHSL, OKHSV, OKLAB, OKLCH, Percent, Picker, RGB, XYZ, YCbCr, and YXY.

Referenced by _build().

◆ hue_2_rgb()

static float Inkscape::Colors::Space::hue_2_rgb ( float  v1,
float  v2,
float  h 
)
static

Definition at line 19 of file hsl.cpp.

Referenced by Inkscape::Colors::Space::HSL::spaceToProfile().

◆ l2y()

static double Inkscape::Colors::Space::l2y ( double  l)
static

Utility function used to convert from CIELuv colorspace to XYZ.

Parameters
lLuminance component of Luv color.
Returns
Y component of the XYZ color.

Definition at line 87 of file luv.cpp.

References KAPPA.

Referenced by Inkscape::Colors::Space::Luv::toXYZ().

◆ max_chroma_for_lh()

static double Inkscape::Colors::Space::max_chroma_for_lh ( double  l,
double  h 
)
static

Calculate the maximum in gamut chromaticity for the given luminance and hue.

Parameters
lLuminance.
hHue.
Returns
The maximum chromaticity.

Definition at line 61 of file hsluv.cpp.

References Inkscape::Colors::Space::HSLuv::get_bounds(), and len.

Referenced by Inkscape::Colors::Space::HSLuv::fromLch(), and Inkscape::Colors::Space::HSLuv::toLch().

◆ operator&()

Traits Inkscape::Colors::Space::operator& ( const Traits  lhs,
const Traits  rhs 
)
inline

Definition at line 32 of file components.h.

◆ operator|()

Traits Inkscape::Colors::Space::operator| ( const Traits  lhs,
const Traits  rhs 
)
inline

Definition at line 36 of file components.h.

◆ render_hue_scale()

uint8_t const * Inkscape::Colors::Space::render_hue_scale ( double  s,
double  l,
std::array< uint8_t, 4 *1024 > *  map 
)

◆ render_lightness_scale()

uint8_t const * Inkscape::Colors::Space::render_lightness_scale ( double  h,
double  s,
std::array< uint8_t, 4 *1024 > *  map 
)

◆ render_saturation_scale()

uint8_t const * Inkscape::Colors::Space::render_saturation_scale ( double  h,
double  l,
std::array< uint8_t, 4 *1024 > *  map 
)

Definition at line 296 of file oklch.cpp.

References c, data, Inkscape::Colors::Space::OkLch::max_chroma(), OKLCH, RGB, rgb, and SP_COLOR_F_TO_U().

◆ to_linear()

double Inkscape::Colors::Space::to_linear ( double  c)

Convenience function used for RGB conversions.

Parameters
cValue.
Returns
XYZ color component.

Definition at line 41 of file linear-rgb.cpp.

References c.

Referenced by Inkscape::Colors::Space::LinearRGB::fromRGB().

◆ y2l()

static double Inkscape::Colors::Space::y2l ( double  y)
static

Utility function used to convert from the XYZ colorspace to CIELuv.

https://en.wikipedia.org/wiki/CIELUV

Parameters
yY component of the XYZ color.
Returns
Luminance component of Luv color.

Definition at line 73 of file luv.cpp.

References EPSILON, and KAPPA.

Referenced by Inkscape::Colors::Space::Luv::fromXYZ().

Variable Documentation

◆ _lcmssig_to_space

std::map<cmsUInt32Number, Space::Type> Inkscape::Colors::Space::_lcmssig_to_space
static
Initial value:
= {
{cmsSigRgbData, Space::Type::RGB}, {cmsSigHlsData, Space::Type::HSL},
{cmsSigCmykData, Space::Type::CMYK}, {cmsSigCmyData, Space::Type::CMY},
{cmsSigHsvData, Space::Type::HSV}, {cmsSigLuvData, Space::Type::HSLUV},
{customSigOKLabData, Space::Type::OKLAB}, {cmsSigXYZData, Space::Type::XYZ},
{cmsSigXYZData, Space::Type::YXY}, {cmsSigLabData, Space::Type::LAB},
{cmsSigYCbCrData, Space::Type::YCbCr}, {cmsSigGrayData, Space::Type::Gray},
}
static cmsUInt32Number customSigOKLabData
Definition cms.cpp:23

Definition at line 25 of file cms.cpp.

◆ CHROMA_SCALE

◆ COLOR_SCALE_INTERVALS

unsigned const Inkscape::Colors::Space::COLOR_SCALE_INTERVALS = 32

How many intervals a color scale should be subdivided into for the chroma bounds probing.

The reason this constant exists is because probing chroma bounds requires solving 6 cubic equations, which would not be feasible for all 1024 pixels on a scale without slowing down the UI. To speed things up, we subdivide the scale into COLOR_SCALE_INTERVALS intervals and linearly interpolate the chroma bound on each interval. Note that the actual color interpolation is still done in the OKLab space, but the computed absolute chroma may be slightly off in the middle of each interval (hopefully, in an imperceptible way).

Todo:
Consider rendering the color sliders asynchronously, which might make this interpolation unnecessary. We would then get full precision gradients.

Definition at line 263 of file oklch.cpp.

Referenced by render_hue_scale(), and render_lightness_scale().

◆ CONE2LRGB

Matrix Inkscape::Colors::Space::CONE2LRGB
Initial value:
= {
{ 4.0767416613479942676681908333711298900607278264432, -3.30771159040819331315866078424893188865618253342, 0.230969928729427886449650619561935920170561518112 },
{ -1.2684380040921760691815055595117506020901414005992, 2.60975740066337143024050095284233623056192338553, -0.341319396310219620992658250306535533187548361872 },
{ -0.0041960865418371092973767821251846315637521173374, -0.70341861445944960601310996913659932654899822384, 1.707614700930944853864541790660472961199090408527 }
}

The inverse of the matrix LRGB2CONE.

Definition at line 53 of file oklab.cpp.

Referenced by Inkscape::Colors::Space::OkLab::toLinearRGB().

◆ customSigOKLabData

cmsUInt32Number Inkscape::Colors::Space::customSigOKLabData = 0x4f4b4c42
static

Definition at line 23 of file cms.cpp.

◆ d65

const std::vector<double> Inkscape::Colors::Space::d65[3]
inline
Initial value:
= {{3.24096994190452134377, -1.53738317757009345794, -0.49861076029300328366},
{-0.96924363628087982613, 1.87596750150772066772, 0.04155505740717561247},
{0.05563007969699360846, -0.20397695888897656435, 1.05697151424287856072}}

Definition at line 23 of file xyz.h.

Referenced by Inkscape::Colors::Space::HSLuv::get_bounds(), and Inkscape::Colors::Space::XYZ::toLinearRGB().

◆ d65_inv

const std::vector<double> Inkscape::Colors::Space::d65_inv[3]
inline
Initial value:
= {{0.41239079926595949381, 0.35758433938387799725, 0.18048078840183429261},
{0.21263900587151036595, 0.71516867876775596569, 0.07219231536073371975},
{0.019330818715591851469, 0.1191947797946259924, 0.9505321522496605464}}

Definition at line 27 of file xyz.h.

Referenced by Inkscape::Colors::Space::XYZ::fromLinearRGB().

◆ EPSILON

constexpr double Inkscape::Colors::Space::EPSILON = 0.00885645167903563082
constexpr

Definition at line 20 of file luv.h.

Referenced by Inkscape::Colors::Space::HSLuv::get_bounds(), and y2l().

◆ HUE_SCALE

◆ illuminant_d65

const std::vector<double> Inkscape::Colors::Space::illuminant_d65 = {0.9504, 1.0000, 1.0888}
inline

◆ KAPPA

constexpr double Inkscape::Colors::Space::KAPPA = 903.29629629629629629630
constexpr

Definition at line 19 of file luv.h.

Referenced by Inkscape::Colors::Space::HSLuv::get_bounds(), l2y(), and y2l().

◆ LAB_BOUNDS

ChromaLineCoefficients const Inkscape::Colors::Space::LAB_BOUNDS[]

Definition at line 88 of file oklch.cpp.

Referenced by component_coefficients().

◆ LRGB2CONE

Matrix Inkscape::Colors::Space::LRGB2CONE
Initial value:
= {{0.4122214708, 0.5363325363, 0.0514459929},
{0.2119034982, 0.6806995451, 0.1073969566},
{0.0883024619, 0.2817188376, 0.6299787005}}

Matrix of the linear transformation from linear RGB space to linear cone responses, used in the first step of RGB to OKLab conversion.

Definition at line 48 of file oklab.cpp.

Referenced by Inkscape::Colors::Space::OkLab::fromLinearRGB().

◆ LUMA_SCALE

◆ M2

Matrix Inkscape::Colors::Space::M2
Initial value:
= {{0.2104542553, 0.793617785, -0.0040720468},
{1.9779984951, -2.428592205, 0.4505937099},
{0.0259040371, 0.7827717662, -0.808675766}}

The matrix M2 used in the second step of RGB to OKLab conversion.

Taken from https://bottosson.github.io/posts/oklab/ (retrieved 2022).

Definition at line 62 of file oklab.cpp.

Referenced by Inkscape::Colors::Space::OkLab::fromLinearRGB().

◆ M2_INVERSE

Matrix Inkscape::Colors::Space::M2_INVERSE
Initial value:
= {
{ 0.99999999845051981426207542502031373637162589278552, 0.39633779217376785682345989261573192476766903603, 0.215803758060758803423141461830037892590617787467 },
{ 1.00000000888176077671607524567047071276183677410134, -0.10556134232365634941095687705472233997368274024, -0.063854174771705903405254198817795633810975771082 },
{ 1.00000005467241091770129286515344610721841028698942, -0.08948418209496575968905274586339134130669669716, -1.291485537864091739948928752914772401878545675371 }
}

The inverse of the matrix M2.

The first column looks like it wants to be 1 but this form is closer to the actual inverse (due to numerics).

Definition at line 68 of file oklab.cpp.

Referenced by Inkscape::Colors::Space::OkLab::toLinearRGB().

◆ MAX_CSS_SCALE

constexpr double Inkscape::Colors::Space::MAX_CSS_SCALE = 125
constexpr

◆ MAX_SCALE

◆ MAX_U

constexpr double Inkscape::Colors::Space::MAX_U = 200
constexpr

◆ MAX_V

constexpr double Inkscape::Colors::Space::MAX_V = 120
constexpr

◆ MIN_CSS_SCALE

constexpr double Inkscape::Colors::Space::MIN_CSS_SCALE = -125
constexpr

Definition at line 25 of file lab.cpp.

Referenced by Inkscape::Colors::Space::Lab::toString().

◆ MIN_SCALE

◆ MIN_U

constexpr double Inkscape::Colors::Space::MIN_U = -100
constexpr

◆ MIN_V

constexpr double Inkscape::Colors::Space::MIN_V = -200
constexpr

◆ REF_U

constexpr double Inkscape::Colors::Space::REF_U = 0.19783000664283680764
constexpr

◆ REF_V

constexpr double Inkscape::Colors::Space::REF_V = 0.46831999493879100370
constexpr