Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For special image modes, revert default resize resampling to NEAREST #5411

Merged
merged 1 commit into from
Apr 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Tests/test_image_resize.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,7 @@ def test_default_filter(self):
for mode in "1", "P":
im = hopper(mode)
assert im.resize((20, 20), Image.NEAREST) == im.resize((20, 20))

for mode in "I;16", "I;16L", "I;16B", "BGR;15", "BGR;16":
im = hopper(mode)
assert im.resize((20, 20), Image.NEAREST) == im.resize((20, 20))
15 changes: 10 additions & 5 deletions src/PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -1849,7 +1849,7 @@ def _get_safe_box(self, size, resample, box):
min(self.size[1], math.ceil(box[3] + support_y)),
)

def resize(self, size, resample=BICUBIC, box=None, reducing_gap=None):
def resize(self, size, resample=None, box=None, reducing_gap=None):
"""
Returns a resized copy of this image.

Expand All @@ -1859,9 +1859,11 @@ def resize(self, size, resample=BICUBIC, box=None, reducing_gap=None):
one of :py:data:`PIL.Image.NEAREST`, :py:data:`PIL.Image.BOX`,
:py:data:`PIL.Image.BILINEAR`, :py:data:`PIL.Image.HAMMING`,
:py:data:`PIL.Image.BICUBIC` or :py:data:`PIL.Image.LANCZOS`.
Default filter is :py:data:`PIL.Image.BICUBIC`.
If the image has mode "1" or "P", it is
always set to :py:data:`PIL.Image.NEAREST`.
If the image has mode "1" or "P", it is always set to
:py:data:`PIL.Image.NEAREST`.
If the image mode specifies a number of bits, such as "I;16", then the
default filter is :py:data:`PIL.Image.NEAREST`.
Otherwise, the default filter is :py:data:`PIL.Image.BICUBIC`.
See: :ref:`concept-filters`.
:param box: An optional 4-tuple of floats providing
the source image region to be scaled.
Expand All @@ -1882,7 +1884,10 @@ def resize(self, size, resample=BICUBIC, box=None, reducing_gap=None):
:returns: An :py:class:`~PIL.Image.Image` object.
"""

if resample not in (NEAREST, BILINEAR, BICUBIC, LANCZOS, BOX, HAMMING):
if resample is None:
type_special = ";" in self.mode
resample = NEAREST if type_special else BICUBIC
elif resample not in (NEAREST, BILINEAR, BICUBIC, LANCZOS, BOX, HAMMING):
message = f"Unknown resampling filter ({resample})."

filters = [
Expand Down