File indexing completed on 2024-05-12 04:44:33

0001 // SPDX-FileCopyrightText: Lukas Sommer <sommerluk@gmail.com>
0002 // SPDX-License-Identifier: BSD-2-Clause OR MIT
0003 
0004 // Own header
0005 #include "helperconversion.h"
0006 
0007 #include "lchdouble.h"
0008 #include <qglobal.h>
0009 
0010 namespace PerceptualColor
0011 {
0012 
0013 /** @internal
0014  *
0015  * @brief Type conversion.
0016  * @param value An LCH value
0017  * @returns Same LCH value as <tt>cmsCIELCh</tt>. */
0018 cmsCIELCh toCmsLch(const LchDouble &value)
0019 {
0020     cmsCIELCh result;
0021     result.L = value.l;
0022     result.C = value.c;
0023     result.h = value.h;
0024     return result;
0025 }
0026 
0027 /** @internal
0028  *
0029  * @brief Type conversion.
0030  * @param value An LCH value
0031  * @returns Same LCH value as @ref LchDouble. */
0032 LchDouble toLchDouble(const cmsCIELCh &value)
0033 {
0034     LchDouble result;
0035     result.l = value.L;
0036     result.c = value.C;
0037     result.h = value.h;
0038     return result;
0039 }
0040 
0041 /** @internal
0042  *
0043  * @brief Conversion to @ref LchDouble
0044  * @param value a point in Lab representation
0045  * @returns the same point in @ref LchDouble representation */
0046 LchDouble toLchDouble(const cmsCIELab &value)
0047 {
0048     cmsCIELCh tempLch;
0049     cmsLab2LCh(&tempLch, &value);
0050     return toLchDouble(tempLch);
0051 }
0052 
0053 /** @internal
0054  *
0055  * @brief Conversion to <tt>cmsCIELab</tt>
0056  * @param value the value to convert
0057  * @returns the same value as <tt>cmsCIELab</tt> */
0058 cmsCIELab toCmsLab(const cmsCIELCh &value)
0059 {
0060     cmsCIELab lab; // uses cmsFloat64Number internally
0061     // convert from LCH to Lab
0062     cmsLCh2Lab(&lab, &value);
0063     return lab;
0064 }
0065 
0066 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
0067 /** @internal
0068  *
0069  * @brief A qHash function for @ref ColorSpace.
0070  *
0071  * Qt5 needs a qHash function if QHash’s key is an enum class. Qt6 does not
0072  * need this. Therefore, this function is only compiled into the Qt5 builds.
0073  *
0074  * @warning This is not part of the public API! It can change or be
0075  * removed totally at any time. */
0076 uint qHash(const ColorModel t, uint seed) // clazy:exclude=qt6-qhash-signature
0077 {
0078     using UnderlyingType = std::underlying_type<ColorModel>::type;
0079     const auto underlyingValue = static_cast<UnderlyingType>(t);
0080     // “::” selects one of Qt’s qHash functions (instead of recursively calling
0081     // this very same function).
0082     return ::qHash(underlyingValue, seed);
0083 }
0084 #endif
0085 
0086 } // namespace PerceptualColor