Krita Source Code Documentation
Loading...
Searching...
No Matches
RgbF16ColorSpace.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 "RgbF16ColorSpace.h"
9
10#include <QDomElement>
11
12#include <klocalizedstring.h>
13#include <KoColorConversions.h>
16
21#include <kis_dom_utils.h>
23#include <KoColorProfileQuery.h>
24
26 LcmsColorSpace<KoRgbF16Traits>(colorSpaceId(), name, TYPE_RGBA_HALF_FLT, cmsSigRgbData, p)
27{
28 addChannel(new KoChannelInfo(i18n("Red"), 0 * sizeof(half), 0, KoChannelInfo::COLOR, KoChannelInfo::FLOAT16, 2, QColor(255, 0, 0)));
29 addChannel(new KoChannelInfo(i18n("Green"), 1 * sizeof(half), 1, KoChannelInfo::COLOR, KoChannelInfo::FLOAT16, 2, QColor(0, 255, 0)));
30 addChannel(new KoChannelInfo(i18n("Blue"), 2 * sizeof(half), 2, KoChannelInfo::COLOR, KoChannelInfo::FLOAT16, 2, QColor(0, 0, 255)));
31 addChannel(new KoChannelInfo(i18n("Alpha"), 3 * sizeof(half), 3, KoChannelInfo::ALPHA, KoChannelInfo::FLOAT16, 2));
32
33 init();
34
35 addStandardCompositeOps<KoRgbF16Traits>(this);
36 addStandardDitherOps<KoRgbF16Traits>(this);
37
41}
42
44{
45 if (independence == TO_RGBA16) {
46 return true;
47 } else {
48 return false;
49 }
50}
51
53{
54 return new RgbF16ColorSpace(name(), profile()->clone());
55}
56
57void RgbF16ColorSpace::colorToXML(const quint8 *pixel, QDomDocument &doc, QDomElement &colorElt) const
58{
59 const KoRgbF16Traits::Pixel *p = reinterpret_cast<const KoRgbF16Traits::Pixel *>(pixel);
60 QDomElement labElt = doc.createElement("RGB");
64 labElt.setAttribute("space", profile()->name());
65 colorElt.appendChild(labElt);
66}
67
68void RgbF16ColorSpace::colorFromXML(quint8 *pixel, const QDomElement &elt) const
69{
70 KoRgbF16Traits::Pixel *p = reinterpret_cast<KoRgbF16Traits::Pixel *>(pixel);
74 p->alpha = 1.0;
75}
76
77void RgbF16ColorSpace::toHSY(const QVector<double> &channelValues, qreal *hue, qreal *sat, qreal *luma) const
78{
79 RGBToHSY(channelValues[0],channelValues[1],channelValues[2], hue, sat, luma, lumaCoefficients()[0], lumaCoefficients()[1], lumaCoefficients()[2]);
80}
81
82QVector <double> RgbF16ColorSpace::fromHSY(qreal *hue, qreal *sat, qreal *luma) const
83{
84 QVector <double> channelValues(4);
85 HSYToRGB(*hue, *sat, *luma, &channelValues[0],&channelValues[1],&channelValues[2], lumaCoefficients()[0], lumaCoefficients()[1], lumaCoefficients()[2]);
86 channelValues[3]=1.0;
87 return channelValues;
88}
89
90void RgbF16ColorSpace::toYUV(const QVector<double> &channelValues, qreal *y, qreal *u, qreal *v) const
91{
92
93
94 RGBToYUV(channelValues[0],channelValues[1],channelValues[2], y, u, v, lumaCoefficients()[0], lumaCoefficients()[1], lumaCoefficients()[2]);
95}
96
97QVector <double> RgbF16ColorSpace::fromYUV(qreal *y, qreal *u, qreal *v) const
98{
99 QVector <double> channelValues(4);
100
101 YUVToRGB(*y, *u, *v, &channelValues[0],&channelValues[1],&channelValues[2], lumaCoefficients()[0], lumaCoefficients()[1], lumaCoefficients()[2]);
102 channelValues[3]=1.0;
103 return channelValues;
104}
105
106void RgbF16ColorSpace::fillGrayBrushWithColorAndLightnessOverlay(quint8 *dst, const QRgb *brush, quint8 *brushColor, qint32 nPixels) const
107{
108 fillGrayBrushWithColorPreserveLightnessRGB<KoRgbF16Traits>(dst, brush, brushColor, 1.0, nPixels);
109}
110
111void RgbF16ColorSpace::fillGrayBrushWithColorAndLightnessWithStrength(quint8* dst, const QRgb* brush, quint8* brushColor, qreal strength, qint32 nPixels) const
112{
113 fillGrayBrushWithColorPreserveLightnessRGB<KoRgbF16Traits>(dst, brush, brushColor, strength, nPixels);
114}
115
116void RgbF16ColorSpace::modulateLightnessByGrayBrush(quint8 *dst, const QRgb *brush, qreal strength, qint32 nPixels) const
117{
118 modulateLightnessByGrayBrushRGB<KoRgbF16Traits>(dst, brush, strength, nPixels);
119}
120
122{
124 && profile->getColorPrimaries() != PRIMARIES_UNSPECIFIED) {
125
128 QString linear = registry->profileFor(query)->name();
129
131 return factory.colorConversionLinks();
132 } else if (profile->name() == "High Dynamic Range UHDTV Wide Color Gamut Display (Rec. 2020) - SMPTE ST 2084 PQ EOTF") {
135 return factory.colorConversionLinks();
136 }
138}
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_RGBA16
@ ALPHA
The channel represents the opacity of a pixel.
@ COLOR
The channel represents a color.
@ FLOAT16
use this for a float 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 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
void toYUV(const QVector< double > &channelValues, qreal *y, qreal *u, qreal *v) const override
void colorToXML(const quint8 *pixel, QDomDocument &doc, QDomElement &colorElt) const override
void toHSY(const QVector< double > &channelValues, qreal *hue, qreal *sat, qreal *luma) const override
void colorFromXML(quint8 *pixel, const QDomElement &elt) const override
bool willDegrade(ColorSpaceIndependence independence) const override
void fillGrayBrushWithColorAndLightnessOverlay(quint8 *dst, const QRgb *brush, quint8 *brushColor, qint32 nPixels) const override
virtual KoColorSpace * clone() const
RgbF16ColorSpace(const QString &name, KoColorProfile *p)
QVector< double > fromHSY(qreal *hue, qreal *sat, qreal *luma) 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