Skip to content

Commit 7a69fb1

Browse files
authored
Merge pull request #1 from radarhere/fixresample
Simplified code
2 parents b3b39f7 + d4bf19f commit 7a69fb1

1 file changed

Lines changed: 14 additions & 20 deletions

File tree

Tests/test_image_resample.py

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -633,31 +633,25 @@ class TestCoreResample16bpc:
633633
def test_resampling_clamp(self) -> None:
634634
# Lanczos weighting during downsampling can push accumulated float sums
635635
# above 65535. These must be clamped to 65535, not corrupted byte-by-byte.
636+
ims = {}
636637
width, height = 100, 10
637-
# I;16 image: left half = 0, right half = 65535
638-
im_16 = Image.new("I;16", (width, height))
639-
for y in range(height):
640-
for x in range(width // 2, width):
641-
im_16.putpixel((x, y), 65535)
642-
# F image: same values as float reference
643-
im_f = Image.new("F", (width, height))
644-
for y in range(height):
645-
for x in range(width // 2, width):
646-
im_f.putpixel((x, y), 65535.0)
638+
for mode in ("I;16", "F"):
639+
# Left half = 0, right half = 65535
640+
im = Image.new(mode, (width, height))
641+
for y in range(height):
642+
for x in range(width // 2, width):
643+
im.putpixel((x, y), 65535)
647644

648-
# 5x downsampling with Lanczos creates ~8.7% overshoot at the step edge
649-
result_16 = im_16.resize((20, height), Image.Resampling.LANCZOS)
650-
result_f = im_f.resize((20, height), Image.Resampling.LANCZOS)
645+
# 5x downsampling with Lanczos creates ~8.7% overshoot at the step edge
646+
ims[mode] = im.resize((20, height), Image.Resampling.LANCZOS)
651647

652-
px_16 = result_16.load()
653-
px_f = result_f.load()
654-
assert px_16 is not None
655-
assert px_f is not None
656648
for y in range(height):
657649
for x in range(20):
658-
v = px_f[x, y]
650+
v = ims["F"].getpixel((x, y))
659651
assert isinstance(v, float)
660652
expected = max(0, min(65535, round(v)))
653+
654+
value = ims["I;16"].getpixel((x, y))
661655
assert (
662-
px_16[x, y] == expected
663-
), f"Pixel ({x}, {y}): expected {expected}, got {px_16[x, y]}"
656+
value == expected
657+
), f"Pixel ({x}, {y}): expected {expected}, got {value}"

0 commit comments

Comments
 (0)