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

Unified Diff: src/effects/SkBlurImageFilter.cpp

Issue 57513002: Change SkBlurImageFilter to use fixed-point division. Yields ~1.8X speedup on (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Updated ignored-tests.txt. Created 7 years, 1 month 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 | « expectations/gm/ignored-tests.txt ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/effects/SkBlurImageFilter.cpp
diff --git a/src/effects/SkBlurImageFilter.cpp b/src/effects/SkBlurImageFilter.cpp
index a820152fb39c6a1f9ed4b31b6af8ee6669957e68..2b823bc98b2b915db6086b87256c3e2e21940d4a 100644
--- a/src/effects/SkBlurImageFilter.cpp
+++ b/src/effects/SkBlurImageFilter.cpp
@@ -44,6 +44,10 @@ static void boxBlurX(const SkBitmap& src, SkBitmap* dst, int kernelSize,
{
int width = bounds.width(), height = bounds.height();
int rightBorder = SkMin32(rightOffset + 1, width);
+#ifndef SK_DISABLE_BLUR_DIVISION_OPTIMIZATION
+ uint32_t scale = (1 << 24) / kernelSize;
+ uint32_t half = 1 << 23;
+#endif
for (int y = 0; y < height; ++y) {
int sumA = 0, sumR = 0, sumG = 0, sumB = 0;
SkPMColor* p = src.getAddr32(bounds.fLeft, y + bounds.fTop);
@@ -58,10 +62,17 @@ static void boxBlurX(const SkBitmap& src, SkBitmap* dst, int kernelSize,
const SkColor* sptr = src.getAddr32(bounds.fLeft, bounds.fTop + y);
SkColor* dptr = dst->getAddr32(0, y);
for (int x = 0; x < width; ++x) {
+#ifndef SK_DISABLE_BLUR_DIVISION_OPTIMIZATION
+ *dptr = SkPackARGB32((sumA * scale + half) >> 24,
+ (sumR * scale + half) >> 24,
+ (sumG * scale + half) >> 24,
+ (sumB * scale + half) >> 24);
+#else
*dptr = SkPackARGB32(sumA / kernelSize,
sumR / kernelSize,
sumG / kernelSize,
sumB / kernelSize);
+#endif
if (x >= leftOffset) {
SkColor l = *(sptr - leftOffset);
sumA -= SkGetPackedA32(l);
@@ -89,6 +100,10 @@ static void boxBlurY(const SkBitmap& src, SkBitmap* dst, int kernelSize,
int bottomBorder = SkMin32(bottomOffset + 1, height);
int srcStride = src.rowBytesAsPixels();
int dstStride = dst->rowBytesAsPixels();
+#ifndef SK_DISABLE_BLUR_DIVISION_OPTIMIZATION
+ uint32_t scale = (1 << 24) / kernelSize;
+ uint32_t half = 1 << 23;
+#endif
for (int x = 0; x < width; ++x) {
int sumA = 0, sumR = 0, sumG = 0, sumB = 0;
SkColor* p = src.getAddr32(bounds.fLeft + x, bounds.fTop);
@@ -103,10 +118,17 @@ static void boxBlurY(const SkBitmap& src, SkBitmap* dst, int kernelSize,
const SkColor* sptr = src.getAddr32(bounds.fLeft + x, bounds.fTop);
SkColor* dptr = dst->getAddr32(x, 0);
for (int y = 0; y < height; ++y) {
+#ifndef SK_DISABLE_BLUR_DIVISION_OPTIMIZATION
+ *dptr = SkPackARGB32((sumA * scale + half) >> 24,
+ (sumR * scale + half) >> 24,
+ (sumG * scale + half) >> 24,
+ (sumB * scale + half) >> 24);
+#else
*dptr = SkPackARGB32(sumA / kernelSize,
sumR / kernelSize,
sumG / kernelSize,
sumB / kernelSize);
+#endif
if (y >= topOffset) {
SkColor l = *(sptr - topOffset * srcStride);
sumA -= SkGetPackedA32(l);
« no previous file with comments | « expectations/gm/ignored-tests.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698