mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 09:56:17 +03:00
Merge pull request #4626 from radarhere/stripbytecounts
Change STRIPBYTECOUNTS to LONG if necessary when saving
This commit is contained in:
commit
8383e840e4
|
@ -156,6 +156,23 @@ def test_write_metadata(tmp_path):
|
|||
assert value == reloaded[tag], "%s didn't roundtrip" % tag
|
||||
|
||||
|
||||
def test_change_stripbytecounts_tag_type(tmp_path):
|
||||
out = str(tmp_path / "temp.tiff")
|
||||
with Image.open("Tests/images/hopper.tif") as im:
|
||||
info = im.tag_v2
|
||||
|
||||
# Resize the image so that STRIPBYTECOUNTS will be larger than a SHORT
|
||||
im = im.resize((500, 500))
|
||||
|
||||
# STRIPBYTECOUNTS can be a SHORT or a LONG
|
||||
info.tagtype[TiffImagePlugin.STRIPBYTECOUNTS] = TiffTags.SHORT
|
||||
|
||||
im.save(out, tiffinfo=info)
|
||||
|
||||
with Image.open(out) as reloaded:
|
||||
assert reloaded.tag_v2.tagtype[TiffImagePlugin.STRIPBYTECOUNTS] == TiffTags.LONG
|
||||
|
||||
|
||||
def test_no_duplicate_50741_tag():
|
||||
assert TAG_IDS["MakerNoteSafety"] == 50741
|
||||
assert TAG_IDS["BestQualityScale"] == 50780
|
||||
|
|
|
@ -1491,7 +1491,10 @@ def _save(im, fp, filename):
|
|||
# data orientation
|
||||
stride = len(bits) * ((im.size[0] * bits[0] + 7) // 8)
|
||||
ifd[ROWSPERSTRIP] = im.size[1]
|
||||
ifd[STRIPBYTECOUNTS] = stride * im.size[1]
|
||||
strip_byte_counts = stride * im.size[1]
|
||||
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
|
||||
# no compression by default:
|
||||
ifd[COMPRESSION] = COMPRESSION_INFO_REV.get(compression, 1)
|
||||
|
|
Loading…
Reference in New Issue
Block a user