Krita Source Code Documentation
Loading...
Searching...
No Matches
GrayF32ColorSpace.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 "GrayF32ColorSpace.h"
9
10#include <QDomElement>
11
12#include <QDebug>
13#include <klocalizedstring.h>
14
15#include <KoIntegerMaths.h>
17
20#include <kis_dom_utils.h>
21
23 : LcmsColorSpace<KoGrayF32Traits>(colorSpaceId(), name, TYPE_GRAYA_FLT, cmsSigGrayData, p)
24{
25 const IccColorProfile *icc_p = dynamic_cast<const IccColorProfile *>(p);
26 Q_ASSERT(icc_p);
28 Q_ASSERT(uiRanges.size() == 1);
29
30 addChannel(new KoChannelInfo(i18n("Gray"), 0 * sizeof(float), 0, KoChannelInfo::COLOR, KoChannelInfo::FLOAT32, sizeof(float), Qt::gray, uiRanges[0]));
31 addChannel(new KoChannelInfo(i18n("Alpha"), 1 * sizeof(float), 1, KoChannelInfo::ALPHA, KoChannelInfo::FLOAT32, sizeof(float)));
32
33 init();
34
35 addStandardCompositeOps<KoGrayF32Traits>(this);
36 addStandardDitherOps<KoGrayF32Traits>(this);
37}
38
43
44void GrayF32ColorSpace::colorToXML(const quint8 *pixel, QDomDocument &doc, QDomElement &colorElt) const
45{
46 const KoGrayF32Traits::channels_type *p = reinterpret_cast<const KoGrayF32Traits::channels_type *>(pixel);
47 QDomElement labElt = doc.createElement("Gray");
49 labElt.setAttribute("space", profile()->name());
50 colorElt.appendChild(labElt);
51}
52
53void GrayF32ColorSpace::colorFromXML(quint8 *pixel, const QDomElement &elt) const
54{
57 p[1] = 1.0;
58}
59
60void GrayF32ColorSpace::toHSY(const QVector<double> &channelValues, qreal *, qreal *, qreal *luma) const
61{
62 *luma = channelValues[0];
63}
64
65QVector <double> GrayF32ColorSpace::fromHSY(qreal *, qreal *, qreal *luma) const
66{
67 QVector <double> channelValues(2);
68 channelValues.fill(*luma);
69 channelValues[1]=1.0;
70 return channelValues;
71}
72
73void GrayF32ColorSpace::toYUV(const QVector<double> &channelValues, qreal *y, qreal *, qreal *) const
74{
75 *y = channelValues[0];
76}
77
78QVector <double> GrayF32ColorSpace::fromYUV(qreal *y, qreal *, qreal *) const
79{
80 QVector <double> channelValues(2);
81 channelValues.fill(*y);
82 channelValues[1]=1.0;
83 return channelValues;
84}
#define TYPE_GRAYA_FLT
const Params2D p
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
GrayF32ColorSpace(const QString &name, KoColorProfile *p)
void colorToXML(const quint8 *pixel, QDomDocument &doc, QDomElement &colorElt) const override
QVector< double > fromYUV(qreal *y, qreal *u, qreal *v) const override
void colorFromXML(quint8 *pixel, const QDomElement &elt) const override
void toYUV(const QVector< double > &channelValues, qreal *y, qreal *u, qreal *v) const override
virtual KoColorSpace * clone() const
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
double toDouble(const QString &str, bool *ok=nullptr)
QString toString(const QString &value)
_channels_type_ channels_type
the type of the value of the channels of this color space