Krita Source Code Documentation
Loading...
Searching...
No Matches
RgbU16ColorSpace.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006 Cyrille Berger <cberger@cberger.net>
3 * SPDX-FileCopyrightText: 2021 L. E. Segovia <amy@amyspark.me>
4 *
5 * SPDX-License-Identifier: LGPL-2.1-or-later
6 */
7
8#include "RgbU16ColorSpace.h"
9
10#include <QDomElement>
11
12#include <klocalizedstring.h>
13
18#include "kis_dom_utils.h"
19#include <KoColorConversions.h>
21#include <KoColorProfileQuery.h>
22
24 LcmsColorSpace<KoBgrU16Traits>(colorSpaceId(), name, TYPE_BGRA_16, cmsSigRgbData, p)
25{
26 addChannel(new KoChannelInfo(i18n("Blue"), 0 * sizeof(quint16), 2, KoChannelInfo::COLOR, KoChannelInfo::UINT16, 2, QColor(0, 0, 255)));
27 addChannel(new KoChannelInfo(i18n("Green"), 1 * sizeof(quint16), 1, KoChannelInfo::COLOR, KoChannelInfo::UINT16, 2, QColor(0, 255, 0)));
28 addChannel(new KoChannelInfo(i18n("Red"), 2 * sizeof(quint16), 0, KoChannelInfo::COLOR, KoChannelInfo::UINT16, 2, QColor(255, 0, 0)));
29 addChannel(new KoChannelInfo(i18n("Alpha"), 3 * sizeof(quint16), 3, KoChannelInfo::ALPHA, KoChannelInfo::UINT16, 2));
30 init();
31
32 addStandardCompositeOps<KoBgrU16Traits>(this);
33 addStandardDitherOps<KoBgrU16Traits>(this);
34
38}
39
41{
42 if (independence == TO_RGBA8) {
43 return true;
44 } else {
45 return false;
46 }
47}
48
50{
51 return new RgbU16ColorSpace(name(), profile()->clone());
52}
53
54void RgbU16ColorSpace::colorToXML(const quint8 *pixel, QDomDocument &doc, QDomElement &colorElt) const
55{
56 const KoBgrU16Traits::Pixel *p = reinterpret_cast<const KoBgrU16Traits::Pixel *>(pixel);
57 QDomElement labElt = doc.createElement("RGB");
61 labElt.setAttribute("space", profile()->name());
62 colorElt.appendChild(labElt);
63}
64
65void RgbU16ColorSpace::colorFromXML(quint8 *pixel, const QDomElement &elt) const
66{
67 KoBgrU16Traits::Pixel *p = reinterpret_cast<KoBgrU16Traits::Pixel *>(pixel);
72}
73
74void RgbU16ColorSpace::toHSY(const QVector<double> &channelValues, qreal *hue, qreal *sat, qreal *luma) const
75{
76 RGBToHSY(channelValues[0],channelValues[1],channelValues[2], hue, sat, luma, lumaCoefficients()[0], lumaCoefficients()[1], lumaCoefficients()[2]);
77}
78
79QVector <double> RgbU16ColorSpace::fromHSY(qreal *hue, qreal *sat, qreal *luma) const
80{
81 QVector <double> channelValues(4);
82 HSYToRGB(*hue, *sat, *luma, &channelValues[0],&channelValues[1],&channelValues[2], lumaCoefficients()[0], lumaCoefficients()[1], lumaCoefficients()[2]);
83 channelValues[3]=1.0;
84 return channelValues;
85}
86
87void RgbU16ColorSpace::toYUV(const QVector<double> &channelValues, qreal *y, qreal *u, qreal *v) const
88{
89
90
91 RGBToYUV(channelValues[0],channelValues[1],channelValues[2], y, u, v, lumaCoefficients()[0], lumaCoefficients()[1], lumaCoefficients()[2]);
92}
93
94QVector <double> RgbU16ColorSpace::fromYUV(qreal *y, qreal *u, qreal *v) const
95{
96 QVector <double> channelValues(4);
97
98 YUVToRGB(*y, *u, *v, &channelValues[0],&channelValues[1],&channelValues[2], lumaCoefficients()[0], lumaCoefficients()[1], lumaCoefficients()[2]);
99 channelValues[3]=1.0;
100 return channelValues;
101}
102
103void RgbU16ColorSpace::fillGrayBrushWithColorAndLightnessOverlay(quint8* dst, const QRgb* brush, quint8* brushColor, qint32 nPixels) const
104{
105 fillGrayBrushWithColorPreserveLightnessRGB<KoBgrU16Traits>(dst, brush, brushColor, 1.0, nPixels);
106}
107
108void RgbU16ColorSpace::fillGrayBrushWithColorAndLightnessWithStrength(quint8* dst, const QRgb* brush, quint8* brushColor, qreal strength, qint32 nPixels) const
109{
110 fillGrayBrushWithColorPreserveLightnessRGB<KoBgrU16Traits>(dst, brush, brushColor, strength, nPixels);
111}
112
113void RgbU16ColorSpace::modulateLightnessByGrayBrush(quint8 *dst, const QRgb *brush, qreal strength, qint32 nPixels) const
114{
115 modulateLightnessByGrayBrushRGB<KoBgrU16Traits>(dst, brush, strength, nPixels);
116}
117
119{
121 && profile->getColorPrimaries() != PRIMARIES_UNSPECIFIED) {
122
125 QString linear = registry->profileFor(query)->name();
126
128 return factory.colorConversionLinks();
129 } else if (profile->name() == "High Dynamic Range UHDTV Wide Color Gamut Display (Rec. 2020) - SMPTE ST 2084 PQ EOTF") {
132 return factory.colorConversionLinks();
133 }
135}
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
ColorSpaceIndependence
@ TO_RGBA8
@ ALPHA
The channel represents the opacity of a pixel.
@ COLOR
The channel represents a color.
@ UINT16
use this for an integer 16bits 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 fillGrayBrushWithColorAndLightnessOverlay(quint8 *dst, const QRgb *brush, quint8 *brushColor, qint32 nPixels) const override
RgbU16ColorSpace(const QString &name, KoColorProfile *p)
void modulateLightnessByGrayBrush(quint8 *dst, const QRgb *brush, qreal strength, qint32 nPixels) const override
void colorToXML(const quint8 *pixel, QDomDocument &doc, QDomElement &colorElt) const override
bool willDegrade(ColorSpaceIndependence independence) const override
void fillGrayBrushWithColorAndLightnessWithStrength(quint8 *dst, const QRgb *brush, quint8 *brushColor, qreal strength, qint32 nPixels) const override
QVector< double > fromHSY(qreal *hue, qreal *sat, qreal *luma) const override
void toHSY(const QVector< double > &channelValues, qreal *hue, qreal *sat, qreal *luma) const override
virtual KoColorSpace * clone() const
void toYUV(const QVector< double > &channelValues, qreal *y, qreal *u, qreal *v) const override
void colorFromXML(quint8 *pixel, const QDomElement &elt) const override
QVector< double > fromYUV(qreal *y, qreal *u, qreal *v) 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