From e098481279477c0091d7947d589276afd587983d Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Thu, 10 Feb 2022 11:02:13 +1100 Subject: [PATCH 1/2] Combined width and height into size --- Tests/test_file_tiff.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Tests/test_file_tiff.py b/Tests/test_file_tiff.py index 55e2c8be3..d4ffe88bb 100644 --- a/Tests/test_file_tiff.py +++ b/Tests/test_file_tiff.py @@ -91,17 +91,17 @@ class TestFileTiff: assert_image_similar_tofile(im, "Tests/images/pil136.png", 1) @pytest.mark.parametrize( - "file_name,mode,w,h,offset", + "file_name,mode,size,offset", [ - ("tiff_wrong_bits_per_sample.tiff", "RGBA", 52, 53, 160), - ("tiff_wrong_bits_per_sample_2.tiff", "RGB", 16, 16, 8), + ("tiff_wrong_bits_per_sample.tiff", "RGBA", (52, 53), 160), + ("tiff_wrong_bits_per_sample_2.tiff", "RGB", (16, 16), 8), ], ) - def test_wrong_bits_per_sample(self, file_name, mode, w, h, offset): + def test_wrong_bits_per_sample(self, file_name, mode, size, offset): with Image.open("Tests/images/" + file_name) as im: assert im.mode == mode - assert im.size == (w, h) - assert im.tile == [("raw", (0, 0, w, h), offset, (mode, 0, 1))] + assert im.size == size + assert im.tile == [("raw", (0, 0) + size, offset, (mode, 0, 1))] im.load() def test_set_legacy_api(self): From 1f82202998db41f135878e96c2dfed1321323361 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Thu, 10 Feb 2022 11:08:25 +1100 Subject: [PATCH 2/2] Adjusted comments --- src/PIL/TiffImagePlugin.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/PIL/TiffImagePlugin.py b/src/PIL/TiffImagePlugin.py index 307a08cea..d6f23f11b 100644 --- a/src/PIL/TiffImagePlugin.py +++ b/src/PIL/TiffImagePlugin.py @@ -1307,13 +1307,14 @@ class TiffImageFile(ImageFile.ImageFile): else: bps_count = 1 bps_count += len(extra_tuple) - # Some files have only one value in bps_tuple, - # while should have more. Or have more values - # than expected. Fix it bps_actual_count = len(bps_tuple) if bps_count < bps_actual_count: + # If a file has more values in bps_tuple than expected, + # remove the excess. bps_tuple = bps_tuple[:bps_count] elif bps_count > bps_actual_count and bps_actual_count == 1: + # If a file has only one value in bps_tuple, when it should have more, + # presume it is the same number of bits for all of the samples. bps_tuple = bps_tuple * bps_count samplesPerPixel = self.tag_v2.get(