Krita Source Code Documentation
Loading...
Searching...
No Matches
XyzU8ColorSpace.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 "XyzU8ColorSpace.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<KoXyzU8Traits>(colorSpaceId(), name, TYPE_XYZA_8, cmsSigXYZData, p)
21{
22 addChannel(new KoChannelInfo(i18n("X"), KoXyzU8Traits::x_pos * sizeof(quint8), KoXyzU8Traits::x_pos, KoChannelInfo::COLOR, KoChannelInfo::UINT8, sizeof(quint8), Qt::cyan));
23 addChannel(new KoChannelInfo(i18n("Y"), KoXyzU8Traits::y_pos * sizeof(quint8), KoXyzU8Traits::y_pos, KoChannelInfo::COLOR, KoChannelInfo::UINT8, sizeof(quint8), Qt::magenta));
24 addChannel(new KoChannelInfo(i18n("Z"), KoXyzU8Traits::z_pos * sizeof(quint8), KoXyzU8Traits::z_pos, KoChannelInfo::COLOR, KoChannelInfo::UINT8, sizeof(quint8), Qt::yellow));
26
27 init();
28
29 addStandardCompositeOps<KoXyzU8Traits>(this);
30 addStandardDitherOps<KoXyzU8Traits>(this);
31}
32
34{
35 return false;
36}
37
39{
40 return new XyzU8ColorSpace(name(), profile()->clone());
41}
42
43void XyzU8ColorSpace::colorToXML(const quint8 *pixel, QDomDocument &doc, QDomElement &colorElt) const
44{
45 const KoXyzU8Traits::Pixel *p = reinterpret_cast<const KoXyzU8Traits::Pixel *>(pixel);
46 QDomElement labElt = doc.createElement("XYZ");
50 labElt.setAttribute("space", profile()->name());
51 colorElt.appendChild(labElt);
52}
53
54void XyzU8ColorSpace::colorFromXML(quint8 *pixel, const QDomElement &elt) const
55{
56 KoXyzU8Traits::Pixel *p = reinterpret_cast<KoXyzU8Traits::Pixel *>(pixel);
61}
62
63void XyzU8ColorSpace::toHSY(const QVector<double> &channelValues, qreal *hue, qreal *sat, qreal *luma) const
64{
65 qreal xyx, xyy, xyY = 0.0;
66 XYZToxyY(channelValues[0],channelValues[1],channelValues[2], &xyx, &xyy, &xyY);
67 LabToLCH(xyY,xyx,xyY, hue, sat, luma);
68}
69
70QVector <double> XyzU8ColorSpace::fromHSY(qreal *hue, qreal *sat, qreal *luma) const
71{
72 QVector <double> channelValues(4);
73 qreal xyx, xyy, xyY = 0.0;
74 LCHToLab(*luma, *sat, *hue, &xyY,&xyx,&xyy);
75 xyYToXYZ(xyx, xyy, xyY, &channelValues[0],&channelValues[1],&channelValues[2]);
76 channelValues[3]=1.0;
77 return channelValues;
78}
79
80void XyzU8ColorSpace::toYUV(const QVector<double> &channelValues, qreal *y, qreal *u, qreal *v) const
81{
82 XYZToxyY(channelValues[0],channelValues[1],channelValues[2], u, v, y);
83}
84
85QVector <double> XyzU8ColorSpace::fromYUV(qreal *y, qreal *u, qreal *v) const
86{
87 QVector <double> channelValues(4);
88 xyYToXYZ(*u, *v, *y, &channelValues[0],&channelValues[1],&channelValues[2]);
89 channelValues[3]=1.0;
90 return channelValues;
91}
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
#define TYPE_XYZA_8
@ 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 addChannel(KoChannelInfo *ci)
const KoColorProfile * profile() const override
void toYUV(const QVector< double > &channelValues, qreal *y, qreal *u, qreal *v) const override
void toHSY(const QVector< double > &channelValues, qreal *hue, qreal *sat, qreal *luma) const override
XyzU8ColorSpace(const QString &name, KoColorProfile *p)
QVector< double > fromHSY(qreal *hue, qreal *sat, qreal *luma) const override
void colorFromXML(quint8 *pixel, const QDomElement &elt) const override
virtual KoColorSpace * clone() const
void colorToXML(const quint8 *pixel, QDomDocument &doc, QDomElement &colorElt) const override
bool willDegrade(ColorSpaceIndependence independence) const override
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