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 "lchdouble.h"
9#include <lcms2.h>
10#include <qdebug.h>
11#include <qlist.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. */
20struct GenericColor {
21public:
22 /** @brief Default constructor. */
23 constexpr GenericColor() = default;
24
25 /** @brief Constructor.
26 *
27 * @param init Initial value. @ref fourth is set to <tt>0</tt>. */
28 explicit GenericColor(const Trio &init)
29 : first(init(0, 0))
30 , second(init(1, 0))
31 , third(init(2, 0))
32 , fourth(0)
33 {
34 }
35
36 /** @brief Constructor.
37 *
38 * @param init Initial value. @ref fourth is set to <tt>0</tt>. */
39 explicit constexpr GenericColor(const cmsCIELab &init)
40 : first(init.L)
41 , second(init.a)
42 , third(init.b)
43 , fourth(0)
44 {
45 }
46
47 /** @brief Constructor.
48 *
49 * @param init Initial value. @ref fourth is set to <tt>0</tt>. */
50 explicit constexpr GenericColor(const cmsCIEXYZ &init)
51 : first(init.X)
52 , second(init.Y)
53 , third(init.Z)
54 , fourth(0)
55 {
56 }
57
58 /** @brief Constructor.
59 *
60 * @param init Initial value. @ref fourth is set to <tt>0</tt>. */
61 explicit constexpr GenericColor(const LchDouble &init)
62 : first(init.l)
63 , second(init.c)
64 , third(init.h)
65 , fourth(0)
66 {
67 }
68
69 /** @brief Constructor.
70 *
71 * @param v1 Initial value for @ref first
72 * @param v2 Initial value for @ref second
73 * @param v3 Initial value for @ref third
74 *
75 * @ref fourth is set to <tt>0</tt>. */
76 constexpr GenericColor(const double v1, const double v2, const double v3)
77 : first(v1)
78 , second(v2)
79 , third(v3)
80 , fourth(0)
81 {
82 }
83
84 /** @brief Constructor.
85 *
86 * @param v1 Initial value for @ref first
87 * @param v2 Initial value for @ref second
88 * @param v3 Initial value for @ref third
89 * @param v4 Initial value for @ref fourth */
90 constexpr GenericColor(const double v1, const double v2, const double v3, const double v4)
91 : first(v1)
92 , second(v2)
93 , third(v3)
94 , fourth(v4)
95 {
96 }
97
98 explicit GenericColor(const QList<double> &list);
99
100 bool operator==(const GenericColor &other) const;
101 bool operator!=(const GenericColor &other) const;
102
103 [[nodiscard]] cmsCIELab reinterpretAsLabToCmscielab() const;
104 [[nodiscard]] LchDouble reinterpretAsLchToLchDouble() const;
105 [[nodiscard]] cmsCIEXYZ reinterpretAsXyzToCmsciexyz() const;
106 [[nodiscard]] QList<double> toQList3() const;
107 [[nodiscard]] Trio toTrio() const;
108
109 /** @brief First value. */
110 double first = 0;
111 /** @brief Second value. */
112 double second = 0;
113 /** @brief Third value. */
114 double third = 0;
115 /** @brief Forth value.
116 *
117 * Note that is is for color spaces that have four components (like CMYK).
118 * It must <em>never</em> be used for opacity/alpha values. */
119 double fourth = 0;
120};
121
122QDebug operator<<(QDebug dbg, const PerceptualColor::GenericColor &value);
123
124} // namespace PerceptualColor
125
126#endif // GENERICCOLOR_H
KTEXTEDITOR_EXPORT QDebug operator<<(QDebug s, const MovingCursor &cursor)
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 Fri May 24 2024 11:48:43 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.