12#include <klocalizedstring.h>
14#include "../compositeops/KoCompositeOps.h"
29 addStandardCompositeOps<KoLabU16Traits>(
this);
30 addStandardDitherOps<KoLabU16Traits>(
this);
49 const KoLabU16Traits::Pixel *
p =
reinterpret_cast<const KoLabU16Traits::Pixel *
>(pixel);
50 QDomElement labElt = doc.createElement(
"Lab");
55 if (
p->a <= halfValue) {
56 a = double(
double(halfValue -
p->a) / halfValue);
59 a = double(
double(
p->a - halfValue) / halfValue);
63 if (
p->b <= halfValue) {
64 b = double(
double(halfValue -
p->b) / halfValue);
67 b = double(
double(
p->b - halfValue) / halfValue);
75 colorElt.appendChild(labElt);
80 KoLabU16Traits::Pixel *
p =
reinterpret_cast<KoLabU16Traits::Pixel *
>(pixel);
93 p->a = halfValue - (a * halfValue);
96 p->a = (a * halfValue) + halfValue;
101 p->b = halfValue - (b * halfValue);
104 p->b = (b * halfValue) + halfValue;
111 LabToLCH(channelValues[0],channelValues[1],channelValues[2], luma, sat, hue);
116 QVector <double> channelValues(4);
117 LCHToLab(*luma, *sat, *hue, &channelValues[0],&channelValues[1],&channelValues[2]);
118 channelValues[3]=1.0;
119 return channelValues;
124 *y =channelValues[0];
131 QVector <double> channelValues(4);
135 channelValues[3]=1.0;
136 return channelValues;
141 typename ColorSpaceTraits::channels_type c = ColorSpaceTraits::nativeArray(srcPixel)[channelIndex];
143 switch (channelIndex) {
144 case ColorSpaceTraits::L_pos:
145 b = ((qreal)c) / ColorSpaceTraits::math_trait::unitValueL;
147 case ColorSpaceTraits::a_pos:
148 case ColorSpaceTraits::b_pos:
149 if (c <= ColorSpaceTraits::math_trait::halfValueAB) {
150 b = ((qreal)c - ColorSpaceTraits::math_trait::zeroValueAB) / (2.0 * (ColorSpaceTraits::math_trait::halfValueAB - ColorSpaceTraits::math_trait::zeroValueAB));
152 b = 0.5 + ((qreal)c - ColorSpaceTraits::math_trait::halfValueAB) / (2.0 * (ColorSpaceTraits::math_trait::unitValueAB - ColorSpaceTraits::math_trait::halfValueAB));
156 b = ((qreal)c) / ColorSpaceTraits::math_trait::unitValue;
165 for (
uint pixelIndex = 0; pixelIndex < nPixels; ++pixelIndex) {
166 for (
uint channelIndex = 0; channelIndex < ColorSpaceTraits::channels_nb; ++channelIndex) {
167 if (channelIndex != ColorSpaceTraits::alpha_pos) {
168 if (channelIndex == ColorSpaceTraits::L_pos) {
169 ColorSpaceTraits::channels_type c = ColorSpaceTraits::nativeArray((src + (pixelIndex * ColorSpaceTraits::pixelSize)))[selectedChannelIndex];
170 switch (selectedChannelIndex) {
171 case ColorSpaceTraits::L_pos:
173 case ColorSpaceTraits::a_pos:
174 case ColorSpaceTraits::b_pos:
175 if (c <= ColorSpaceTraits::math_trait::halfValueAB) {
176 c = ColorSpaceTraits::math_trait::unitValueL * (((qreal)c - ColorSpaceTraits::math_trait::zeroValueAB) / (2.0 * (ColorSpaceTraits::math_trait::halfValueAB - ColorSpaceTraits::math_trait::zeroValueAB)));
178 c = ColorSpaceTraits::math_trait::unitValueL * (0.5 + ((qreal)c - ColorSpaceTraits::math_trait::halfValueAB) / (2.0 * (ColorSpaceTraits::math_trait::unitValueAB - ColorSpaceTraits::math_trait::halfValueAB)));
183 c = ColorSpaceTraits::math_trait::unitValueL * (qreal)c / ColorSpaceTraits::math_trait::unitValue;
186 ColorSpaceTraits::nativeArray(dst + (pixelIndex * ColorSpaceTraits::pixelSize))[channelIndex] = c;
188 ColorSpaceTraits::nativeArray(dst + (pixelIndex * ColorSpaceTraits::pixelSize))[channelIndex] = ColorSpaceTraits::math_trait::halfValueAB;
191 ColorSpaceTraits::nativeArray((dst + (pixelIndex * ColorSpaceTraits::pixelSize)))[channelIndex] =
192 ColorSpaceTraits::nativeArray((src + (pixelIndex * ColorSpaceTraits::pixelSize)))[channelIndex];
200 for (
uint pixelIndex = 0; pixelIndex < nPixels; ++pixelIndex) {
201 for (
uint channelIndex = 0; channelIndex < ColorSpaceTraits::channels_nb; ++channelIndex) {
202 if (selectedChannels.testBit(channelIndex)) {
203 ColorSpaceTraits::nativeArray((dst + (pixelIndex * ColorSpaceTraits::pixelSize)))[channelIndex] =
204 ColorSpaceTraits::nativeArray((src + (pixelIndex * ColorSpaceTraits::pixelSize)))[channelIndex];
206 ColorSpaceTraits::channels_type
v;
207 switch (channelIndex) {
208 case ColorSpaceTraits::L_pos:
209 v = ColorSpaceTraits::math_trait::halfValueL;
211 case ColorSpaceTraits::a_pos:
212 case ColorSpaceTraits::b_pos:
213 v = ColorSpaceTraits::math_trait::halfValueAB;
216 v = ColorSpaceTraits::math_trait::zeroValue;
219 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)
@ ALPHA
The channel represents the opacity of a pixel.
@ COLOR
The channel represents a color.
@ UINT16
use this for an integer 16bits channel
static _Tdst scaleToA(_T a)
virtual void addChannel(KoChannelInfo *ci)
void colorFromXML(quint8 *pixel, const QDomElement &elt) const override
quint8 scaleToU8(const quint8 *srcPixel, qint32 channelIndex) const override
bool willDegrade(ColorSpaceIndependence independence) const override
void convertChannelToVisualRepresentation(const quint8 *src, quint8 *dst, quint32 nPixels, const qint32 selectedChannelIndex) const override
virtual KoColorSpace * clone() const
void colorToXML(const quint8 *pixel, QDomDocument &doc, QDomElement &colorElt) const override
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 toYUV(const QVector< double > &channelValues, qreal *y, qreal *u, qreal *v) const override
QVector< double > fromHSY(qreal *hue, qreal *sat, qreal *luma) const override
LabU16ColorSpace(const QString &name, KoColorProfile *p)
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