mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 01:46:18 +03:00
Merge pull request #3273 from radarhere/imagefilter
Changed Kernel to subclass BuiltinFilter
This commit is contained in:
commit
fda3db6494
|
@ -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")
|
||||
|
|
|
@ -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):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue
Block a user