Krita Source Code Documentation
Loading...
Searching...
No Matches
YCbCrU8ColorSpace.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 "YCbCrU8ColorSpace.h"
9#include <QDomElement>
10
11#include <QDebug>
12#include <klocalizedstring.h>
13
16#include <KoColorConversions.h>
17
18#include <kis_dom_utils.h>
19
21 : LcmsColorSpace<KoYCbCrU8Traits>(colorSpaceId(), name, TYPE_YCbCrA_8, cmsSigYCbCrData, p)
22{
23 addChannel(new KoChannelInfo(i18n("Y"), KoYCbCrU8Traits::Y_pos * sizeof(quint8), KoYCbCrU8Traits::Y_pos, KoChannelInfo::COLOR, KoChannelInfo::UINT8, sizeof(quint8), Qt::cyan));
24 addChannel(new KoChannelInfo(i18n("Cb"), KoYCbCrU8Traits::Cb_pos * sizeof(quint8), KoYCbCrU8Traits::Cb_pos, KoChannelInfo::COLOR, KoChannelInfo::UINT8, sizeof(quint8), Qt::magenta));
25 addChannel(new KoChannelInfo(i18n("Cr"), KoYCbCrU8Traits::Cr_pos * sizeof(quint8), KoYCbCrU8Traits::Cr_pos, KoChannelInfo::COLOR, KoChannelInfo::UINT8, sizeof(quint8), Qt::yellow));
27
28 init();
29
30 addStandardCompositeOps<KoYCbCrU8Traits>(this);
31 addStandardDitherOps<KoYCbCrU8Traits>(this);
32}
33
35{
36 return false;
37}
38
43
44void YCbCrU8ColorSpace::colorToXML(const quint8 *pixel, QDomDocument &doc, QDomElement &colorElt) const
45{
46 const KoYCbCrU8Traits::Pixel *p = reinterpret_cast<const KoYCbCrU8Traits::Pixel *>(pixel);
47 QDomElement labElt = doc.createElement("YCbCr");
51 labElt.setAttribute("space", profile()->name());
52 colorElt.appendChild(labElt);
53}
54
55void YCbCrU8ColorSpace::colorFromXML(quint8 *pixel, const QDomElement &elt) const
56{
57 KoYCbCrU8Traits::Pixel *p = reinterpret_cast<KoYCbCrU8Traits::Pixel *>(pixel);
62}
63
64void YCbCrU8ColorSpace::toHSY(const QVector<double> &channelValues, qreal *hue, qreal *sat, qreal *luma) const
65{
66 LabToLCH(channelValues[0],channelValues[1],channelValues[2], luma, sat, hue);
67}
68
69QVector <double> YCbCrU8ColorSpace::fromHSY(qreal *hue, qreal *sat, qreal *luma) const
70{
71 QVector <double> channelValues(4);
72 LCHToLab(*luma, *sat, *hue, &channelValues[0],&channelValues[1],&channelValues[2]);
73 channelValues[3]=1.0;
74 return channelValues;
75}
76void YCbCrU8ColorSpace::toYUV(const QVector<double> &channelValues, qreal *y, qreal *u, qreal *v) const
77{
78 *y =channelValues[0];
79 *u=channelValues[1];
80 *v=channelValues[2];
81}
82
83QVector <double> YCbCrU8ColorSpace::fromYUV(qreal *y, qreal *u, qreal *v) const
84{
85 QVector <double> channelValues(4);
86 channelValues[0]=*y;
87 channelValues[1]=*u;
88 channelValues[2]=*v;
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 LCHToLab(const qreal L, const qreal C, const qreal H, qreal *l, qreal *a, qreal *b)
ColorSpaceIndependence
#define TYPE_YCbCrA_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 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
bool willDegrade(ColorSpaceIndependence independence) const override
QVector< double > fromYUV(qreal *y, qreal *u, qreal *v) const override
virtual KoColorSpace * clone() const
void colorFromXML(quint8 *pixel, const QDomElement &elt) const override
QVector< double > fromHSY(qreal *hue, qreal *sat, qreal *luma) const override
void colorToXML(const quint8 *pixel, QDomDocument &doc, QDomElement &colorElt) const override
YCbCrU8ColorSpace(const QString &name, KoColorProfile *p)
double toDouble(const QString &str, bool *ok=nullptr)
QString toString(const QString &value)
static const qint32 alpha_pos