mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-02-28 18:10:33 +03:00
Merge pull request #5750 from radarhere/zero
Fixed Python errors when saving a (0, 0) TIFF image
This commit is contained in:
commit
b34430b402
|
@ -986,3 +986,10 @@ class TestFileLibTiff(LibTiffTestCase):
|
||||||
with Image.open(out) as im:
|
with Image.open(out) as im:
|
||||||
# Assert that there are multiple strips
|
# Assert that there are multiple strips
|
||||||
assert len(im.tag_v2[STRIPOFFSETS]) > 1
|
assert len(im.tag_v2[STRIPOFFSETS]) > 1
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("compression", ("tiff_adobe_deflate", None))
|
||||||
|
def test_save_zero(self, compression, tmp_path):
|
||||||
|
im = Image.new("RGB", (0, 0))
|
||||||
|
out = str(tmp_path / "temp.tif")
|
||||||
|
with pytest.raises(SystemError):
|
||||||
|
im.save(out, compression=compression)
|
||||||
|
|
|
@ -1619,13 +1619,17 @@ def _save(im, fp, filename):
|
||||||
stride = len(bits) * ((im.size[0] * bits[0] + 7) // 8)
|
stride = len(bits) * ((im.size[0] * bits[0] + 7) // 8)
|
||||||
# aim for 64 KB strips when using libtiff writer
|
# aim for 64 KB strips when using libtiff writer
|
||||||
if libtiff:
|
if libtiff:
|
||||||
rows_per_strip = min((2 ** 16 + stride - 1) // stride, im.size[1])
|
rows_per_strip = (
|
||||||
|
1 if stride == 0 else min((2 ** 16 + stride - 1) // stride, im.size[1])
|
||||||
|
)
|
||||||
# JPEG encoder expects multiple of 8 rows
|
# JPEG encoder expects multiple of 8 rows
|
||||||
if compression == "jpeg":
|
if compression == "jpeg":
|
||||||
rows_per_strip = min(((rows_per_strip + 7) // 8) * 8, im.size[1])
|
rows_per_strip = min(((rows_per_strip + 7) // 8) * 8, im.size[1])
|
||||||
else:
|
else:
|
||||||
rows_per_strip = im.size[1]
|
rows_per_strip = im.size[1]
|
||||||
strip_byte_counts = stride * rows_per_strip
|
if rows_per_strip == 0:
|
||||||
|
rows_per_strip = 1
|
||||||
|
strip_byte_counts = 1 if stride == 0 else stride * rows_per_strip
|
||||||
strips_per_image = (im.size[1] + rows_per_strip - 1) // rows_per_strip
|
strips_per_image = (im.size[1] + rows_per_strip - 1) // rows_per_strip
|
||||||
ifd[ROWSPERSTRIP] = rows_per_strip
|
ifd[ROWSPERSTRIP] = rows_per_strip
|
||||||
if strip_byte_counts >= 2 ** 16:
|
if strip_byte_counts >= 2 ** 16:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user