Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qcolortransferfunction_p.h
Go to the documentation of this file.
1// Copyright (C) 2018 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QCOLORTRANSFERFUNCTION_P_H
6#define QCOLORTRANSFERFUNCTION_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtGui/private/qtguiglobal_p.h>
20#include <QtCore/QFlags>
21
22#include <cmath>
23
25
26// Defines a ICC parametric curve type 4
28{
29public:
31 : m_a(1.0f), m_b(0.0f), m_c(1.0f), m_d(0.0f), m_e(0.0f), m_f(0.0f), m_g(1.0f)
33 { }
34
35 QColorTransferFunction(float a, float b, float c, float d, float e, float f, float g) noexcept
36 : m_a(a), m_b(b), m_c(c), m_d(d), m_e(e), m_f(f), m_g(g), m_flags()
37 { }
38
39 bool isGamma() const
40 {
41 updateHints();
42 return m_flags & Hint::IsGamma;
43 }
44 bool isIdentity() const
45 {
46 updateHints();
47 return m_flags & Hint::IsIdentity;
48 }
49 bool isSRgb() const
50 {
51 updateHints();
52 return m_flags & Hint::IsSRgb;
53 }
54
55 float apply(float x) const
56 {
57 if (x < m_d)
58 return m_c * x + m_f;
59 float t = std::pow(m_a * x + m_b, m_g);
60 // Avoid NaN math, and leave room to multiply with 65280 and store in an int.
61 if (std::isfinite(t) && t > std::numeric_limits<short>::min() && t < std::numeric_limits<short>::max())
62 return t + m_e;
63 if (t > 0.f)
64 return 1.f;
65 else
66 return 0.f;
67 }
68
70 {
71 float a, b, c, d, e, f, g;
72
73 d = m_c * m_d + m_f;
74
75 if (std::isnormal(m_c)) {
76 c = 1.0f / m_c;
77 f = -m_f / m_c;
78 } else {
79 c = 0.0f;
80 f = 0.0f;
81 }
82
83 bool valid_abeg = std::isnormal(m_a) && std::isnormal(m_g);
84 if (valid_abeg)
85 a = std::pow(1.0f / m_a, m_g);
86 if (valid_abeg && !std::isfinite(a))
87 valid_abeg = false;
88 if (valid_abeg) {
89 b = -a * m_e;
90 e = -m_b / m_a;
91 g = 1.0f / m_g;
92 } else {
93 a = 0.0f;
94 b = 0.0f;
95 e = 1.0f;
96 g = 1.0f;
97 }
98
99 return QColorTransferFunction(a, b, c, d, e, f, g);
100 }
101
102 // A few predefined curves:
104 {
105 return QColorTransferFunction(1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, gamma,
107 (paramCompare(gamma, 1.0f) ? Hint::IsIdentity : Hint::NoHint));
108 }
110 {
111 return QColorTransferFunction(1.0f / 1.055f, 0.055f / 1.055f, 1.0f / 12.92f, 0.04045f, 0.0f, 0.0f, 2.4f,
113 }
115 {
116 return QColorTransferFunction(1.0f, 0.0f, 1.0f / 16.0f, 16.0f / 512.0f, 0.0f, 0.0f, 1.8f,
117 Hints(Hint::Calculated));
118 }
120 {
121 return QColorTransferFunction(1.0f / 1.0993f, 0.0993f / 1.0993f, 1.0f / 4.5f, 0.08145f, 0.0f, 0.0f, 2.2f,
122 Hints(Hint::Calculated));
123 }
124 bool matches(const QColorTransferFunction &o) const
125 {
126 return paramCompare(m_a, o.m_a) && paramCompare(m_b, o.m_b)
127 && paramCompare(m_c, o.m_c) && paramCompare(m_d, o.m_d)
128 && paramCompare(m_e, o.m_e) && paramCompare(m_f, o.m_f)
129 && paramCompare(m_g, o.m_g);
130 }
131 friend inline bool operator==(const QColorTransferFunction &f1, const QColorTransferFunction &f2);
132 friend inline bool operator!=(const QColorTransferFunction &f1, const QColorTransferFunction &f2);
133
134 float m_a;
135 float m_b;
136 float m_c;
137 float m_d;
138 float m_e;
139 float m_f;
140 float m_g;
141
142 enum class Hint : quint32 {
148 };
149
151
152private:
153 QColorTransferFunction(float a, float b, float c, float d, float e, float f, float g, Hints flags) noexcept
154 : m_a(a), m_b(b), m_c(c), m_d(d), m_e(e), m_f(f), m_g(g), m_flags(flags)
155 { }
156 static inline bool paramCompare(float p1, float p2)
157 {
158 // Much fuzzier than fuzzy compare.
159 // It tries match parameters that has been passed through a 8.8
160 // fixed point form.
161 return (qAbs(p1 - p2) <= (1.0f / 512.0f));
162 }
163
164 void updateHints() const
165 {
166 if (m_flags & Hint::Calculated)
167 return;
168 // We do not consider the case with m_d = 1.0f linear or simple,
169 // since it wouldn't be linear for applyExtended().
170 bool simple = paramCompare(m_a, 1.0f) && paramCompare(m_b, 0.0f)
171 && paramCompare(m_d, 0.0f)
172 && paramCompare(m_e, 0.0f);
173 if (simple) {
174 m_flags |= Hint::IsGamma;
175 if (qFuzzyCompare(m_g, 1.0f))
176 m_flags |= Hint::IsIdentity;
177 } else {
178 if (*this == fromSRgb())
179 m_flags |= Hint::IsSRgb;
180 }
181 m_flags |= Hint::Calculated;
182 }
183
184 mutable Hints m_flags;
185};
186
188
189inline bool operator==(const QColorTransferFunction &f1, const QColorTransferFunction &f2)
190{
191 return f1.matches(f2);
192}
193inline bool operator!=(const QColorTransferFunction &f1, const QColorTransferFunction &f2)
194{
195 return !f1.matches(f2);
196}
197
198QT_END_NAMESPACE
199
200#endif // QCOLORTRANSFERFUNCTION_P_H
QList< QColorVector > table
uint32_t gridPointsY
uint32_t gridPointsW
bool isEmpty() const
uint32_t gridPointsX
uint32_t gridPointsZ
QColorMatrix inverted() const
static QColorMatrix toXyzFromSRgb()
static QColorMatrix toXyzFromAdobeRgb()
bool isValid() const
friend bool comparesEqual(const QColorMatrix &lhs, const QColorMatrix &rhs) noexcept
QColorVector g
constexpr float determinant() const
static QColorMatrix identity()
QColorMatrix transposed() const
static QColorMatrix fromScale(QColorVector v)
friend constexpr QColorMatrix operator*(const QColorMatrix &a, const QColorMatrix &o)
QColorVector b
QColorVector r
bool isIdentity() const noexcept
static QColorMatrix toXyzFromDciP3D65()
static QColorMatrix chromaticAdaptation(const QColorVector &whitePoint)
static QColorMatrix toXyzFromProPhotoRgb()
QColorVector map(const QColorVector &c) const
static QColorMatrix toXyzFromBt2020()
constexpr bool isNull() const
void setTransferFunctionTables(const QList< uint16_t > &redTransferFunctionTable, const QList< uint16_t > &greenTransferFunctionTable, const QList< uint16_t > &blueTransferFunctionTable)
QColorSpacePrivate(QPointF whitePoint, const QList< uint16_t > &transferFunctionTable)
QColorVector whitePoint
QColorSpacePrivate(QPointF whitePoint, QColorSpace::TransferFunction transferFunction, float gamma)
QColorSpacePrivate(const QColorSpace::PrimaryPoints &primaries, const QList< uint16_t > &transferFunctionTable)
QColorTransform transformationToColorSpace(const QColorSpacePrivate *out) const
QList< Element > mAB
QList< Element > mBA
void clearElementListProcessingForEdit()
QColorMatrix chad
void setTransferFunctionTable(const QList< uint16_t > &transferFunctionTable)
QColorTransform transformationToXYZ() const
bool isThreeComponentMatrix() const
QColorSpacePrivate(const QColorSpace::PrimaryPoints &primaries, const QList< uint16_t > &redTransferFunctionTable, const QList< uint16_t > &greenTransferFunctionTable, const QList< uint16_t > &blueRransferFunctionTable)
QColorSpacePrivate(const QColorSpacePrivate &other)=default
static const QColorSpacePrivate * get(const QColorSpace &colorSpace)
QColorSpacePrivate(const QColorSpace::PrimaryPoints &primaries, QColorSpace::TransferFunction transferFunction, float gamma)
static QColorSpacePrivate * get(QColorSpace &colorSpace)
bool isValid() const noexcept
QColorMatrix toXyz
QColorSpacePrivate(QColorSpace::NamedColorSpace namedColorSpace)
bool equals(const QColorSpacePrivate *other) const
Q_DECLARE_FLAGS(Hints, Hint)
QColorTransferFunction inverted() const
friend bool operator!=(const QColorTransferFunction &f1, const QColorTransferFunction &f2)
QColorTransferFunction(float a, float b, float c, float d, float e, float f, float g) noexcept
static QColorTransferFunction fromGamma(float gamma)
bool matches(const QColorTransferFunction &o) const
static QColorTransferFunction fromBt2020()
friend bool operator==(const QColorTransferFunction &f1, const QColorTransferFunction &f2)
static QColorTransferFunction fromProPhotoRgb()
static QColorTransferFunction fromSRgb()
The QColorTransform class is a transformation between color spaces.
Combined button and popup list for selecting options.
bool comparesEqual(const QColorVector &v1, const QColorVector &v2) noexcept
static void cleanupPredefinedColorspaces()
static bool compareElement(const QColorSpacePrivate::TransferElement &element, const QColorSpacePrivate::TransferElement &other)
QDebug operator<<(QDebug dbg, const QColorCLUT &)
QDebug operator<<(QDebug dbg, const QColorSpace &colorSpace)
QDebug operator<<(QDebug dbg, const QColorMatrix &)
static bool compareElement(const QColorMatrix &element, const QColorMatrix &other)
QDataStream & operator>>(QDataStream &s, QColorSpace &colorSpace)
QDataStream & operator<<(QDataStream &s, const QColorSpace &image)
QDebug operator<<(QDebug dbg, const QColorVector &)
QColorMatrix qColorSpacePrimaryPointsToXyzMatrix(const QColorSpace::PrimaryPoints &primaries)
static bool compareElements(const T &element, const QColorSpacePrivate::Element &other)
static bool compareElement(const QColorCLUT &element, const QColorCLUT &other)
static bool compareElement(const QColorVector &element, const QColorVector &other)
QDebug operator<<(QDebug dbg, const QColorSpacePrivate::TransferElement &)
QT_BEGIN_NAMESPACE bool qColorSpacePrimaryPointsAreValid(const QColorSpace::PrimaryPoints &primaries)
Q_DECLARE_OPERATORS_FOR_FLAGS(QColorTransferFunction::Hints)
QDebug operator<<(QDebug dbg, const QFileInfo &fi)
bool comparesEqual(const QFileInfo &lhs, const QFileInfo &rhs)
LUT(const LUT &other)
const std::shared_ptr< QColorTrcLut > & operator[](int i) const
std::shared_ptr< QColorTrcLut > & operator[](int i)
std::shared_ptr< QColorTrcLut > table[3]