12#include <klocalizedstring.h>
14#include "../compositeops/KoCompositeOps.h"
25 Q_ASSERT(uiRanges.size() == 3);
27 addChannel(
new KoChannelInfo(i18nc(
"Lightness value in Lab color model",
"Lightness"), 0 *
sizeof(
float), 0,
KoChannelInfo::COLOR,
KoChannelInfo::FLOAT32,
sizeof(
float), QColor(100, 100, 100), uiRanges[0]));
34 addStandardCompositeOps<KoLabF32Traits>(
this);
35 addStandardDitherOps<KoLabF32Traits>(
this);
37 dbgPlugins <<
"La*b* (float) channel bounds for: " << icc_p->
name();
38 dbgPlugins <<
"L: " << uiRanges[0].minVal << uiRanges[0].maxVal;
39 dbgPlugins <<
"a: " << uiRanges[1].minVal << uiRanges[1].maxVal;
40 dbgPlugins <<
"b: " << uiRanges[2].minVal << uiRanges[2].maxVal;
59 const KoLabF32Traits::Pixel *
p =
reinterpret_cast<const KoLabF32Traits::Pixel *
>(pixel);
60 QDomElement labElt = doc.createElement(
"Lab");
70 colorElt.appendChild(labElt);
75 KoLabF32Traits::Pixel *
p =
reinterpret_cast<KoLabF32Traits::Pixel *
>(pixel);
84 LabToLCH(channelValues[0],channelValues[1],channelValues[2], luma, sat, hue);
89 QVector <double> channelValues(4);
90 LCHToLab(*luma, *sat, *hue, &channelValues[0],&channelValues[1],&channelValues[2]);
103 QVector <double> channelValues(4);
107 channelValues[3]=1.0;
108 return channelValues;
113 typename ColorSpaceTraits::channels_type c = ColorSpaceTraits::nativeArray(srcPixel)[channelIndex];
115 switch (channelIndex) {
116 case ColorSpaceTraits::L_pos:
117 b = ((qreal)c) / ColorSpaceTraits::math_trait::unitValueL;
119 case ColorSpaceTraits::a_pos:
120 case ColorSpaceTraits::b_pos:
121 if (c <= ColorSpaceTraits::math_trait::halfValueAB) {
122 b = ((qreal)c - ColorSpaceTraits::math_trait::zeroValueAB) / (2.0 * (ColorSpaceTraits::math_trait::halfValueAB - ColorSpaceTraits::math_trait::zeroValueAB));
124 b = 0.5 + ((qreal)c - ColorSpaceTraits::math_trait::halfValueAB) / (2.0 * (ColorSpaceTraits::math_trait::unitValueAB - ColorSpaceTraits::math_trait::halfValueAB));
128 b = ((qreal)c) / ColorSpaceTraits::math_trait::unitValue;
137 for (
uint pixelIndex = 0; pixelIndex < nPixels; ++pixelIndex) {
138 for (
uint channelIndex = 0; channelIndex < ColorSpaceTraits::channels_nb; ++channelIndex) {
139 if (channelIndex != ColorSpaceTraits::alpha_pos) {
140 if (channelIndex == ColorSpaceTraits::L_pos) {
141 ColorSpaceTraits::channels_type c = ColorSpaceTraits::nativeArray((src + (pixelIndex * ColorSpaceTraits::pixelSize)))[selectedChannelIndex];
142 switch (selectedChannelIndex) {
143 case ColorSpaceTraits::L_pos:
145 case ColorSpaceTraits::a_pos:
146 case ColorSpaceTraits::b_pos:
147 if (c <= ColorSpaceTraits::math_trait::halfValueAB) {
148 c = ColorSpaceTraits::math_trait::unitValueL * (((qreal)c - ColorSpaceTraits::math_trait::zeroValueAB) / (2.0 * (ColorSpaceTraits::math_trait::halfValueAB - ColorSpaceTraits::math_trait::zeroValueAB)));
150 c = ColorSpaceTraits::math_trait::unitValueL * (0.5 + ((qreal)c - ColorSpaceTraits::math_trait::halfValueAB) / (2.0 * (ColorSpaceTraits::math_trait::unitValueAB - ColorSpaceTraits::math_trait::halfValueAB)));
155 c = ColorSpaceTraits::math_trait::unitValueL * (qreal)c / ColorSpaceTraits::math_trait::unitValue;
158 ColorSpaceTraits::nativeArray(dst + (pixelIndex * ColorSpaceTraits::pixelSize))[channelIndex] = c;
160 ColorSpaceTraits::nativeArray(dst + (pixelIndex * ColorSpaceTraits::pixelSize))[channelIndex] = ColorSpaceTraits::math_trait::halfValueAB;
163 ColorSpaceTraits::nativeArray((dst + (pixelIndex * ColorSpaceTraits::pixelSize)))[channelIndex] =
164 ColorSpaceTraits::nativeArray((src + (pixelIndex * ColorSpaceTraits::pixelSize)))[channelIndex];
172 for (
uint pixelIndex = 0; pixelIndex < nPixels; ++pixelIndex) {
173 for (
uint channelIndex = 0; channelIndex < this->
channelCount(); ++channelIndex) {
174 if (selectedChannels.testBit(channelIndex)) {
175 ColorSpaceTraits::nativeArray((dst + (pixelIndex * ColorSpaceTraits::pixelSize)))[channelIndex] =
176 ColorSpaceTraits::nativeArray((src + (pixelIndex * ColorSpaceTraits::pixelSize)))[channelIndex];
178 ColorSpaceTraits::channels_type
v;
179 switch (channelIndex) {
180 case ColorSpaceTraits::L_pos:
181 v = ColorSpaceTraits::math_trait::halfValueL;
183 case ColorSpaceTraits::a_pos:
184 case ColorSpaceTraits::b_pos:
185 v = ColorSpaceTraits::math_trait::halfValueAB;
188 v = ColorSpaceTraits::math_trait::zeroValue;
191 ColorSpaceTraits::nativeArray((dst + (pixelIndex * ColorSpaceTraits::pixelSize)))[channelIndex] =
v;
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)
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
quint32 channelCount() const override
static _Tdst scaleToA(_T a)
virtual void addChannel(KoChannelInfo *ci)
void convertChannelToVisualRepresentation(const quint8 *src, quint8 *dst, quint32 nPixels, const qint32 selectedChannelIndex) const override
QVector< double > fromYUV(qreal *y, qreal *u, qreal *v) const override
void toYUV(const QVector< double > &channelValues, qreal *y, qreal *u, qreal *v) const override
LabF32ColorSpace(const QString &name, KoColorProfile *p)
void colorFromXML(quint8 *pixel, const QDomElement &elt) const override
void toHSY(const QVector< double > &channelValues, qreal *hue, qreal *sat, qreal *luma) const override
virtual KoColorSpace * clone() const
void colorToXML(const quint8 *pixel, QDomDocument &doc, QDomElement &colorElt) const override
quint8 scaleToU8(const quint8 *srcPixel, qint32 channelIndex) const override
QVector< double > fromHSY(qreal *hue, qreal *sat, qreal *luma) const override
bool willDegrade(ColorSpaceIndependence independence) const override
const KoColorProfile * profile() const override
double toDouble(const QString &str, bool *ok=nullptr)
QString toString(const QString &value)