mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-11 04:07:21 +03:00
Merge pull request #6042 from radarhere/tiff_bits
Clarify code and comments
This commit is contained in:
commit
89768e3d57
|
@ -91,17 +91,17 @@ class TestFileTiff:
|
||||||
assert_image_similar_tofile(im, "Tests/images/pil136.png", 1)
|
assert_image_similar_tofile(im, "Tests/images/pil136.png", 1)
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@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.tiff", "RGBA", (52, 53), 160),
|
||||||
("tiff_wrong_bits_per_sample_2.tiff", "RGB", 16, 16, 8),
|
("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:
|
with Image.open("Tests/images/" + file_name) as im:
|
||||||
assert im.mode == mode
|
assert im.mode == mode
|
||||||
assert im.size == (w, h)
|
assert im.size == size
|
||||||
assert im.tile == [("raw", (0, 0, w, h), offset, (mode, 0, 1))]
|
assert im.tile == [("raw", (0, 0) + size, offset, (mode, 0, 1))]
|
||||||
im.load()
|
im.load()
|
||||||
|
|
||||||
def test_set_legacy_api(self):
|
def test_set_legacy_api(self):
|
||||||
|
|
|
@ -1332,13 +1332,14 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
else:
|
else:
|
||||||
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,
|
|
||||||
# while should have more. Or have more values
|
|
||||||
# than expected. Fix it
|
|
||||||
bps_actual_count = len(bps_tuple)
|
bps_actual_count = len(bps_tuple)
|
||||||
if bps_count < bps_actual_count:
|
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]
|
bps_tuple = bps_tuple[:bps_count]
|
||||||
elif bps_count > bps_actual_count and bps_actual_count == 1:
|
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
|
bps_tuple = bps_tuple * bps_count
|
||||||
|
|
||||||
samplesPerPixel = self.tag_v2.get(
|
samplesPerPixel = self.tag_v2.get(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user