1/****************************************************************************
2**
3** Copyright (C) 2018 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QCOLORSPACE_H
41#define QCOLORSPACE_H
42
43#include <QtGui/qtguiglobal.h>
44#include <QtGui/qcolortransform.h>
45#include <QtCore/qobjectdefs.h>
46#include <QtCore/qshareddata.h>
47#include <QtCore/qvariant.h>
48
49QT_BEGIN_NAMESPACE
50
51class QColorSpacePrivate;
52class QPointF;
53
54QT_DECLARE_QESDP_SPECIALIZATION_DTOR_WITH_EXPORT(QColorSpacePrivate, Q_GUI_EXPORT)
55
56class Q_GUI_EXPORT QColorSpace
57{
58 Q_GADGET
59public:
60 enum NamedColorSpace {
61 SRgb = 1,
62 SRgbLinear,
63 AdobeRgb,
64 DisplayP3,
65 ProPhotoRgb
66 };
67 Q_ENUM(NamedColorSpace)
68 enum class Primaries {
69 Custom = 0,
70 SRgb,
71 AdobeRgb,
72 DciP3D65,
73 ProPhotoRgb
74 };
75 Q_ENUM(Primaries)
76 enum class TransferFunction {
77 Custom = 0,
78 Linear,
79 Gamma,
80 SRgb,
81 ProPhotoRgb
82 };
83 Q_ENUM(TransferFunction)
84
85 QColorSpace() noexcept = default;
86 QColorSpace(NamedColorSpace namedColorSpace);
87 QColorSpace(Primaries primaries, TransferFunction transferFunction, float gamma = 0.0f);
88 QColorSpace(Primaries primaries, float gamma);
89 QColorSpace(Primaries primaries, const QList<uint16_t> &transferFunctionTable);
90 QColorSpace(const QPointF &whitePoint, const QPointF &redPoint,
91 const QPointF &greenPoint, const QPointF &bluePoint,
92 TransferFunction transferFunction, float gamma = 0.0f);
93 QColorSpace(const QPointF &whitePoint, const QPointF &redPoint,
94 const QPointF &greenPoint, const QPointF &bluePoint,
95 const QList<uint16_t> &transferFunctionTable);
96 QColorSpace(const QPointF &whitePoint, const QPointF &redPoint,
97 const QPointF &greenPoint, const QPointF &bluePoint,
98 const QList<uint16_t> &redTransferFunctionTable,
99 const QList<uint16_t> &greenTransferFunctionTable,
100 const QList<uint16_t> &blueTransferFunctionTable);
101 ~QColorSpace();
102
103 QColorSpace(const QColorSpace &colorSpace) noexcept;
104 QColorSpace &operator=(const QColorSpace &colorSpace) noexcept
105 {
106 QColorSpace copy(colorSpace);
107 swap(copy);
108 return *this;
109 }
110
111 QColorSpace(QColorSpace &&colorSpace) noexcept = default;
112 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QColorSpace)
113
114 void swap(QColorSpace &colorSpace) noexcept
115 { qSwap(d_ptr, colorSpace.d_ptr); }
116
117 Primaries primaries() const noexcept;
118 TransferFunction transferFunction() const noexcept;
119 float gamma() const noexcept;
120
121 QString description() const noexcept;
122 void setDescription(const QString &description);
123
124 void setTransferFunction(TransferFunction transferFunction, float gamma = 0.0f);
125 void setTransferFunction(const QList<uint16_t> &transferFunctionTable);
126 void setTransferFunctions(const QList<uint16_t> &redTransferFunctionTable,
127 const QList<uint16_t> &greenTransferFunctionTable,
128 const QList<uint16_t> &blueTransferFunctionTable);
129 QColorSpace withTransferFunction(TransferFunction transferFunction, float gamma = 0.0f) const;
130 QColorSpace withTransferFunction(const QList<uint16_t> &transferFunctionTable) const;
131 QColorSpace withTransferFunctions(const QList<uint16_t> &redTransferFunctionTable,
132 const QList<uint16_t> &greenTransferFunctionTable,
133 const QList<uint16_t> &blueTransferFunctionTable) const;
134
135 void setPrimaries(Primaries primariesId);
136 void setPrimaries(const QPointF &whitePoint, const QPointF &redPoint,
137 const QPointF &greenPoint, const QPointF &bluePoint);
138
139 void detach();
140 bool isValid() const noexcept;
141
142 friend inline bool operator==(const QColorSpace &colorSpace1, const QColorSpace &colorSpace2)
143 { return colorSpace1.equals(colorSpace2); }
144 friend inline bool operator!=(const QColorSpace &colorSpace1, const QColorSpace &colorSpace2)
145 { return !(colorSpace1 == colorSpace2); }
146
147 static QColorSpace fromIccProfile(const QByteArray &iccProfile);
148 QByteArray iccProfile() const;
149
150 QColorTransform transformationToColorSpace(const QColorSpace &colorspace) const;
151
152 operator QVariant() const;
153
154private:
155 friend class QColorSpacePrivate;
156 bool equals(const QColorSpace &other) const;
157
158 QExplicitlySharedDataPointer<QColorSpacePrivate> d_ptr;
159
160#ifndef QT_NO_DEBUG_STREAM
161 friend Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QColorSpace &colorSpace);
162#endif
163};
164
165Q_DECLARE_SHARED(QColorSpace)
166
167// QColorSpace stream functions
168#if !defined(QT_NO_DATASTREAM)
169Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QColorSpace &);
170Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QColorSpace &);
171#endif
172
173#ifndef QT_NO_DEBUG_STREAM
174Q_GUI_EXPORT QDebug operator<<(QDebug, const QColorSpace &);
175#endif
176
177QT_END_NAMESPACE
178
179#endif // QCOLORSPACE_P_H
180

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