mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-04-05 09:54:13 +03:00
Merge pull request #6874 from hugovk/invalid-box-blur-filter
Raise ValueError for BoxBlur filter with negative radius
This commit is contained in:
commit
eb89e3a2b1
|
@ -24,6 +24,7 @@ from .helper import assert_image_equal, hopper
|
|||
ImageFilter.ModeFilter,
|
||||
ImageFilter.GaussianBlur,
|
||||
ImageFilter.GaussianBlur(5),
|
||||
ImageFilter.BoxBlur(0),
|
||||
ImageFilter.BoxBlur(5),
|
||||
ImageFilter.UnsharpMask,
|
||||
ImageFilter.UnsharpMask(10),
|
||||
|
@ -173,3 +174,14 @@ def test_consistency_5x5(mode):
|
|||
Image.merge(mode, source[: len(mode)]).filter(kernel),
|
||||
Image.merge(mode, reference[: len(mode)]),
|
||||
)
|
||||
|
||||
|
||||
def test_invalid_box_blur_filter():
|
||||
with pytest.raises(ValueError):
|
||||
ImageFilter.BoxBlur(-2)
|
||||
|
||||
im = hopper()
|
||||
box_blur_filter = ImageFilter.BoxBlur(2)
|
||||
box_blur_filter.radius = -2
|
||||
with pytest.raises(ValueError):
|
||||
im.filter(box_blur_filter)
|
||||
|
|
|
@ -183,6 +183,9 @@ class BoxBlur(MultibandFilter):
|
|||
name = "BoxBlur"
|
||||
|
||||
def __init__(self, radius):
|
||||
if radius < 0:
|
||||
msg = "radius must be >= 0"
|
||||
raise ValueError(msg)
|
||||
self.radius = radius
|
||||
|
||||
def filter(self, image):
|
||||
|
|
|
@ -237,6 +237,9 @@ ImagingBoxBlur(Imaging imOut, Imaging imIn, float radius, int n) {
|
|||
if (n < 1) {
|
||||
return ImagingError_ValueError("number of passes must be greater than zero");
|
||||
}
|
||||
if (radius < 0) {
|
||||
return ImagingError_ValueError("radius must be >= 0");
|
||||
}
|
||||
|
||||
if (strcmp(imIn->mode, imOut->mode) || imIn->type != imOut->type ||
|
||||
imIn->bands != imOut->bands || imIn->xsize != imOut->xsize ||
|
||||
|
|
Loading…
Reference in New Issue
Block a user