File indexing completed on 2024-05-12 04:44:32
0001 // SPDX-FileCopyrightText: Lukas Sommer <sommerluk@gmail.com> 0002 // SPDX-License-Identifier: BSD-2-Clause OR MIT 0003 0004 #ifndef GENERICCOLOR_H 0005 #define GENERICCOLOR_H 0006 0007 #include "helpermath.h" 0008 #include "lchdouble.h" 0009 #include <lcms2.h> 0010 #include <qdebug.h> 0011 #include <qlist.h> 0012 0013 namespace PerceptualColor 0014 { 0015 0016 /** @internal 0017 * 0018 * @brief Numeric representation of an opaque color with up to four components 0019 * without specifying the color space or the opacity/alpha. */ 0020 struct GenericColor { 0021 public: 0022 /** @brief Default constructor. */ 0023 constexpr GenericColor() = default; 0024 0025 /** @brief Constructor. 0026 * 0027 * @param init Initial value. @ref fourth is set to <tt>0</tt>. */ 0028 explicit GenericColor(const Trio &init) 0029 : first(init(0, 0)) 0030 , second(init(1, 0)) 0031 , third(init(2, 0)) 0032 , fourth(0) 0033 { 0034 } 0035 0036 /** @brief Constructor. 0037 * 0038 * @param init Initial value. @ref fourth is set to <tt>0</tt>. */ 0039 explicit constexpr GenericColor(const cmsCIELab &init) 0040 : first(init.L) 0041 , second(init.a) 0042 , third(init.b) 0043 , fourth(0) 0044 { 0045 } 0046 0047 /** @brief Constructor. 0048 * 0049 * @param init Initial value. @ref fourth is set to <tt>0</tt>. */ 0050 explicit constexpr GenericColor(const cmsCIEXYZ &init) 0051 : first(init.X) 0052 , second(init.Y) 0053 , third(init.Z) 0054 , fourth(0) 0055 { 0056 } 0057 0058 /** @brief Constructor. 0059 * 0060 * @param init Initial value. @ref fourth is set to <tt>0</tt>. */ 0061 explicit constexpr GenericColor(const LchDouble &init) 0062 : first(init.l) 0063 , second(init.c) 0064 , third(init.h) 0065 , fourth(0) 0066 { 0067 } 0068 0069 /** @brief Constructor. 0070 * 0071 * @param v1 Initial value for @ref first 0072 * @param v2 Initial value for @ref second 0073 * @param v3 Initial value for @ref third 0074 * 0075 * @ref fourth is set to <tt>0</tt>. */ 0076 constexpr GenericColor(const double v1, const double v2, const double v3) 0077 : first(v1) 0078 , second(v2) 0079 , third(v3) 0080 , fourth(0) 0081 { 0082 } 0083 0084 /** @brief Constructor. 0085 * 0086 * @param v1 Initial value for @ref first 0087 * @param v2 Initial value for @ref second 0088 * @param v3 Initial value for @ref third 0089 * @param v4 Initial value for @ref fourth */ 0090 constexpr GenericColor(const double v1, const double v2, const double v3, const double v4) 0091 : first(v1) 0092 , second(v2) 0093 , third(v3) 0094 , fourth(v4) 0095 { 0096 } 0097 0098 explicit GenericColor(const QList<double> &list); 0099 0100 bool operator==(const GenericColor &other) const; 0101 bool operator!=(const GenericColor &other) const; 0102 0103 [[nodiscard]] cmsCIELab reinterpretAsLabToCmscielab() const; 0104 [[nodiscard]] LchDouble reinterpretAsLchToLchDouble() const; 0105 [[nodiscard]] cmsCIEXYZ reinterpretAsXyzToCmsciexyz() const; 0106 [[nodiscard]] QList<double> toQList3() const; 0107 [[nodiscard]] Trio toTrio() const; 0108 0109 /** @brief First value. */ 0110 double first = 0; 0111 /** @brief Second value. */ 0112 double second = 0; 0113 /** @brief Third value. */ 0114 double third = 0; 0115 /** @brief Forth value. 0116 * 0117 * Note that is is for color spaces that have four components (like CMYK). 0118 * It must <em>never</em> be used for opacity/alpha values. */ 0119 double fourth = 0; 0120 }; 0121 0122 QDebug operator<<(QDebug dbg, const PerceptualColor::GenericColor &value); 0123 0124 } // namespace PerceptualColor 0125 0126 #endif // GENERICCOLOR_H