Skip to content

Commit d33270a

Browse files
committed
Set default resize sampling for I;16* images to BICUBIC
1 parent 04a00d2 commit d33270a

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

Tests/test_image_resize.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -315,14 +315,14 @@ def test_transposed(self) -> None:
315315
im = im.resize((64, 64))
316316
assert im.size == (64, 64)
317317

318-
@pytest.mark.parametrize("mode", ("L", "RGB", "I", "F"))
318+
@pytest.mark.parametrize(
319+
"mode", ("L", "RGB", "I", "I;16", "I;16L", "I;16B", "I;16N", "F")
320+
)
319321
def test_default_filter_bicubic(self, mode: str) -> None:
320322
im = hopper(mode)
321323
assert im.resize((20, 20), Image.Resampling.BICUBIC) == im.resize((20, 20))
322324

323-
@pytest.mark.parametrize(
324-
"mode", ("1", "P", "I;16", "I;16L", "I;16B", "BGR;15", "BGR;16")
325-
)
325+
@pytest.mark.parametrize("mode", ("1", "P", "BGR;15", "BGR;16"))
326326
def test_default_filter_nearest(self, mode: str) -> None:
327327
im = hopper(mode)
328328
assert im.resize((20, 20), Image.Resampling.NEAREST) == im.resize((20, 20))

docs/releasenotes/11.0.0.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,11 @@ Specific WebP Feature Checks
119119
API Changes
120120
===========
121121

122-
TODO
123-
^^^^
122+
Default resampling filter for I;16* image modes
123+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
124124

125-
TODO
125+
The default resampling filter for I;16, I;16L, I;16B and I;16N has been changed from
126+
``Image.NEAREST`` to ``Image.BICUBIC``, to match the majority of modes.
126127

127128
API Additions
128129
=============

src/PIL/Image.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2278,8 +2278,8 @@ def resize(
22782278
:py:data:`Resampling.BILINEAR`, :py:data:`Resampling.HAMMING`,
22792279
:py:data:`Resampling.BICUBIC` or :py:data:`Resampling.LANCZOS`.
22802280
If the image has mode "1" or "P", it is always set to
2281-
:py:data:`Resampling.NEAREST`. If the image mode specifies a number
2282-
of bits, such as "I;16", then the default filter is
2281+
:py:data:`Resampling.NEAREST`. If the image mode is "BGR;15",
2282+
"BGR;16" or "BGR;24", then the default filter is
22832283
:py:data:`Resampling.NEAREST`. Otherwise, the default filter is
22842284
:py:data:`Resampling.BICUBIC`. See: :ref:`concept-filters`.
22852285
:param box: An optional 4-tuple of floats providing
@@ -2302,8 +2302,8 @@ def resize(
23022302
"""
23032303

23042304
if resample is None:
2305-
type_special = ";" in self.mode
2306-
resample = Resampling.NEAREST if type_special else Resampling.BICUBIC
2305+
bgr = self.mode.startswith("BGR;")
2306+
resample = Resampling.NEAREST if bgr else Resampling.BICUBIC
23072307
elif resample not in (
23082308
Resampling.NEAREST,
23092309
Resampling.BILINEAR,

0 commit comments

Comments
 (0)