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
19#include <KoColorConversions.h>
22#include <KoColorProfileQuery.h>
23#include <KoIntegerMaths.h>
24#include <kis_dom_utils.h>
25
26#define downscale(quantum) (quantum) //((unsigned char) ((quantum)/257UL))
27#define upscale(value) (value) // ((quint8) (257UL*(value)))
28
30 LcmsColorSpace<KoBgrU8Traits>(colorSpaceId(), name, TYPE_BGRA_8, cmsSigRgbData, p)
31{
32 addChannel(new KoChannelInfo(i18n("Blue"), 0, 2, KoChannelInfo::COLOR, KoChannelInfo::UINT8, 1, QColor(0, 0, 255)));
33 addChannel(new KoChannelInfo(i18n("Green"), 1, 1, KoChannelInfo::COLOR, KoChannelInfo::UINT8, 1, QColor(0, 255, 0)));
34 addChannel(new KoChannelInfo(i18n("Red"), 2, 0, KoChannelInfo::COLOR, KoChannelInfo::UINT8, 1, QColor(255, 0, 0)));
36
37 init();
38
39 addStandardCompositeOps<KoBgrU8Traits>(this);
40 addStandardDitherOps<KoBgrU8Traits>(this);
41
45}
46
48{
49 return new RgbU8ColorSpace(name(), profile()->clone());
50}
51
52void RgbU8ColorSpace::colorToXML(const quint8 *pixel, QDomDocument &doc, QDomElement &colorElt) const
53{
54 const KoBgrU8Traits::Pixel *p = reinterpret_cast<const KoBgrU8Traits::Pixel *>(pixel);
55 QDomElement labElt = doc.createElement("RGB");
59 labElt.setAttribute("space", profile()->name());
60 colorElt.appendChild(labElt);
61}
62
63void RgbU8ColorSpace::colorFromXML(quint8 *pixel, const QDomElement &elt) const
64{
65 KoBgrU8Traits::Pixel *p = reinterpret_cast<KoBgrU8Traits::Pixel *>(pixel);
70}
71
72quint8 RgbU8ColorSpace::intensity8(const quint8 *src) const
73{
74 const KoBgrU8Traits::Pixel *p = reinterpret_cast<const KoBgrU8Traits::Pixel *>(src);
75 // Integer version of:
76 // static_cast<quint8>(qRound(p->red * 0.30 + p->green * 0.59 + p->blue * 0.11))
77 // The "+ 50" is used for rounding
78 return static_cast<quint8>((p->red * 30 + p->green * 59 + p->blue * 11 + 50) / 100);
79}
80
81qreal RgbU8ColorSpace::intensityF(const quint8 *src) const
82{
83 const KoBgrU8Traits::Pixel *p = reinterpret_cast<const KoBgrU8Traits::Pixel *>(src);
84 // Integer version of:
85 // (p->red * 0.30 + p->green * 0.59 + p->blue * 0.11) / 255.0
86 return static_cast<qreal>(p->red * 30 + p->green * 59 + p->blue * 11) / (100.0 * 255.0);
87}
88
89void RgbU8ColorSpace::toHSY(const QVector<double> &channelValues, qreal *hue, qreal *sat, qreal *luma) const
90{
91 RGBToHSY(channelValues[0],channelValues[1],channelValues[2], hue, sat, luma, lumaCoefficients()[0], lumaCoefficients()[1], lumaCoefficients()[2]);
92}
93
94QVector <double> RgbU8ColorSpace::fromHSY(qreal *hue, qreal *sat, qreal *luma) const
95{
96 QVector <double> channelValues(4);
97 HSYToRGB(*hue, *sat, *luma, &channelValues[0],&channelValues[1],&channelValues[2], lumaCoefficients()[0], lumaCoefficients()[1], lumaCoefficients()[2]);
98 channelValues[3]=1.0;
99 return channelValues;
100}
101
102void RgbU8ColorSpace::toYUV(const QVector<double> &channelValues, qreal *y, qreal *u, qreal *v) const
103{
104
105
106 RGBToYUV(channelValues[0],channelValues[1],channelValues[2], y, u, v, lumaCoefficients()[0], lumaCoefficients()[1], lumaCoefficients()[2]);
107}
108
109QVector <double> RgbU8ColorSpace::fromYUV(qreal *y, qreal *u, qreal *v) const
110{
111 QVector <double> channelValues(4);
112
113 YUVToRGB(*y, *u, *v, &channelValues[0],&channelValues[1],&channelValues[2], lumaCoefficients()[0], lumaCoefficients()[1], lumaCoefficients()[2]);
114 channelValues[3]=1.0;
115 return channelValues;
116}
117
118void RgbU8ColorSpace::fillGrayBrushWithColorAndLightnessOverlay(quint8* dst, const QRgb* brush, quint8* brushColor, qint32 nPixels) const
119{
120 fillGrayBrushWithColorPreserveLightnessRGB<KoBgrU8Traits>(dst, brush, brushColor, 1.0, nPixels);
121}
122
123void RgbU8ColorSpace::fillGrayBrushWithColorAndLightnessWithStrength(quint8* dst, const QRgb* brush, quint8* brushColor, qreal strength, qint32 nPixels) const
124{
125 fillGrayBrushWithColorPreserveLightnessRGB<KoBgrU8Traits>(dst, brush, brushColor, strength, nPixels);
126}
127
128void RgbU8ColorSpace::modulateLightnessByGrayBrush(quint8 *dst, const QRgb *brush, qreal strength, qint32 nPixels) const
129{
130 modulateLightnessByGrayBrushRGB<KoBgrU8Traits>(dst, brush, strength, nPixels);
131}
132
134{
136 && profile->getColorPrimaries() != PRIMARIES_UNSPECIFIED) {
137
140 QString linear = registry->profileFor(query)->name();
141
143 return factory.colorConversionLinks();
144 } else if (profile->name() == "High Dynamic Range UHDTV Wide Color Gamut Display (Rec. 2020) - SMPTE ST 2084 PQ EOTF") {
147 return factory.colorConversionLinks();
148 }
150}
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)
@ PRIMARIES_UNSPECIFIED
@ TRC_ITU_R_BT_2100_0_PQ
@ 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
QList< KoColorConversionTransformationFactory * > colorConversionLinks() const override
QList< KoColorConversionTransformationFactory * > colorConversionLinksFromProfile(const KoColorProfile *profile) const override
colorConversionLinksFromProfile Sometimes, we need to generate special color conversion links based o...
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)
The KoColorProfileQuery struct.
virtual ColorPrimaries getColorPrimaries() const
getColorPrimaries
virtual TransferCharacteristics getTransferCharacteristics() const
getTransferCharacteristics This function should be subclassed at some point so we can get the value f...
static KoColorSpaceRegistry * instance()
const KoColorProfile * profileFor(const KoColorProfileQuery &query, const bool generate=true) const
profileFor tries to find the profile that matches these characteristics, if no such profile is found,...
const KoColorProfile * p2020G10Profile() const