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
4#ifndef QCOLORSPACE_P_H
5#define QCOLORSPACE_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include "qcolorspace.h"
19#include "qcolormatrix_p.h"
20#include "qcolortrc_p.h"
21#include "qcolortrclut_p.h"
22
23#include <QtCore/qmutex.h>
24#include <QtCore/qpoint.h>
25#include <QtCore/qshareddata.h>
26
27#include <memory>
28
29QT_BEGIN_NAMESPACE
30
31class Q_AUTOTEST_EXPORT QColorSpacePrimaries
32{
33public:
34 QColorSpacePrimaries() = default;
35 QColorSpacePrimaries(QColorSpace::Primaries primaries);
36 QColorSpacePrimaries(QPointF whitePoint,
37 QPointF redPoint,
38 QPointF greenPoint,
39 QPointF bluePoint)
40 : whitePoint(whitePoint)
41 , redPoint(redPoint)
42 , greenPoint(greenPoint)
43 , bluePoint(bluePoint)
44 { }
45
46 QColorMatrix toXyzMatrix() const;
47 bool areValid() const;
48
49 QPointF whitePoint;
50 QPointF redPoint;
51 QPointF greenPoint;
52 QPointF bluePoint;
53};
54
55class QColorSpacePrivate : public QSharedData
56{
57public:
58 QColorSpacePrivate();
59 QColorSpacePrivate(QColorSpace::NamedColorSpace namedColorSpace);
60 QColorSpacePrivate(QColorSpace::Primaries primaries, QColorSpace::TransferFunction transferFunction, float gamma);
61 QColorSpacePrivate(QColorSpace::Primaries primaries, const QList<uint16_t> &transferFunctionTable);
62 QColorSpacePrivate(const QColorSpacePrimaries &primaries, QColorSpace::TransferFunction transferFunction, float gamma);
63 QColorSpacePrivate(const QColorSpacePrimaries &primaries, const QList<uint16_t> &transferFunctionTable);
64 QColorSpacePrivate(const QColorSpacePrimaries &primaries,
65 const QList<uint16_t> &redTransferFunctionTable,
66 const QList<uint16_t> &greenTransferFunctionTable,
67 const QList<uint16_t> &blueRransferFunctionTable);
68 QColorSpacePrivate(const QColorSpacePrivate &other) = default;
69
70 static const QColorSpacePrivate *get(const QColorSpace &colorSpace)
71 {
72 return colorSpace.d_ptr.get();
73 }
74
75 static QColorSpacePrivate *get(QColorSpace &colorSpace)
76 {
77 return colorSpace.d_ptr.get();
78 }
79
80 void initialize();
81 void setToXyzMatrix();
82 void setTransferFunction();
83 void identifyColorSpace();
84 void setTransferFunctionTable(const QList<uint16_t> &transferFunctionTable);
85 void setTransferFunctionTables(const QList<uint16_t> &redTransferFunctionTable,
86 const QList<uint16_t> &greenTransferFunctionTable,
87 const QList<uint16_t> &blueTransferFunctionTable);
88 QColorTransform transformationToColorSpace(const QColorSpacePrivate *out) const;
89 QColorTransform transformationToXYZ() const;
90
91 static constexpr QColorSpace::NamedColorSpace Unknown = QColorSpace::NamedColorSpace(0);
92 QColorSpace::NamedColorSpace namedColorSpace = Unknown;
93
94 QColorSpace::Primaries primaries = QColorSpace::Primaries::Custom;
95 QColorSpace::TransferFunction transferFunction = QColorSpace::TransferFunction::Custom;
96 float gamma = 0.0f;
97 QColorVector whitePoint;
98
99 QColorTrc trc[3];
100 QColorMatrix toXyz;
101
102 QString description;
103 QString userDescription;
104 QByteArray iccProfile;
105
106 Q_CONSTINIT static QBasicMutex s_lutWriteLock;
107 struct LUT {
108 LUT() = default;
109 ~LUT() = default;
110 LUT(const LUT &other)
111 {
112 if (other.generated.loadAcquire()) {
113 table[0] = other.table[0];
114 table[1] = other.table[1];
115 table[2] = other.table[2];
116 generated.storeRelaxed(newValue: 1);
117 }
118 }
119 std::shared_ptr<QColorTrcLut> &operator[](int i) { return table[i]; }
120 const std::shared_ptr<QColorTrcLut> &operator[](int i) const { return table[i]; }
121 std::shared_ptr<QColorTrcLut> table[3];
122 QAtomicInt generated;
123 } mutable lut;
124};
125
126QT_END_NAMESPACE
127
128#endif // QCOLORSPACE_P_H
129

source code of qtbase/src/gui/painting/qcolorspace_p.h