Krita

ManagedColor.h
1/*
2 * SPDX-FileCopyrightText: 2017 Boudewijn Rempt <boud@valdyas.org>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
7#ifndef MANAGEDCOLOR_H
8#define MANAGEDCOLOR_H
9
10#include <QObject>
11#include <QVector>
12#include <QScopedPointer>
13
14#include "kritalibkis_export.h"
15#include "libkis.h"
16
17class KoColor;
18
19/**
20 * @brief The ManagedColor class is a class to handle colors that are color managed.
21 * A managed color is a color of which we know the model(RGB, LAB, CMYK, etc), the bitdepth and
22 * the specific properties of its colorspace, such as the whitepoint, chromaticities, trc, etc, as represented
23 * by the color profile.
24 *
25 * Krita has two color management systems. LCMS and OCIO.
26 * LCMS is the one handling the ICC profile stuff, and the major one handling that ManagedColor deals with.
27 * OCIO support is only in the display of the colors. ManagedColor has some support for it in colorForCanvas()
28 *
29 * All colors in Krita are color managed. QColors are understood as RGB-type colors in the sRGB space.
30 *
31 * We recommend you make a color like this:
32 *
33 * @code
34 * colorYellow = ManagedColor("RGBA", "U8", "")
35 * QVector<float> yellowComponents = colorYellow.components()
36 * yellowComponents[0] = 1.0
37 * yellowComponents[1] = 1.0
38 * yellowComponents[2] = 0
39 * yellowComponents[3] = 1.0
40 *
41 * colorYellow.setComponents(yellowComponents)
42 * QColor yellow = colorYellow.colorForCanvas(canvas)
43 * @endcode
44 */
45class KRITALIBKIS_EXPORT ManagedColor : public QObject
46{
47 Q_OBJECT
48public:
49 /**
50 * @brief ManagedColor
51 * Create a ManagedColor that is black and transparent.
52 */
53 explicit ManagedColor(QObject *parent = 0);
54 /**
55 * @brief ManagedColor create a managed color with the given color space properties.
56 * @see setColorModel() for more details.
57 */
58 ManagedColor(const QString &colorModel, const QString &colorDepth, const QString &colorProfile, QObject *parent = 0);
59 ManagedColor(KoColor color, QObject *parent = 0);
60 ~ManagedColor() override;
61
62 bool operator==(const ManagedColor &other) const;
63
64 /**
65 * @brief colorForCanvas
66 * @param canvas the canvas whose color management you'd like to use. In Krita, different views have
67 * separate canvasses, and these can have different OCIO configurations active.
68 * @return the QColor as it would be displaying on the canvas. This result can be used to draw widgets with
69 * the correct configuration applied.
70 */
71 QColor colorForCanvas(Canvas *canvas) const;
72
73 /**
74 * @brief fromQColor is the (approximate) reverse of colorForCanvas()
75 * @param qcolor the QColor to convert to a KoColor.
76 * @param canvas the canvas whose color management you'd like to use.
77 * @return the approximated ManagedColor, to use for canvas resources.
78 */
79 static ManagedColor *fromQColor(const QColor &qcolor, Canvas *canvas = 0);
80
81 /**
82 * colorDepth A string describing the color depth of the image:
83 * <ul>
84 * <li>U8: unsigned 8 bits integer, the most common type</li>
85 * <li>U16: unsigned 16 bits integer</li>
86 * <li>F16: half, 16 bits floating point. Only available if Krita was built with OpenEXR</li>
87 * <li>F32: 32 bits floating point</li>
88 * </ul>
89 * @return the color depth.
90 */
91 QString colorDepth() const;
92
93 /**
94 * @brief colorModel retrieve the current color model of this document:
95 * <ul>
96 * <li>A: Alpha mask</li>
97 * <li>RGBA: RGB with alpha channel (The actual order of channels is most often BGR!)</li>
98 * <li>XYZA: XYZ with alpha channel</li>
99 * <li>LABA: LAB with alpha channel</li>
100 * <li>CMYKA: CMYK with alpha channel</li>
101 * <li>GRAYA: Gray with alpha channel</li>
102 * <li>YCbCrA: YCbCr with alpha channel</li>
103 * </ul>
104 * @return the internal color model string.
105 */
106 QString colorModel() const;
107
108 /**
109 * @return the name of the current color profile
110 */
111 QString colorProfile() const;
112
113 /**
114 * @brief setColorProfile set the color profile of the image to the given profile. The profile has to
115 * be registered with krita and be compatible with the current color model and depth; the image data
116 * is <i>not</i> converted.
117 * @param colorProfile
118 * @return false if the colorProfile name does not correspond to to a registered profile or if assigning
119 * the profile failed.
120 */
121 bool setColorProfile(const QString &colorProfile);
122
123 /**
124 * @brief setColorSpace convert the nodes and the image to the given colorspace. The conversion is
125 * done with Perceptual as intent, High Quality and No LCMS Optimizations as flags and no blackpoint
126 * compensation.
127 *
128 * @param colorModel A string describing the color model of the image:
129 * <ul>
130 * <li>A: Alpha mask</li>
131 * <li>RGBA: RGB with alpha channel (The actual order of channels is most often BGR!)</li>
132 * <li>XYZA: XYZ with alpha channel</li>
133 * <li>LABA: LAB with alpha channel</li>
134 * <li>CMYKA: CMYK with alpha channel</li>
135 * <li>GRAYA: Gray with alpha channel</li>
136 * <li>YCbCrA: YCbCr with alpha channel</li>
137 * </ul>
138 * @param colorDepth A string describing the color depth of the image:
139 * <ul>
140 * <li>U8: unsigned 8 bits integer, the most common type</li>
141 * <li>U16: unsigned 16 bits integer</li>
142 * <li>F16: half, 16 bits floating point. Only available if Krita was built with OpenEXR</li>
143 * <li>F32: 32 bits floating point</li>
144 * </ul>
145 * @param colorProfile a valid color profile for this color model and color depth combination.
146 * @return false the combination of these arguments does not correspond to a colorspace.
147 */
148 bool setColorSpace(const QString &colorModel, const QString &colorDepth, const QString &colorProfile);
149
150 /**
151 * @brief components
152 * @return a QVector containing the channel/components of this color normalized. This includes the alphachannel.
153 */
154 QVector<float> components() const;
155
156 /**
157 * @brief componentsOrdered()
158 * @return same as Components, except the values are ordered to the display.
159 */
160 QVector<float> componentsOrdered() const;
161
162 /**
163 * @brief setComponents
164 * Set the channel/components with normalized values. For integer colorspace, this obviously means the limit
165 * is between 0.0-1.0, but for floating point colorspaces, 2.4 or 103.5 are still meaningful (if bright) values.
166 * @param values the QVector containing the new channel/component values. These should be normalized.
167 */
168 void setComponents(const QVector<float> &values);
169
170 /**
171 * Serialize this color following Create's swatch color specification available
172 * at https://web.archive.org/web/20110826002520/http://create.freedesktop.org/wiki/Swatches_-_color_file_format/Draft
173 */
174 QString toXML() const;
175
176 /**
177 * Unserialize a color following Create's swatch color specification available
178 * at https://web.archive.org/web/20110826002520/http://create.freedesktop.org/wiki/Swatches_-_color_file_format/Draft
179 *
180 * @param xml an XML color
181 *
182 * @return the unserialized color, or an empty color object if the function failed
183 * to unserialize the color
184 */
185 void fromXML(const QString &xml);
186
187 /**
188 * @brief toQString create a user-visible string of the channel names and the channel values
189 * @return a string that can be used to display the values of this color to the user.
190 */
191 QString toQString();
192
193
194private:
195
196 friend class View;
197 friend class PaletteView;
198 friend class Swatch;
199 friend class ColorizeMask;
200
201 KoColor color() const;
202
203 struct Private;
205
206};
207
208#endif // MANAGEDCOLOR_H
Canvas wraps the canvas inside a view on an image/document.
Definition Canvas.h:23
The ColorizeMask class A colorize mask is a mask type node that can be used to color in line art.
The ManagedColor class is a class to handle colors that are color managed.
The PaletteView class is a wrapper around a MVC method for handling palettes.
Definition PaletteView.h:32
The Swatch class is a thin wrapper around the KisSwatch class.
Definition Swatch.h:22
View represents one view on a document.
Definition View.h:25
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sun Feb 25 2024 18:47:29 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.