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

Unified Diff: src/core/SkBitmapFilter.cpp

Issue 502953004: Improve performance of highQualityFilter (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 4 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/core/SkBitmapFilter.cpp
diff --git a/src/core/SkBitmapFilter.cpp b/src/core/SkBitmapFilter.cpp
index a9c3223fbc731531c88263a189412ea11425a85b..20a05142506c1890e2c4eea964299def656da068 100644
--- a/src/core/SkBitmapFilter.cpp
+++ b/src/core/SkBitmapFilter.cpp
@@ -28,6 +28,7 @@ template <typename Color, typename ColorPacker>
void highQualityFilter(ColorPacker pack, const SkBitmapProcState& s, int x, int y, Color* SK_RESTRICT colors, int count) {
const int maxX = s.fBitmap->width();
const int maxY = s.fBitmap->height();
+ SkAutoTMalloc<SkScalar> xWeights(maxX);
while (count-- > 0) {
SkPoint srcPt;
@@ -44,11 +45,16 @@ void highQualityFilter(ColorPacker pack, const SkBitmapProcState& s, int x, int
int x0 = SkClampMax(SkScalarCeilToInt(srcPt.fX-s.getBitmapFilter()->width()), maxX);
int x1 = SkClampMax(SkScalarFloorToInt(srcPt.fX+s.getBitmapFilter()->width())+1, maxX);
+ for (int srcX = x0; srcX < x1 ; srcX++) {
+ // Looking these up once instead of each loop is a ~15% speedup.
+ xWeights[srcX - x0] = s.getBitmapFilter()->lookupScalar((srcPt.fX - srcX));
+ }
+
for (int srcY = y0; srcY < y1; srcY++) {
SkScalar yWeight = s.getBitmapFilter()->lookupScalar((srcPt.fY - srcY));
for (int srcX = x0; srcX < x1 ; srcX++) {
- SkScalar xWeight = s.getBitmapFilter()->lookupScalar((srcPt.fX - srcX));
+ SkScalar xWeight = xWeights[srcX - x0];
SkScalar combined_weight = SkScalarMul(xWeight, yWeight);
« 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