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

0001 // SPDX-FileCopyrightText: Lukas Sommer <sommerluk@gmail.com>
0002 // SPDX-License-Identifier: BSD-2-Clause OR MIT
0003 
0004 #ifndef LCHDOUBLE_H
0005 #define LCHDOUBLE_H
0006 
0007 #include "importexport.h"
0008 #include <qdebug.h>
0009 #include <qmetatype.h>
0010 
0011 namespace PerceptualColor
0012 {
0013 /** @brief A LCH color (Oklch, CielchD50, CielchD65…)
0014  *
0015  * Storage of floating point LCH values with <tt>double</tt> precision.
0016  *
0017  * The data is not default-initialized; it is undefined when the object
0018  * is created.
0019  *
0020  * Example:
0021  * @snippet testlchdouble.cpp Use LchDouble
0022  *
0023  * More details about the valid range: @ref lchrange
0024  *
0025  * This class intentionally does not provide the operators <em>equal
0026  * to</em> (<tt>operator==</tt>) and <em>not equal to</em>
0027  * (<tt>operator!=</tt>). As LCH colors are polar coordinates,
0028  * there are various valid representations of the same angle.
0029  * And h is even meaningless when C is zero; on the other hand,
0030  * there might nevertheless be an interest in preserving h. And
0031  * invalid values with L=200 or L=300: Should they be equal because
0032  * both are invalid? Or are they different? The answer to all
0033  * these questions depends on your use case. To avoid confusion,
0034  * no comparison operators are provided by this class. See also
0035  * @ref hasSameCoordinates.
0036  *
0037  * This type is declared as type to Qt’s type system via
0038  * <tt>Q_DECLARE_METATYPE</tt>. Depending on your use case (for
0039  * example if you want to use for <em>queued</em> signal-slot connections),
0040  * you might consider calling <tt>qRegisterMetaType()</tt> for
0041  * this type, once you have a QApplication object.
0042  *
0043  * This data type can be passed to QDebug thanks to
0044  * @ref operator<<(QDebug dbg, const PerceptualColor::LchDouble &value)
0045  *
0046  * @internal
0047  *
0048  * @todo Would it make sense to normalize the hue (1° instead
0049  * of 361°, and only non-negative radii)? */
0050 struct PERCEPTUALCOLOR_IMPORTEXPORT LchDouble {
0051 public:
0052     /** @brief Lightness, mesured in percent.
0053      *
0054      * The valid range is <tt>[0, 100]</tt>. */
0055     double l;
0056     /** @brief Chroma.
0057      *
0058      * <tt>0</tt> means no chroma (grayscale). The maximum value depends on
0059      * the gamut. For sRGB for example it’s a given value, but other gamuts
0060      * can be bigger, but the practical limit is the gamut of the
0061      * @ref lchrange "human perception", beyond which a
0062      * Chroma value does not make sense. */
0063     double c;
0064     /** @brief Hue, measured in degree.
0065      *
0066      * The valid range is <tt>[0, 360[</tt>. */
0067     double h;
0068     [[nodiscard]] bool hasSameCoordinates(const LchDouble &other) const;
0069 };
0070 
0071 PERCEPTUALCOLOR_IMPORTEXPORT QDebug operator<<(QDebug dbg, const PerceptualColor::LchDouble &value);
0072 
0073 } // namespace PerceptualColor
0074 
0075 Q_DECLARE_METATYPE(PerceptualColor::LchDouble)
0076 
0077 #endif // LCHDOUBLE_H