Krita Source Code Documentation
Loading...
Searching...
No Matches
KisColorimetryUtils.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2023 Xaver Hugl <xaver.hugl@gmail.com>
3 * SPDX-FileCopyrightText: 2025 Dmitry Kazakov <dimula73@gmail.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 */
7#ifndef KISCOLORIMETRYUTILS_H
8#define KISCOLORIMETRYUTILS_H
9
10#include <QVector2D>
11#include <QVector3D>
12#include <QMatrix4x4>
13#include <boost/operators.hpp>
14#include <QDebug>
15
16#include <kritasurfacecolormanagementapi_export.h>
17
18namespace KisColorimetryUtils
19{
20
21// these functions were taken from KWin's colorimetry code
22// https://invent.kde.org/plasma/kwin/-/blob/master/src/core/colorspace.h
23
24QMatrix4x4 matrixFromColumns(const QVector3D &first, const QVector3D &second, const QVector3D &third);
25
26struct XYZ;
27
31struct KRITASURFACECOLORMANAGEMENTAPI_EXPORT xy {
32 double x;
33 double y;
34
35 XYZ toXYZ() const;
36 QVector2D asVector() const;
37 bool operator==(const xy &other) const;
38};
39
40struct KRITASURFACECOLORMANAGEMENTAPI_EXPORT xyY {
41 double x;
42 double y;
43 double Y;
44
45 XYZ toXYZ() const;
46 bool operator==(const xyY &other) const;
47};
48
49struct KRITASURFACECOLORMANAGEMENTAPI_EXPORT XYZ {
50 double X;
51 double Y;
52 double Z;
53
54 xyY toxyY() const;
55 xy toxy() const;
56 QVector3D asVector() const;
57 XYZ operator*(double factor) const;
58 XYZ operator/(double factor) const;
59 XYZ operator+(const XYZ &other) const;
60 bool operator==(const XYZ &other) const;
61
62 static XYZ fromVector(const QVector3D &vector);
63};
64
70class KRITASURFACECOLORMANAGEMENTAPI_EXPORT Colorimetry
71{
72public:
73 static const Colorimetry BT709;
74 static const Colorimetry PAL_M;
75 static const Colorimetry PAL;
76 static const Colorimetry NTSC;
78 static const Colorimetry BT2020;
79 static const Colorimetry CIEXYZ;
80 static const Colorimetry DCIP3;
81 static const Colorimetry DisplayP3;
82 static const Colorimetry AdobeRGB;
83
87 static QMatrix4x4 chromaticAdaptationMatrix(XYZ sourceWhitepoint, XYZ destinationWhitepoint);
88
89 static QMatrix4x4 calculateToXYZMatrix(XYZ red, XYZ green, XYZ blue, XYZ white);
90
94 static bool isValid(xy red, xy green, xy blue, xy white);
98 static bool isReal(xy red, xy green, xy blue, xy white);
99
100 explicit Colorimetry(XYZ red, XYZ green, XYZ blue, XYZ white);
101 explicit Colorimetry(xyY red, xyY green, xyY blue, xyY white);
102 explicit Colorimetry(xy red, xy green, xy blue, xy white);
103
107 const QMatrix4x4 &toXYZ() const;
111 const QMatrix4x4 &fromXYZ() const;
112 QMatrix4x4 toLMS() const;
113 QMatrix4x4 fromLMS() const;
114
115 bool operator==(const Colorimetry &other) const;
119 Colorimetry adaptedTo(xyY newWhitepoint) const;
124 Colorimetry withWhitepoint(xyY newWhitePoint) const;
128 Colorimetry interpolateGamutTo(const Colorimetry &one, double factor) const;
129
130 QMatrix4x4 relativeColorimetricTo(const Colorimetry &other) const;
131 QMatrix4x4 absoluteColorimetricTo(const Colorimetry &other) const;
132
133 const XYZ &red() const;
134 const XYZ &green() const;
135 const XYZ &blue() const;
136 const XYZ &white() const;
137
138private:
143 QMatrix4x4 m_toXYZ;
144 QMatrix4x4 m_fromXYZ;
145};
146
147KRITASURFACECOLORMANAGEMENTAPI_EXPORT QDebug operator<<(QDebug debug, const xy &value);
148KRITASURFACECOLORMANAGEMENTAPI_EXPORT QDebug operator<<(QDebug debug, const xyY &value);
149KRITASURFACECOLORMANAGEMENTAPI_EXPORT QDebug operator<<(QDebug debug, const XYZ &value);
150KRITASURFACECOLORMANAGEMENTAPI_EXPORT QDebug operator<<(QDebug debug, const Colorimetry &value);
151
152} // namespace KisColorimetryUtils
153
154#endif /* KISCOLORIMETRYUTILS_H */
float value(const T *src, size_t ch)
bool operator==(const KisRegion &lhs, const KisRegion &rhs)
static const Colorimetry GenericFilm
static const Colorimetry AdobeRGB
static const Colorimetry DisplayP3
QMatrix4x4 matrixFromColumns(const QVector3D &first, const QVector3D &second, const QVector3D &third)
QDebug operator<<(QDebug debug, const xy &value)