OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 The Android Open Source Project | 2 * Copyright 2012 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 "SkMatrixConvolutionImageFilter.h" | 8 #include "SkMatrixConvolutionImageFilter.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 } else { | 145 } else { |
146 return *src.getAddr32(x, y); | 146 return *src.getAddr32(x, y); |
147 } | 147 } |
148 } | 148 } |
149 }; | 149 }; |
150 | 150 |
151 template<class PixelFetcher, bool convolveAlpha> | 151 template<class PixelFetcher, bool convolveAlpha> |
152 void SkMatrixConvolutionImageFilter::filterPixels(const SkBitmap& src, | 152 void SkMatrixConvolutionImageFilter::filterPixels(const SkBitmap& src, |
153 SkBitmap* result, | 153 SkBitmap* result, |
154 const SkIRect& rect, | 154 const SkIRect& rect, |
155 const SkIRect& bounds) { | 155 const SkIRect& bounds) const { |
156 for (int y = rect.fTop; y < rect.fBottom; ++y) { | 156 for (int y = rect.fTop; y < rect.fBottom; ++y) { |
157 SkPMColor* dptr = result->getAddr32(rect.fLeft - bounds.fLeft, y - bound
s.fTop); | 157 SkPMColor* dptr = result->getAddr32(rect.fLeft - bounds.fLeft, y - bound
s.fTop); |
158 for (int x = rect.fLeft; x < rect.fRight; ++x) { | 158 for (int x = rect.fLeft; x < rect.fRight; ++x) { |
159 SkScalar sumA = 0, sumR = 0, sumG = 0, sumB = 0; | 159 SkScalar sumA = 0, sumR = 0, sumG = 0, sumB = 0; |
160 for (int cy = 0; cy < fKernelSize.fHeight; cy++) { | 160 for (int cy = 0; cy < fKernelSize.fHeight; cy++) { |
161 for (int cx = 0; cx < fKernelSize.fWidth; cx++) { | 161 for (int cx = 0; cx < fKernelSize.fWidth; cx++) { |
162 SkPMColor s = PixelFetcher::fetch(src, | 162 SkPMColor s = PixelFetcher::fetch(src, |
163 x + cx - fTarget.fX, | 163 x + cx - fTarget.fX, |
164 y + cy - fTarget.fY, | 164 y + cy - fTarget.fY, |
165 bounds); | 165 bounds); |
(...skipping 19 matching lines...) Expand all Loading... |
185 *dptr++ = SkPackARGB32(a, r, g, b); | 185 *dptr++ = SkPackARGB32(a, r, g, b); |
186 } | 186 } |
187 } | 187 } |
188 } | 188 } |
189 } | 189 } |
190 | 190 |
191 template<class PixelFetcher> | 191 template<class PixelFetcher> |
192 void SkMatrixConvolutionImageFilter::filterPixels(const SkBitmap& src, | 192 void SkMatrixConvolutionImageFilter::filterPixels(const SkBitmap& src, |
193 SkBitmap* result, | 193 SkBitmap* result, |
194 const SkIRect& rect, | 194 const SkIRect& rect, |
195 const SkIRect& bounds) { | 195 const SkIRect& bounds) const { |
196 if (fConvolveAlpha) { | 196 if (fConvolveAlpha) { |
197 filterPixels<PixelFetcher, true>(src, result, rect, bounds); | 197 filterPixels<PixelFetcher, true>(src, result, rect, bounds); |
198 } else { | 198 } else { |
199 filterPixels<PixelFetcher, false>(src, result, rect, bounds); | 199 filterPixels<PixelFetcher, false>(src, result, rect, bounds); |
200 } | 200 } |
201 } | 201 } |
202 | 202 |
203 void SkMatrixConvolutionImageFilter::filterInteriorPixels(const SkBitmap& src, | 203 void SkMatrixConvolutionImageFilter::filterInteriorPixels(const SkBitmap& src, |
204 SkBitmap* result, | 204 SkBitmap* result, |
205 const SkIRect& rect, | 205 const SkIRect& rect, |
206 const SkIRect& bounds)
{ | 206 const SkIRect& bounds)
const { |
207 filterPixels<UncheckedPixelFetcher>(src, result, rect, bounds); | 207 filterPixels<UncheckedPixelFetcher>(src, result, rect, bounds); |
208 } | 208 } |
209 | 209 |
210 void SkMatrixConvolutionImageFilter::filterBorderPixels(const SkBitmap& src, | 210 void SkMatrixConvolutionImageFilter::filterBorderPixels(const SkBitmap& src, |
211 SkBitmap* result, | 211 SkBitmap* result, |
212 const SkIRect& rect, | 212 const SkIRect& rect, |
213 const SkIRect& bounds) { | 213 const SkIRect& bounds) c
onst { |
214 switch (fTileMode) { | 214 switch (fTileMode) { |
215 case kClamp_TileMode: | 215 case kClamp_TileMode: |
216 filterPixels<ClampPixelFetcher>(src, result, rect, bounds); | 216 filterPixels<ClampPixelFetcher>(src, result, rect, bounds); |
217 break; | 217 break; |
218 case kRepeat_TileMode: | 218 case kRepeat_TileMode: |
219 filterPixels<RepeatPixelFetcher>(src, result, rect, bounds); | 219 filterPixels<RepeatPixelFetcher>(src, result, rect, bounds); |
220 break; | 220 break; |
221 case kClampToBlack_TileMode: | 221 case kClampToBlack_TileMode: |
222 filterPixels<ClampToBlackPixelFetcher>(src, result, rect, bounds); | 222 filterPixels<ClampToBlackPixelFetcher>(src, result, rect, bounds); |
223 break; | 223 break; |
(...skipping 22 matching lines...) Expand all Loading... |
246 dstRow[x] = SkUnPreMultiply::PMColorToColor(srcRow[x]); | 246 dstRow[x] = SkUnPreMultiply::PMColorToColor(srcRow[x]); |
247 } | 247 } |
248 } | 248 } |
249 return result; | 249 return result; |
250 } | 250 } |
251 | 251 |
252 bool SkMatrixConvolutionImageFilter::onFilterImage(Proxy* proxy, | 252 bool SkMatrixConvolutionImageFilter::onFilterImage(Proxy* proxy, |
253 const SkBitmap& source, | 253 const SkBitmap& source, |
254 const SkMatrix& matrix, | 254 const SkMatrix& matrix, |
255 SkBitmap* result, | 255 SkBitmap* result, |
256 SkIPoint* offset) { | 256 SkIPoint* offset) const { |
257 SkBitmap src = source; | 257 SkBitmap src = source; |
258 SkIPoint srcOffset = SkIPoint::Make(0, 0); | 258 SkIPoint srcOffset = SkIPoint::Make(0, 0); |
259 if (getInput(0) && !getInput(0)->filterImage(proxy, source, matrix, &src, &s
rcOffset)) { | 259 if (getInput(0) && !getInput(0)->filterImage(proxy, source, matrix, &src, &s
rcOffset)) { |
260 return false; | 260 return false; |
261 } | 261 } |
262 | 262 |
263 if (src.config() != SkBitmap::kARGB_8888_Config) { | 263 if (src.config() != SkBitmap::kARGB_8888_Config) { |
264 return false; | 264 return false; |
265 } | 265 } |
266 | 266 |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
664 fBias, | 664 fBias, |
665 fTarget, | 665 fTarget, |
666 fTileMode, | 666 fTileMode, |
667 fConvolveAlpha); | 667 fConvolveAlpha); |
668 return true; | 668 return true; |
669 } | 669 } |
670 | 670 |
671 /////////////////////////////////////////////////////////////////////////////// | 671 /////////////////////////////////////////////////////////////////////////////// |
672 | 672 |
673 #endif | 673 #endif |
OLD | NEW |