Krita Source Code Documentation
Loading...
Searching...
No Matches
GrayF16ColorSpace.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: GPL-2.0-or-later
6 */
7
8#include "GrayF16ColorSpace.h"
9
10#include <QDomElement>
11
12#include <klocalizedstring.h>
13
14#include <KoIntegerMaths.h>
16
19#include <kis_dom_utils.h>
20
22 : LcmsColorSpace<KoGrayF16Traits>(colorSpaceId(), name, TYPE_GRAYA_HALF_FLT, cmsSigGrayData, p)
23{
24 const IccColorProfile *icc_p = dynamic_cast<const IccColorProfile *>(p);
25 Q_ASSERT(icc_p);
26 Q_UNUSED(icc_p);
27 addChannel(new KoChannelInfo(i18n("Gray"), 0 * sizeof(half), 0, KoChannelInfo::COLOR, KoChannelInfo::FLOAT16, 2, Qt::gray));
28 addChannel(new KoChannelInfo(i18n("Alpha"), 1 * sizeof(half), 1, KoChannelInfo::ALPHA, KoChannelInfo::FLOAT16, 2));
29
30 init();
31
32 addStandardCompositeOps<KoGrayF16Traits>(this);
33 addStandardDitherOps<KoGrayF16Traits>(this);
34}
35
40
41void GrayF16ColorSpace::colorToXML(const quint8 *pixel, QDomDocument &doc, QDomElement &colorElt) const
42{
43 const KoGrayF16Traits::channels_type *p = reinterpret_cast<const KoGrayF16Traits::channels_type *>(pixel);
44 QDomElement labElt = doc.createElement("Gray");
46 labElt.setAttribute("space", profile()->name());
47 colorElt.appendChild(labElt);
48}
49
50void GrayF16ColorSpace::colorFromXML(quint8 *pixel, const QDomElement &elt) const
51{
52 KoGrayF16Traits::channels_type *p = reinterpret_cast<KoGrayF16Traits::channels_type *>(pixel);
54 p[1] = 1.0;
55}
56
57void GrayF16ColorSpace::toHSY(const QVector<double> &channelValues, qreal *, qreal *, qreal *luma) const
58{
59 *luma = channelValues[0];
60}
61
62QVector <double> GrayF16ColorSpace::fromHSY(qreal *, qreal *, qreal *luma) const
63{
64 QVector <double> channelValues(2);
65 channelValues.fill(*luma);
66 channelValues[1]=1.0;
67 return channelValues;
68}
69
70void GrayF16ColorSpace::toYUV(const QVector<double> &channelValues, qreal *y, qreal *, qreal *) const
71{
72 *y = channelValues[0];
73}
74
75QVector <double> GrayF16ColorSpace::fromYUV(qreal *y, qreal *, qreal *) const
76{
77 QVector <double> channelValues(2);
78 channelValues.fill(*y);
79 channelValues[1]=1.0;
80 return channelValues;
81}
#define TYPE_GRAYA_HALF_FLT
const Params2D p
GrayF16ColorSpace(const QString &name, KoColorProfile *p)
virtual KoColorSpace * clone() const
QVector< double > fromYUV(qreal *y, qreal *u, qreal *v) const override
void toHSY(const QVector< double > &channelValues, qreal *hue, qreal *sat, qreal *luma) 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
void colorFromXML(quint8 *pixel, const QDomElement &elt) const override
QVector< double > fromHSY(qreal *hue, qreal *sat, qreal *luma) const override
@ 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 addChannel(KoChannelInfo *ci)
const KoColorProfile * profile() const override
double toDouble(const QString &str, bool *ok=nullptr)
QString toString(const QString &value)