From 1c4deefe11042f4a1a9c5270fc32d7e1fea652b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milo=C5=A1=20Komar=C4=8Devi=C4=87?= Date: Wed, 2 Jun 2021 12:06:27 +0200 Subject: [PATCH] Make strip calculation more readable --- src/PIL/TiffImagePlugin.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/PIL/TiffImagePlugin.py b/src/PIL/TiffImagePlugin.py index 68e2759b0..12c829ea5 100644 --- a/src/PIL/TiffImagePlugin.py +++ b/src/PIL/TiffImagePlugin.py @@ -1558,12 +1558,12 @@ def _save(im, fp, filename): ifd[COLORMAP] = tuple(v * 256 for v in lut) # data orientation stride = len(bits) * ((im.size[0] * bits[0] + 7) // 8) - rows_per_strip = im.size[1] - strip_byte_counts = stride * im.size[1] # aim for 64 KB strips when using libtiff writer - while libtiff and strip_byte_counts > 2 ** 16 and rows_per_strip > 1: - rows_per_strip = (rows_per_strip + 1) // 2 - strip_byte_counts = stride * rows_per_strip + if libtiff: + rows_per_strip = (2 ** 16 + stride - 1) // stride + else: + rows_per_strip = im.size[1] + strip_byte_counts = stride * rows_per_strip strips_per_image = (im.size[1] + rows_per_strip - 1) // rows_per_strip ifd[ROWSPERSTRIP] = rows_per_strip if strip_byte_counts >= 2 ** 16: