mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-13 18:56:17 +03:00
Drop excess values in BITSPERSAMPLE
This commit is contained in:
parent
8b7c37dc0c
commit
bb5a090f60
BIN
Tests/images/tiff_wrong_bits_per_sample_2.tiff
Normal file
BIN
Tests/images/tiff_wrong_bits_per_sample_2.tiff
Normal file
Binary file not shown.
|
@ -90,11 +90,15 @@ class TestFileTiff:
|
||||||
|
|
||||||
assert_image_similar_tofile(im, "Tests/images/pil136.png", 1)
|
assert_image_similar_tofile(im, "Tests/images/pil136.png", 1)
|
||||||
|
|
||||||
def test_wrong_bits_per_sample(self):
|
@pytest.mark.parametrize("file_name,mode,w,h,offset", [
|
||||||
with Image.open("Tests/images/tiff_wrong_bits_per_sample.tiff") as im:
|
("tiff_wrong_bits_per_sample.tiff","RGBA",52,53,160),
|
||||||
assert im.mode == "RGBA"
|
("tiff_wrong_bits_per_sample_2.tiff","RGB",16,16,8),
|
||||||
assert im.size == (52, 53)
|
])
|
||||||
assert im.tile == [("raw", (0, 0, 52, 53), 160, ("RGBA", 0, 1))]
|
def test_wrong_bits_per_sample(self, file_name, mode, w, h, 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))]
|
||||||
im.load()
|
im.load()
|
||||||
|
|
||||||
def test_set_legacy_api(self):
|
def test_set_legacy_api(self):
|
||||||
|
|
|
@ -1308,8 +1308,12 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
bps_count = 1
|
bps_count = 1
|
||||||
bps_count += len(extra_tuple)
|
bps_count += len(extra_tuple)
|
||||||
# Some files have only one value in bps_tuple,
|
# Some files have only one value in bps_tuple,
|
||||||
# while should have more. Fix it
|
# while should have more. Or have more values
|
||||||
if bps_count > len(bps_tuple) and len(bps_tuple) == 1:
|
# than expected. Fix it
|
||||||
|
bps_actual_count = len(bps_tuple)
|
||||||
|
if bps_count < bps_actual_count:
|
||||||
|
bps_tuple = bps_tuple[:bps_count]
|
||||||
|
elif bps_count > bps_actual_count and bps_actual_count == 1:
|
||||||
bps_tuple = bps_tuple * bps_count
|
bps_tuple = bps_tuple * bps_count
|
||||||
|
|
||||||
samplesPerPixel = self.tag_v2.get(
|
samplesPerPixel = self.tag_v2.get(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user