Raise ValueError for BoxBlur filter with negative radius

This commit is contained in:
Hugo van Kemenade 2023-01-09 19:04:55 +02:00
parent 50f7888e3a
commit 08c7b17e23
2 changed files with 9 additions and 0 deletions

View File

@ -24,6 +24,7 @@ from .helper import assert_image_equal, hopper
ImageFilter.ModeFilter, ImageFilter.ModeFilter,
ImageFilter.GaussianBlur, ImageFilter.GaussianBlur,
ImageFilter.GaussianBlur(5), ImageFilter.GaussianBlur(5),
ImageFilter.BoxBlur(0),
ImageFilter.BoxBlur(5), ImageFilter.BoxBlur(5),
ImageFilter.UnsharpMask, ImageFilter.UnsharpMask,
ImageFilter.UnsharpMask(10), ImageFilter.UnsharpMask(10),
@ -173,3 +174,8 @@ def test_consistency_5x5(mode):
Image.merge(mode, source[: len(mode)]).filter(kernel), Image.merge(mode, source[: len(mode)]).filter(kernel),
Image.merge(mode, reference[: len(mode)]), Image.merge(mode, reference[: len(mode)]),
) )
def test_invalid_box_blur_filter():
with pytest.raises(ValueError):
ImageFilter.BoxBlur(-2)

View File

@ -183,6 +183,9 @@ class BoxBlur(MultibandFilter):
name = "BoxBlur" name = "BoxBlur"
def __init__(self, radius): def __init__(self, radius):
if radius < 0:
msg = "radius must be >= 0"
raise ValueError(msg)
self.radius = radius self.radius = radius
def filter(self, image): def filter(self, image):