mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-14 03:21:44 +03:00
Corrected length of Tiff BYTE tags
This commit is contained in:
parent
d167f9e0bd
commit
dd0e4ac0a1
|
@ -234,11 +234,11 @@ class TestFileLibTiff(LibTiffTestCase):
|
||||||
|
|
||||||
def test_custom_metadata(self):
|
def test_custom_metadata(self):
|
||||||
custom = {
|
custom = {
|
||||||
37000: 4,
|
37000: [4, TiffTags.SHORT],
|
||||||
37001: 4.2,
|
37001: [4.2, TiffTags.RATIONAL],
|
||||||
37002: 'custom tag value',
|
37002: ['custom tag value', TiffTags.ASCII],
|
||||||
37003: u'custom tag value',
|
37003: [u'custom tag value', TiffTags.ASCII],
|
||||||
37004: b'custom tag value'
|
37004: [b'custom tag value', TiffTags.BYTE]
|
||||||
}
|
}
|
||||||
|
|
||||||
libtiff_version = TiffImagePlugin._libtiff_version()
|
libtiff_version = TiffImagePlugin._libtiff_version()
|
||||||
|
@ -251,17 +251,33 @@ class TestFileLibTiff(LibTiffTestCase):
|
||||||
for libtiff in libtiffs:
|
for libtiff in libtiffs:
|
||||||
TiffImagePlugin.WRITE_LIBTIFF = libtiff
|
TiffImagePlugin.WRITE_LIBTIFF = libtiff
|
||||||
|
|
||||||
im = hopper()
|
def check_tags(tiffinfo):
|
||||||
|
im = hopper()
|
||||||
|
|
||||||
out = self.tempfile("temp.tif")
|
out = self.tempfile("temp.tif")
|
||||||
im.save(out, tiffinfo=custom)
|
im.save(out, tiffinfo=tiffinfo)
|
||||||
TiffImagePlugin.WRITE_LIBTIFF = False
|
|
||||||
|
|
||||||
reloaded = Image.open(out)
|
reloaded = Image.open(out)
|
||||||
for tag, value in custom.items():
|
for tag, value in tiffinfo.items():
|
||||||
if libtiff and isinstance(value, bytes):
|
reloaded_value = reloaded.tag_v2[tag]
|
||||||
value = value.decode()
|
if isinstance(reloaded_value, TiffImagePlugin.IFDRational):
|
||||||
self.assertEqual(reloaded.tag_v2[tag], value)
|
reloaded_value = float(reloaded_value)
|
||||||
|
|
||||||
|
if libtiff and isinstance(value, bytes):
|
||||||
|
value = value.decode()
|
||||||
|
|
||||||
|
self.assertEqual(reloaded_value, value)
|
||||||
|
|
||||||
|
# Test with types
|
||||||
|
ifd = TiffImagePlugin.ImageFileDirectory_v2()
|
||||||
|
for tag, tagdata in custom.items():
|
||||||
|
ifd[tag] = tagdata[0]
|
||||||
|
ifd.tagtype[tag] = tagdata[1]
|
||||||
|
check_tags(ifd)
|
||||||
|
|
||||||
|
# Test without types
|
||||||
|
check_tags({tag: tagdata[0] for tag, tagdata in custom.items()})
|
||||||
|
TiffImagePlugin.WRITE_LIBTIFF = False
|
||||||
|
|
||||||
def test_int_dpi(self):
|
def test_int_dpi(self):
|
||||||
# issue #1765
|
# issue #1765
|
||||||
|
|
|
@ -819,7 +819,7 @@ class ImageFileDirectory_v2(MutableMapping):
|
||||||
print("- value:", values)
|
print("- value:", values)
|
||||||
|
|
||||||
# count is sum of lengths for string and arbitrary data
|
# count is sum of lengths for string and arbitrary data
|
||||||
if typ in [TiffTags.ASCII, TiffTags.UNDEFINED]:
|
if typ in [TiffTags.BYTE, TiffTags.ASCII, TiffTags.UNDEFINED]:
|
||||||
count = len(data)
|
count = len(data)
|
||||||
else:
|
else:
|
||||||
count = len(values)
|
count = len(values)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user