Perceptual Color

chromalightnessimageparameters.h
1// SPDX-FileCopyrightText: Lukas Sommer <sommerluk@gmail.com>
2// SPDX-License-Identifier: BSD-2-Clause OR MIT
3
4#ifndef CHROMALIGHTNESSIMAGEPARAMETERS_H
5#define CHROMALIGHTNESSIMAGEPARAMETERS_H
6
7#include <qglobal.h>
8#include <qmetatype.h>
9#include <qsharedpointer.h>
10#include <qsize.h>
11#include <qvariant.h>
12
13namespace PerceptualColor
14{
15
16class AsyncImageRenderCallback;
17class RgbColorSpace;
18
19/** @internal
20 *
21 * @brief An image of a chroma-lightness plane.
22 *
23 * This is a cut through the gamut body at a given hue.
24 *
25 * For the y axis, its height covers the lightness range [0, 100].
26 * Coordinate point <tt>(0)</tt> corresponds to value 100.
27 * Coordinate point <tt>height</tt> corresponds to value 0.
28 * Its x axis uses always the same scale as the y axis. So if the size
29 * is a square, both x range and y range are from 0 to 100. If the
30 * width is larger than the height, the x range goes beyond 100. The
31 * image paints all the LCH values that are within the gamut and x/y range.
32 * Each pixel show the color of the coordinate point at its center. So
33 * the pixel at pixel position <tt>(2, 3)</tt> shows the color corresponding
34 * to coordinate point <tt>(2.5, 3.5)</tt>.
35 *
36 * @todo Solve the problem with nearestNeighborSearch to respond immediately,
37 * without waiting for the rendering to complete, to avoid using things like
38 * <a href="https://api.kde.org/frameworks/kwidgetsaddons/html/classKBusyIndicatorWidget.html">
39 * KBusyIndicatorWidget</a>.
40 *
41 * @note Intentionally there is no anti-aliasing because this would be much
42 * slower: As there is no mathematical description of the shape of the color
43 * solid, the only easy way to get anti-aliasing would be to render at a
44 * higher resolution (say two times higher, which would yet mean four times
45 * more data), and then downscale it to the final resolution. This would be
46 * too slow. */
47class ChromaLightnessImageParameters final
48{
49public:
50 [[nodiscard]] bool operator==(const ChromaLightnessImageParameters &other) const;
51 [[nodiscard]] bool operator!=(const ChromaLightnessImageParameters &other) const;
52 static void render(const QVariant &variantParameters, AsyncImageRenderCallback &callbackObject);
53
54 /** @brief The LCH-hue.
55 *
56 * Valid range: 0° ≤ value < 360° */
57 qreal hue = 0;
58 /** @brief Image size, measured in physical pixels. */
59 QSize imageSizePhysical;
60 /** @brief Pointer to @ref RgbColorSpace object */
62
63private:
64 /** @internal @brief Only for unit tests. */
65 friend class TestChromaLightnessImageParameters;
66
67 /** @brief Calculate one-dimensional index for given <tt>x</tt> and
68 * <tt>y</tt> coordinates.
69 *
70 * @param x The <tt>x</tt> coordinate
71 * @param y The <tt>y</tt> coordinate
72 * @param imageSizePhysical The image size
73 * @returns The corresponding index, assuming a one-dimensional array
74 * that contains one element for each pixel, starting with the elements
75 * <tt>(0, 0)</tt>, than <tt>(0, 1)</tt> and so on, line by line. */
76 [[nodiscard]] static constexpr int maskIndex(const int x, const int y, const QSize imageSizePhysical)
77 {
78 return x + y * imageSizePhysical.width();
79 }
80};
81
82} // namespace PerceptualColor
83
84Q_DECLARE_METATYPE(PerceptualColor::ChromaLightnessImageParameters)
85
86#endif // CHROMALIGHTNESSIMAGEPARAMETERS_H
The namespace of this library.
int width() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:20:36 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.