Perceptual Color

absolutecolor.h
1// SPDX-FileCopyrightText: Lukas Sommer <sommerluk@gmail.com>
2// SPDX-License-Identifier: BSD-2-Clause OR MIT
3
4#ifndef ABSOLUTECOLOR_H
5#define ABSOLUTECOLOR_H
6
7#include "genericcolor.h"
8#include "helperconversion.h"
9#include <array>
10#include <optional>
11#include <qglobal.h>
12#include <qhash.h>
13#include <qlist.h>
14
15#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
16#include <qobjectdefs.h>
17#include <qstring.h>
18#endif
19
21{
22
23/** @internal
24 *
25 * @brief Toolbox for color conversions.
26 *
27 * @sa @ref RgbColor */
28class AbsoluteColor final
29{
30public:
31 AbsoluteColor() = delete;
32
33 [[nodiscard]] static QHash<ColorModel, GenericColor> allConversions(const ColorModel model, const GenericColor &value);
34 [[nodiscard]] static std::optional<GenericColor> convert(const ColorModel from, const GenericColor &value, const ColorModel to);
35 static GenericColor fromXyzD50ToXyzD65(const GenericColor &value);
36 static GenericColor fromXyzD65ToXyzD50(const GenericColor &value);
37 static GenericColor fromXyzD65ToOklab(const GenericColor &value);
38 static GenericColor fromOklabToXyzD65(const GenericColor &value);
39 static GenericColor fromXyzD50ToCielabD50(const GenericColor &value);
40 static GenericColor fromCielabD50ToXyzD50(const GenericColor &value);
41 static GenericColor fromPolarToCartesian(const GenericColor &value);
42 static GenericColor fromCartesianToPolar(const GenericColor &value);
43
44private:
45 /** @brief Function pointer type for the conversion functions. */
46 // NOTE std::function<> has nicer syntax for function pointers, but does
47 // not allow constexpr.
48 using ConversionFunction = GenericColor (*)(const GenericColor &);
49
50 /** @brief Gives access to a conversion function. */
51 struct Conversion {
52 public:
53 /** @brief The color space from which the function converts. */
54 ColorModel from;
55 /** @brief The color space to which the function converts. */
56 ColorModel to;
57 /** @brief The function. */
58 ConversionFunction conversionFunction;
59 };
60
61 /** @brief List of all conversion accesses. */
62 static constexpr std::array<Conversion, 10> conversionList //
63 {{{ColorModel::XyzD50, ColorModel::XyzD65, fromXyzD50ToXyzD65},
64 {ColorModel::XyzD65, ColorModel::XyzD50, fromXyzD65ToXyzD50},
65 {ColorModel::OklabD65, ColorModel::XyzD65, fromOklabToXyzD65},
66 {ColorModel::XyzD65, ColorModel::OklabD65, fromXyzD65ToOklab},
67 {ColorModel::XyzD50, ColorModel::CielabD50, fromXyzD50ToCielabD50},
68 {ColorModel::CielabD50, ColorModel::XyzD50, fromCielabD50ToXyzD50},
69 {ColorModel::CielchD50, ColorModel::CielabD50, fromPolarToCartesian},
70 {ColorModel::OklchD65, ColorModel::OklabD65, fromPolarToCartesian},
71 {ColorModel::CielabD50, ColorModel::CielchD50, fromCartesianToPolar},
72 {ColorModel::OklabD65, ColorModel::OklchD65, fromCartesianToPolar}}};
73
74 [[nodiscard]] static QList<AbsoluteColor::Conversion> conversionsFrom(const ColorModel model);
75
76 static void addDirectConversionsRecursivly(QHash<ColorModel, GenericColor> *values, const ColorModel model);
77};
78
79} // namespace PerceptualColor
80
81#endif // ABSOLUTECOLOR_H
The namespace of this library.
ColorModel
Identifiers for color models.
@ OklabD65
The Oklab color space, which by definition always and exclusively uses a D65 illuminant.
@ XyzD50
The Xyz color space using a D50 illuminant.
@ CielabD50
The Cielab color space using a D50 illuminant.
@ OklchD65
The Oklch color space, which by definition always and exclusively uses a D65 illuminant.
@ XyzD65
The Xzy color space using a D65 illuminant.
@ CielchD50
The Cielch color space using a D50 illuminant.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:18:38 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.