mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-08-26 07:04:45 +03:00
Typing: ImageFilter Image.filter.
Also renamed filter parameter to not shadow builtin
This commit is contained in:
parent
6e79536e09
commit
00fef4b5f5
|
@ -1176,7 +1176,7 @@ class Image(object):
|
||||||
self.load()
|
self.load()
|
||||||
return self._new(self.im.expand(xmargin, ymargin, 0))
|
return self._new(self.im.expand(xmargin, ymargin, 0))
|
||||||
|
|
||||||
def filter(self, filter):
|
def filter(self, kernel):
|
||||||
# type: (Union[Filter, Callable[[], Filter]]) -> Image
|
# type: (Union[Filter, Callable[[], Filter]]) -> Image
|
||||||
"""
|
"""
|
||||||
Filters this image using the given filter. For a list of
|
Filters this image using the given filter. For a list of
|
||||||
|
@ -1189,19 +1189,21 @@ class Image(object):
|
||||||
|
|
||||||
self.load()
|
self.load()
|
||||||
|
|
||||||
if isinstance(filter, collections.Callable):
|
if callable(kernel):
|
||||||
filter = filter()
|
image_filter = kernel() # type: Filter
|
||||||
if not hasattr(filter, "filter"):
|
else:
|
||||||
|
image_filter = kernel
|
||||||
|
if not hasattr(image_filter, "filter"):
|
||||||
raise TypeError("filter argument should be ImageFilter.Filter " +
|
raise TypeError("filter argument should be ImageFilter.Filter " +
|
||||||
"instance or class")
|
"instance or class")
|
||||||
|
|
||||||
multiband = isinstance(filter, ImageFilter.MultibandFilter)
|
multiband = isinstance(image_filter, ImageFilter.MultibandFilter)
|
||||||
if self.im.bands == 1 or multiband:
|
if self.im.bands == 1 or multiband:
|
||||||
return self._new(filter.filter(self.im))
|
return self._new(image_filter.filter(self.im))
|
||||||
|
|
||||||
ims = []
|
ims = []
|
||||||
for c in range(self.im.bands):
|
for c in range(self.im.bands):
|
||||||
ims.append(self._new(filter.filter(self.im.getband(c))))
|
ims.append(self._new(image_filter.filter(self.im.getband(c))))
|
||||||
return merge(self.mode, ims)
|
return merge(self.mode, ims)
|
||||||
|
|
||||||
def getbands(self):
|
def getbands(self):
|
||||||
|
|
|
@ -19,8 +19,8 @@ import functools
|
||||||
|
|
||||||
|
|
||||||
class Filter(object):
|
class Filter(object):
|
||||||
pass
|
def filter(self, image):
|
||||||
|
return image.im
|
||||||
|
|
||||||
class MultibandFilter(Filter):
|
class MultibandFilter(Filter):
|
||||||
pass
|
pass
|
||||||
|
|
Loading…
Reference in New Issue
Block a user