Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(113)

Unified Diff: src/effects/SkMatrixConvolutionImageFilter.cpp

Issue 1886553002: quick hackup of SkNx SkMatrixConvolutionImageFilter (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/effects/SkMatrixConvolutionImageFilter.cpp
diff --git a/src/effects/SkMatrixConvolutionImageFilter.cpp b/src/effects/SkMatrixConvolutionImageFilter.cpp
index f5d9a3f7d220e2fd01b6a964334be0799c4b7720..870ef159581160d5b928d9709935740cfc0a6bdd 100644
--- a/src/effects/SkMatrixConvolutionImageFilter.cpp
+++ b/src/effects/SkMatrixConvolutionImageFilter.cpp
@@ -8,6 +8,7 @@
#include "SkMatrixConvolutionImageFilter.h"
#include "SkBitmap.h"
#include "SkColorPriv.h"
+#include "SkNx.h"
#include "SkReadBuffer.h"
#include "SkSpecialImage.h"
#include "SkSpecialSurface.h"
@@ -174,7 +175,7 @@ void SkMatrixConvolutionImageFilter::filterPixels(const SkBitmap& src,
for (int y = rect.fTop; y < rect.fBottom; ++y) {
SkPMColor* dptr = result->getAddr32(rect.fLeft - bounds.fLeft, y - bounds.fTop);
for (int x = rect.fLeft; x < rect.fRight; ++x) {
- SkScalar sumA = 0, sumR = 0, sumG = 0, sumB = 0;
+ Sk4s sum = 0;
for (int cy = 0; cy < fKernelSize.fHeight; cy++) {
for (int cx = 0; cx < fKernelSize.fWidth; cx++) {
SkPMColor s = PixelFetcher::fetch(src,
@@ -182,26 +183,19 @@ void SkMatrixConvolutionImageFilter::filterPixels(const SkBitmap& src,
y + cy - fKernelOffset.fY,
bounds);
SkScalar k = fKernel[cy * fKernelSize.fWidth + cx];
- if (convolveAlpha) {
- sumA += SkScalarMul(SkIntToScalar(SkGetPackedA32(s)), k);
- }
- sumR += SkScalarMul(SkIntToScalar(SkGetPackedR32(s)), k);
- sumG += SkScalarMul(SkIntToScalar(SkGetPackedG32(s)), k);
- sumB += SkScalarMul(SkIntToScalar(SkGetPackedB32(s)), k);
+
+ sum += k * SkNx_cast<SkScalar>(Sk4b::Load(&s));
}
}
- int a = convolveAlpha
- ? SkClampMax(SkScalarFloorToInt(SkScalarMul(sumA, fGain) + fBias), 255)
- : 255;
- int r = SkClampMax(SkScalarFloorToInt(SkScalarMul(sumR, fGain) + fBias), a);
- int g = SkClampMax(SkScalarFloorToInt(SkScalarMul(sumG, fGain) + fBias), a);
- int b = SkClampMax(SkScalarFloorToInt(SkScalarMul(sumB, fGain) + fBias), a);
- if (!convolveAlpha) {
- a = SkGetPackedA32(PixelFetcher::fetch(src, x, y, bounds));
- *dptr++ = SkPreMultiplyARGB(a, r, g, b);
+ Sk4s d = Sk4s::Max(0, Sk4s::Min(sum * fGain + fBias, 255.0f));
+
+ if (convolveAlpha) {
+ d = Sk4s::Min(d, d[3]);
} else {
- *dptr++ = SkPackARGB32(a, r, g, b);
+ SkScalar a01 = (1/255.0f) * SkGetPackedA32(PixelFetcher::fetch(src, x, y, bounds));
+ d = Sk4s{d[0],d[1],d[2], 255} * a01;
}
+ SkNx_cast<uint8_t>(d).store(dptr++);
}
}
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698