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 The values @ref first, @ref second, @ref third as @ref Trio.
26 *
27 * @returns The values @ref first, @ref second, @ref third as @ref Trio. */
28Trio GenericColor::toTrio() const
29{
30 return createMatrix<1, 3, double>(first, second, third);
31}
32
33/** @brief The values @ref first, @ref second, @ref third as QList.
34 *
35 * @returns The values @ref first, @ref second, @ref third as QList. */
36QList<double> GenericColor::toQList3() const
37{
38 return QList<double>{first, second, third};
39}
40
41/** @brief Type conversion.
42 *
43 * @warning Interprets the current data members as XZY.
44 *
45 * @returns Type conversion. */
46cmsCIEXYZ GenericColor::reinterpretAsXyzToCmsciexyz() const
47{
48 return cmsCIEXYZ{first, second, third};
49}
50
51/** @brief Type conversion.
52 *
53 * @warning Interprets the current data members as Lab.
54 *
55 * @returns Type conversion. */
56cmsCIELab GenericColor::reinterpretAsLabToCmscielab() const
57{
58 return cmsCIELab{first, second, third};
59}
60
61/** @brief Type conversion.
62 *
63 * @warning Interprets the current data members as LCh.
64 *
65 * @returns Type conversion. */
66cmsCIELCh GenericColor::reinterpretAsLchToCmscielch() const
67{
68 return cmsCIELCh{first, second, third};
69}
70
71/** @brief Equal operator
72 *
73 * @param other The object to compare with.
74 *
75 * @returns <tt>true</tt> if equal, <tt>false</tt> otherwise. */
76bool GenericColor::operator==(const GenericColor &other) const
77{
78 return ( //
79 (first == other.first) //
80 && (second == other.second) //
81 && (third == other.third) //
82 && (fourth == other.fourth) //
83 );
84}
85
86/** @brief Unequal operator
87 *
88 * @param other The object to compare with.
89 *
90 * @returns <tt>true</tt> if unequal, <tt>false</tt> otherwise. */
91bool GenericColor::operator!=(const GenericColor &other) const
92{
93 return !(*this == other);
94}
95
96/** @internal
97 *
98 * @brief Adds QDebug() support for data type
99 * @ref PerceptualColor::GenericColor
100 *
101 * @param dbg Existing debug object
102 * @param value Value to stream into the debug object
103 * @returns Debug object with value streamed in */
104QDebug operator<<(QDebug dbg, const PerceptualColor::GenericColor &value)
105{
106 dbg.nospace() //
107 << "GenericColor(" << //
108 value.first << ", " //
109 << value.second << ", " //
110 << value.third << ", " //
111 << value.fourth << ")";
112 return dbg.maybeSpace();
113}
114
115} // namespace PerceptualColor
QDebug operator<<(QDebug dbg, const DcrawInfoContainer &c)
KIOCORE_EXPORT QStringList list(const QString &fileClass)
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 Sat Dec 21 2024 16:57:18 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.