diff options
author | qiankun.miao <qiankun.miao@intel.com> | 2014-08-26 19:06:41 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-08-26 19:06:42 -0700 |
commit | d3f6e893df53fb0cfeefd01a8a49a77c72d742bd (patch) | |
tree | 33035ec717c4d81de7cb633989cb966598b80230 /src/core | |
parent | 2a65a238b0e688356aee09d08f3f8a317359b4d2 (diff) |
Improve performance of highQualityFilter
Move loop invariant caculation out of loop. This gives about 15% speedup
for bitmap_BGRA_8888_A_scale_rotate_bicubic on my desktop i7-3770.
BUG=skia:
R=humper@google.com, mtklein@google.com, reed@google.com
Author: qiankun.miao@intel.com
Review URL: https://codereview.chromium.org/502953004
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/SkBitmapFilter.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/core/SkBitmapFilter.cpp b/src/core/SkBitmapFilter.cpp index a9c3223fbc..20a0514250 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); |