Commit e6545fdf authored by Dmitry Kazakov's avatar Dmitry Kazakov

Optimize Sharp brushes by 5% more

When Fade is 100% and "Antialias Edges" option is off, there is no need
to calculate vNormFade term. Anyway the result will be +-inf :)
parent 282d2f0c
......@@ -60,19 +60,17 @@ void KisMaskGeneratorBenchmark::benchmarkCircle()
#include "krita_utils.h"
void KisMaskGeneratorBenchmark::benchmarkSIMD()
{
#ifdef HAVE_VC
void benchmarkSIMD(qreal fade) {
const KoColorSpace * cs = KoColorSpaceRegistry::instance()->rgb8();
KisFixedPaintDeviceSP dev = new KisFixedPaintDevice(cs);
dev->setRect(QRect(0, 0, 100, 100));
dev->setRect(QRect(0, 0, 1000, 1000));
dev->initialize();
MaskProcessingData data(dev, cs,
0.0, 1.0,
50, 50, 0);
500, 500, 0);
KisCircleMaskGenerator gen(100, 0.5, 0.5, 0.5, 2, false);
KisCircleMaskGenerator gen(1000, 1.0, fade, fade, 2, false);
KisBrushMaskApplicatorBase *applicator = gen.applicator();
applicator->initializeData(&data);
......@@ -84,7 +82,16 @@ void KisMaskGeneratorBenchmark::benchmarkSIMD()
applicator->process(rc);
}
}
#endif
}
void KisMaskGeneratorBenchmark::benchmarkSIMD_SharpBrush()
{
benchmarkSIMD(1.0);
}
void KisMaskGeneratorBenchmark::benchmarkSIMD_FadedBrush()
{
benchmarkSIMD(0.5);
}
void KisMaskGeneratorBenchmark::benchmarkSquare()
......
......@@ -26,9 +26,10 @@ class KisMaskGeneratorBenchmark : public QObject
Q_OBJECT
private Q_SLOTS:
void benchmarkCircle();
void benchmarkSIMD();
void benchmarkSIMD_SharpBrush();
void benchmarkSIMD_FadedBrush();
void benchmarkSquare();
};
#endif
......@@ -61,6 +61,7 @@ FastRowProcessor::process<Vc::CurrentImplementation::current()>(float* buffer, i
float centerX, float centerY)
{
const bool useSmoothing = d->copyOfAntialiasEdges;
const bool noFading = d->noFading;
float y_ = y - centerY;
float sinay_ = sina * y_;
......@@ -84,7 +85,7 @@ FastRowProcessor::process<Vc::CurrentImplementation::current()>(float* buffer, i
Vc::float_v vTransformedFadeX(d->transformedFadeX);
Vc::float_v vTransformedFadeY(d->transformedFadeY);
Vc::float_v vOne(1.0f);
Vc::float_v vOne(Vc::One);
for (int i=0; i < width; i+= Vc::float_v::Size){
......@@ -98,24 +99,30 @@ FastRowProcessor::process<Vc::CurrentImplementation::current()>(float* buffer, i
if (!outsideMask.isFull()) {
if (useSmoothing) {
xr = Vc::abs(xr) + vOne;
yr = Vc::abs(yr) + vOne;
}
if (noFading) {
Vc::float_v vFade(Vc::Zero);
vFade(outsideMask) = vOne;
vFade.store(bufferPointer, Vc::Aligned);
} else {
if (useSmoothing) {
xr = Vc::abs(xr) + vOne;
yr = Vc::abs(yr) + vOne;
}
Vc::float_v vNormFade = pow2(xr * vTransformedFadeX) + pow2(yr * vTransformedFadeY);
Vc::float_v vNormFade = pow2(xr * vTransformedFadeX) + pow2(yr * vTransformedFadeY);
//255 * n * (normeFade - 1) / (normeFade - n)
Vc::float_v vFade = n * (vNormFade - vOne) / (vNormFade - n);
//255 * n * (normeFade - 1) / (normeFade - n)
Vc::float_v vFade = n * (vNormFade - vOne) / (vNormFade - n);
// Mask in the inner circe of the mask
Vc::float_m mask = vNormFade < vOne;
vFade.setZero(mask);
// Mask in the inner circe of the mask
Vc::float_m mask = vNormFade < vOne;
vFade.setZero(mask);
// Mask out the outer circe of the mask
vFade(outsideMask) = vOne;
// Mask out the outer circe of the mask
vFade(outsideMask) = vOne;
vFade.store(bufferPointer, Vc::Aligned);
vFade.store(bufferPointer, Vc::Aligned);
}
} else {
// Mask out everything outside the circle
vOne.store(bufferPointer, Vc::Aligned);
......
......@@ -70,6 +70,10 @@ void KisCircleMaskGenerator::setScale(qreal scaleX, qreal scaleY)
d->yfadecoef = (verticalFade() == 0) ? 1 : (2.0 / (verticalFade() * effectiveSrcHeight()));
d->transformedFadeX = KisMaskGenerator::softness() * d->xfadecoef;
d->transformedFadeY = KisMaskGenerator::softness() * d->yfadecoef;
d->noFading = !d->copyOfAntialiasEdges &&
qFuzzyCompare(d->xcoef, d->transformedFadeX) &&
qFuzzyCompare(d->ycoef, d->transformedFadeY);
}
KisCircleMaskGenerator::~KisCircleMaskGenerator()
......
......@@ -24,6 +24,7 @@ struct Q_DECL_HIDDEN KisCircleMaskGenerator::Private {
double xfadecoef, yfadecoef;
double transformedFadeX, transformedFadeY;
bool copyOfAntialiasEdges;
bool noFading;
KisBrushMaskApplicatorBase *applicator;
};
......
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