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 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 dstRow[x] = SkUnPreMultiply::PMColorToColor(srcRow[x]); | 245 dstRow[x] = SkUnPreMultiply::PMColorToColor(srcRow[x]); |
246 } | 246 } |
247 } | 247 } |
248 return result; | 248 return result; |
249 } | 249 } |
250 | 250 |
251 bool SkMatrixConvolutionImageFilter::onFilterImage(Proxy* proxy, | 251 bool SkMatrixConvolutionImageFilter::onFilterImage(Proxy* proxy, |
252 const SkBitmap& source, | 252 const SkBitmap& source, |
253 const SkMatrix& matrix, | 253 const SkMatrix& matrix, |
254 SkBitmap* result, | 254 SkBitmap* result, |
255 SkIPoint* loc) { | 255 SkIPoint* offset) { |
256 SkBitmap src = source; | 256 SkBitmap src = source; |
257 if (getInput(0) && !getInput(0)->filterImage(proxy, source, matrix, &src, lo
c)) { | 257 SkIPoint srcOffset = SkIPoint::Make(0, 0); |
| 258 if (getInput(0) && !getInput(0)->filterImage(proxy, source, matrix, &src, &s
rcOffset)) { |
258 return false; | 259 return false; |
259 } | 260 } |
260 | 261 |
261 if (src.config() != SkBitmap::kARGB_8888_Config) { | 262 if (src.config() != SkBitmap::kARGB_8888_Config) { |
262 return false; | 263 return false; |
263 } | 264 } |
264 | 265 |
265 SkIRect bounds; | 266 SkIRect bounds; |
266 src.getBounds(&bounds); | 267 src.getBounds(&bounds); |
| 268 bounds.offset(srcOffset); |
267 if (!this->applyCropRect(&bounds, matrix)) { | 269 if (!this->applyCropRect(&bounds, matrix)) { |
268 return false; | 270 return false; |
269 } | 271 } |
270 | 272 |
271 if (!fConvolveAlpha && !src.isOpaque()) { | 273 if (!fConvolveAlpha && !src.isOpaque()) { |
272 src = unpremultiplyBitmap(src); | 274 src = unpremultiplyBitmap(src); |
273 } | 275 } |
274 | 276 |
275 SkAutoLockPixels alp(src); | 277 SkAutoLockPixels alp(src); |
276 if (!src.getPixels()) { | 278 if (!src.getPixels()) { |
277 return false; | 279 return false; |
278 } | 280 } |
279 | 281 |
280 result->setConfig(src.config(), bounds.width(), bounds.height()); | 282 result->setConfig(src.config(), bounds.width(), bounds.height()); |
281 result->allocPixels(); | 283 result->allocPixels(); |
282 if (!result->getPixels()) { | 284 if (!result->getPixels()) { |
283 return false; | 285 return false; |
284 } | 286 } |
285 | 287 |
| 288 offset->fX = bounds.fLeft; |
| 289 offset->fY = bounds.fTop; |
| 290 bounds.offset(-srcOffset); |
286 SkIRect interior = SkIRect::MakeXYWH(bounds.left() + fTarget.fX, | 291 SkIRect interior = SkIRect::MakeXYWH(bounds.left() + fTarget.fX, |
287 bounds.top() + fTarget.fY, | 292 bounds.top() + fTarget.fY, |
288 bounds.width() - fKernelSize.fWidth + 1
, | 293 bounds.width() - fKernelSize.fWidth + 1
, |
289 bounds.height() - fKernelSize.fHeight +
1); | 294 bounds.height() - fKernelSize.fHeight +
1); |
290 SkIRect top = SkIRect::MakeLTRB(bounds.left(), bounds.top(), bounds.right(),
interior.top()); | 295 SkIRect top = SkIRect::MakeLTRB(bounds.left(), bounds.top(), bounds.right(),
interior.top()); |
291 SkIRect bottom = SkIRect::MakeLTRB(bounds.left(), interior.bottom(), | 296 SkIRect bottom = SkIRect::MakeLTRB(bounds.left(), interior.bottom(), |
292 bounds.right(), bounds.bottom()); | 297 bounds.right(), bounds.bottom()); |
293 SkIRect left = SkIRect::MakeLTRB(bounds.left(), interior.top(), | 298 SkIRect left = SkIRect::MakeLTRB(bounds.left(), interior.top(), |
294 interior.left(), interior.bottom()); | 299 interior.left(), interior.bottom()); |
295 SkIRect right = SkIRect::MakeLTRB(interior.right(), interior.top(), | 300 SkIRect right = SkIRect::MakeLTRB(interior.right(), interior.top(), |
296 bounds.right(), interior.bottom()); | 301 bounds.right(), interior.bottom()); |
297 filterBorderPixels(src, result, top, bounds); | 302 filterBorderPixels(src, result, top, bounds); |
298 filterBorderPixels(src, result, left, bounds); | 303 filterBorderPixels(src, result, left, bounds); |
299 filterInteriorPixels(src, result, interior, bounds); | 304 filterInteriorPixels(src, result, interior, bounds); |
300 filterBorderPixels(src, result, right, bounds); | 305 filterBorderPixels(src, result, right, bounds); |
301 filterBorderPixels(src, result, bottom, bounds); | 306 filterBorderPixels(src, result, bottom, bounds); |
302 loc->fX += bounds.fLeft; | |
303 loc->fY += bounds.fTop; | |
304 return true; | 307 return true; |
305 } | 308 } |
306 | 309 |
307 #if SK_SUPPORT_GPU | 310 #if SK_SUPPORT_GPU |
308 | 311 |
309 /////////////////////////////////////////////////////////////////////////////// | 312 /////////////////////////////////////////////////////////////////////////////// |
310 | 313 |
311 class GrGLMatrixConvolutionEffect; | 314 class GrGLMatrixConvolutionEffect; |
312 | 315 |
313 class GrMatrixConvolutionEffect : public GrSingleTextureEffect { | 316 class GrMatrixConvolutionEffect : public GrSingleTextureEffect { |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
660 fBias, | 663 fBias, |
661 fTarget, | 664 fTarget, |
662 fTileMode, | 665 fTileMode, |
663 fConvolveAlpha); | 666 fConvolveAlpha); |
664 return true; | 667 return true; |
665 } | 668 } |
666 | 669 |
667 /////////////////////////////////////////////////////////////////////////////// | 670 /////////////////////////////////////////////////////////////////////////////// |
668 | 671 |
669 #endif | 672 #endif |
OLD | NEW |