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 // Own header
0005 #include "lchdouble.h"
0006 
0007 #include <type_traits>
0008 
0009 #include <lcms2.h>
0010 
0011 /** @internal
0012  *
0013  * @file
0014  *
0015  * This file defines some static asserts for the data type
0016  * @ref PerceptualColor::LchDouble. */
0017 
0018 namespace PerceptualColor
0019 {
0020 // We are using double. Check that we stay compatible with cmsCIELCh
0021 // which is based on cmsFloat64Number.
0022 static_assert(std::is_same_v<cmsFloat64Number, double>);
0023 
0024 static_assert(sizeof(double) == sizeof(cmsFloat64Number));
0025 
0026 static_assert(sizeof(LchDouble) == sizeof(cmsCIELCh));
0027 
0028 static_assert(std::is_trivially_copyable_v<LchDouble>);
0029 static_assert(std::is_trivial_v<LchDouble>);
0030 
0031 static_assert(std::is_standard_layout_v<LchDouble>);
0032 
0033 static_assert(std::is_default_constructible_v<LchDouble>);
0034 static_assert(std::is_trivially_default_constructible_v<LchDouble>);
0035 static_assert(std::is_nothrow_default_constructible_v<LchDouble>);
0036 
0037 static_assert(std::is_copy_constructible_v<LchDouble>);
0038 static_assert(std::is_trivially_copy_constructible_v<LchDouble>);
0039 static_assert(std::is_nothrow_copy_constructible_v<LchDouble>);
0040 
0041 static_assert(std::is_move_constructible_v<LchDouble>);
0042 static_assert(std::is_trivially_move_constructible_v<LchDouble>);
0043 static_assert(std::is_nothrow_move_constructible_v<LchDouble>);
0044 
0045 /** @brief Adds QDebug() support for data type
0046  * @ref PerceptualColor::LchDouble
0047  *
0048  * @param dbg Existing debug object
0049  * @param value Value to stream into the debug object
0050  * @returns Debug object with value streamed in
0051  *
0052  * @internal
0053  *
0054  * @todo This is originally declared in the global namespace instead of
0055  * the @ref PerceptualColor namespace, because the supported value was
0056  * a <tt>typedef</tt> for a LittleCMS type in the global; when declaring
0057  * this function in @ref PerceptualColor namespace, it did not work
0058  * in the global namespace. Now, things have changed. But we should write
0059  * a unit test for if it works in global namespace! */
0060 QDebug operator<<(QDebug dbg, const PerceptualColor::LchDouble &value)
0061 {
0062     dbg.nospace() << "LchDouble(" << value.l << "% " << value.c << " " << value.h << "°)";
0063     return dbg.maybeSpace();
0064 }
0065 
0066 /** @brief Compares coordinates with another object.
0067  *
0068  * @param other The object to compare with
0069  * @returns <tt>true</tt> if all three coordinates @ref l, @ref c and @ref h
0070  * of <em>this</em> object are all equal to the coordinates of <em>other</em>.
0071  * <tt>false</tt> otherwise. Note that two objects with equal @ref l and
0072  * equal @ref c, but one with h = 5° and the other with h = 365°, are
0073  * considered non-equal thought both describe the same point in the
0074  * coordinate space. */
0075 bool LchDouble::hasSameCoordinates(const PerceptualColor::LchDouble &other) const
0076 {
0077     return ((l == other.l) && (c == other.c) && (h == other.h));
0078 }
0079 
0080 } // namespace PerceptualColor