Krita Source Code Documentation
Loading...
Searching...
No Matches
RgbU8ColorSpace.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2002 Patrick Julien <freak@codepimps.org>
3 * SPDX-FileCopyrightText: 2004 Boudewijn Rempt <boud@valdyas.org>
4 * SPDX-FileCopyrightText: 2021 L. E. Segovia <amy@amyspark.me>
5 *
6 * SPDX-License-Identifier: LGPL-2.1-or-later
7 */
8#include "RgbU8ColorSpace.h"
9
10#include <QColor>
11#include <QDomElement>
12
13#include <klocalizedstring.h>
14
18#include <KoColorConversions.h>
21#include <KoIntegerMaths.h>
22#include <kis_dom_utils.h>
23
24#define downscale(quantum) (quantum) //((unsigned char) ((quantum)/257UL))
25#define upscale(value) (value) // ((quint8) (257UL*(value)))
26
28 LcmsColorSpace<KoBgrU8Traits>(colorSpaceId(), name, TYPE_BGRA_8, cmsSigRgbData, p)
29{
30 addChannel(new KoChannelInfo(i18n("Blue"), 0, 2, KoChannelInfo::COLOR, KoChannelInfo::UINT8, 1, QColor(0, 0, 255)));
31 addChannel(new KoChannelInfo(i18n("Green"), 1, 1, KoChannelInfo::COLOR, KoChannelInfo::UINT8, 1, QColor(0, 255, 0)));
32 addChannel(new KoChannelInfo(i18n("Red"), 2, 0, KoChannelInfo::COLOR, KoChannelInfo::UINT8, 1, QColor(255, 0, 0)));
34
35 init();
36
37 addStandardCompositeOps<KoBgrU8Traits>(this);
38 addStandardDitherOps<KoBgrU8Traits>(this);
39
43}
44
46{
47 return new RgbU8ColorSpace(name(), profile()->clone());
48}
49
50void RgbU8ColorSpace::colorToXML(const quint8 *pixel, QDomDocument &doc, QDomElement &colorElt) const
51{
52 const KoBgrU8Traits::Pixel *p = reinterpret_cast<const KoBgrU8Traits::Pixel *>(pixel);
53 QDomElement labElt = doc.createElement("RGB");
57 labElt.setAttribute("space", profile()->name());
58 colorElt.appendChild(labElt);
59}
60
61void RgbU8ColorSpace::colorFromXML(quint8 *pixel, const QDomElement &elt) const
62{
63 KoBgrU8Traits::Pixel *p = reinterpret_cast<KoBgrU8Traits::Pixel *>(pixel);
68}
69
70quint8 RgbU8ColorSpace::intensity8(const quint8 *src) const
71{
72 const KoBgrU8Traits::Pixel *p = reinterpret_cast<const KoBgrU8Traits::Pixel *>(src);
73 // Integer version of:
74 // static_cast<quint8>(qRound(p->red * 0.30 + p->green * 0.59 + p->blue * 0.11))
75 // The "+ 50" is used for rounding
76 return static_cast<quint8>((p->red * 30 + p->green * 59 + p->blue * 11 + 50) / 100);
77}
78
79qreal RgbU8ColorSpace::intensityF(const quint8 *src) const
80{
81 const KoBgrU8Traits::Pixel *p = reinterpret_cast<const KoBgrU8Traits::Pixel *>(src);
82 // Integer version of:
83 // (p->red * 0.30 + p->green * 0.59 + p->blue * 0.11) / 255.0
84 return static_cast<qreal>(p->red * 30 + p->green * 59 + p->blue * 11) / (100.0 * 255.0);
85}
86
87void RgbU8ColorSpace::toHSY(const QVector<double> &channelValues, qreal *hue, qreal *sat, qreal *luma) const
88{
89 RGBToHSY(channelValues[0],channelValues[1],channelValues[2], hue, sat, luma, lumaCoefficients()[0], lumaCoefficients()[1], lumaCoefficients()[2]);
90}
91
92QVector <double> RgbU8ColorSpace::fromHSY(qreal *hue, qreal *sat, qreal *luma) const
93{
94 QVector <double> channelValues(4);
95 HSYToRGB(*hue, *sat, *luma, &channelValues[0],&channelValues[1],&channelValues[2], lumaCoefficients()[0], lumaCoefficients()[1], lumaCoefficients()[2]);
96 channelValues[3]=1.0;
97 return channelValues;
98}
99
100void RgbU8ColorSpace::toYUV(const QVector<double> &channelValues, qreal *y, qreal *u, qreal *v) const
101{
102
103
104 RGBToYUV(channelValues[0],channelValues[1],channelValues[2], y, u, v, lumaCoefficients()[0], lumaCoefficients()[1], lumaCoefficients()[2]);
105}
106
107QVector <double> RgbU8ColorSpace::fromYUV(qreal *y, qreal *u, qreal *v) const
108{
109 QVector <double> channelValues(4);
110
111 YUVToRGB(*y, *u, *v, &channelValues[0],&channelValues[1],&channelValues[2], lumaCoefficients()[0], lumaCoefficients()[1], lumaCoefficients()[2]);
112 channelValues[3]=1.0;
113 return channelValues;
114}
115
116void RgbU8ColorSpace::fillGrayBrushWithColorAndLightnessOverlay(quint8* dst, const QRgb* brush, quint8* brushColor, qint32 nPixels) const
117{
118 fillGrayBrushWithColorPreserveLightnessRGB<KoBgrU8Traits>(dst, brush, brushColor, 1.0, nPixels);
119}
120
121void RgbU8ColorSpace::fillGrayBrushWithColorAndLightnessWithStrength(quint8* dst, const QRgb* brush, quint8* brushColor, qreal strength, qint32 nPixels) const
122{
123 fillGrayBrushWithColorPreserveLightnessRGB<KoBgrU8Traits>(dst, brush, brushColor, strength, nPixels);
124}
125
126void RgbU8ColorSpace::modulateLightnessByGrayBrush(quint8 *dst, const QRgb *brush, qreal strength, qint32 nPixels) const
127{
128 modulateLightnessByGrayBrushRGB<KoBgrU8Traits>(dst, brush, strength, nPixels);
129}
const Params2D p
qreal v
qreal u
void HSYToRGB(const qreal h, const qreal s, const qreal y, qreal *red, qreal *green, qreal *blue, qreal R, qreal G, qreal B)
void RGBToYUV(const qreal r, const qreal g, const qreal b, qreal *y, qreal *u, qreal *v, qreal R, qreal G, qreal B)
void RGBToHSY(const qreal r, const qreal g, const qreal b, qreal *h, qreal *s, qreal *y, qreal R, qreal G, qreal B)
void YUVToRGB(const qreal y, const qreal u, const qreal v, qreal *r, qreal *g, qreal *b, qreal R, qreal G, qreal B)
@ ALPHA
The channel represents the opacity of a pixel.
@ COLOR
The channel represents a color.
@ UINT8
use this for an unsigned integer 8bits channel
static _Tdst scaleToA(_T a)
virtual void addCompositeOp(const KoCompositeOp *op)
QVector< qreal > lumaCoefficients
virtual void addChannel(KoChannelInfo *ci)
const KoColorProfile * profile() const override
void colorFromXML(quint8 *pixel, const QDomElement &elt) const override
QVector< double > fromYUV(qreal *y, qreal *u, qreal *v) const override
virtual KoColorSpace * clone() const
quint8 intensity8(const quint8 *src) const override
RgbU8ColorSpace(const QString &name, KoColorProfile *p)
void fillGrayBrushWithColorAndLightnessOverlay(quint8 *dst, const QRgb *brush, quint8 *brushColor, qint32 nPixels) const override
void toHSY(const QVector< double > &channelValues, qreal *hue, qreal *sat, qreal *luma) const override
void toYUV(const QVector< double > &channelValues, qreal *y, qreal *u, qreal *v) const override
qreal intensityF(const quint8 *src) const override
QVector< double > fromHSY(qreal *hue, qreal *sat, qreal *luma) const override
void colorToXML(const quint8 *pixel, QDomDocument &doc, QDomElement &colorElt) const override
void fillGrayBrushWithColorAndLightnessWithStrength(quint8 *dst, const QRgb *brush, quint8 *brushColor, qreal strength, qint32 nPixels) const override
void modulateLightnessByGrayBrush(quint8 *dst, const QRgb *brush, qreal strength, qint32 nPixels) const override
unsigned int QRgb
double toDouble(const QString &str, bool *ok=nullptr)
QString toString(const QString &value)