diff --git a/Tests/test_image_filter.py b/Tests/test_image_filter.py index 75665d20a..6936a84f0 100644 --- a/Tests/test_image_filter.py +++ b/Tests/test_image_filter.py @@ -94,15 +94,15 @@ class TestImageFilter(PillowTestCase): self.assertEqual(rankfilter.size, 1) self.assertEqual(rankfilter.rank, 2) + def test_builtinfilter_p(self): + builtinFilter = ImageFilter.BuiltinFilter() + + self.assertRaises(ValueError, builtinFilter.filter, hopper("P")) + def test_kernel_not_enough_coefficients(self): self.assertRaises(ValueError, lambda: ImageFilter.Kernel((3, 3), (0, 0))) - def test_kernel_filter_p(self): - kernel = ImageFilter.Kernel((2, 2), (0, 0, 0, 0)) - - self.assertRaises(ValueError, kernel.filter, hopper("P")) - def test_consistency_3x3(self): source = Image.open("Tests/images/hopper.bmp") reference = Image.open("Tests/images/hopper_emboss.bmp") diff --git a/src/PIL/ImageFilter.py b/src/PIL/ImageFilter.py index e77349df0..de99e6410 100644 --- a/src/PIL/ImageFilter.py +++ b/src/PIL/ImageFilter.py @@ -33,7 +33,14 @@ class MultibandFilter(Filter): pass -class Kernel(MultibandFilter): +class BuiltinFilter(MultibandFilter): + def filter(self, image): + if image.mode == "P": + raise ValueError("cannot filter palette images") + return image.filter(*self.filterargs) + + +class Kernel(BuiltinFilter): """ Create a convolution kernel. The current version only supports 3x3 and 5x5 integer and floating point kernels. @@ -60,16 +67,6 @@ class Kernel(MultibandFilter): raise ValueError("not enough coefficients in kernel") self.filterargs = size, scale, offset, kernel - def filter(self, image): - if image.mode == "P": - raise ValueError("cannot filter palette images") - return image.filter(*self.filterargs) - - -class BuiltinFilter(Kernel): - def __init__(self): - pass - class RankFilter(Filter): """