Krita Source Code Documentation
Loading...
Searching...
No Matches
KisColorimetryUtils::Colorimetry Class Reference

#include <KisColorimetryUtils.h>

Public Member Functions

QMatrix4x4 absoluteColorimetricTo (const Colorimetry &other) const
 
Colorimetry adaptedTo (xyY newWhitepoint) const
 
const XYZblue () const
 
 Colorimetry (xy red, xy green, xy blue, xy white)
 
 Colorimetry (xyY red, xyY green, xyY blue, xyY white)
 
 Colorimetry (XYZ red, XYZ green, XYZ blue, XYZ white)
 
QMatrix4x4 fromLMS () const
 
const QMatrix4x4 & fromXYZ () const
 
const XYZgreen () const
 
Colorimetry interpolateGamutTo (const Colorimetry &one, double factor) const
 
bool operator== (const Colorimetry &other) const
 
const XYZred () const
 
QMatrix4x4 relativeColorimetricTo (const Colorimetry &other) const
 
QMatrix4x4 toLMS () const
 
const QMatrix4x4 & toXYZ () const
 
const XYZwhite () const
 
Colorimetry withWhitepoint (xyY newWhitePoint) const
 

Static Public Member Functions

static QMatrix4x4 calculateToXYZMatrix (XYZ red, XYZ green, XYZ blue, XYZ white)
 
static QMatrix4x4 chromaticAdaptationMatrix (XYZ sourceWhitepoint, XYZ destinationWhitepoint)
 
static bool isReal (xy red, xy green, xy blue, xy white)
 
static bool isValid (xy red, xy green, xy blue, xy white)
 

Static Public Attributes

static const Colorimetry AdobeRGB
 
static const Colorimetry BT2020
 
static const Colorimetry BT709
 
static const Colorimetry CIEXYZ
 
static const Colorimetry DCIP3
 
static const Colorimetry DisplayP3
 
static const Colorimetry GenericFilm
 
static const Colorimetry NTSC
 
static const Colorimetry PAL
 
static const Colorimetry PAL_M
 

Private Attributes

XYZ m_blue
 
QMatrix4x4 m_fromXYZ
 
XYZ m_green
 
XYZ m_red
 
QMatrix4x4 m_toXYZ
 
XYZ m_white
 

Detailed Description

Describes the definition of colors in a color space. Red, green and blue define the chromaticities ("absolute colors") of the red, green and blue LEDs on a display in xy coordinates White defines the the chromaticity of the reference white in xy coordinates

Definition at line 70 of file KisColorimetryUtils.h.

Constructor & Destructor Documentation

◆ Colorimetry() [1/3]

KisColorimetryUtils::Colorimetry::Colorimetry ( XYZ red,
XYZ green,
XYZ blue,
XYZ white )
explicit

◆ Colorimetry() [2/3]

KisColorimetryUtils::Colorimetry::Colorimetry ( xyY red,
xyY green,
xyY blue,
xyY white )
explicit

Definition at line 257 of file KisColorimetryUtils.cpp.

258 : Colorimetry(red.toXYZ(), green.toXYZ(), blue.toXYZ(), white.toXYZ())
259{
260}
Colorimetry(XYZ red, XYZ green, XYZ blue, XYZ white)

◆ Colorimetry() [3/3]

KisColorimetryUtils::Colorimetry::Colorimetry ( xy red,
xy green,
xy blue,
xy white )
explicit

Definition at line 262 of file KisColorimetryUtils.cpp.

263 : m_white(xyY{white.x, white.y, 1.0}.toXYZ())
264{
265 const auto brightness = (matrixFromColumns(xyY{red.x, red.y, 1.0}.toXYZ().asVector(),
266 xyY{green.x, green.y, 1.0}.toXYZ().asVector(),
267 xyY{blue.x, blue.y, 1.0}.toXYZ().asVector()))
268 .inverted().map(
269 xyY{white.x, white.y, 1.0}.toXYZ().asVector());
270 m_red = xyY{red.x, red.y, brightness.x()}.toXYZ();
271 m_green = xyY{green.x, green.y, brightness.y()}.toXYZ();
272 m_blue = xyY{blue.x, blue.y, brightness.z()}.toXYZ();
274 m_fromXYZ = m_toXYZ.inverted();
275}
QMatrix4x4 matrixFromColumns(const QVector3D &first, const QVector3D &second, const QVector3D &third)

References KisColorimetryUtils::XYZ::asVector(), blue(), calculateToXYZMatrix(), green(), m_blue, m_fromXYZ, m_green, m_red, m_toXYZ, m_white, KisColorimetryUtils::matrixFromColumns(), red(), and white().

Member Function Documentation

◆ absoluteColorimetricTo()

QMatrix4x4 KisColorimetryUtils::Colorimetry::absoluteColorimetricTo ( const Colorimetry & other) const

Definition at line 340 of file KisColorimetryUtils.cpp.

341{
342 return other.fromXYZ() * toXYZ();
343}

References fromXYZ(), and toXYZ().

◆ adaptedTo()

Colorimetry KisColorimetryUtils::Colorimetry::adaptedTo ( xyY newWhitepoint) const
Returns
this colorimetry, adapted to the new whitepoint using the Bradford transform

Definition at line 313 of file KisColorimetryUtils.cpp.

314{
315 const auto mat = chromaticAdaptationMatrix(this->white(), newWhitepoint.toXYZ());
316 return Colorimetry{
317 XYZ::fromVector(mat.map(red().asVector())),
318 XYZ::fromVector(mat.map(green().asVector())),
319 XYZ::fromVector(mat.map(blue().asVector())),
320 newWhitepoint.toXYZ(),
321 };
322}
static QMatrix4x4 chromaticAdaptationMatrix(XYZ sourceWhitepoint, XYZ destinationWhitepoint)
static XYZ fromVector(const QVector3D &vector)

References blue(), chromaticAdaptationMatrix(), KisColorimetryUtils::XYZ::fromVector(), green(), red(), KisColorimetryUtils::xyY::toXYZ(), and white().

◆ blue()

const XYZ & KisColorimetryUtils::Colorimetry::blue ( ) const

Definition at line 360 of file KisColorimetryUtils.cpp.

361{
362 return m_blue;
363}

References m_blue.

◆ calculateToXYZMatrix()

QMatrix4x4 KisColorimetryUtils::Colorimetry::calculateToXYZMatrix ( XYZ red,
XYZ green,
XYZ blue,
XYZ white )
static

Definition at line 188 of file KisColorimetryUtils.cpp.

189{
190 const QVector3D r = red.asVector();
191 const QVector3D g = green.asVector();
192 const QVector3D b = blue.asVector();
193 const auto component_scale = (matrixFromColumns(r, g, b)).inverted().map(white.asVector());
194 return matrixFromColumns(r * component_scale.x(), g * component_scale.y(), b * component_scale.z());
195}

References KisColorimetryUtils::XYZ::asVector(), blue(), green(), KisColorimetryUtils::matrixFromColumns(), red(), and white().

◆ chromaticAdaptationMatrix()

QMatrix4x4 KisColorimetryUtils::Colorimetry::chromaticAdaptationMatrix ( XYZ sourceWhitepoint,
XYZ destinationWhitepoint )
static
Returns
a matrix adapting XYZ values from the source whitepoint to the destination whitepoint with the Bradford transform

Definition at line 149 of file KisColorimetryUtils.cpp.

150{
151 static const QMatrix4x4 bradford = []() {
152 QMatrix4x4 ret;
153 ret(0, 0) = 0.8951;
154 ret(0, 1) = 0.2664;
155 ret(0, 2) = -0.1614;
156 ret(1, 0) = -0.7502;
157 ret(1, 1) = 1.7135;
158 ret(1, 2) = 0.0367;
159 ret(2, 0) = 0.0389;
160 ret(2, 1) = -0.0685;
161 ret(2, 2) = 1.0296;
162 return ret;
163 }();
164 static const QMatrix4x4 inverseBradford = []() {
165 QMatrix4x4 ret;
166 ret(0, 0) = 0.9869929;
167 ret(0, 1) = -0.1470543;
168 ret(0, 2) = 0.1599627;
169 ret(1, 0) = 0.4323053;
170 ret(1, 1) = 0.5183603;
171 ret(1, 2) = 0.0492912;
172 ret(2, 0) = -0.0085287;
173 ret(2, 1) = 0.0400428;
174 ret(2, 2) = 0.9684867;
175 return ret;
176 }();
177 if (sourceWhitepoint == destinationWhitepoint) {
178 return QMatrix4x4{};
179 }
180 const QVector3D factors = (bradford.map(destinationWhitepoint.asVector())) / (bradford.map(sourceWhitepoint.asVector()));
181 QMatrix4x4 adaptation{};
182 adaptation(0, 0) = factors.x();
183 adaptation(1, 1) = factors.y();
184 adaptation(2, 2) = factors.z();
185 return inverseBradford * adaptation * bradford;
186}

References KisColorimetryUtils::XYZ::asVector().

◆ fromLMS()

QMatrix4x4 KisColorimetryUtils::Colorimetry::fromLMS ( ) const

Definition at line 308 of file KisColorimetryUtils.cpp.

309{
311}
static const QMatrix4x4 s_inverseDolbyLMS

References m_fromXYZ, and KisColorimetryUtils::s_inverseDolbyLMS.

◆ fromXYZ()

const QMatrix4x4 & KisColorimetryUtils::Colorimetry::fromXYZ ( ) const
Returns
a matrix that transforms from the XYZ representation to the linear RGB representation of colors in this colorimetry

Definition at line 282 of file KisColorimetryUtils.cpp.

283{
284 return m_fromXYZ;
285}

References m_fromXYZ.

◆ green()

const XYZ & KisColorimetryUtils::Colorimetry::green ( ) const

Definition at line 355 of file KisColorimetryUtils.cpp.

356{
357 return m_green;
358}

References m_green.

◆ interpolateGamutTo()

Colorimetry KisColorimetryUtils::Colorimetry::interpolateGamutTo ( const Colorimetry & one,
double factor ) const

interpolates the primaries depending on the passed factor. The whitepoint stays unchanged

Definition at line 197 of file KisColorimetryUtils.cpp.

198{
199 return Colorimetry{
200 m_red * (1 - factor) + one.red() * factor,
201 m_green * (1 - factor) + one.green() * factor,
202 m_blue * (1 - factor) + one.blue() * factor,
203 m_white, // whitepoint should stay the same
204 };
205}

References blue(), green(), m_blue, m_green, m_red, m_white, and red().

◆ isReal()

bool KisColorimetryUtils::Colorimetry::isReal ( xy red,
xy green,
xy blue,
xy white )
static

checks if the colorimetry could be from a real display

Definition at line 233 of file KisColorimetryUtils.cpp.

234{
235 if (!isValid(red, green, blue, white)) {
236 return false;
237 }
238 // outside of XYZ definitely can't be shown on a display
239 // TODO maybe calculate if all values are within the human-visible gamut too?
240 if (red.x < 0 || red.x > 1 || red.y < 0 || red.y > 1 || green.x < 0 || green.x > 1 || green.y < 0 || green.y > 1 || blue.x < 0 || blue.x > 1 || blue.y < 0
241 || blue.y > 1 || white.x < 0 || white.x > 1 || white.y < 0 || white.y > 1) {
242 return false;
243 }
244 return true;
245}
static bool isValid(xy red, xy green, xy blue, xy white)

References blue(), green(), isValid(), red(), and white().

◆ isValid()

bool KisColorimetryUtils::Colorimetry::isValid ( xy red,
xy green,
xy blue,
xy white )
static

checks if the colorimetry is sane and won't cause crashes or glitches

Definition at line 212 of file KisColorimetryUtils.cpp.

213{
214 // this is more of a heuristic than a hard rule
215 // but if the gamut is too small, it's not really usable
216 const double gamutArea = triangleArea(red.asVector(), green.asVector(), blue.asVector());
217 if (gamutArea < 0.02) {
218 return false;
219 }
220 // if the white point is inside the gamut triangle,
221 // the three triangles made up between the primaries and the whitepoint
222 // must have the same area as the gamut triangle
223 const double area1 = triangleArea(white.asVector(), green.asVector(), blue.asVector());
224 const double area2 = triangleArea(red.asVector(), white.asVector(), blue.asVector());
225 const double area3 = triangleArea(red.asVector(), green.asVector(), white.asVector());
226 if (std::abs(area1 + area2 + area3 - gamutArea) > 0.001) {
227 // this would cause terrible glitches
228 return false;
229 }
230 return true;
231}
static double triangleArea(QVector2D p1, QVector2D p2, QVector2D p3)

References KisColorimetryUtils::XYZ::asVector(), blue(), green(), red(), KisColorimetryUtils::triangleArea(), and white().

◆ operator==()

bool KisColorimetryUtils::Colorimetry::operator== ( const Colorimetry & other) const

Definition at line 345 of file KisColorimetryUtils.cpp.

346{
347 return red() == other.red() && green() == other.green() && blue() == other.blue() && white() == other.white();
348}

References blue(), green(), red(), and white().

◆ red()

const XYZ & KisColorimetryUtils::Colorimetry::red ( ) const

Definition at line 350 of file KisColorimetryUtils.cpp.

351{
352 return m_red;
353}

References m_red.

◆ relativeColorimetricTo()

QMatrix4x4 KisColorimetryUtils::Colorimetry::relativeColorimetricTo ( const Colorimetry & other) const

Definition at line 335 of file KisColorimetryUtils.cpp.

336{
337 return other.fromXYZ() * chromaticAdaptationMatrix(white(), other.white()) * toXYZ();
338}

References chromaticAdaptationMatrix(), fromXYZ(), toXYZ(), and white().

◆ toLMS()

QMatrix4x4 KisColorimetryUtils::Colorimetry::toLMS ( ) const

Definition at line 303 of file KisColorimetryUtils.cpp.

304{
305 return s_xyzToDolbyLMS * m_toXYZ;
306}
static const QMatrix4x4 s_xyzToDolbyLMS

References m_toXYZ, and KisColorimetryUtils::s_xyzToDolbyLMS.

◆ toXYZ()

const QMatrix4x4 & KisColorimetryUtils::Colorimetry::toXYZ ( ) const
Returns
a matrix that transforms from the linear RGB representation of colors in this colorimetry to the XYZ representation

Definition at line 277 of file KisColorimetryUtils.cpp.

278{
279 return m_toXYZ;
280}

References m_toXYZ.

◆ white()

const XYZ & KisColorimetryUtils::Colorimetry::white ( ) const

Definition at line 365 of file KisColorimetryUtils.cpp.

366{
367 return m_white;
368}

References m_white.

◆ withWhitepoint()

Colorimetry KisColorimetryUtils::Colorimetry::withWhitepoint ( xyY newWhitePoint) const

replaces the current whitepoint with the new one this does not do whitepoint adaptation!

Definition at line 324 of file KisColorimetryUtils.cpp.

325{
326 newWhitePoint.Y = 1;
327 return Colorimetry{
328 m_red,
329 m_green,
330 m_blue,
331 newWhitePoint.toXYZ(),
332 };
333}

References m_blue, m_green, m_red, KisColorimetryUtils::xyY::toXYZ(), and KisColorimetryUtils::xyY::Y.

Member Data Documentation

◆ AdobeRGB

const Colorimetry KisColorimetryUtils::Colorimetry::AdobeRGB
static
Initial value:
xy{0.6400, 0.3300},
xy{0.2100, 0.7100},
xy{0.1500, 0.0600},
xy{0.3127, 0.3290},
}

Definition at line 82 of file KisColorimetryUtils.h.

◆ BT2020

const Colorimetry KisColorimetryUtils::Colorimetry::BT2020
static
Initial value:
xy{0.708, 0.292},
xy{0.170, 0.797},
xy{0.131, 0.046},
xy{0.3127, 0.3290},
}

Definition at line 78 of file KisColorimetryUtils.h.

◆ BT709

const Colorimetry KisColorimetryUtils::Colorimetry::BT709
static
Initial value:
xy{0.64, 0.33},
xy{0.30, 0.60},
xy{0.15, 0.06},
xy{0.3127, 0.3290},
}

Definition at line 73 of file KisColorimetryUtils.h.

◆ CIEXYZ

const Colorimetry KisColorimetryUtils::Colorimetry::CIEXYZ
static
Initial value:
XYZ{1.0, 0.0, 0.0},
XYZ{0.0, 1.0, 0.0},
XYZ{0.0, 0.0, 1.0},
xy{1.0 / 3.0, 1.0 / 3.0}.toXYZ(),
}

Definition at line 79 of file KisColorimetryUtils.h.

◆ DCIP3

const Colorimetry KisColorimetryUtils::Colorimetry::DCIP3
static
Initial value:
xy{0.680, 0.320},
xy{0.265, 0.690},
xy{0.150, 0.060},
xy{0.314, 0.351},
}

Definition at line 80 of file KisColorimetryUtils.h.

◆ DisplayP3

const Colorimetry KisColorimetryUtils::Colorimetry::DisplayP3
static
Initial value:
xy{0.680, 0.320},
xy{0.265, 0.690},
xy{0.150, 0.060},
xy{0.3127, 0.3290},
}

Definition at line 81 of file KisColorimetryUtils.h.

◆ GenericFilm

const Colorimetry KisColorimetryUtils::Colorimetry::GenericFilm
static
Initial value:
xy{0.681, 0.319},
xy{0.243, 0.692},
xy{0.145, 0.049},
xy{0.310, 0.316},
}

Definition at line 77 of file KisColorimetryUtils.h.

◆ m_blue

XYZ KisColorimetryUtils::Colorimetry::m_blue
private

Definition at line 141 of file KisColorimetryUtils.h.

◆ m_fromXYZ

QMatrix4x4 KisColorimetryUtils::Colorimetry::m_fromXYZ
private

Definition at line 144 of file KisColorimetryUtils.h.

◆ m_green

XYZ KisColorimetryUtils::Colorimetry::m_green
private

Definition at line 140 of file KisColorimetryUtils.h.

◆ m_red

XYZ KisColorimetryUtils::Colorimetry::m_red
private

Definition at line 139 of file KisColorimetryUtils.h.

◆ m_toXYZ

QMatrix4x4 KisColorimetryUtils::Colorimetry::m_toXYZ
private

Definition at line 143 of file KisColorimetryUtils.h.

◆ m_white

XYZ KisColorimetryUtils::Colorimetry::m_white
private

Definition at line 142 of file KisColorimetryUtils.h.

◆ NTSC

const Colorimetry KisColorimetryUtils::Colorimetry::NTSC
static
Initial value:
xy{0.630, 0.340},
xy{0.310, 0.595},
xy{0.155, 0.070},
xy{0.3127, 0.3290},
}

Definition at line 76 of file KisColorimetryUtils.h.

◆ PAL

const Colorimetry KisColorimetryUtils::Colorimetry::PAL
static
Initial value:
xy{0.640, 0.330},
xy{0.290, 0.600},
xy{0.150, 0.060},
xy{0.3127, 0.3290},
}

Definition at line 75 of file KisColorimetryUtils.h.

◆ PAL_M

const Colorimetry KisColorimetryUtils::Colorimetry::PAL_M
static
Initial value:
xy{0.67, 0.33},
xy{0.21, 0.71},
xy{0.14, 0.08},
xy{0.310, 0.316},
}

Definition at line 74 of file KisColorimetryUtils.h.


The documentation for this class was generated from the following files: