Ensure TIFF RowsPerStrip is multiple of 8 for JPEG compression

This commit is contained in:
Miloš Komarčević 2021-07-07 09:38:06 +02:00 committed by Hugo van Kemenade
parent c0615e74b2
commit 39e36368e7

View File

@ -1577,6 +1577,9 @@ def _save(im, fp, filename):
# 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 = min((2 ** 16 + stride - 1) // stride, im.size[1])
# JPEG encoder expects multiple of 8 rows
if compression == "jpeg":
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 strip_byte_counts = stride * rows_per_strip