bool SkMatrixConvolutionImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& source, const Context& ctx, SkBitmap* result, SkIPoint* offset) const { SkBitmap src = source; SkIPoint srcOffset = SkIPoint::Make(0, 0); if (!this->filterInput(0, proxy, source, ctx, &src, &srcOffset)) { return false; } if (src.colorType() != kN32_SkColorType) { return false; } SkIRect bounds; if (!this->applyCropRect(ctx, proxy, src, &srcOffset, &bounds, &src)) { return false; } if (!fConvolveAlpha && !src.isOpaque()) { src = unpremultiplyBitmap(proxy, src); } SkAutoLockPixels alp(src); if (!src.getPixels()) { return false; } SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bounds.height())); if (!device) { return false; } *result = device->accessBitmap(false); SkAutoLockPixels alp_result(*result); offset->fX = bounds.fLeft; offset->fY = bounds.fTop; bounds.offset(-srcOffset); SkIRect interior = SkIRect::MakeXYWH(bounds.left() + fKernelOffset.fX, bounds.top() + fKernelOffset.fY, bounds.width() - fKernelSize.fWidth + 1, bounds.height() - fKernelSize.fHeight + 1); SkIRect top = SkIRect::MakeLTRB(bounds.left(), bounds.top(), bounds.right(), interior.top()); SkIRect bottom = SkIRect::MakeLTRB(bounds.left(), interior.bottom(), bounds.right(), bounds.bottom()); SkIRect left = SkIRect::MakeLTRB(bounds.left(), interior.top(), interior.left(), interior.bottom()); SkIRect right = SkIRect::MakeLTRB(interior.right(), interior.top(), bounds.right(), interior.bottom()); filterBorderPixels(src, result, top, bounds); filterBorderPixels(src, result, left, bounds); filterInteriorPixels(src, result, interior, bounds); filterBorderPixels(src, result, right, bounds); filterBorderPixels(src, result, bottom, bounds); return true; }
bool SkMatrixConvolutionImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& source, const SkMatrix& matrix, SkBitmap* result, SkIPoint* loc) { SkBitmap src = source; if (getInput(0) && !getInput(0)->filterImage(proxy, source, matrix, &src, loc)) { return false; } if (src.config() != SkBitmap::kARGB_8888_Config) { return false; } if (!fConvolveAlpha && !src.isOpaque()) { src = unpremultiplyBitmap(src); } SkAutoLockPixels alp(src); if (!src.getPixels()) { return false; } result->setConfig(src.config(), src.width(), src.height()); result->allocPixels(); SkIRect interior = SkIRect::MakeXYWH(fTarget.fX, fTarget.fY, src.width() - fKernelSize.fWidth + 1, src.height() - fKernelSize.fHeight + 1); SkIRect top = SkIRect::MakeWH(src.width(), fTarget.fY); SkIRect bottom = SkIRect::MakeLTRB(0, interior.bottom(), src.width(), src.height()); SkIRect left = SkIRect::MakeXYWH(0, interior.top(), fTarget.fX, interior.height()); SkIRect right = SkIRect::MakeLTRB(interior.right(), interior.top(), src.width(), interior.bottom()); filterBorderPixels(src, result, top); filterBorderPixels(src, result, left); filterInteriorPixels(src, result, interior); filterBorderPixels(src, result, right); filterBorderPixels(src, result, bottom); return true; }