Perceptual Color

genericcolor.h
1// SPDX-FileCopyrightText: Lukas Sommer <sommerluk@gmail.com>
2// SPDX-License-Identifier: BSD-2-Clause OR MIT
3
4#ifndef GENERICCOLOR_H
5#define GENERICCOLOR_H
6
7#include "helpermath.h"
8#include <lcms2.h>
9#include <qdebug.h>
10#include <qlist.h>
11#include <qmetatype.h>
12
13namespace PerceptualColor
14{
15
16/** @internal
17 *
18 * @brief Numeric representation of an opaque color with up to four components
19 * without specifying the color space or the opacity/alpha.
20 *
21 * This type is declared as type to Qt’s type system via
22 * <tt>Q_DECLARE_METATYPE</tt>. Depending on your use case (for
23 * example if you want to use for <em>queued</em> signal-slot connections),
24 * you might consider calling <tt>qRegisterMetaType()</tt> for
25 * this type, once you have a QApplication object.
26 */
27struct GenericColor {
28public:
29 /** @brief Default constructor. */
30 constexpr GenericColor() = default;
31
32 /** @brief Constructor.
33 *
34 * @param init Initial value. @ref fourth is set to <tt>0</tt>. */
35 explicit GenericColor(const Trio &init)
36 : first(init(0, 0))
37 , second(init(1, 0))
38 , third(init(2, 0))
39 , fourth(0)
40 {
41 }
42
43 /** @brief Constructor.
44 *
45 * @param init Initial value. @ref fourth is set to <tt>0</tt>. */
46 explicit constexpr GenericColor(const cmsCIELab &init)
47 : first(init.L)
48 , second(init.a)
49 , third(init.b)
50 , fourth(0)
51 {
52 }
53
54 /** @brief Constructor.
55 *
56 * @param init Initial value. @ref fourth is set to <tt>0</tt>. */
57 explicit constexpr GenericColor(const cmsCIELCh &init)
58 : first(init.L)
59 , second(init.C)
60 , third(init.h)
61 , fourth(0)
62 {
63 }
64
65 /** @brief Constructor.
66 *
67 * @param init Initial value. @ref fourth is set to <tt>0</tt>. */
68 explicit constexpr GenericColor(const cmsCIEXYZ &init)
69 : first(init.X)
70 , second(init.Y)
71 , third(init.Z)
72 , fourth(0)
73 {
74 }
75
76 /** @brief Constructor.
77 *
78 * @param v1 Initial value for @ref first
79 * @param v2 Initial value for @ref second
80 * @param v3 Initial value for @ref third
81 *
82 * @ref fourth is set to <tt>0</tt>. */
83 constexpr GenericColor(const double v1, const double v2, const double v3)
84 : first(v1)
85 , second(v2)
86 , third(v3)
87 , fourth(0)
88 {
89 }
90
91 /** @brief Constructor.
92 *
93 * @param v1 Initial value for @ref first
94 * @param v2 Initial value for @ref second
95 * @param v3 Initial value for @ref third
96 * @param v4 Initial value for @ref fourth */
97 constexpr GenericColor(const double v1, const double v2, const double v3, const double v4)
98 : first(v1)
99 , second(v2)
100 , third(v3)
101 , fourth(v4)
102 {
103 }
104
105 explicit GenericColor(const QList<double> &list);
106
107 bool operator==(const GenericColor &other) const;
108 bool operator!=(const GenericColor &other) const;
109
110 [[nodiscard]] cmsCIELab reinterpretAsLabToCmscielab() const;
111 [[nodiscard]] cmsCIELCh reinterpretAsLchToCmscielch() const;
112 [[nodiscard]] cmsCIEXYZ reinterpretAsXyzToCmsciexyz() const;
113 [[nodiscard]] QList<double> toQList3() const;
114 [[nodiscard]] Trio toTrio() const;
115
116 /** @brief First value. */
117 double first = 0;
118 /** @brief Second value. */
119 double second = 0;
120 /** @brief Third value. */
121 double third = 0;
122 /** @brief Forth value.
123 *
124 * Note that is is for color spaces that have four components (like CMYK).
125 * It must <em>never</em> be used for opacity/alpha values. */
126 double fourth = 0;
127};
128
129QDebug operator<<(QDebug dbg, const PerceptualColor::GenericColor &value);
130
131} // namespace PerceptualColor
132
133Q_DECLARE_METATYPE(PerceptualColor::GenericColor)
134
135#endif // GENERICCOLOR_H
QDebug operator<<(QDebug dbg, const DcrawInfoContainer &c)
The namespace of this library.
QCA_EXPORT void init()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:18:38 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.