Skip to content

Correct byte order when resampling I;16B and I;16N images - #10286

Merged
radarhere merged 2 commits into
python-pillow:mainfrom
mkantautas:fix/i16b-resample
Oct 23, 2026
Merged

radarhere merged 2 commits into
python-pillow:mainfrom
mkantautas:fix/i16b-resample

Conversation

@mkantautas

Copy link
Copy Markdown
Contributor

Changes proposed in this pull request:

  • On little-endian systems, resize() read and wrote I;16B and I;16N pixels in the wrong byte order when using a filter other than NEAREST. Since Support all resampling filters when resizing I;16* images #8422, _ImagingResampleHorizontal_16bpc() and _ImagingResampleVertical_16bpc() have treated I;16N as big-endian and I;16B as little-endian. They now use the same check as BoxBlur.c, Filter.c and Draw.c.
  • Added a test that resizes I;16L, I;16B and I;16N images horizontally and vertically, and compares the values with the same data resized as I;16.
from PIL import Image

im = Image.new("I", (4, 1))
im.putdata([1000, 2000, 3000, 4000])
for mode in ("I;16", "I;16B"):
    resized = im.convert(mode).resize((2, 1), Image.Resampling.BILINEAR)
    print(mode, list(resized.convert("I").get_flattened_data()))

On main, this prints [1714, 3286] for I;16 and [57814, 12721] for I;16B. Big-endian 16-bit grayscale TIFF files open as I;16B, so resizing them with the default filter is affected.

@radarhere
radarhere enabled auto-merge (squash) October 23, 2026 00:19
@radarhere
radarhere merged commit 4315b49 into python-pillow:main Oct 23, 2026
14 of 61 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants