mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-02-04 21:50:54 +03:00
Limit TIFF strip size when saving with libtiff
This commit is contained in:
parent
20bd9e9261
commit
7752fb5131
|
@ -1558,12 +1558,18 @@ 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)
|
||||
ifd[ROWSPERSTRIP] = im.size[1]
|
||||
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
|
||||
strips_per_image = (im.size[1] + rows_per_strip - 1) // rows_per_strip
|
||||
ifd[ROWSPERSTRIP] = rows_per_strip
|
||||
if strip_byte_counts >= 2 ** 16:
|
||||
ifd.tagtype[STRIPBYTECOUNTS] = TiffTags.LONG
|
||||
ifd[STRIPBYTECOUNTS] = strip_byte_counts
|
||||
ifd[STRIPOFFSETS] = 0 # this is adjusted by IFD writer
|
||||
ifd[STRIPBYTECOUNTS] = (strip_byte_counts,) * (strips_per_image - 1) + (stride * im.size[1] - strip_byte_counts * (strips_per_image - 1),)
|
||||
ifd[STRIPOFFSETS] = tuple(range(0, strip_byte_counts * strips_per_image, strip_byte_counts)) # this is adjusted by IFD writer
|
||||
# no compression by default:
|
||||
ifd[COMPRESSION] = COMPRESSION_INFO_REV.get(compression, 1)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user