Krita Source Code Documentation
Loading...
Searching...
No Matches
ManagedColor Class Reference

The ManagedColor class is a class to handle colors that are color managed. A managed color is a color of which we know the model(RGB, LAB, CMYK, etc), the bitdepth and the specific properties of its colorspace, such as the whitepoint, chromaticities, trc, etc, as represented by the color profile. More...

#include <ManagedColor.h>

+ Inheritance diagram for ManagedColor:

Public Member Functions

QString colorDepth () const
 
QColor colorForCanvas (Canvas *canvas) const
 colorForCanvas
 
QString colorModel () const
 colorModel retrieve the current color model of this document:
 
QString colorProfile () const
 
QVector< float > components () const
 components
 
QVector< float > componentsOrdered () const
 componentsOrdered()
 
void fromXML (const QString &xml)
 
 ManagedColor (const QString &colorModel, const QString &colorDepth, const QString &colorProfile, QObject *parent=0)
 ManagedColor create a managed color with the given color space properties.
 
 ManagedColor (KoColor color, QObject *parent=0)
 
 ManagedColor (QObject *parent=0)
 ManagedColor Create a ManagedColor that is black and transparent.
 
bool operator== (const ManagedColor &other) const
 
bool setColorProfile (const QString &colorProfile)
 setColorProfile set the color profile of the image to the given profile. The profile has to be registered with krita and be compatible with the current color model and depth; the image data is not converted.
 
bool setColorSpace (const QString &colorModel, const QString &colorDepth, const QString &colorProfile)
 setColorSpace convert the nodes and the image to the given colorspace. The conversion is done with Perceptual as intent, High Quality and No LCMS Optimizations as flags and no blackpoint compensation.
 
void setComponents (const QVector< float > &values)
 setComponents Set the channel/components with normalized values. For integer colorspace, this obviously means the limit is between 0.0-1.0, but for floating point colorspaces, 2.4 or 103.5 are still meaningful (if bright) values.
 
QString toQString ()
 toQString create a user-visible string of the channel names and the channel values
 
QString toXML () const
 
 ~ManagedColor () override
 

Static Public Member Functions

static ManagedColorfromQColor (const QColor &qcolor, Canvas *canvas=0)
 fromQColor is the (approximate) reverse of colorForCanvas()
 

Private Member Functions

KoColor color () const
 

Private Attributes

const QScopedPointer< Privated
 

Friends

class ColorizeMask
 
class PaletteView
 
class Swatch
 
class View
 Assistance tools: guides, reference, etc.
 

Detailed Description

The ManagedColor class is a class to handle colors that are color managed. A managed color is a color of which we know the model(RGB, LAB, CMYK, etc), the bitdepth and the specific properties of its colorspace, such as the whitepoint, chromaticities, trc, etc, as represented by the color profile.

Krita has two color management systems. LCMS and OCIO. LCMS is the one handling the ICC profile stuff, and the major one handling that ManagedColor deals with. OCIO support is only in the display of the colors. ManagedColor has some support for it in colorForCanvas()

All colors in Krita are color managed. QColors are understood as RGB-type colors in the sRGB space.

We recommend you make a color like this:

colorYellow = ManagedColor("RGBA", "U8", "")
QVector<float> yellowComponents = colorYellow.components()
yellowComponents[0] = 1.0
yellowComponents[1] = 1.0
yellowComponents[2] = 0
yellowComponents[3] = 1.0
colorYellow.setComponents(yellowComponents)
QColor yellow = colorYellow.colorForCanvas(canvas)
ManagedColor(QObject *parent=0)
ManagedColor Create a ManagedColor that is black and transparent.
QVector< float > components() const
components
QColor colorForCanvas(Canvas *canvas) const
colorForCanvas
void setComponents(const QVector< float > &values)
setComponents Set the channel/components with normalized values. For integer colorspace,...

Definition at line 45 of file ManagedColor.h.

Constructor & Destructor Documentation

◆ ManagedColor() [1/3]

ManagedColor::ManagedColor ( QObject * parent = 0)
explicit

ManagedColor Create a ManagedColor that is black and transparent.

Definition at line 26 of file ManagedColor.cpp.

27 : QObject(parent)
28 , d(new Private())
29{
30 // Default black rgb color
31}
const QScopedPointer< Private > d

◆ ManagedColor() [2/3]

ManagedColor::ManagedColor ( const QString & colorModel,
const QString & colorDepth,
const QString & colorProfile,
QObject * parent = 0 )

ManagedColor create a managed color with the given color space properties.

See also
setColorModel() for more details.

Definition at line 33 of file ManagedColor.cpp.

34 : QObject(parent)
35 , d(new Private())
36{
38 if (colorSpace) {
39 d->color = KoColor(colorSpace);
40 }
41}
QString colorModel() const
colorModel retrieve the current color model of this document:
QString colorProfile() const
QString colorDepth() const
const KoColorSpace * colorSpace(const QString &colorModelId, const QString &colorDepthId, const KoColorProfile *profile)
static KoColorSpaceRegistry * instance()

References colorDepth(), colorModel(), colorProfile(), KoColorSpaceRegistry::colorSpace(), d, and KoColorSpaceRegistry::instance().

◆ ManagedColor() [3/3]

ManagedColor::ManagedColor ( KoColor color,
QObject * parent = 0 )

Definition at line 44 of file ManagedColor.cpp.

45 : QObject(parent)
46 , d(new Private())
47{
48 d->color = color;
49}
KoColor color() const

References color(), and d.

◆ ~ManagedColor()

ManagedColor::~ManagedColor ( )
override

Definition at line 51 of file ManagedColor.cpp.

52{
53}

Member Function Documentation

◆ color()

KoColor ManagedColor::color ( ) const
private

Definition at line 176 of file ManagedColor.cpp.

177{
178 return d->color;
179}

References d.

◆ colorDepth()

QString ManagedColor::colorDepth ( ) const

colorDepth A string describing the color depth of the image:

  • U8: unsigned 8 bits integer, the most common type
  • U16: unsigned 16 bits integer
  • F16: half, 16 bits floating point. Only available if Krita was built with OpenEXR
  • F32: 32 bits floating point
Returns
the color depth.

Definition at line 92 of file ManagedColor.cpp.

93{
94 return d->color.colorSpace()->colorDepthId().id();
95}

References d.

◆ colorForCanvas()

QColor ManagedColor::colorForCanvas ( Canvas * canvas) const

colorForCanvas

Parameters
canvasthe canvas whose color management you'd like to use. In Krita, different views have separate canvasses, and these can have different OCIO configurations active.
Returns
the QColor as it would be displaying on the canvas. This result can be used to draw widgets with the correct configuration applied.

Definition at line 60 of file ManagedColor.cpp.

61{
62 QColor c = QColor(0,0,0);
63 if (canvas && canvas->displayColorConverter() && canvas->displayColorConverter()->displayRendererInterface()) {
65 if (converter) {
66 c = converter->toQColor(d->color);
67 } else {
69 }
70 } else {
72 }
73 return c;
74}
KisDisplayColorConverter * displayColorConverter() const
Definition Canvas.cpp:131
KoColorDisplayRendererInterface * displayRendererInterface() const
virtual QColor toQColor(const KoColor &c, bool proofToPaintColors=false) const =0
static KoColorDisplayRendererInterface * instance()

References d, Canvas::displayColorConverter(), KisDisplayColorConverter::displayRendererInterface(), KoDumbColorDisplayRenderer::instance(), and KoColorDisplayRendererInterface::toQColor().

◆ colorModel()

QString ManagedColor::colorModel ( ) const

colorModel retrieve the current color model of this document:

  • A: Alpha mask
  • RGBA: RGB with alpha channel (The actual order of channels is most often BGR!)
  • XYZA: XYZ with alpha channel
  • LABA: LAB with alpha channel
  • CMYKA: CMYK with alpha channel
  • GRAYA: Gray with alpha channel
  • YCbCrA: YCbCr with alpha channel
Returns
the internal color model string.

Definition at line 97 of file ManagedColor.cpp.

98{
99 return d->color.colorSpace()->colorModelId().id();
100}

References d.

◆ colorProfile()

QString ManagedColor::colorProfile ( ) const
Returns
the name of the current color profile

Definition at line 102 of file ManagedColor.cpp.

103{
104 return d->color.colorSpace()->profile()->name();
105}

References d.

◆ components()

QVector< float > ManagedColor::components ( ) const

components

Returns
a QVector containing the channel/components of this color normalized. This includes the alphachannel.

Definition at line 123 of file ManagedColor.cpp.

124{
125 QVector<float> values(d->color.colorSpace()->channelCount());
126 d->color.colorSpace()->normalisedChannelsValue(d->color.data(), values);
127 return values;
128}

References d.

◆ componentsOrdered()

QVector< float > ManagedColor::componentsOrdered ( ) const

componentsOrdered()

Returns
same as Components, except the values are ordered to the display.

Definition at line 130 of file ManagedColor.cpp.

131{
132 const QList<KoChannelInfo *> channelInfo = d->color.colorSpace()->channels();
133 QVector<float> valuesUnsorted = components();
134 QVector<float> values(channelInfo.size());
135 for (int i=0; i<values.size();i++) {
136 int location = KoChannelInfo::displayPositionToChannelIndex(i, channelInfo);
137 values[location] = valuesUnsorted[i];
138 }
139 return values;
140}
static int displayPositionToChannelIndex(int displayPosition, const QList< KoChannelInfo * > &channels)

References components(), d, and KoChannelInfo::displayPositionToChannelIndex().

◆ fromQColor()

ManagedColor * ManagedColor::fromQColor ( const QColor & qcolor,
Canvas * canvas = 0 )
static

fromQColor is the (approximate) reverse of colorForCanvas()

Parameters
qcolorthe QColor to convert to a KoColor.
canvasthe canvas whose color management you'd like to use.
Returns
the approximated ManagedColor, to use for canvas resources.

Definition at line 76 of file ManagedColor.cpp.

77{
78 KoColor c;
79 if (canvas && canvas->displayColorConverter() && canvas->displayColorConverter()->displayRendererInterface()) {
81 if (converter) {
82 c = converter->approximateFromRenderedQColor(qcolor);
83 } else {
85 }
86 } else {
88 }
89 return new ManagedColor(c);
90}
virtual KoColor approximateFromRenderedQColor(const QColor &c) const =0

References KoColorDisplayRendererInterface::approximateFromRenderedQColor(), Canvas::displayColorConverter(), KisDisplayColorConverter::displayRendererInterface(), KoDumbColorDisplayRenderer::instance(), and ManagedColor().

◆ fromXML()

void ManagedColor::fromXML ( const QString & xml)

Unserialize a color following Create's swatch color specification available at https://web.archive.org/web/20110826002520/http://create.freedesktop.org/wiki/Swatches_-_color_file_format/Draft

Parameters
xmlan XML color
Returns
the unserialized color, or an empty color object if the function failed to unserialize the color

Definition at line 157 of file ManagedColor.cpp.

158{
159 QDomDocument doc;
160 doc.setContent(xml);
161 QDomElement e = doc.documentElement();
162 QDomElement c = e.firstChildElement("Color");
163 KoColor kc;
164 if (!c.isNull()) {
165 QString colorDepthId = c.attribute("bitdepth", Integer8BitsColorDepthID.id());
166 d->color = KoColor::fromXML(c, colorDepthId);
167 }
168
169}
const KoID Integer8BitsColorDepthID("U8", ki18n("8-bit integer/channel"))
static KoColor fromXML(const QDomElement &elt, const QString &channelDepthId)
Definition KoColor.cpp:350
QString id() const
Definition KoID.cpp:63

References d, KoColor::fromXML(), KoID::id(), and Integer8BitsColorDepthID.

◆ operator==()

bool ManagedColor::operator== ( const ManagedColor & other) const

Definition at line 55 of file ManagedColor.cpp.

56{
57 return d->color == other.d->color;
58}

References d.

◆ setColorProfile()

bool ManagedColor::setColorProfile ( const QString & colorProfile)

setColorProfile set the color profile of the image to the given profile. The profile has to be registered with krita and be compatible with the current color model and depth; the image data is not converted.

Parameters
colorProfile
Returns
false if the colorProfile name does not correspond to to a registered profile or if assigning the profile failed.

Definition at line 107 of file ManagedColor.cpp.

108{
110 if (!profile) return false;
111 d->color.setProfile(profile);
112 return true;
113}
const KoColorProfile * profileByName(const QString &name) const

References colorProfile(), d, KoColorSpaceRegistry::instance(), and KoColorSpaceRegistry::profileByName().

◆ setColorSpace()

bool ManagedColor::setColorSpace ( const QString & colorModel,
const QString & colorDepth,
const QString & colorProfile )

setColorSpace convert the nodes and the image to the given colorspace. The conversion is done with Perceptual as intent, High Quality and No LCMS Optimizations as flags and no blackpoint compensation.

Parameters
colorModelA string describing the color model of the image:
  • A: Alpha mask
  • RGBA: RGB with alpha channel (The actual order of channels is most often BGR!)
  • XYZA: XYZ with alpha channel
  • LABA: LAB with alpha channel
  • CMYKA: CMYK with alpha channel
  • GRAYA: Gray with alpha channel
  • YCbCrA: YCbCr with alpha channel
colorDepthA string describing the color depth of the image:
  • U8: unsigned 8 bits integer, the most common type
  • U16: unsigned 16 bits integer
  • F16: half, 16 bits floating point. Only available if Krita was built with OpenEXR
  • F32: 32 bits floating point
colorProfilea valid color profile for this color model and color depth combination.
Returns
false the combination of these arguments does not correspond to a colorspace.

Definition at line 115 of file ManagedColor.cpp.

116{
118 if (!colorSpace) return false;
119 d->color.convertTo(colorSpace);
120 return true;
121}

References colorDepth(), colorModel(), colorProfile(), KoColorSpaceRegistry::colorSpace(), d, and KoColorSpaceRegistry::instance().

◆ setComponents()

void ManagedColor::setComponents ( const QVector< float > & values)

setComponents Set the channel/components with normalized values. For integer colorspace, this obviously means the limit is between 0.0-1.0, but for floating point colorspaces, 2.4 or 103.5 are still meaningful (if bright) values.

Parameters
valuesthe QVector containing the new channel/component values. These should be normalized.

Definition at line 142 of file ManagedColor.cpp.

143{
144 d->color.colorSpace()->fromNormalisedChannelsValue(d->color.data(), values);
145}

References d.

◆ toQString()

QString ManagedColor::toQString ( )

toQString create a user-visible string of the channel names and the channel values

Returns
a string that can be used to display the values of this color to the user.

Definition at line 171 of file ManagedColor.cpp.

172{
173 return KoColor::toQString(d->color);
174}
static QString toQString(const KoColor &color)
toQString create a user-visible string of the channel names and the channel values
Definition KoColor.cpp:655

References d, and KoColor::toQString().

◆ toXML()

QString ManagedColor::toXML ( ) const

Serialize this color following Create's swatch color specification available at https://web.archive.org/web/20110826002520/http://create.freedesktop.org/wiki/Swatches_-_color_file_format/Draft

Definition at line 147 of file ManagedColor.cpp.

148{
149 QDomDocument doc;
150 QDomElement root = doc.createElement("Color");
151 root.setAttribute("bitdepth", colorDepth());
152 doc.appendChild(root);
153 d->color.toXML(doc, root);
154 return doc.toString();
155}

References colorDepth(), and d.

Friends And Related Symbol Documentation

◆ ColorizeMask

friend class ColorizeMask
friend

Definition at line 199 of file ManagedColor.h.

◆ PaletteView

friend class PaletteView
friend

Definition at line 197 of file ManagedColor.h.

◆ Swatch

friend class Swatch
friend

Definition at line 198 of file ManagedColor.h.

◆ View

friend class View
friend

Assistance tools: guides, reference, etc.

Definition at line 196 of file ManagedColor.h.

Member Data Documentation

◆ d

const QScopedPointer<Private> ManagedColor::d
private

Definition at line 204 of file ManagedColor.h.


The documentation for this class was generated from the following files: