| 1 | // Copyright (C) 2023 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 QCMYK_P_H |
| 5 | #define QCMYK_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 <QtGui/private/qtguiglobal_p.h> |
| 19 | #include <QtGui/qcolor.h> |
| 20 | |
| 21 | QT_BEGIN_NAMESPACE |
| 22 | |
| 23 | class QCmyk32 |
| 24 | { |
| 25 | private: |
| 26 | uint m_cmyk = 0; |
| 27 | friend constexpr bool comparesEqual(const QCmyk32 &lhs, const QCmyk32 &rhs) noexcept |
| 28 | { |
| 29 | return lhs.m_cmyk == rhs.m_cmyk; |
| 30 | } |
| 31 | |
| 32 | public: |
| 33 | QCmyk32() = default; |
| 34 | |
| 35 | constexpr QCmyk32(int cyan, int magenta, int yellow, int black) : |
| 36 | #if Q_BYTE_ORDER == Q_BIG_ENDIAN |
| 37 | m_cmyk(uint(cyan) << 24 | magenta << 16 | yellow << 8 | black) |
| 38 | #else |
| 39 | m_cmyk(cyan | magenta << 8 | yellow << 16 | uint(black) << 24) |
| 40 | #endif |
| 41 | { |
| 42 | } |
| 43 | |
| 44 | #if Q_BYTE_ORDER == Q_BIG_ENDIAN |
| 45 | constexpr int cyan() const noexcept { return (m_cmyk >> 24) & 0xff; } |
| 46 | constexpr int magenta() const noexcept { return (m_cmyk >> 16) & 0xff; } |
| 47 | constexpr int yellow() const noexcept { return (m_cmyk >> 8) & 0xff; } |
| 48 | constexpr int black() const noexcept { return (m_cmyk ) & 0xff; } |
| 49 | #else |
| 50 | constexpr int cyan() const noexcept { return (m_cmyk ) & 0xff; } |
| 51 | constexpr int magenta() const noexcept { return (m_cmyk >> 8) & 0xff; } |
| 52 | constexpr int yellow() const noexcept { return (m_cmyk >> 16) & 0xff; } |
| 53 | constexpr int black() const noexcept { return (m_cmyk >> 24) & 0xff; } |
| 54 | #endif |
| 55 | |
| 56 | QColor toColor() const noexcept |
| 57 | { |
| 58 | return QColor::fromCmyk(c: cyan(), m: magenta(), y: yellow(), k: black()); |
| 59 | } |
| 60 | |
| 61 | constexpr uint toUint() const noexcept |
| 62 | { |
| 63 | return m_cmyk; |
| 64 | } |
| 65 | |
| 66 | constexpr static QCmyk32 fromCmyk32(uint cmyk) noexcept |
| 67 | { |
| 68 | QCmyk32 result; |
| 69 | result.m_cmyk = cmyk; |
| 70 | return result; |
| 71 | } |
| 72 | |
| 73 | static QCmyk32 fromRgba(QRgb rgba) noexcept |
| 74 | { |
| 75 | const QColor c = QColor(rgba).toCmyk(); |
| 76 | return QCmyk32(c.cyan(), c.magenta(), c.yellow(), c.black()); |
| 77 | } |
| 78 | |
| 79 | static QCmyk32 fromColor(const QColor &color) noexcept |
| 80 | { |
| 81 | QColor c = color.toCmyk(); |
| 82 | return QCmyk32(c.cyan(), c.magenta(), c.yellow(), c.black()); |
| 83 | } |
| 84 | |
| 85 | Q_DECLARE_EQUALITY_COMPARABLE_LITERAL_TYPE(QCmyk32) |
| 86 | }; |
| 87 | |
| 88 | static_assert(sizeof(QCmyk32) == sizeof(int)); |
| 89 | static_assert(alignof(QCmyk32) == alignof(int)); |
| 90 | static_assert(std::is_standard_layout_v<QCmyk32>); |
| 91 | |
| 92 | QT_END_NAMESPACE |
| 93 | |
| 94 | #endif // QCMYK_P_H |
| 95 | |