Fix for SkMatrixConvolutionImageFilter with large borders.

Intersect the requested processing rect with the destination
bounds.

R=junov@chromium.org

Review URL: https://codereview.chromium.org/267863004

git-svn-id: http://skia.googlecode.com/svn/trunk@14543 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
senorblanco@chromium.org 2014-05-02 19:13:11 +00:00
parent 82bc432683
commit 8c7372bbe8
2 changed files with 35 additions and 2 deletions

View File

@ -151,9 +151,10 @@ public:
template<class PixelFetcher, bool convolveAlpha>
void SkMatrixConvolutionImageFilter::filterPixels(const SkBitmap& src,
SkBitmap* result,
const SkIRect& rect,
const SkIRect& r,
const SkIRect& bounds) const {
if (rect.isEmpty()) {
SkIRect rect(r);
if (!rect.intersect(bounds)) {
return;
}
for (int y = rect.fTop; y < rect.fBottom; ++y) {

View File

@ -398,6 +398,38 @@ DEF_TEST(ImageFilterMatrixConvolution, reporter) {
canvas.drawRect(rect, paint);
}
DEF_TEST(ImageFilterMatrixConvolutionBorder, reporter) {
// Check that a filter with borders outside the target bounds
// does not crash.
SkScalar kernel[3] = {
0, 0, 0,
};
SkISize kernelSize = SkISize::Make(3, 1);
SkScalar gain = SK_Scalar1, bias = 0;
SkIPoint kernelOffset = SkIPoint::Make(2, 0);
SkAutoTUnref<SkImageFilter> filter(
SkMatrixConvolutionImageFilter::Create(
kernelSize, kernel, gain, bias, kernelOffset,
SkMatrixConvolutionImageFilter::kClamp_TileMode, true));
SkBitmap result;
int width = 10, height = 10;
result.allocN32Pixels(width, height);
SkCanvas canvas(result);
canvas.clear(0);
SkPaint filterPaint;
filterPaint.setImageFilter(filter);
SkRect bounds = SkRect::MakeWH(1, 10);
SkRect rect = SkRect::Make(SkIRect::MakeWH(width, height));
SkPaint rectPaint;
canvas.saveLayer(&bounds, &filterPaint);
canvas.drawRect(rect, rectPaint);
canvas.restore();
}
DEF_TEST(ImageFilterCropRect, reporter) {
SkBitmap temp;
temp.allocN32Pixels(100, 100);