4#ifndef QCOLORTRANSFERTABLE_P_H
5#define QCOLORTRANSFERTABLE_P_H
18#include <QtGui/private/qtguiglobal_p.h>
36 QColorTransferTable()
noexcept =
default;
37 QColorTransferTable(uint32_t size,
const QList<uint8_t> &table, Type type = TwoWay)
noexcept
38 : m_type(type), m_tableSize(size), m_table8(table)
40 Q_ASSERT(qsizetype(size) <= table.size());
42 QColorTransferTable(uint32_t size,
const QList<uint16_t> &table, Type type = TwoWay)
noexcept
43 : m_type(type), m_tableSize(size), m_table16(table)
45 Q_ASSERT(qsizetype(size) <= table.size());
48 bool isEmpty()
const noexcept
50 return m_tableSize == 0;
53 bool isIdentity()
const
59 if (!m_table8.isEmpty())
60 return m_table8[0] == 0 && m_table8[1] == 255;
61 return m_table16[0] == 0 && m_table16[1] == 65535;
64 bool checkValidity()
const
69 if (!m_table8.isEmpty() && !m_table16.isEmpty())
74 return (m_type == OneWay) || checkInvertibility();
76 bool checkInvertibility()
const
79 if (!m_table8.isEmpty()) {
81 for (uint i = 0; i < m_tableSize; ++i) {
82 if (m_table8[i] < val)
87 if (!m_table16.isEmpty()) {
89 for (uint i = 0; i < m_tableSize; ++i) {
90 if (m_table16[i] < val)
98 float apply(
float x)
const
102 x = std::clamp(x, 0.0f, 1.0f);
103 x *= m_tableSize - 1;
104 const uint32_t lo =
static_cast<uint32_t>(x);
105 const uint32_t hi = std::min(lo + 1, m_tableSize - 1);
106 const float frac = x - lo;
107 if (!m_table16.isEmpty())
108 return (m_table16[lo] + (m_table16[hi] - m_table16[lo]) * frac) * (1.0f/65535.0f);
109 if (!m_table8.isEmpty())
110 return (m_table8[lo] + (m_table8[hi] - m_table8[lo]) * frac) * (1.0f/255.0f);
115 float applyInverse(
float x,
float resultLargerThan = 0.0f)
const
117 Q_ASSERT(resultLargerThan >= 0.0f && resultLargerThan <= 1.0f);
118 Q_ASSERT(m_type == TwoWay);
123 if (!m_table16.isEmpty())
124 return inverseLookup(x * 65535.0f, resultLargerThan, m_table16, m_tableSize - 1);
125 if (!m_table8.isEmpty())
126 return inverseLookup(x * 255.0f, resultLargerThan, m_table8, m_tableSize - 1);
130 bool asColorTransferFunction(QColorTransferFunction *transferFn)
132 Q_ASSERT(transferFn);
134 *transferFn = QColorTransferFunction();
139 if (!m_table8.isEmpty() && (m_table8[0] != 0 || m_table8[m_tableSize - 1] != 255))
141 if (!m_table16.isEmpty() && (m_table16[0] != 0 || m_table16[m_tableSize - 1] != 65535))
143 if (m_tableSize == 2) {
144 *transferFn = QColorTransferFunction();
148 if (m_tableSize == 26 && !m_table16.isEmpty()) {
150 if (m_table16[6] != 3062)
152 if (m_table16[12] != 12824)
154 if (m_table16[18] != 31237)
156 *transferFn = QColorTransferFunction::fromSRgb();
159 if (m_tableSize == 1024 && !m_table16.isEmpty()) {
161 if (m_table16[257] != 3366)
163 if (m_table16[513] != 14116)
165 if (m_table16[768] != 34318)
167 *transferFn = QColorTransferFunction::fromSRgb();
170 if (m_tableSize == 4096 && !m_table16.isEmpty()) {
172 if (m_table16[515] != 960)
174 if (m_table16[1025] != 3342)
176 if (m_table16[2051] != 14079)
178 *transferFn = QColorTransferFunction::fromSRgb();
183 friend inline bool operator!=(
const QColorTransferTable &t1,
const QColorTransferTable &t2);
184 friend inline bool operator==(
const QColorTransferTable &t1,
const QColorTransferTable &t2);
186 Type m_type = TwoWay;
187 uint32_t m_tableSize = 0;
188 QList<uint8_t> m_table8;
189 QList<uint16_t> m_table16;
192 static float inverseLookup(
float needle,
float resultLargerThan,
const QList<T> &table, quint32 tableMax)
194 uint32_t i = qMax(
static_cast<uint32_t>(resultLargerThan * tableMax), 1U) - 1;
195 auto it = std::lower_bound(table.cbegin() + i, table.cend(), needle);
196 i = it - table.cbegin();
201 const float y1 = table[i - 1];
202 const float y2 = table[i];
203 Q_ASSERT(needle >= y1 && needle <= y2);
204 const float fr = (needle - y1) / (y2 - y1);
205 return (i + fr) * (1.0f / tableMax);
210inline bool operator!=(
const QColorTransferTable &t1,
const QColorTransferTable &t2)
212 if (t1.m_tableSize != t2.m_tableSize)
214 if (t1.m_type != t2.m_type)
216 if (t1.m_table8.isEmpty() != t2.m_table8.isEmpty())
218 if (t1.m_table16.isEmpty() != t2.m_table16.isEmpty())
220 if (!t1.m_table8.isEmpty()) {
221 for (uint32_t i = 0; i < t1.m_tableSize; ++i) {
222 if (t1.m_table8[i] != t2.m_table8[i])
226 if (!t1.m_table16.isEmpty()) {
227 for (uint32_t i = 0; i < t1.m_tableSize; ++i) {
228 if (t1.m_table16[i] != t2.m_table16[i])
235inline bool operator==(
const QColorTransferTable &t1,
const QColorTransferTable &t2)
friend bool operator==(const QByteArray::FromBase64Result &lhs, const QByteArray::FromBase64Result &rhs) noexcept
Returns true if lhs and rhs are equal, otherwise returns false.
friend bool operator!=(const QByteArray::FromBase64Result &lhs, const QByteArray::FromBase64Result &rhs) noexcept
Returns true if lhs and rhs are different, otherwise returns false.
QColorVector apply(const QColorVector &v) const
QList< QColorVector > table
QColorMatrix inverted() const
static QColorMatrix toXyzFromSRgb()
static QColorMatrix toXyzFromAdobeRgb()
friend bool comparesEqual(const QColorMatrix &lhs, const QColorMatrix &rhs) noexcept
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)
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)
QColorSpacePrivate(QPointF whitePoint, QColorSpace::TransferFunction transferFunction, float gamma)
QColorSpacePrivate(const QColorSpace::PrimaryPoints &primaries, const QList< uint16_t > &transferFunctionTable)
QColorTransform transformationToColorSpace(const QColorSpacePrivate *out) const
void clearElementListProcessingForEdit()
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)
void setTransferFunction()
static QColorSpacePrivate * get(QColorSpace &colorSpace)
void identifyColorSpace()
bool isValid() const noexcept
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()
float apply(float x) const
QColorTransferFunction() noexcept
static QColorTransferFunction fromSRgb()
float apply(float x) const
float(*)(float) ConverterPtr
static QColorTransferGenericFunction pq()
static QColorTransferGenericFunction hlg()
bool operator==(const QColorTransferGenericFunction &o) const noexcept
bool operator!=(const QColorTransferGenericFunction &o) const noexcept
float applyInverse(float x) const
constexpr QColorTransferGenericFunction(ConverterPtr toLinear=nullptr, ConverterPtr fromLinear=nullptr) noexcept
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)
const std::shared_ptr< QColorTrcLut > & operator[](int i) const
std::shared_ptr< QColorTrcLut > & operator[](int i)
std::shared_ptr< QColorTrcLut > table[3]