1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QCMYK_P_H
#define QCMYK_P_H
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists purely as an
// implementation detail. This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//
#include <QtGui/private/qtguiglobal_p.h>
#include <QtGui/qcolor.h>
QT_BEGIN_NAMESPACE
class QCmyk32
{
private:
uint m_cmyk = 0;
public:
QCmyk32() = default;
constexpr QCmyk32(int cyan, int magenta, int yellow, int black) :
#if QT_BYTE_ORDER == Q_BIG_ENDIAN
m_cmyk(cyan << 24 | magenta << 16 | yellow << 8 | black)
#else
m_cmyk(cyan | magenta << 8 | yellow << 16 | black << 24)
#endif
{
}
#if QT_BYTE_ORDER == Q_BIG_ENDIAN
constexpr int cyan() const noexcept { return (m_cmyk >> 24) & 0xff; }
constexpr int magenta() const noexcept { return (m_cmyk >> 16) & 0xff; }
constexpr int yellow() const noexcept { return (m_cmyk >> 8) & 0xff; }
constexpr int black() const noexcept { return (m_cmyk ) & 0xff; }
#else
constexpr int cyan() const noexcept { return (m_cmyk ) & 0xff; }
constexpr int magenta() const noexcept { return (m_cmyk >> 8) & 0xff; }
constexpr int yellow() const noexcept { return (m_cmyk >> 16) & 0xff; }
constexpr int black() const noexcept { return (m_cmyk >> 24) & 0xff; }
#endif
QColor toColor() const noexcept
{
return QColor::fromCmyk(cyan(), magenta(), yellow(), black());
}
constexpr uint toUint() const noexcept
{
return m_cmyk;
}
constexpr static QCmyk32 fromCmyk32(uint cmyk) noexcept
{
QCmyk32 result;
result.m_cmyk = cmyk;
return result;
}
static QCmyk32 fromRgba(QRgb rgba) noexcept
{
const QColor c = QColor(rgba).toCmyk();
return QCmyk32(c.cyan(), c.magenta(), c.yellow(), c.black());
}
static QCmyk32 fromColor(const QColor &color) noexcept
{
QColor c = color.toCmyk();
return QCmyk32(c.cyan(), c.magenta(), c.yellow(), c.black());
}
};
static_assert(sizeof(QCmyk32) == sizeof(int));
static_assert(alignof(QCmyk32) == alignof(int));
static_assert(std::is_standard_layout_v<QCmyk32>);
QT_END_NAMESPACE
#endif // QCMYK_P_H
|