Skip to content

Commit 1c4deef

Browse files
kmilosradarhere
authored andcommitted
Make strip calculation more readable
1 parent c949d54 commit 1c4deef

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/PIL/TiffImagePlugin.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -1558,12 +1558,12 @@ def _save(im, fp, filename):
15581558
ifd[COLORMAP] = tuple(v * 256 for v in lut)
15591559
# data orientation
15601560
stride = len(bits) * ((im.size[0] * bits[0] + 7) // 8)
1561-
rows_per_strip = im.size[1]
1562-
strip_byte_counts = stride * im.size[1]
15631561
# aim for 64 KB strips when using libtiff writer
1564-
while libtiff and strip_byte_counts > 2 ** 16 and rows_per_strip > 1:
1565-
rows_per_strip = (rows_per_strip + 1) // 2
1566-
strip_byte_counts = stride * rows_per_strip
1562+
if libtiff:
1563+
rows_per_strip = (2 ** 16 + stride - 1) // stride
1564+
else:
1565+
rows_per_strip = im.size[1]
1566+
strip_byte_counts = stride * rows_per_strip
15671567
strips_per_image = (im.size[1] + rows_per_strip - 1) // rows_per_strip
15681568
ifd[ROWSPERSTRIP] = rows_per_strip
15691569
if strip_byte_counts >= 2 ** 16:

0 commit comments

Comments
 (0)