Commit 7d4b91b5 authored by Sven Langkamp's avatar Sven Langkamp

change the brush mask from range 0.0-255.0 to 0.0-1.0, that allows a faster...

change the brush mask from range 0.0-255.0 to 0.0-1.0, that allows a faster upscaling when applying the alpha mask
added two functions to apply a float mask row instead of single quint8 alpha values
parent bab57d67
......@@ -142,7 +142,6 @@ void KisCircleMaskGenerator::processRowFast(float* buffer, int width, float y, f
Vc::float_v vTransformedFadeY(d->transformedFadeY);
Vc::float_v vOne(1.0f);
Vc::float_v v255(255.0f);
for (int i=0; i < width; i+= Vc::float_v::Size){
......@@ -156,11 +155,11 @@ void KisCircleMaskGenerator::processRowFast(float* buffer, int width, float y, f
Vc::float_v vNormFade = normeSIMD(xr * vTransformedFadeX, yr * vTransformedFadeY);
//255 * n * (normeFade - 1) / (normeFade - n)
Vc::float_v vFade = v255 * n * (vNormFade - vOne) / (vNormFade - n);
Vc::float_v vFade = n * (vNormFade - vOne) / (vNormFade - n);
// Mask out the inner circe of the mask
Vc::float_m mask = vNormFade < vOne;
vFade.setZero(mask);
vFade = Vc::min(vFade, v255);
vFade = Vc::min(vFade, vOne);
vFade.store(bufferPointer);
currentIndices = currentIndices + increment;
......
......@@ -206,6 +206,10 @@ public:
virtual void applyInverseAlphaU8Mask(quint8 * /*pixels*/, const quint8 * /*alpha*/, qint32 /*nPixels*/) const { }
virtual void applyAlphaNormedFloatMask(quint8 * /*pixels*/, const float * /*alpha*/, qint32 /*nPixels*/) const { }
virtual void applyInverseNormedFloatMask(quint8 * /*pixels*/, const float * /*alpha*/, qint32 /*nPixels*/) const { }
virtual quint8 difference(const quint8* /*src1*/, const quint8* /*src2*/) const {
return 255;
}
......
......@@ -184,7 +184,7 @@ struct SIMDMaskProcessor
random = (1.0 - m_randomness) + m_randomness * float(rand()) / RAND_MAX;
}
alphaValue = quint8( (OPACITY_OPAQUE_U8 - buffer[x]) * random);
alphaValue = quint8( (OPACITY_OPAQUE_U8 - buffer[x]*255) * random);
// avoid computation of random numbers if density is full
if (m_density != 1.0){
......@@ -200,11 +200,8 @@ struct SIMDMaskProcessor
dabPointer += m_pixelSize;
}
} else {
for (int x = 0; x < width; x++) {
alphaValue = quint8( (OPACITY_OPAQUE_U8 - buffer[x]));
m_cs->applyAlphaU8Mask(dabPointer, &alphaValue, 1);
dabPointer += m_pixelSize;
}
m_cs->applyInverseNormedFloatMask(dabPointer, buffer, width);
dabPointer += width*m_pixelSize;
}//endfor x
dabPointer += offset;
}//endfor y
......
......@@ -423,6 +423,18 @@ public:
*/
virtual void applyInverseAlphaU8Mask(quint8 * pixels, const quint8 * alpha, qint32 nPixels) const = 0;
/**
* Applies the specified float alpha mask to the pixels. We assume that there are just
* as many alpha values as pixels but we do not check this; alpha values have to be between 0.0 and 1.0
*/
virtual void applyAlphaNormedFloatMask(quint8 * pixels, const float * alpha, qint32 nPixels) const = 0;
/**
* Applies the inverted specified float alpha mask to the pixels. We assume that there are just
* as many alpha values as pixels but we do not check this; alpha values have to be between 0.0 and 1.0
*/
virtual void applyInverseNormedFloatMask(quint8 * pixels, const float * alpha, qint32 nPixels) const = 0;
/**
* Create an adjustment object for adjusting the brightness and contrast
* transferValues is a 256 bins array with values from 0 to 0xFFFF
......
......@@ -130,6 +130,14 @@ public:
_CSTrait::applyInverseAlphaU8Mask(pixels, alpha, nPixels);
}
virtual void applyAlphaNormedFloatMask(quint8 * pixels, const float * alpha, qint32 nPixels) const {
_CSTrait::applyAlphaNormedFloatMask(pixels, alpha, nPixels);
}
virtual void applyInverseNormedFloatMask(quint8 * pixels, const float * alpha, qint32 nPixels) const {
_CSTrait::applyInverseAlphaNormedFloatMask(pixels, alpha, nPixels);
}
virtual quint8 intensity8(const quint8 * src) const {
QColor c;
const_cast<KoColorSpaceAbstract<_CSTrait> *>(this)->toQColor(src, &c);
......
......@@ -193,6 +193,25 @@ struct KoColorSpaceTrait {
}
}
inline static void applyAlphaNormedFloatMask(quint8 * pixels, const float * alpha, qint32 nPixels) {
if (alpha_pos < 0) return;
for (; nPixels > 0; --nPixels, pixels += pixelSize, ++alpha) {
channels_type valpha = channels_type(KoColorSpaceMathsTraits<channels_type>::unitValue * (*alpha));
channels_type* alphapixel = nativeArray(pixels) + alpha_pos;
*alphapixel = KoColorSpaceMaths<channels_type>::multiply(*alphapixel, valpha);
}
}
inline static void applyInverseAlphaNormedFloatMask(quint8 * pixels, const float * alpha, qint32 nPixels) {
if (alpha_pos < 0) return;
for (; nPixels > 0; --nPixels, pixels += pixelSize, ++alpha) {
channels_type valpha = channels_type(KoColorSpaceMathsTraits<channels_type>::unitValue * (1.0f - *alpha));
channels_type* alphapixel = nativeArray(pixels) + alpha_pos;
*alphapixel = KoColorSpaceMaths<channels_type>::multiply(*alphapixel, valpha);
}
}
};
#include "KoRgbColorSpaceTraits.h"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment