Add a fix for a spurious assert in SkMatrixConvolutionImageFilter.
When matrix convolution processes border pixels with zero width, it
asserts in getAddr32() with an invalid x coordinate. The assert is
harmless, since the returned pointer is never accessed (the next line
is a loop from left to right, which does nothing, since left == right).
However, the fix is simple: early out on an empty rect before entering
the outer loop.
R=sugoi@chromium.org
Review URL: https://codereview.chromium.org/265693005
git-svn-id: http://skia.googlecode.com/svn/trunk@14497 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/effects/SkMatrixConvolutionImageFilter.cpp b/src/effects/SkMatrixConvolutionImageFilter.cpp
index 3c9fc87..be1dcb4 100644
--- a/src/effects/SkMatrixConvolutionImageFilter.cpp
+++ b/src/effects/SkMatrixConvolutionImageFilter.cpp
@@ -153,6 +153,9 @@
SkBitmap* result,
const SkIRect& rect,
const SkIRect& bounds) const {
+ if (rect.isEmpty()) {
+ return;
+ }
for (int y = rect.fTop; y < rect.fBottom; ++y) {
SkPMColor* dptr = result->getAddr32(rect.fLeft - bounds.fLeft, y - bounds.fTop);
for (int x = rect.fLeft; x < rect.fRight; ++x) {
diff --git a/tests/ImageFilterTest.cpp b/tests/ImageFilterTest.cpp
index dac948e..ffefb2c 100644
--- a/tests/ImageFilterTest.cpp
+++ b/tests/ImageFilterTest.cpp
@@ -372,6 +372,32 @@
}
}
+DEF_TEST(ImageFilterMatrixConvolution, reporter) {
+ // Check that a 1x3 filter does not cause a spurious assert.
+ SkScalar kernel[3] = {
+ SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1),
+ };
+ SkISize kernelSize = SkISize::Make(1, 3);
+ SkScalar gain = SK_Scalar1, bias = 0;
+ SkIPoint kernelOffset = SkIPoint::Make(0, 0);
+
+ SkAutoTUnref<SkImageFilter> filter(
+ SkMatrixConvolutionImageFilter::Create(
+ kernelSize, kernel, gain, bias, kernelOffset,
+ SkMatrixConvolutionImageFilter::kRepeat_TileMode, false));
+
+ SkBitmap result;
+ int width = 16, height = 16;
+ result.allocN32Pixels(width, height);
+ SkCanvas canvas(result);
+ canvas.clear(0);
+
+ SkPaint paint;
+ paint.setImageFilter(filter);
+ SkRect rect = SkRect::Make(SkIRect::MakeWH(width, height));
+ canvas.drawRect(rect, paint);
+}
+
DEF_TEST(ImageFilterCropRect, reporter) {
SkBitmap temp;
temp.allocN32Pixels(100, 100);