OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 The Android Open Source Project | 2 * Copyright 2011 The Android Open Source Project |
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 "SkBitmap.h" | 8 #include "SkBitmap.h" |
9 #include "SkBlurImageFilter.h" | 9 #include "SkBlurImageFilter.h" |
10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 | 65 |
66 template<BlurDirection srcDirection, BlurDirection dstDirection> | 66 template<BlurDirection srcDirection, BlurDirection dstDirection> |
67 static void boxBlur(const SkPMColor* src, int srcStride, SkPMColor* dst, int ker
nelSize, | 67 static void boxBlur(const SkPMColor* src, int srcStride, SkPMColor* dst, int ker
nelSize, |
68 int leftOffset, int rightOffset, int width, int height) | 68 int leftOffset, int rightOffset, int width, int height) |
69 { | 69 { |
70 int rightBorder = SkMin32(rightOffset + 1, width); | 70 int rightBorder = SkMin32(rightOffset + 1, width); |
71 int srcStrideX = srcDirection == kX ? 1 : srcStride; | 71 int srcStrideX = srcDirection == kX ? 1 : srcStride; |
72 int dstStrideX = dstDirection == kX ? 1 : height; | 72 int dstStrideX = dstDirection == kX ? 1 : height; |
73 int srcStrideY = srcDirection == kX ? srcStride : 1; | 73 int srcStrideY = srcDirection == kX ? srcStride : 1; |
74 int dstStrideY = dstDirection == kX ? width : 1; | 74 int dstStrideY = dstDirection == kX ? width : 1; |
75 #ifndef SK_DISABLE_BLUR_DIVISION_OPTIMIZATION | |
76 uint32_t scale = (1 << 24) / kernelSize; | 75 uint32_t scale = (1 << 24) / kernelSize; |
77 uint32_t half = 1 << 23; | 76 uint32_t half = 1 << 23; |
78 #endif | |
79 for (int y = 0; y < height; ++y) { | 77 for (int y = 0; y < height; ++y) { |
80 int sumA = 0, sumR = 0, sumG = 0, sumB = 0; | 78 int sumA = 0, sumR = 0, sumG = 0, sumB = 0; |
81 const SkPMColor* p = src; | 79 const SkPMColor* p = src; |
82 for (int i = 0; i < rightBorder; ++i) { | 80 for (int i = 0; i < rightBorder; ++i) { |
83 sumA += SkGetPackedA32(*p); | 81 sumA += SkGetPackedA32(*p); |
84 sumR += SkGetPackedR32(*p); | 82 sumR += SkGetPackedR32(*p); |
85 sumG += SkGetPackedG32(*p); | 83 sumG += SkGetPackedG32(*p); |
86 sumB += SkGetPackedB32(*p); | 84 sumB += SkGetPackedB32(*p); |
87 p += srcStrideX; | 85 p += srcStrideX; |
88 } | 86 } |
89 | 87 |
90 const SkPMColor* sptr = src; | 88 const SkPMColor* sptr = src; |
91 SkColor* dptr = dst; | 89 SkColor* dptr = dst; |
92 for (int x = 0; x < width; ++x) { | 90 for (int x = 0; x < width; ++x) { |
93 #ifndef SK_DISABLE_BLUR_DIVISION_OPTIMIZATION | |
94 *dptr = SkPackARGB32((sumA * scale + half) >> 24, | 91 *dptr = SkPackARGB32((sumA * scale + half) >> 24, |
95 (sumR * scale + half) >> 24, | 92 (sumR * scale + half) >> 24, |
96 (sumG * scale + half) >> 24, | 93 (sumG * scale + half) >> 24, |
97 (sumB * scale + half) >> 24); | 94 (sumB * scale + half) >> 24); |
98 #else | |
99 *dptr = SkPackARGB32(sumA / kernelSize, | |
100 sumR / kernelSize, | |
101 sumG / kernelSize, | |
102 sumB / kernelSize); | |
103 #endif | |
104 if (x >= leftOffset) { | 95 if (x >= leftOffset) { |
105 SkColor l = *(sptr - leftOffset * srcStrideX); | 96 SkColor l = *(sptr - leftOffset * srcStrideX); |
106 sumA -= SkGetPackedA32(l); | 97 sumA -= SkGetPackedA32(l); |
107 sumR -= SkGetPackedR32(l); | 98 sumR -= SkGetPackedR32(l); |
108 sumG -= SkGetPackedG32(l); | 99 sumG -= SkGetPackedG32(l); |
109 sumB -= SkGetPackedB32(l); | 100 sumB -= SkGetPackedB32(l); |
110 } | 101 } |
111 if (x + rightOffset + 1 < width) { | 102 if (x + rightOffset + 1 < width) { |
112 SkColor r = *(sptr + (rightOffset + 1) * srcStrideX); | 103 SkColor r = *(sptr + (rightOffset + 1) * srcStrideX); |
113 sumA += SkGetPackedA32(r); | 104 sumA += SkGetPackedA32(r); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 int sw = src.rowBytesAsPixels(); | 186 int sw = src.rowBytesAsPixels(); |
196 SkBoxBlurProc boxBlurX, boxBlurY, boxBlurXY, boxBlurYX; | 187 SkBoxBlurProc boxBlurX, boxBlurY, boxBlurXY, boxBlurYX; |
197 if (!SkBoxBlurGetPlatformProcs(&boxBlurX, &boxBlurY, &boxBlurXY, &boxBlurYX)
) { | 188 if (!SkBoxBlurGetPlatformProcs(&boxBlurX, &boxBlurY, &boxBlurXY, &boxBlurYX)
) { |
198 boxBlurX = boxBlur<kX, kX>; | 189 boxBlurX = boxBlur<kX, kX>; |
199 boxBlurY = boxBlur<kY, kY>; | 190 boxBlurY = boxBlur<kY, kY>; |
200 boxBlurXY = boxBlur<kX, kY>; | 191 boxBlurXY = boxBlur<kX, kY>; |
201 boxBlurYX = boxBlur<kY, kX>; | 192 boxBlurYX = boxBlur<kY, kX>; |
202 } | 193 } |
203 | 194 |
204 if (kernelSizeX > 0 && kernelSizeY > 0) { | 195 if (kernelSizeX > 0 && kernelSizeY > 0) { |
205 #ifndef SK_DISABLE_BLUR_DIVISION_OPTIMIZATION | |
206 boxBlurX(s, sw, t, kernelSizeX, lowOffsetX, highOffsetX, w, h); | 196 boxBlurX(s, sw, t, kernelSizeX, lowOffsetX, highOffsetX, w, h); |
207 boxBlurX(t, w, d, kernelSizeX, highOffsetX, lowOffsetX, w, h); | 197 boxBlurX(t, w, d, kernelSizeX, highOffsetX, lowOffsetX, w, h); |
208 boxBlurXY(d, w, t, kernelSizeX3, highOffsetX, highOffsetX, w, h); | 198 boxBlurXY(d, w, t, kernelSizeX3, highOffsetX, highOffsetX, w, h); |
209 boxBlurX(t, h, d, kernelSizeY, lowOffsetY, highOffsetY, h, w); | 199 boxBlurX(t, h, d, kernelSizeY, lowOffsetY, highOffsetY, h, w); |
210 boxBlurX(d, h, t, kernelSizeY, highOffsetY, lowOffsetY, h, w); | 200 boxBlurX(d, h, t, kernelSizeY, highOffsetY, lowOffsetY, h, w); |
211 boxBlurXY(t, h, d, kernelSizeY3, highOffsetY, highOffsetY, h, w); | 201 boxBlurXY(t, h, d, kernelSizeY3, highOffsetY, highOffsetY, h, w); |
212 #else | |
213 boxBlurX(s, sw, t, kernelSizeX, lowOffsetX, highOffsetX, w, h); | |
214 boxBlurY(t, w, d, kernelSizeY, lowOffsetY, highOffsetY, h, w); | |
215 boxBlurX(d, w, t, kernelSizeX, highOffsetX, lowOffsetX, w, h); | |
216 boxBlurY(t, w, d, kernelSizeY, highOffsetY, lowOffsetY, h, w); | |
217 boxBlurX(d, w, t, kernelSizeX3, highOffsetX, highOffsetX, w, h); | |
218 boxBlurY(t, w, d, kernelSizeY3, highOffsetY, highOffsetY, h, w); | |
219 #endif | |
220 } else if (kernelSizeX > 0) { | 202 } else if (kernelSizeX > 0) { |
221 boxBlurX(s, sw, d, kernelSizeX, lowOffsetX, highOffsetX, w, h); | 203 boxBlurX(s, sw, d, kernelSizeX, lowOffsetX, highOffsetX, w, h); |
222 boxBlurX(d, w, t, kernelSizeX, highOffsetX, lowOffsetX, w, h); | 204 boxBlurX(d, w, t, kernelSizeX, highOffsetX, lowOffsetX, w, h); |
223 boxBlurX(t, w, d, kernelSizeX3, highOffsetX, highOffsetX, w, h); | 205 boxBlurX(t, w, d, kernelSizeX3, highOffsetX, highOffsetX, w, h); |
224 } else if (kernelSizeY > 0) { | 206 } else if (kernelSizeY > 0) { |
225 boxBlurYX(s, sw, d, kernelSizeY, lowOffsetY, highOffsetY, h, w); | 207 boxBlurYX(s, sw, d, kernelSizeY, lowOffsetY, highOffsetY, h, w); |
226 boxBlurX(d, h, t, kernelSizeY, highOffsetY, lowOffsetY, h, w); | 208 boxBlurX(d, h, t, kernelSizeY, highOffsetY, lowOffsetY, h, w); |
227 boxBlurXY(t, h, d, kernelSizeY3, highOffsetY, highOffsetY, h, w); | 209 boxBlurXY(t, h, d, kernelSizeY3, highOffsetY, highOffsetY, h, w); |
228 } | 210 } |
229 offset->fX += srcBounds.fLeft; | 211 offset->fX += srcBounds.fLeft; |
(...skipping 22 matching lines...) Expand all Loading... |
252 fSigma.width(), | 234 fSigma.width(), |
253 fSigma.height())); | 235 fSigma.height())); |
254 offset->fX += rect.fLeft; | 236 offset->fX += rect.fLeft; |
255 offset->fY += rect.fTop; | 237 offset->fY += rect.fTop; |
256 return SkImageFilterUtils::WrapTexture(tex, rect.width(), rect.height(), res
ult); | 238 return SkImageFilterUtils::WrapTexture(tex, rect.width(), rect.height(), res
ult); |
257 #else | 239 #else |
258 SkDEBUGFAIL("Should not call in GPU-less build"); | 240 SkDEBUGFAIL("Should not call in GPU-less build"); |
259 return false; | 241 return false; |
260 #endif | 242 #endif |
261 } | 243 } |
OLD | NEW |