| 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 | |
| 13 | QT_BEGIN_NAMESPACE |
| 14 | |
| 15 | class QColorSpacePrivate; |
| 16 | class QPointF; |
| 17 | |
| 18 | QT_DECLARE_QESDP_SPECIALIZATION_DTOR_WITH_EXPORT(QColorSpacePrivate, Q_GUI_EXPORT) |
| 19 | |
| 20 | class Q_GUI_EXPORT QColorSpace |
| 21 | { |
| 22 | Q_GADGET |
| 23 | public: |
| 24 | enum NamedColorSpace { |
| 25 | SRgb = 1, |
| 26 | SRgbLinear, |
| 27 | AdobeRgb, |
| 28 | DisplayP3, |
| 29 | ProPhotoRgb, |
| 30 | Bt2020, |
| 31 | Bt2100Pq, |
| 32 | Bt2100Hlg, |
| 33 | }; |
| 34 | Q_ENUM(NamedColorSpace) |
| 35 | enum class Primaries { |
| 36 | Custom = 0, |
| 37 | SRgb, |
| 38 | AdobeRgb, |
| 39 | DciP3D65, |
| 40 | ProPhotoRgb, |
| 41 | Bt2020, |
| 42 | }; |
| 43 | Q_ENUM(Primaries) |
| 44 | enum class TransferFunction { |
| 45 | Custom = 0, |
| 46 | Linear, |
| 47 | Gamma, |
| 48 | SRgb, |
| 49 | ProPhotoRgb, |
| 50 | Bt2020, |
| 51 | St2084, |
| 52 | Hlg, |
| 53 | }; |
| 54 | Q_ENUM(TransferFunction) |
| 55 | enum class TransformModel : uint8_t { |
| 56 | ThreeComponentMatrix = 0, |
| 57 | ElementListProcessing, |
| 58 | }; |
| 59 | Q_ENUM(TransformModel) |
| 60 | enum class ColorModel : uint8_t { |
| 61 | Undefined = 0, |
| 62 | Rgb = 1, |
| 63 | Gray = 2, |
| 64 | Cmyk = 3, |
| 65 | }; |
| 66 | Q_ENUM(ColorModel) |
| 67 | |
| 68 | QColorSpace() noexcept = default; |
| 69 | QColorSpace(NamedColorSpace namedColorSpace); |
| 70 | explicit QColorSpace(QPointF whitePoint, TransferFunction transferFunction, float gamma = 0.0f); |
| 71 | explicit QColorSpace(QPointF whitePoint, const QList<uint16_t> &transferFunctionTable); |
| 72 | QColorSpace(Primaries primaries, TransferFunction transferFunction, float gamma = 0.0f); |
| 73 | QColorSpace(Primaries primaries, float gamma); |
| 74 | QColorSpace(Primaries primaries, const QList<uint16_t> &transferFunctionTable); |
| 75 | QColorSpace(const QPointF &whitePoint, const QPointF &redPoint, |
| 76 | const QPointF &greenPoint, const QPointF &bluePoint, |
| 77 | TransferFunction transferFunction, float gamma = 0.0f); |
| 78 | QColorSpace(const QPointF &whitePoint, const QPointF &redPoint, |
| 79 | const QPointF &greenPoint, const QPointF &bluePoint, |
| 80 | const QList<uint16_t> &transferFunctionTable); |
| 81 | QColorSpace(const QPointF &whitePoint, const QPointF &redPoint, |
| 82 | const QPointF &greenPoint, const QPointF &bluePoint, |
| 83 | const QList<uint16_t> &redTransferFunctionTable, |
| 84 | const QList<uint16_t> &greenTransferFunctionTable, |
| 85 | const QList<uint16_t> &blueTransferFunctionTable); |
| 86 | ~QColorSpace(); |
| 87 | |
| 88 | QColorSpace(const QColorSpace &colorSpace) noexcept; |
| 89 | QColorSpace &operator=(const QColorSpace &colorSpace) noexcept |
| 90 | { |
| 91 | QColorSpace copy(colorSpace); |
| 92 | swap(colorSpace&: copy); |
| 93 | return *this; |
| 94 | } |
| 95 | |
| 96 | QColorSpace(QColorSpace &&colorSpace) noexcept = default; |
| 97 | QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QColorSpace) |
| 98 | |
| 99 | void swap(QColorSpace &colorSpace) noexcept |
| 100 | { d_ptr.swap(other&: colorSpace.d_ptr); } |
| 101 | |
| 102 | Primaries primaries() const noexcept; |
| 103 | TransferFunction transferFunction() const noexcept; |
| 104 | float gamma() const noexcept; |
| 105 | |
| 106 | QString description() const noexcept; |
| 107 | void setDescription(const QString &description); |
| 108 | |
| 109 | void setTransferFunction(TransferFunction transferFunction, float gamma = 0.0f); |
| 110 | void setTransferFunction(const QList<uint16_t> &transferFunctionTable); |
| 111 | void setTransferFunctions(const QList<uint16_t> &redTransferFunctionTable, |
| 112 | const QList<uint16_t> &greenTransferFunctionTable, |
| 113 | const QList<uint16_t> &blueTransferFunctionTable); |
| 114 | QColorSpace withTransferFunction(TransferFunction transferFunction, float gamma = 0.0f) const; |
| 115 | QColorSpace withTransferFunction(const QList<uint16_t> &transferFunctionTable) const; |
| 116 | QColorSpace withTransferFunctions(const QList<uint16_t> &redTransferFunctionTable, |
| 117 | const QList<uint16_t> &greenTransferFunctionTable, |
| 118 | const QList<uint16_t> &blueTransferFunctionTable) const; |
| 119 | |
| 120 | void setPrimaries(Primaries primariesId); |
| 121 | void setPrimaries(const QPointF &whitePoint, const QPointF &redPoint, |
| 122 | const QPointF &greenPoint, const QPointF &bluePoint); |
| 123 | void setWhitePoint(QPointF whitePoint); |
| 124 | QPointF whitePoint() const; |
| 125 | |
| 126 | TransformModel transformModel() const noexcept; |
| 127 | ColorModel colorModel() const noexcept; |
| 128 | void detach(); |
| 129 | bool isValid() const noexcept; |
| 130 | bool isValidTarget() const noexcept; |
| 131 | |
| 132 | friend inline bool operator==(const QColorSpace &colorSpace1, const QColorSpace &colorSpace2) |
| 133 | { return colorSpace1.equals(other: colorSpace2); } |
| 134 | friend inline bool operator!=(const QColorSpace &colorSpace1, const QColorSpace &colorSpace2) |
| 135 | { return !(colorSpace1 == colorSpace2); } |
| 136 | |
| 137 | static QColorSpace fromIccProfile(const QByteArray &iccProfile); |
| 138 | QByteArray iccProfile() const; |
| 139 | |
| 140 | QColorTransform transformationToColorSpace(const QColorSpace &colorspace) const; |
| 141 | |
| 142 | operator QVariant() const; |
| 143 | |
| 144 | private: |
| 145 | friend class QColorSpacePrivate; |
| 146 | bool equals(const QColorSpace &other) const; |
| 147 | |
| 148 | QExplicitlySharedDataPointer<QColorSpacePrivate> d_ptr; |
| 149 | |
| 150 | #ifndef QT_NO_DEBUG_STREAM |
| 151 | friend Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QColorSpace &colorSpace); |
| 152 | #endif |
| 153 | }; |
| 154 | |
| 155 | Q_DECLARE_SHARED(QColorSpace) |
| 156 | |
| 157 | // QColorSpace stream functions |
| 158 | #if !defined(QT_NO_DATASTREAM) |
| 159 | Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QColorSpace &); |
| 160 | Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QColorSpace &); |
| 161 | #endif |
| 162 | |
| 163 | #ifndef QT_NO_DEBUG_STREAM |
| 164 | Q_GUI_EXPORT QDebug operator<<(QDebug, const QColorSpace &); |
| 165 | #endif |
| 166 | |
| 167 | QT_END_NAMESPACE |
| 168 | |
| 169 | #endif // QCOLORSPACE_P_H |
| 170 | |