12#include <klocalizedstring.h>
14#include "../compositeops/KoCompositeOps.h"
27 addStandardCompositeOps<KoLabU8Traits>(
this);
28 addStandardDitherOps<KoLabU8Traits>(
this);
43 const KoLabU8Traits::Pixel *
p =
reinterpret_cast<const KoLabU8Traits::Pixel *
>(pixel);
44 QDomElement labElt = doc.createElement(
"Lab");
49 if (
p->a <= halfValue) {
50 a = double(
double(halfValue -
p->a) / halfValue);
53 a = double(
double(
p->a - halfValue) / halfValue);
57 if (
p->b <= halfValue) {
58 b = double(
double(halfValue -
p->b) / halfValue);
61 b = double(
double(
p->b - halfValue) / halfValue);
69 colorElt.appendChild(labElt);
74 KoLabU8Traits::Pixel *
p =
reinterpret_cast<KoLabU8Traits::Pixel *
>(pixel);
88 p->a = halfValue - (a * halfValue);
91 p->a = (a * halfValue) + halfValue;
96 p->b = halfValue - (b * halfValue);
99 p->b = (b * halfValue) + halfValue;
107 LabToLCH(channelValues[0],channelValues[1],channelValues[2], luma, sat, hue);
112 QVector <double> channelValues(4);
113 LCHToLab(*luma, *sat, *hue, &channelValues[0],&channelValues[1],&channelValues[2]);
114 channelValues[3]=1.0;
115 return channelValues;
120 *y =channelValues[0];
127 QVector <double> channelValues(4);
131 channelValues[3]=1.0;
132 return channelValues;
137 typename ColorSpaceTraits::channels_type c = ColorSpaceTraits::nativeArray(srcPixel)[channelIndex];
139 switch (channelIndex) {
140 case ColorSpaceTraits::L_pos:
141 b = ((qreal)c) / ColorSpaceTraits::math_trait::unitValueL;
143 case ColorSpaceTraits::a_pos:
144 case ColorSpaceTraits::b_pos:
145 if (c <= ColorSpaceTraits::math_trait::halfValueAB) {
146 b = ((qreal)c - ColorSpaceTraits::math_trait::zeroValueAB) / (2.0 * (ColorSpaceTraits::math_trait::halfValueAB - ColorSpaceTraits::math_trait::zeroValueAB));
148 b = 0.5 + ((qreal)c - ColorSpaceTraits::math_trait::halfValueAB) / (2.0 * (ColorSpaceTraits::math_trait::unitValueAB - ColorSpaceTraits::math_trait::halfValueAB));
152 b = ((qreal)c) / ColorSpaceTraits::math_trait::unitValue;
161 for (
uint pixelIndex = 0; pixelIndex < nPixels; ++pixelIndex) {
162 for (
uint channelIndex = 0; channelIndex < ColorSpaceTraits::channels_nb; ++channelIndex) {
163 if (channelIndex != ColorSpaceTraits::alpha_pos) {
164 if (channelIndex == ColorSpaceTraits::L_pos) {
165 ColorSpaceTraits::channels_type c = ColorSpaceTraits::nativeArray((src + (pixelIndex * ColorSpaceTraits::pixelSize)))[selectedChannelIndex];
166 switch (selectedChannelIndex) {
167 case ColorSpaceTraits::L_pos:
169 case ColorSpaceTraits::a_pos:
170 case ColorSpaceTraits::b_pos:
171 if (c <= ColorSpaceTraits::math_trait::halfValueAB) {
172 c = ColorSpaceTraits::math_trait::unitValueL * (((qreal)c - ColorSpaceTraits::math_trait::zeroValueAB) / (2.0 * (ColorSpaceTraits::math_trait::halfValueAB - ColorSpaceTraits::math_trait::zeroValueAB)));
174 c = ColorSpaceTraits::math_trait::unitValueL * (0.5 + ((qreal)c - ColorSpaceTraits::math_trait::halfValueAB) / (2.0 * (ColorSpaceTraits::math_trait::unitValueAB - ColorSpaceTraits::math_trait::halfValueAB)));
179 c = ColorSpaceTraits::math_trait::unitValueL * (qreal)c / ColorSpaceTraits::math_trait::unitValue;
182 ColorSpaceTraits::nativeArray(dst + (pixelIndex * ColorSpaceTraits::pixelSize))[channelIndex] = c;
184 ColorSpaceTraits::nativeArray(dst + (pixelIndex * ColorSpaceTraits::pixelSize))[channelIndex] = ColorSpaceTraits::math_trait::halfValueAB;
187 ColorSpaceTraits::nativeArray((dst + (pixelIndex * ColorSpaceTraits::pixelSize)))[channelIndex] =
188 ColorSpaceTraits::nativeArray((src + (pixelIndex * ColorSpaceTraits::pixelSize)))[channelIndex];
196 for (
uint pixelIndex = 0; pixelIndex < nPixels; ++pixelIndex) {
197 for (
uint channelIndex = 0; channelIndex < ColorSpaceTraits::channels_nb; ++channelIndex) {
198 if (selectedChannels.testBit(channelIndex)) {
199 ColorSpaceTraits::nativeArray((dst + (pixelIndex * ColorSpaceTraits::pixelSize)))[channelIndex] =
200 ColorSpaceTraits::nativeArray((src + (pixelIndex * ColorSpaceTraits::pixelSize)))[channelIndex];
202 ColorSpaceTraits::channels_type
v;
203 switch (channelIndex) {
204 case ColorSpaceTraits::L_pos:
205 v = ColorSpaceTraits::math_trait::halfValueL;
207 case ColorSpaceTraits::a_pos:
208 case ColorSpaceTraits::b_pos:
209 v = ColorSpaceTraits::math_trait::halfValueAB;
212 v = ColorSpaceTraits::math_trait::zeroValue;
215 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.
@ UINT8
use this for an unsigned integer 8bits channel
static _Tdst scaleToA(_T a)
virtual void addChannel(KoChannelInfo *ci)
quint8 scaleToU8(const quint8 *srcPixel, qint32 channelIndex) const override
QVector< double > fromHSY(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
void convertChannelToVisualRepresentation(const quint8 *src, quint8 *dst, quint32 nPixels, const qint32 selectedChannelIndex) const override
void colorToXML(const quint8 *pixel, QDomDocument &doc, QDomElement &colorElt) const override
void toHSY(const QVector< double > &channelValues, qreal *hue, qreal *sat, qreal *luma) const override
void colorFromXML(quint8 *pixel, const QDomElement &elt) const override
virtual KoColorSpace * clone() const
LabU8ColorSpace(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