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_H
5#define QCOLORSPACE_H
6
7#include <QtGui/qtguiglobal.h>
8#include <QtGui/qcolortransform.h>
9#include <QtCore/qobjectdefs.h>
10#include <QtCore/qshareddata.h>
11#include <QtCore/qvariant.h>
12
13QT_BEGIN_NAMESPACE
14
15class QColorSpacePrivate;
16class QPointF;
17
18QT_DECLARE_QESDP_SPECIALIZATION_DTOR_WITH_EXPORT(QColorSpacePrivate, Q_GUI_EXPORT)
19
20class Q_GUI_EXPORT QColorSpace
21{
22 Q_GADGET
23public:
24 enum NamedColorSpace {
25 SRgb = 1,
26 SRgbLinear,
27 AdobeRgb,
28 DisplayP3,
29 ProPhotoRgb
30 };
31 Q_ENUM(NamedColorSpace)
32 enum class Primaries {
33 Custom = 0,
34 SRgb,
35 AdobeRgb,
36 DciP3D65,
37 ProPhotoRgb
38 };
39 Q_ENUM(Primaries)
40 enum class TransferFunction {
41 Custom = 0,
42 Linear,
43 Gamma,
44 SRgb,
45 ProPhotoRgb
46 };
47 Q_ENUM(TransferFunction)
48
49 QColorSpace() noexcept = default;
50 QColorSpace(NamedColorSpace namedColorSpace);
51 QColorSpace(Primaries primaries, TransferFunction transferFunction, float gamma = 0.0f);
52 QColorSpace(Primaries primaries, float gamma);
53 QColorSpace(Primaries primaries, const QList<uint16_t> &transferFunctionTable);
54 QColorSpace(const QPointF &whitePoint, const QPointF &redPoint,
55 const QPointF &greenPoint, const QPointF &bluePoint,
56 TransferFunction transferFunction, float gamma = 0.0f);
57 QColorSpace(const QPointF &whitePoint, const QPointF &redPoint,
58 const QPointF &greenPoint, const QPointF &bluePoint,
59 const QList<uint16_t> &transferFunctionTable);
60 QColorSpace(const QPointF &whitePoint, const QPointF &redPoint,
61 const QPointF &greenPoint, const QPointF &bluePoint,
62 const QList<uint16_t> &redTransferFunctionTable,
63 const QList<uint16_t> &greenTransferFunctionTable,
64 const QList<uint16_t> &blueTransferFunctionTable);
65 ~QColorSpace();
66
67 QColorSpace(const QColorSpace &colorSpace) noexcept;
68 QColorSpace &operator=(const QColorSpace &colorSpace) noexcept
69 {
70 QColorSpace copy(colorSpace);
71 swap(colorSpace&: copy);
72 return *this;
73 }
74
75 QColorSpace(QColorSpace &&colorSpace) noexcept = default;
76 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QColorSpace)
77
78 void swap(QColorSpace &colorSpace) noexcept
79 { d_ptr.swap(other&: colorSpace.d_ptr); }
80
81 Primaries primaries() const noexcept;
82 TransferFunction transferFunction() const noexcept;
83 float gamma() const noexcept;
84
85 QString description() const noexcept;
86 void setDescription(const QString &description);
87
88 void setTransferFunction(TransferFunction transferFunction, float gamma = 0.0f);
89 void setTransferFunction(const QList<uint16_t> &transferFunctionTable);
90 void setTransferFunctions(const QList<uint16_t> &redTransferFunctionTable,
91 const QList<uint16_t> &greenTransferFunctionTable,
92 const QList<uint16_t> &blueTransferFunctionTable);
93 QColorSpace withTransferFunction(TransferFunction transferFunction, float gamma = 0.0f) const;
94 QColorSpace withTransferFunction(const QList<uint16_t> &transferFunctionTable) const;
95 QColorSpace withTransferFunctions(const QList<uint16_t> &redTransferFunctionTable,
96 const QList<uint16_t> &greenTransferFunctionTable,
97 const QList<uint16_t> &blueTransferFunctionTable) const;
98
99 void setPrimaries(Primaries primariesId);
100 void setPrimaries(const QPointF &whitePoint, const QPointF &redPoint,
101 const QPointF &greenPoint, const QPointF &bluePoint);
102
103 void detach();
104 bool isValid() const noexcept;
105
106 friend inline bool operator==(const QColorSpace &colorSpace1, const QColorSpace &colorSpace2)
107 { return colorSpace1.equals(other: colorSpace2); }
108 friend inline bool operator!=(const QColorSpace &colorSpace1, const QColorSpace &colorSpace2)
109 { return !(colorSpace1 == colorSpace2); }
110
111 static QColorSpace fromIccProfile(const QByteArray &iccProfile);
112 QByteArray iccProfile() const;
113
114 QColorTransform transformationToColorSpace(const QColorSpace &colorspace) const;
115
116 operator QVariant() const;
117
118private:
119 friend class QColorSpacePrivate;
120 bool equals(const QColorSpace &other) const;
121
122 QExplicitlySharedDataPointer<QColorSpacePrivate> d_ptr;
123
124#ifndef QT_NO_DEBUG_STREAM
125 friend Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QColorSpace &colorSpace);
126#endif
127};
128
129Q_DECLARE_SHARED(QColorSpace)
130
131// QColorSpace stream functions
132#if !defined(QT_NO_DATASTREAM)
133Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QColorSpace &);
134Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QColorSpace &);
135#endif
136
137#ifndef QT_NO_DEBUG_STREAM
138Q_GUI_EXPORT QDebug operator<<(QDebug, const QColorSpace &);
139#endif
140
141QT_END_NAMESPACE
142
143#endif // QCOLORSPACE_P_H
144

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