Krita Source Code Documentation
Loading...
Searching...
No Matches
XyzF32ColorSpace.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2007 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 "XyzF32ColorSpace.h"
9#include <QDomElement>
10
11#include <QDebug>
12#include <klocalizedstring.h>
13
16#include <KoColorConversions.h>
17#include <kis_dom_utils.h>
18
20 LcmsColorSpace<KoXyzF32Traits>(colorSpaceId(), name, TYPE_XYZA_FLT, cmsSigXYZData, p)
21{
22 const IccColorProfile *icc_p = dynamic_cast<const IccColorProfile *>(p);
23 Q_ASSERT(icc_p);
25 Q_ASSERT(uiRanges.size() == 3);
26
27 addChannel(new KoChannelInfo(i18n("X"), KoXyzF32Traits::x_pos * sizeof(float), KoXyzF32Traits::x_pos, KoChannelInfo::COLOR, KoChannelInfo::FLOAT32, sizeof(float), Qt::cyan, uiRanges[0]));
28 addChannel(new KoChannelInfo(i18n("Y"), KoXyzF32Traits::y_pos * sizeof(float), KoXyzF32Traits::y_pos, KoChannelInfo::COLOR, KoChannelInfo::FLOAT32, sizeof(float), Qt::magenta, uiRanges[1]));
29 addChannel(new KoChannelInfo(i18n("Z"), KoXyzF32Traits::z_pos * sizeof(float), KoXyzF32Traits::z_pos, KoChannelInfo::COLOR, KoChannelInfo::FLOAT32, sizeof(float), Qt::yellow, uiRanges[2]));
31 init();
32
33 addStandardCompositeOps<KoXyzF32Traits>(this);
34 addStandardDitherOps<KoXyzF32Traits>(this);
35}
36
38{
39 if (independence == TO_RGBA16) {
40 return true;
41 } else {
42 return false;
43 }
44}
45
47{
48 return new XyzF32ColorSpace(name(), profile()->clone());
49}
50
51void XyzF32ColorSpace::colorToXML(const quint8 *pixel, QDomDocument &doc, QDomElement &colorElt) const
52{
53 const KoXyzF32Traits::Pixel *p = reinterpret_cast<const KoXyzF32Traits::Pixel *>(pixel);
54 QDomElement labElt = doc.createElement("XYZ");
58 labElt.setAttribute("space", profile()->name());
59 colorElt.appendChild(labElt);
60}
61
62void XyzF32ColorSpace::colorFromXML(quint8 *pixel, const QDomElement &elt) const
63{
64 KoXyzF32Traits::Pixel *p = reinterpret_cast<KoXyzF32Traits::Pixel *>(pixel);
68 p->alpha = 1.0;
69}
70
71void XyzF32ColorSpace::toHSY(const QVector<double> &channelValues, qreal *hue, qreal *sat, qreal *luma) const
72{
73 qreal xyx, xyy, xyY = 0.0;
74 XYZToxyY(channelValues[0],channelValues[1],channelValues[2], &xyx, &xyy, &xyY);
75 LabToLCH(xyY,xyx,xyY, hue, sat, luma);
76}
77
78QVector <double> XyzF32ColorSpace::fromHSY(qreal *hue, qreal *sat, qreal *luma) const
79{
80 QVector <double> channelValues(4);
81 qreal xyx, xyy, xyY = 0.0;
82 LCHToLab(*luma, *sat, *hue, &xyY,&xyx,&xyy);
83 xyYToXYZ(xyx, xyy, xyY, &channelValues[0],&channelValues[1],&channelValues[2]);
84 channelValues[3]=1.0;
85 return channelValues;
86}
87
88void XyzF32ColorSpace::toYUV(const QVector<double> &channelValues, qreal *y, qreal *u, qreal *v) const
89{
90 XYZToxyY(channelValues[0],channelValues[1],channelValues[2], u, v, y);
91}
92
93QVector <double> XyzF32ColorSpace::fromYUV(qreal *y, qreal *u, qreal *v) const
94{
95 QVector <double> channelValues(4);
96 xyYToXYZ(*u, *v, *y, &channelValues[0],&channelValues[1],&channelValues[2]);
97 channelValues[3]=1.0;
98 return channelValues;
99}
const Params2D p
qreal v
qreal u
void LabToLCH(const qreal l, const qreal a, const qreal b, qreal *L, qreal *C, qreal *H)
void XYZToxyY(const qreal X, const qreal Y, const qreal Z, qreal *x, qreal *y, qreal *yY)
void LCHToLab(const qreal L, const qreal C, const qreal H, qreal *l, qreal *a, qreal *b)
void xyYToXYZ(const qreal x, const qreal y, const qreal yY, qreal *X, qreal *Y, qreal *Z)
ColorSpaceIndependence
@ TO_RGBA16
#define TYPE_XYZA_FLT
const QVector< KoChannelInfo::DoubleRange > & getFloatUIMinMax(void) const
@ ALPHA
The channel represents the opacity of a pixel.
@ COLOR
The channel represents a color.
@ FLOAT32
use this for a float 32bits channel
static _Tdst scaleToA(_T a)
virtual void addChannel(KoChannelInfo *ci)
const KoColorProfile * profile() const override
void colorFromXML(quint8 *pixel, const QDomElement &elt) const override
void colorToXML(const quint8 *pixel, QDomDocument &doc, QDomElement &colorElt) const override
void toYUV(const QVector< double > &channelValues, qreal *y, qreal *u, qreal *v) const override
XyzF32ColorSpace(const QString &name, KoColorProfile *p)
bool willDegrade(ColorSpaceIndependence independence) const override
void toHSY(const QVector< double > &channelValues, qreal *hue, qreal *sat, qreal *luma) const override
QVector< double > fromHSY(qreal *hue, qreal *sat, qreal *luma) const override
virtual KoColorSpace * clone() const
QVector< double > fromYUV(qreal *y, qreal *u, qreal *v) const override
double toDouble(const QString &str, bool *ok=nullptr)
QString toString(const QString &value)
static const qint32 alpha_pos
static const qint32 x_pos
static const qint32 z_pos
static const qint32 y_pos