Commit f7018ae8 authored by Boudewijn Rempt's avatar Boudewijn Rempt

* Add convolve, darken, intensity8 and invert to the colorspaces that didn't

have them, making all conv. filters cs-independent and bumpmap cs-indep, too.
* Made lab::darken the default fallback for 16-bit filters
* Some work on loading adj. layers with per-channel filters, but that's still 
broken.

svn path=/trunk/koffice/; revision=517048
parent 71a1717a
......@@ -98,6 +98,57 @@ void KisCmykU16ColorSpace::mixColors(const Q_UINT8 **colors, const Q_UINT8 *weig
dstPixel -> black = totalBlack;
}
void KisCmykU16ColorSpace::convolveColors(Q_UINT8** colors, Q_INT32* kernelValues, KisChannelInfo::enumChannelFlags channelFlags, Q_UINT8 *dst, Q_INT32 factor, Q_INT32 offset, Q_INT32 nColors) const
{
Q_INT32 totalCyan = 0, totalMagenta = 0, totalYellow = 0, totalK = 0, totalAlpha = 0;
while (nColors--)
{
const Pixel * pixel = reinterpret_cast<const Pixel *>( *colors );
Q_INT32 weight = *kernelValues;
if (weight != 0) {
totalCyan += pixel->cyan * weight;
totalMagenta += pixel->magenta * weight;
totalYellow += pixel->yellow * weight;
totalK += pixel->black * weight;
totalAlpha += pixel->alpha * weight;
}
colors++;
kernelValues++;
}
Pixel * p = reinterpret_cast< Pixel *>( dst );
if (channelFlags & KisChannelInfo::FLAG_COLOR) {
p->cyan = CLAMP( ( totalCyan / factor) + offset, 0, Q_UINT16_MAX);
p->magenta = CLAMP( ( totalMagenta / factor) + offset, 0, Q_UINT16_MAX);
p->yellow = CLAMP( ( totalYellow / factor) + offset, 0, Q_UINT16_MAX);
p->black = CLAMP( ( totalK / factor) + offset, 0, Q_UINT16_MAX);
}
if (channelFlags & KisChannelInfo::FLAG_ALPHA) {
p->alpha = CLAMP((totalAlpha/ factor) + offset, 0, Q_UINT16_MAX);
}
}
void KisCmykU16ColorSpace::invertColor(Q_UINT8 * src, Q_INT32 nPixels)
{
Q_UINT32 psize = pixelSize();
while (nPixels--)
{
Pixel * p = reinterpret_cast< Pixel *>( src );
p->cyan = Q_UINT16_MAX - p->cyan;
p->magenta = Q_UINT16_MAX - p->magenta;
p->yellow = Q_UINT16_MAX - p->yellow;
p->black = Q_UINT16_MAX - p->black;
src += psize;
}
}
void KisCmykU16ColorSpace::applyAdjustment(const Q_UINT8 *src, Q_UINT8 *dst, KisColorAdjustment *adj, Q_INT32 nPixels)
{
......
......@@ -56,10 +56,12 @@ public:
virtual Q_UINT32 nChannels() const;
virtual Q_UINT32 nColorChannels() const;
virtual Q_UINT32 pixelSize() const;
virtual void mixColors(const Q_UINT8 **colors, const Q_UINT8 *weights, Q_UINT32 nColors, Q_UINT8 *dst) const;
virtual void applyAdjustment(const Q_UINT8 *src, Q_UINT8 *dst, KisColorAdjustment *adj, Q_INT32 nPixels);
virtual void applyAdjustment(const Q_UINT8 *src, Q_UINT8 *dst, KisColorAdjustment *adj, Q_INT32 nPixels);
virtual void mixColors(const Q_UINT8 **colors, const Q_UINT8 *weights, Q_UINT32 nColors, Q_UINT8 *dst) const;
virtual void invertColor(Q_UINT8 * src, Q_INT32 nPixels);
virtual void convolveColors(Q_UINT8** colors, Q_INT32 * kernelValues, KisChannelInfo::enumChannelFlags channelFlags, Q_UINT8 *dst, Q_INT32 factor, Q_INT32 offset, Q_INT32 nColors) const;
virtual KisCompositeOpList userVisiblecompositeOps() const;
protected:
......
......@@ -104,14 +104,61 @@ void KisCmykColorSpace::mixColors(const Q_UINT8 **colors, const Q_UINT8 *weights
dst[3] = dstK;
}
void KisCmykColorSpace::convolveColors(Q_UINT8** colors, Q_INT32* kernelValues, KisChannelInfo::enumChannelFlags channelFlags, Q_UINT8 *dst, Q_INT32 factor, Q_INT32 offset, Q_INT32 nColors) const
{
Q_INT32 totalCyan = 0, totalMagenta = 0, totalYellow = 0, totalK = 0, totalAlpha = 0;
while (nColors--)
{
Q_INT32 weight = *kernelValues;
if (weight != 0) {
totalCyan += (*colors)[PIXEL_CYAN] * weight;
totalMagenta += (*colors)[PIXEL_MAGENTA] * weight;
totalYellow += (*colors)[PIXEL_YELLOW] * weight;
totalK += (*colors)[PIXEL_BLACK] * weight;
totalAlpha += (*colors)[PIXEL_CMYK_ALPHA] * weight;
}
colors++;
kernelValues++;
}
if (channelFlags & KisChannelInfo::FLAG_COLOR) {
dst[PIXEL_CYAN] = CLAMP((totalCyan / factor) + offset, 0, Q_UINT8_MAX);
dst[PIXEL_MAGENTA] = CLAMP((totalMagenta / factor) + offset, 0, Q_UINT8_MAX);
dst[PIXEL_YELLOW] = CLAMP((totalYellow / factor) + offset, 0, Q_UINT8_MAX);
dst[PIXEL_BLACK] = CLAMP((totalK / factor) + offset, 0, Q_UINT8_MAX);
}
if (channelFlags & KisChannelInfo::FLAG_ALPHA) {
dst[PIXEL_CMYK_ALPHA] = CLAMP((totalAlpha/ factor) + offset, 0, Q_UINT8_MAX);
}
}
void KisCmykColorSpace::invertColor(Q_UINT8 * src, Q_INT32 nPixels)
{
Q_UINT32 psize = pixelSize();
while (nPixels--)
{
src[PIXEL_CYAN] = Q_UINT8_MAX - src[PIXEL_CYAN];
src[PIXEL_MAGENTA] = Q_UINT8_MAX - src[PIXEL_MAGENTA];
src[PIXEL_YELLOW] = Q_UINT8_MAX - src[PIXEL_YELLOW];
src[PIXEL_BLACK] = Q_UINT8_MAX - src[PIXEL_BLACK];
src += psize;
}
}
void KisCmykColorSpace::applyAdjustment(const Q_UINT8 *src, Q_UINT8 *dst, KisColorAdjustment *adj, Q_INT32 nPixels)
{
Q_UINT32 psize = pixelSize();
Q_UINT8 * tmp = new Q_UINT8[nPixels * psize];
Q_UINT8 * tmpPtr = tmp;
memcpy(tmp, dst, nPixels * psize);
KisAbstractColorSpace::applyAdjustment(src, dst, adj, nPixels);
// Copy the alpha, which lcms doesn't do for us, grumble.
......
......@@ -45,12 +45,16 @@ public:
virtual void mixColors(const Q_UINT8 **colors, const Q_UINT8 *weights, Q_UINT32 nColors, Q_UINT8 *dst) const;
virtual void applyAdjustment(const Q_UINT8 *src, Q_UINT8 *dst, KisColorAdjustment *adj, Q_INT32 nPixels);
virtual void invertColor(Q_UINT8 * src, Q_INT32 nPixels);
virtual void convolveColors(Q_UINT8** colors, Q_INT32 * kernelValues, KisChannelInfo::enumChannelFlags channelFlags, Q_UINT8 *dst, Q_INT32 factor, Q_INT32 offset, Q_INT32 nColors) const;
// XXX: darken & intensity8?
virtual QValueVector<KisChannelInfo *> channels() const;
virtual Q_UINT32 nChannels() const;
virtual Q_UINT32 nColorChannels() const;
virtual Q_UINT32 pixelSize() const;
virtual void bitBlt(Q_UINT8 *dst,
Q_INT32 dstRowSize,
const Q_UINT8 *src,
......
......@@ -90,6 +90,57 @@ void KisGrayU16ColorSpace::mixColors(const Q_UINT8 **colors, const Q_UINT8 *weig
dstPixel -> gray = totalGray;
}
void KisGrayU16ColorSpace::convolveColors(Q_UINT8** colors, Q_INT32* kernelValues, KisChannelInfo::enumChannelFlags channelFlags, Q_UINT8 *dst,
Q_INT32 factor, Q_INT32 offset, Q_INT32 nColors) const
{
Q_INT32 totalGray = 0, totalAlpha = 0;
while (nColors--)
{
const Pixel * pixel = reinterpret_cast<const Pixel *>( *colors );
Q_INT32 weight = *kernelValues;
if (weight != 0) {
totalGray += pixel->gray * weight;
totalAlpha += pixel->alpha * weight;
}
colors++;
kernelValues++;
}
Pixel * p = reinterpret_cast< Pixel *>( dst );
if (channelFlags & KisChannelInfo::FLAG_COLOR) {
p->gray = CLAMP( ( totalGray / factor) + offset, 0, Q_UINT16_MAX);
}
if (channelFlags & KisChannelInfo::FLAG_ALPHA) {
p->alpha = CLAMP((totalAlpha/ factor) + offset, 0, Q_UINT16_MAX);
}
}
void KisGrayU16ColorSpace::invertColor(Q_UINT8 * src, Q_INT32 nPixels)
{
Q_UINT32 psize = pixelSize();
while (nPixels--)
{
Pixel * p = reinterpret_cast< Pixel *>( src );
p->gray = Q_UINT16_MAX - p->gray;
src += psize;
}
}
Q_UINT8 KisGrayU16ColorSpace::intensity8(const Q_UINT8 * src) const
{
const Pixel * p = reinterpret_cast<const Pixel *>( src );
return UINT16_TO_UINT8(p->gray);
}
QValueVector<KisChannelInfo *> KisGrayU16ColorSpace::channels() const
{
return m_channels;
......@@ -365,27 +416,6 @@ void KisGrayU16ColorSpace::compositeBurn(Q_UINT8 *dstRowStart, Q_INT32 dstRowStr
COMMON_COMPOSITE_OP_EPILOG();
}
void KisGrayU16ColorSpace::compositeDarken(Q_UINT8 *dstRowStart, Q_INT32 dstRowStride, const Q_UINT8 *srcRowStart, Q_INT32 srcRowStride, const Q_UINT8 *maskRowStart, Q_INT32 maskRowStride, Q_INT32 rows, Q_INT32 numColumns, Q_UINT16 opacity)
{
COMMON_COMPOSITE_OP_PROLOG();
{
for (int channel = 0; channel < MAX_CHANNEL_GRAY; channel++) {
Q_UINT16 srcColor = src[channel];
Q_UINT16 dstColor = dst[channel];
srcColor = QMIN(srcColor, dstColor);
Q_UINT16 newColor = UINT16_BLEND(srcColor, dstColor, srcBlend);
dst[channel] = newColor;
}
}
COMMON_COMPOSITE_OP_EPILOG();
}
void KisGrayU16ColorSpace::compositeLighten(Q_UINT8 *dstRowStart, Q_INT32 dstRowStride, const Q_UINT8 *srcRowStart, Q_INT32 srcRowStride, const Q_UINT8 *maskRowStart, Q_INT32 maskRowStride, Q_INT32 rows, Q_INT32 numColumns, Q_UINT16 opacity)
{
COMMON_COMPOSITE_OP_PROLOG();
......
......@@ -51,6 +51,9 @@ public:
public:
virtual void mixColors(const Q_UINT8 **colors, const Q_UINT8 *weights, Q_UINT32 nColors, Q_UINT8 *dst) const;
virtual void invertColor(Q_UINT8 * src, Q_INT32 nPixels);
virtual void convolveColors(Q_UINT8** colors, Q_INT32 * kernelValues, KisChannelInfo::enumChannelFlags channelFlags, Q_UINT8 *dst, Q_INT32 factor, Q_INT32 offset, Q_INT32 nColors) const;
virtual Q_UINT8 intensity8(const Q_UINT8 * src) const;
virtual QValueVector<KisChannelInfo *> channels() const;
virtual Q_UINT32 nChannels() const;
......
......@@ -71,12 +71,12 @@ void KisGrayColorSpace::getPixel(const Q_UINT8 *pixel, Q_UINT8 *gray, Q_UINT8 *a
*alpha = pixel[PIXEL_GRAY_ALPHA];
}
void KisGrayColorSpace::getAlpha(const Q_UINT8 *pixel, Q_UINT8 *alpha)
void KisGrayColorSpace::getAlpha(const Q_UINT8 *pixel, Q_UINT8 *alpha) const
{
*alpha = pixel[PIXEL_GRAY_ALPHA];
}
void KisGrayColorSpace::setAlpha(Q_UINT8 *pixels, Q_UINT8 alpha, Q_INT32 nPixels)
void KisGrayColorSpace::setAlpha(Q_UINT8 *pixels, Q_UINT8 alpha, Q_INT32 nPixels) const
{
while (nPixels > 0) {
pixels[PIXEL_GRAY_ALPHA] = alpha;
......@@ -116,6 +116,65 @@ void KisGrayColorSpace::mixColors(const Q_UINT8 **colors, const Q_UINT8 *weights
dst[PIXEL_GRAY] = dstGray;
}
void KisGrayColorSpace::convolveColors(Q_UINT8** colors, Q_INT32* kernelValues, KisChannelInfo::enumChannelFlags channelFlags, Q_UINT8 *dst, Q_INT32 factor, Q_INT32 offset, Q_INT32 nColors) const
{
Q_INT32 totalGray = 0, totalAlpha = 0;
while (nColors--)
{
Q_INT32 weight = *kernelValues;
if (weight != 0) {
totalGray += (*colors)[PIXEL_GRAY] * weight;
totalAlpha += (*colors)[PIXEL_GRAY_ALPHA] * weight;
}
colors++;
kernelValues++;
}
if (channelFlags & KisChannelInfo::FLAG_COLOR) {
dst[PIXEL_GRAY] = CLAMP((totalGray / factor) + offset, 0, Q_UINT8_MAX);
}
if (channelFlags & KisChannelInfo::FLAG_ALPHA) {
dst[PIXEL_GRAY_ALPHA] = CLAMP((totalAlpha/ factor) + offset, 0, Q_UINT8_MAX);
}
}
void KisGrayColorSpace::invertColor(Q_UINT8 * src, Q_INT32 nPixels)
{
Q_UINT32 psize = pixelSize();
while (nPixels--)
{
src[PIXEL_GRAY] = Q_UINT8_MAX - src[PIXEL_GRAY];
src += psize;
}
}
void KisGrayColorSpace::darken(const Q_UINT8 * src, Q_UINT8 * dst, Q_INT32 shade, bool compensate, double compensation, Q_INT32 nPixels) const
{
Q_UINT32 pSize = pixelSize();
while (nPixels--) {
if (compensate) {
dst[PIXEL_GRAY] = (Q_INT8) QMIN(255,((src[PIXEL_GRAY] * shade) / (compensation * 255)));
}
else {
dst[PIXEL_GRAY] = (Q_INT8) QMIN(255, (src[PIXEL_GRAY] * shade / 255));
}
dst += pSize;
src += pSize;
}
}
Q_UINT8 KisGrayColorSpace::intensity8(const Q_UINT8 * src) const
{
return src[PIXEL_GRAY];
}
QValueVector<KisChannelInfo *> KisGrayColorSpace::channels() const
{
return m_channels;
......
......@@ -42,10 +42,14 @@ public:
void setPixel(Q_UINT8 *pixel, Q_UINT8 gray, Q_UINT8 alpha) const;
void getPixel(const Q_UINT8 *pixel, Q_UINT8 *gray, Q_UINT8 *alpha) const;
virtual void getAlpha(const Q_UINT8 *pixel, Q_UINT8 *alpha);
virtual void setAlpha(Q_UINT8 * pixels, Q_UINT8 alpha, Q_INT32 nPixels);
virtual void getAlpha(const Q_UINT8 *pixel, Q_UINT8 *alpha) const;
virtual void setAlpha(Q_UINT8 * pixels, Q_UINT8 alpha, Q_INT32 nPixels) const;
virtual void mixColors(const Q_UINT8 **colors, const Q_UINT8 *weights, Q_UINT32 nColors, Q_UINT8 *dst) const;
virtual void convolveColors(Q_UINT8** colors, Q_INT32* kernelValues, KisChannelInfo::enumChannelFlags channelFlags, Q_UINT8 *dst, Q_INT32 factor, Q_INT32 offset, Q_INT32 nColors) const;
virtual void invertColor(Q_UINT8 * src, Q_INT32 nPixels);
virtual void darken(const Q_UINT8 * src, Q_UINT8 * dst, Q_INT32 shade, bool compensate, double compensation, Q_INT32 nPixels) const;
virtual Q_UINT8 intensity8(const Q_UINT8 * src) const;
virtual QValueVector<KisChannelInfo *> channels() const;
virtual Q_UINT32 nChannels() const;
......
......@@ -164,6 +164,63 @@ void KisRgbF16HalfColorSpace::mixColors(const Q_UINT8 **colors, const Q_UINT8 *w
dstPixel -> blue = totalBlue;
}
void KisRgbF16HalfColorSpace::convolveColors(Q_UINT8** colors, Q_INT32 * kernelValues, KisChannelInfo::enumChannelFlags channelFlags, Q_UINT8 *dst, Q_INT32 factor, Q_INT32 offset, Q_INT32 nColors) const
{
half totalRed = 0, totalGreen = 0, totalBlue = 0, totalAlpha = 0;
while (nColors--)
{
const Pixel * pixel = reinterpret_cast<const Pixel *>( *colors );
half weight = *kernelValues;
if (weight != 0) {
totalRed += pixel->red * UINT8_TO_HALF(weight);
totalGreen += pixel->green * UINT8_TO_HALF(weight);
totalBlue += pixel->blue * UINT8_TO_HALF(weight);
totalAlpha += pixel->alpha * UINT8_TO_HALF(weight);
}
colors++;
kernelValues++;
}
Pixel * p = reinterpret_cast< Pixel *>( dst );
if (channelFlags & KisChannelInfo::FLAG_COLOR) {
p->red = CLAMP( ( totalRed / factor) + offset, 0, HALF_MAX);
p->green = CLAMP( ( totalGreen / factor) + offset, 0, HALF_MAX);
p->blue = CLAMP( ( totalBlue / factor) + offset, 0, HALF_MAX);
}
if (channelFlags & KisChannelInfo::FLAG_ALPHA) {
p->alpha = CLAMP((totalAlpha/ factor) + offset, 0, HALF_MAX);
}
}
void KisRgbF16HalfColorSpace::invertColor(Q_UINT8 * src, Q_INT32 nPixels)
{
Q_UINT32 psize = pixelSize();
while (nPixels--)
{
Pixel * p = reinterpret_cast< Pixel *>( src );
p->red = 1.0 - p->red;
p->green = 1.0 - p->green;
p->blue = 1.0 - p->blue;
src += psize;
}
}
Q_UINT8 KisRgbF16HalfColorSpace::intensity8(const Q_UINT8 * src) const
{
const Pixel * p = reinterpret_cast<const Pixel *>( src );
return HALF_TO_UINT8((p->red * 0.30 + p->green * 0.59 + p->blue * 0.11) + 0.5);
}
QValueVector<KisChannelInfo *> KisRgbF16HalfColorSpace::channels() const
{
return m_channels;
......
......@@ -55,7 +55,10 @@ public:
virtual Q_UINT8 difference(const Q_UINT8 *src1, const Q_UINT8 *src2);
virtual void mixColors(const Q_UINT8 **colors, const Q_UINT8 *weights, Q_UINT32 nColors, Q_UINT8 *dst) const;
virtual void invertColor(Q_UINT8 * src, Q_INT32 nPixels);
virtual void convolveColors(Q_UINT8** colors, Q_INT32 * kernelValues, KisChannelInfo::enumChannelFlags channelFlags, Q_UINT8 *dst, Q_INT32 factor, Q_INT32 offset, Q_INT32 nColors) const;
virtual Q_UINT8 intensity8(const Q_UINT8 * src) const;
virtual QValueVector<KisChannelInfo *> channels() const;
virtual Q_UINT32 nChannels() const;
virtual Q_UINT32 nColorChannels() const;
......
......@@ -163,6 +163,63 @@ void KisRgbF32ColorSpace::mixColors(const Q_UINT8 **colors, const Q_UINT8 *weigh
dstPixel -> blue = totalBlue;
}
void KisRgbF32ColorSpace::convolveColors(Q_UINT8** colors, Q_INT32 * kernelValues, KisChannelInfo::enumChannelFlags channelFlags, Q_UINT8 *dst, Q_INT32 factor, Q_INT32 offset, Q_INT32 nColors) const
{
float totalRed = 0, totalGreen = 0, totalBlue = 0, totalAlpha = 0;
while (nColors--)
{
const Pixel * pixel = reinterpret_cast<const Pixel *>( *colors );
float weight = *kernelValues;
if (weight != 0) {
totalRed += pixel->red * weight;
totalGreen += pixel->green * weight;
totalBlue += pixel->blue * weight;
totalAlpha += pixel->alpha * weight;
}
colors++;
kernelValues++;
}
Pixel * p = reinterpret_cast< Pixel *>( dst );
if (channelFlags & KisChannelInfo::FLAG_COLOR) {
p->red = CLAMP( ( totalRed / factor) + offset, 0, FLOAT_MAX);
p->green = CLAMP( ( totalGreen / factor) + offset, 0, FLOAT_MAX);
p->blue = CLAMP( ( totalBlue / factor) + offset, 0, FLOAT_MAX);
}
if (channelFlags & KisChannelInfo::FLAG_ALPHA) {
p->alpha = CLAMP((totalAlpha/ factor) + offset, 0, FLOAT_MAX);
}
}
void KisRgbF32ColorSpace::invertColor(Q_UINT8 * src, Q_INT32 nPixels)
{
Q_UINT32 psize = pixelSize();
while (nPixels--)
{
Pixel * p = reinterpret_cast< Pixel *>( src );
p->red = FLOAT_MAX - p->red;
p->green = FLOAT_MAX - p->green;
p->blue = FLOAT_MAX - p->blue;
src += psize;
}
}
Q_UINT8 KisRgbF32ColorSpace::intensity8(const Q_UINT8 * src) const
{
const Pixel * p = reinterpret_cast<const Pixel *>( src );
return FLOAT_TO_UINT8((p->red * 0.30 + p->green * 0.59 + p->blue * 0.11) + 0.5);
}
QValueVector<KisChannelInfo *> KisRgbF32ColorSpace::channels() const
{
return m_channels;
......
......@@ -58,12 +58,16 @@ public:
virtual Q_UINT8 difference(const Q_UINT8 *src1, const Q_UINT8 *src2);
virtual void mixColors(const Q_UINT8 **colors, const Q_UINT8 *weights, Q_UINT32 nColors, Q_UINT8 *dst) const;
virtual void invertColor(Q_UINT8 * src, Q_INT32 nPixels);
virtual void convolveColors(Q_UINT8** colors, Q_INT32 * kernelValues, KisChannelInfo::enumChannelFlags channelFlags, Q_UINT8 *dst, Q_INT32 factor, Q_INT32 offset, Q_INT32 nColors) const;
virtual Q_UINT8 intensity8(const Q_UINT8 * src) const;
virtual QValueVector<KisChannelInfo *> channels() const;
virtual Q_UINT32 nChannels() const;
virtual Q_UINT32 nColorChannels() const;
virtual Q_UINT32 pixelSize() const;
virtual QImage convertToQImage(const Q_UINT8 *data, Q_INT32 width, Q_INT32 height,
KisProfile * dstProfile,
Q_INT32 renderingIntent,
......
......@@ -118,6 +118,63 @@ void KisRgbU16ColorSpace::mixColors(const Q_UINT8 **colors, const Q_UINT8 *weigh
dstPixel -> blue = totalBlue;
}
void KisRgbU16ColorSpace::convolveColors(Q_UINT8** colors, Q_INT32* kernelValues, KisChannelInfo::enumChannelFlags channelFlags, Q_UINT8 *dst,
Q_INT32 factor, Q_INT32 offset, Q_INT32 nColors) const
{
Q_INT32 totalRed = 0, totalGreen = 0, totalBlue = 0, totalAlpha = 0;
while (nColors--)
{
const Pixel * pixel = reinterpret_cast<const Pixel *>( *colors );
Q_INT32 weight = *kernelValues;
if (weight != 0) {
totalRed += pixel->red * weight;
totalGreen += pixel->green * weight;
totalBlue += pixel->blue * weight;
totalAlpha +=pixel->alpha * weight;
}
colors++;
kernelValues++;
}
Pixel * p = reinterpret_cast< Pixel *>( dst );
if (channelFlags & KisChannelInfo::FLAG_COLOR) {
p->red = CLAMP( ( totalRed / factor) + offset, 0, Q_UINT16_MAX);
p->green = CLAMP( ( totalGreen / factor) + offset, 0, Q_UINT16_MAX);
p->blue = CLAMP( ( totalBlue / factor) + offset, 0, Q_UINT16_MAX);
}
if (channelFlags & KisChannelInfo::FLAG_ALPHA) {
p->alpha = CLAMP((totalAlpha/ factor) + offset, 0, Q_UINT16_MAX);
}
}
void KisRgbU16ColorSpace::invertColor(Q_UINT8 * src, Q_INT32 nPixels)
{
Q_UINT32 psize = pixelSize();
while (nPixels--)
{
Pixel * p = reinterpret_cast< Pixel *>( src );
p->red = Q_UINT16_MAX - p->red;
p->green = Q_UINT16_MAX - p->green;
p->blue = Q_UINT16_MAX - p->blue;
src += psize;
}
}
Q_UINT8 KisRgbU16ColorSpace::intensity8(const Q_UINT8 * src) const
{
const Pixel * p = reinterpret_cast<const Pixel *>( src );
return UINT16_TO_UINT8(static_cast<Q_UINT16>((p->red * 0.30 + p->green * 0.59 + p->blue * 0.11) + 0.5));
}
QValueVector<KisChannelInfo *> KisRgbU16ColorSpace::channels() const
{
return m_channels;
......
......@@ -56,6 +56,9 @@ public:
void getPixel(const Q_UINT8 *pixel, Q_UINT16 *red, Q_UINT16 *green, Q_UINT16 *blue, Q_UINT16 *alpha) const;
virtual void mixColors(const Q_UINT8 **colors, const Q_UINT8 *weights, Q_UINT32 nColors, Q_UINT8 *dst) const;