OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkErrorInternals.h" | 8 #include "SkErrorInternals.h" |
9 #include "SkConvolver.h" | 9 #include "SkConvolver.h" |
10 #include "SkBitmapProcState.h" | 10 #include "SkBitmapProcState.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 // resampling an image as it is blitted. Typically these are used only when | 21 // resampling an image as it is blitted. Typically these are used only when |
22 // the image is rotated or has some other complex transformation applied. | 22 // the image is rotated or has some other complex transformation applied. |
23 // Scaled images will usually be rescaled directly before rasterization. | 23 // Scaled images will usually be rescaled directly before rasterization. |
24 | 24 |
25 namespace { | 25 namespace { |
26 | 26 |
27 template <typename Color, typename ColorPacker> | 27 template <typename Color, typename ColorPacker> |
28 void highQualityFilter(ColorPacker pack, const SkBitmapProcState& s, int x, int
y, Color* SK_RESTRICT colors, int count) { | 28 void highQualityFilter(ColorPacker pack, const SkBitmapProcState& s, int x, int
y, Color* SK_RESTRICT colors, int count) { |
29 const int maxX = s.fBitmap->width(); | 29 const int maxX = s.fBitmap->width(); |
30 const int maxY = s.fBitmap->height(); | 30 const int maxY = s.fBitmap->height(); |
| 31 SkAutoTMalloc<SkScalar> xWeights(maxX); |
31 | 32 |
32 while (count-- > 0) { | 33 while (count-- > 0) { |
33 SkPoint srcPt; | 34 SkPoint srcPt; |
34 s.fInvProc(s.fInvMatrix, x + 0.5f, | 35 s.fInvProc(s.fInvMatrix, x + 0.5f, |
35 y + 0.5f, &srcPt); | 36 y + 0.5f, &srcPt); |
36 srcPt.fX -= SK_ScalarHalf; | 37 srcPt.fX -= SK_ScalarHalf; |
37 srcPt.fY -= SK_ScalarHalf; | 38 srcPt.fY -= SK_ScalarHalf; |
38 | 39 |
39 SkScalar weight = 0; | 40 SkScalar weight = 0; |
40 SkScalar fr = 0, fg = 0, fb = 0, fa = 0; | 41 SkScalar fr = 0, fg = 0, fb = 0, fa = 0; |
41 | 42 |
42 int y0 = SkClampMax(SkScalarCeilToInt(srcPt.fY-s.getBitmapFilter()->widt
h()), maxY); | 43 int y0 = SkClampMax(SkScalarCeilToInt(srcPt.fY-s.getBitmapFilter()->widt
h()), maxY); |
43 int y1 = SkClampMax(SkScalarFloorToInt(srcPt.fY+s.getBitmapFilter()->wid
th()+1), maxY); | 44 int y1 = SkClampMax(SkScalarFloorToInt(srcPt.fY+s.getBitmapFilter()->wid
th()+1), maxY); |
44 int x0 = SkClampMax(SkScalarCeilToInt(srcPt.fX-s.getBitmapFilter()->widt
h()), maxX); | 45 int x0 = SkClampMax(SkScalarCeilToInt(srcPt.fX-s.getBitmapFilter()->widt
h()), maxX); |
45 int x1 = SkClampMax(SkScalarFloorToInt(srcPt.fX+s.getBitmapFilter()->wid
th())+1, maxX); | 46 int x1 = SkClampMax(SkScalarFloorToInt(srcPt.fX+s.getBitmapFilter()->wid
th())+1, maxX); |
46 | 47 |
| 48 for (int srcX = x0; srcX < x1 ; srcX++) { |
| 49 // Looking these up once instead of each loop is a ~15% speedup. |
| 50 xWeights[srcX - x0] = s.getBitmapFilter()->lookupScalar((srcPt.fX -
srcX)); |
| 51 } |
| 52 |
47 for (int srcY = y0; srcY < y1; srcY++) { | 53 for (int srcY = y0; srcY < y1; srcY++) { |
48 SkScalar yWeight = s.getBitmapFilter()->lookupScalar((srcPt.fY - src
Y)); | 54 SkScalar yWeight = s.getBitmapFilter()->lookupScalar((srcPt.fY - src
Y)); |
49 | 55 |
50 for (int srcX = x0; srcX < x1 ; srcX++) { | 56 for (int srcX = x0; srcX < x1 ; srcX++) { |
51 SkScalar xWeight = s.getBitmapFilter()->lookupScalar((srcPt.fX -
srcX)); | 57 SkScalar xWeight = xWeights[srcX - x0]; |
52 | 58 |
53 SkScalar combined_weight = SkScalarMul(xWeight, yWeight); | 59 SkScalar combined_weight = SkScalarMul(xWeight, yWeight); |
54 | 60 |
55 SkPMColor c = *s.fBitmap->getAddr32(srcX, srcY); | 61 SkPMColor c = *s.fBitmap->getAddr32(srcX, srcY); |
56 fr += combined_weight * SkGetPackedR32(c); | 62 fr += combined_weight * SkGetPackedR32(c); |
57 fg += combined_weight * SkGetPackedG32(c); | 63 fg += combined_weight * SkGetPackedG32(c); |
58 fb += combined_weight * SkGetPackedB32(c); | 64 fb += combined_weight * SkGetPackedB32(c); |
59 fa += combined_weight * SkGetPackedA32(c); | 65 fa += combined_weight * SkGetPackedA32(c); |
60 weight += combined_weight; | 66 weight += combined_weight; |
61 } | 67 } |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 } | 145 } |
140 | 146 |
141 if (fInvType & SkMatrix::kScale_Mask) { | 147 if (fInvType & SkMatrix::kScale_Mask) { |
142 fShaderProc32 = highQualityFilter32; | 148 fShaderProc32 = highQualityFilter32; |
143 fShaderProc16 = highQualityFilter16; | 149 fShaderProc16 = highQualityFilter16; |
144 return true; | 150 return true; |
145 } else { | 151 } else { |
146 return false; | 152 return false; |
147 } | 153 } |
148 } | 154 } |
OLD | NEW |