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
54class Q_GUI_EXPORT QColorSpace
55{
56 Q_GADGET
57public:
58 enum NamedColorSpace {
59 SRgb = 1,
60 SRgbLinear,
61 AdobeRgb,
62 DisplayP3,
63 ProPhotoRgb
64 };
65 Q_ENUM(NamedColorSpace)
66 enum class Primaries {
67 Custom = 0,
68 SRgb,
69 AdobeRgb,
70 DciP3D65,
71 ProPhotoRgb
72 };
73 Q_ENUM(Primaries)
74 enum class TransferFunction {
75 Custom = 0,
76 Linear,
77 Gamma,
78 SRgb,
79 ProPhotoRgb
80 };
81 Q_ENUM(TransferFunction)
82
83 QColorSpace();
84 QColorSpace(NamedColorSpace namedColorSpace);
85 QColorSpace(Primaries primaries, TransferFunction transferFunction, float gamma = 0.0f);
86 QColorSpace(Primaries primaries, float gamma);
87 QColorSpace(const QPointF &whitePoint, const QPointF &redPoint,
88 const QPointF &greenPoint, const QPointF &bluePoint,
89 TransferFunction transferFunction, float gamma = 0.0f);
90 ~QColorSpace();
91
92 QColorSpace(const QColorSpace &colorSpace);
93 QColorSpace &operator=(const QColorSpace &colorSpace);
94
95 QColorSpace(QColorSpace &&colorSpace) noexcept
96 : d_ptr(qExchange(t&: colorSpace.d_ptr, newValue: nullptr))
97 { }
98 QColorSpace &operator=(QColorSpace &&colorSpace) noexcept
99 {
100 // Make the deallocation of this->d_ptr happen in ~QColorSpace()
101 QColorSpace(std::move(colorSpace)).swap(colorSpace&: *this);
102 return *this;
103 }
104
105 void swap(QColorSpace &colorSpace) noexcept
106 { qSwap(value1&: d_ptr, value2&: colorSpace.d_ptr); }
107
108 Primaries primaries() const noexcept;
109 TransferFunction transferFunction() const noexcept;
110 float gamma() const noexcept;
111
112 void setTransferFunction(TransferFunction transferFunction, float gamma = 0.0f);
113 QColorSpace withTransferFunction(TransferFunction transferFunction, float gamma = 0.0f) const;
114
115 void setPrimaries(Primaries primariesId);
116 void setPrimaries(const QPointF &whitePoint, const QPointF &redPoint,
117 const QPointF &greenPoint, const QPointF &bluePoint);
118
119 bool isValid() const noexcept;
120
121 friend Q_GUI_EXPORT bool operator==(const QColorSpace &colorSpace1, const QColorSpace &colorSpace2);
122 friend inline bool operator!=(const QColorSpace &colorSpace1, const QColorSpace &colorSpace2);
123
124 static QColorSpace fromIccProfile(const QByteArray &iccProfile);
125 QByteArray iccProfile() const;
126
127 QColorTransform transformationToColorSpace(const QColorSpace &colorspace) const;
128
129 operator QVariant() const;
130
131private:
132 Q_DECLARE_PRIVATE(QColorSpace)
133 QColorSpacePrivate *d_ptr = nullptr;
134
135#ifndef QT_NO_DEBUG_STREAM
136 friend Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QColorSpace &colorSpace);
137#endif
138};
139
140bool Q_GUI_EXPORT operator==(const QColorSpace &colorSpace1, const QColorSpace &colorSpace2);
141inline bool operator!=(const QColorSpace &colorSpace1, const QColorSpace &colorSpace2)
142{
143 return !(colorSpace1 == colorSpace2);
144}
145
146Q_DECLARE_SHARED(QColorSpace)
147
148// QColorSpace stream functions
149#if !defined(QT_NO_DATASTREAM)
150Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QColorSpace &);
151Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QColorSpace &);
152#endif
153
154#ifndef QT_NO_DEBUG_STREAM
155Q_GUI_EXPORT QDebug operator<<(QDebug, const QColorSpace &);
156#endif
157
158QT_END_NAMESPACE
159
160#endif // QCOLORSPACE_P_H
161

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