Perceptual Color

genericcolor.cpp
1// SPDX-FileCopyrightText: Lukas Sommer <sommerluk@gmail.com>
2// SPDX-License-Identifier: BSD-2-Clause OR MIT
3
4// Own header
5#include "genericcolor.h"
6
7#include <lcms2.h>
8
9namespace PerceptualColor
10{
11
12/** @brief Constructor.
13 *
14 * @param list Initial values. Only the first 4 elements are considered.
15 * Excess elements are ignored. Missing elements are
16 * interpreted as 0. */
17GenericColor::GenericColor(const QList<double> &list)
18 : first(list.value(0, 0))
19 , second(list.value(1, 0))
20 , third(list.value(2, 0))
21 , fourth(list.value(3, 0))
22{
23}
24
25/** @brief Type conversion.
26 *
27 * @warning Interprets the current data members as Lch.
28 *
29 * @returns Type conversion. */
30LchDouble GenericColor::reinterpretAsLchToLchDouble() const
31{
32 LchDouble result;
33 result.l = first;
34 result.c = second;
35 result.h = third;
36 return result;
37}
38
39/** @brief The values @ref first, @ref second, @ref third as @ref Trio.
40 *
41 * @returns The values @ref first, @ref second, @ref third as @ref Trio. */
42Trio GenericColor::toTrio() const
43{
44 return createMatrix<1, 3, double>(first, second, third);
45}
46
47/** @brief The values @ref first, @ref second, @ref third as QList.
48 *
49 * @returns The values @ref first, @ref second, @ref third as QList. */
50QList<double> GenericColor::toQList3() const
51{
52 return QList<double>{first, second, third};
53}
54
55/** @brief Type conversion.
56 *
57 * @warning Interprets the current data members as XZY.
58 *
59 * @returns Type conversion. */
60cmsCIEXYZ GenericColor::reinterpretAsXyzToCmsciexyz() const
61{
62 return cmsCIEXYZ{first, second, third};
63}
64
65/** @brief Type conversion.
66 *
67 * @warning Interprets the current data members as Lab.
68 *
69 * @returns Type conversion. */
70cmsCIELab GenericColor::reinterpretAsLabToCmscielab() const
71{
72 return cmsCIELab{first, second, third};
73}
74
75/** @brief Equal operator
76 *
77 * @param other The object to compare with.
78 *
79 * @returns <tt>true</tt> if equal, <tt>false</tt> otherwise. */
80bool GenericColor::operator==(const GenericColor &other) const
81{
82 return ( //
83 (first == other.first) //
84 && (second == other.second) //
85 && (third == other.third) //
86 && (fourth == other.fourth) //
87 );
88}
89
90/** @brief Unequal operator
91 *
92 * @param other The object to compare with.
93 *
94 * @returns <tt>true</tt> if unequal, <tt>false</tt> otherwise. */
95bool GenericColor::operator!=(const GenericColor &other) const
96{
97 return !(*this == other);
98}
99
100/** @internal
101 *
102 * @brief Adds QDebug() support for data type
103 * @ref PerceptualColor::GenericColor
104 *
105 * @param dbg Existing debug object
106 * @param value Value to stream into the debug object
107 * @returns Debug object with value streamed in */
108QDebug operator<<(QDebug dbg, const PerceptualColor::GenericColor &value)
109{
110 dbg.nospace() //
111 << "GenericColor(" << //
112 value.first << ", " //
113 << value.second << ", " //
114 << value.third << ", " //
115 << value.fourth << ")";
116 return dbg.maybeSpace();
117}
118
119} // namespace PerceptualColor
KIOCORE_EXPORT QStringList list(const QString &fileClass)
KTEXTEDITOR_EXPORT QDebug operator<<(QDebug s, const MovingCursor &cursor)
The namespace of this library.
QDebug & maybeSpace()
QDebug & nospace()
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.