Perceptual Color

helperconversion.cpp
1// SPDX-FileCopyrightText: Lukas Sommer <sommerluk@gmail.com>
2// SPDX-License-Identifier: BSD-2-Clause OR MIT
3
4// Own header
5#include "helperconversion.h"
6
7#include "lchdouble.h"
8#include <qglobal.h>
9
10namespace PerceptualColor
11{
12
13/** @internal
14 *
15 * @brief Type conversion.
16 * @param value An LCH value
17 * @returns Same LCH value as <tt>cmsCIELCh</tt>. */
18cmsCIELCh toCmsLch(const LchDouble &value)
19{
20 cmsCIELCh result;
21 result.L = value.l;
22 result.C = value.c;
23 result.h = value.h;
24 return result;
25}
26
27/** @internal
28 *
29 * @brief Type conversion.
30 * @param value An LCH value
31 * @returns Same LCH value as @ref LchDouble. */
32LchDouble toLchDouble(const cmsCIELCh &value)
33{
34 LchDouble result;
35 result.l = value.L;
36 result.c = value.C;
37 result.h = value.h;
38 return result;
39}
40
41/** @internal
42 *
43 * @brief Conversion to @ref LchDouble
44 * @param value a point in Lab representation
45 * @returns the same point in @ref LchDouble representation */
46LchDouble toLchDouble(const cmsCIELab &value)
47{
48 cmsCIELCh tempLch;
49 cmsLab2LCh(&tempLch, &value);
50 return toLchDouble(tempLch);
51}
52
53/** @internal
54 *
55 * @brief Conversion to <tt>cmsCIELab</tt>
56 * @param value the value to convert
57 * @returns the same value as <tt>cmsCIELab</tt> */
58cmsCIELab toCmsLab(const cmsCIELCh &value)
59{
60 cmsCIELab lab; // uses cmsFloat64Number internally
61 // convert from LCH to Lab
62 cmsLCh2Lab(&lab, &value);
63 return lab;
64}
65
66#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
67/** @internal
68 *
69 * @brief A qHash function for @ref ColorSpace.
70 *
71 * Qt5 needs a qHash function if QHash’s key is an enum class. Qt6 does not
72 * need this. Therefore, this function is only compiled into the Qt5 builds.
73 *
74 * @warning This is not part of the public API! It can change or be
75 * removed totally at any time. */
76uint qHash(const ColorModel t, uint seed) // clazy:exclude=qt6-qhash-signature
77{
78 using UnderlyingType = std::underlying_type<ColorModel>::type;
79 const auto underlyingValue = static_cast<UnderlyingType>(t);
80 // “::” selects one of Qt’s qHash functions (instead of recursively calling
81 // this very same function).
82 return ::qHash(underlyingValue, seed);
83}
84#endif
85
86} // namespace PerceptualColor
KCALENDARCORE_EXPORT size_t qHash(const KCalendarCore::Period &key, size_t seed=0)
The namespace of this library.
double l
Lightness, mesured in percent.
Definition lchdouble.h:55
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 26 2024 11:50:27 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.