mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-13 10:46:16 +03:00
Tests for permitted libtiff metadata
This commit is contained in:
parent
36c48150ea
commit
36d4f5a9b4
|
@ -386,4 +386,17 @@ LIBTIFF_CORE = set ([255, 256, 257, 258, 259, 262, 263, 266, 274, 277,
|
|||
269 # this has been in our tests forever, and works
|
||||
])
|
||||
|
||||
LIBTIFF_CORE.remove(320) # Arrays error?
|
||||
LIBTIFF_CORE.remove(320) # Array of short, crashes
|
||||
LIBTIFF_CORE.remove(301) # Array of short, crashes
|
||||
LIBTIFF_CORE.remove(532) # Array of long, crashes
|
||||
|
||||
LIBTIFF_CORE.remove(255) # We don't have support for subfiletypes
|
||||
LIBTIFF_CORE.remove(322) # We don't have support for tiled images in libtiff
|
||||
LIBTIFF_CORE.remove(323) # Tiled images
|
||||
LIBTIFF_CORE.remove(333) # Ink Names either
|
||||
|
||||
# Note to advanced users: There may be combinations of these
|
||||
# parameters and values that when added properly, will work and
|
||||
# produce valid tiff images that may work in your application.
|
||||
# It is safe to add and remove tags from this set from Pillow's point
|
||||
# of view so long as you test against libtiff.
|
||||
|
|
|
@ -7,7 +7,7 @@ import logging
|
|||
import itertools
|
||||
import os
|
||||
|
||||
from PIL import Image, TiffImagePlugin
|
||||
from PIL import Image, TiffImagePlugin, TiffTags
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
@ -172,6 +172,59 @@ class TestFileLibTiff(LibTiffTestCase):
|
|||
for field in requested_fields:
|
||||
self.assertTrue(field in reloaded, "%s not in metadata" %field)
|
||||
|
||||
def test_additional_metadata(self):
|
||||
# these should not crash. Seriously dummy data, most of it doesn't make
|
||||
# any sense, so we're running up against limits where we're asking
|
||||
# libtiff to do stupid things.
|
||||
|
||||
# Get the list of the ones that we should be able to write
|
||||
|
||||
core_items = dict((tag, info) for tag, info in [(s,TiffTags.lookup(s)) for s
|
||||
in TiffTags.LIBTIFF_CORE]
|
||||
if info.type is not None)
|
||||
|
||||
# Exclude ones that have special meaning that we're already testing them
|
||||
im = Image.open('Tests/images/hopper_g4.tif')
|
||||
for tag in im.tag_v2.keys():
|
||||
try:
|
||||
del(core_items[tag])
|
||||
except: pass
|
||||
|
||||
# Type codes:
|
||||
# 2: "ascii",
|
||||
# 3: "short",
|
||||
# 4: "long",
|
||||
# 5: "rational",
|
||||
# 12: "double",
|
||||
# type: dummy value
|
||||
values = { 2: 'test',
|
||||
3: 1,
|
||||
4: 2**20,
|
||||
5: TiffImagePlugin.IFDRational(100,1),
|
||||
12: 1.05 }
|
||||
|
||||
|
||||
new_ifd = TiffImagePlugin.ImageFileDirectory_v2()
|
||||
for tag, info in core_items.items():
|
||||
if info.length == 1:
|
||||
new_ifd[tag] = values[info.type]
|
||||
if info.length == 0:
|
||||
new_ifd[tag] = tuple(values[info.type] for _ in range(3))
|
||||
else:
|
||||
new_ifd[tag] = tuple(values[info.type] for _ in range(info.length))
|
||||
|
||||
# Extra samples really doesn't make sense in this application.
|
||||
del(new_ifd[338])
|
||||
|
||||
out = self.tempfile("temp.tif")
|
||||
TiffImagePlugin.WRITE_LIBTIFF = True
|
||||
|
||||
im.save(out, tiffinfo=new_ifd)
|
||||
|
||||
TiffImagePlugin.WRITE_LIBTIFF = False
|
||||
|
||||
|
||||
|
||||
def test_g3_compression(self):
|
||||
i = Image.open('Tests/images/hopper_g4_500.tif')
|
||||
out = self.tempfile("temp.tif")
|
||||
|
|
Loading…
Reference in New Issue
Block a user