Fix MPO support, and Python2.6 support.

This commit is contained in:
Antony Lee 2015-01-13 23:07:41 -08:00
parent 4d7a5695b8
commit 157215ec85
4 changed files with 18 additions and 14 deletions

View File

@ -37,7 +37,7 @@ __version__ = "0.6"
import array
import struct
import io
from struct import unpack
from struct import unpack_from
from PIL import Image, ImageFile, TiffImagePlugin, _binary
from PIL.JpegPresets import presets
from PIL._util import isStringType
@ -455,11 +455,12 @@ def _getmp(self):
except KeyError:
raise SyntaxError("malformed MP Index (no number of images)")
# get MP entries
mpentries = []
try:
mpentries = []
rawmpentries = mp[0xB002]
for entrynum in range(0, quant):
rawmpentry = mp[0xB002][entrynum * 16:(entrynum + 1) * 16]
unpackedentry = unpack('{0}LLLHH'.format(endianness), rawmpentry)
unpackedentry = unpack_from(
'{0}LLLHH'.format(endianness), rawmpentries, entrynum * 16)
labels = ('Attribute', 'Size', 'DataOffset', 'EntryNo1',
'EntryNo2')
mpentry = dict(zip(labels, unpackedentry))

View File

@ -278,10 +278,6 @@ class ImageFileDirectory(collections.MutableMapping):
prefix = property(lambda self: self._prefix)
offset = property(lambda self: self._offset)
@property
def offset(self):
return self._offset
def reset(self):
self._tags = {}
self._tagdata = {}
@ -301,8 +297,8 @@ class ImageFileDirectory(collections.MutableMapping):
"""
Returns the complete tag dictionary, with named tags where possible.
"""
return {TAGS.get(code, TagInfo()).name: value
for code, value in self.items()}
return dict((TAGS.get(code, TagInfo()).name, value)
for code, value in self.items())
def __len__(self):
return len(self._tagdata) + len(self._tags)
@ -396,7 +392,7 @@ class ImageFileDirectory(collections.MutableMapping):
TYPES[idx] = name
size = struct.calcsize("=" + fmt)
_load_dispatch[idx] = size, lambda self, data: (
self._unpack("{}{}".format(len(data) // size, fmt), data))
self._unpack("{0}{1}".format(len(data) // size, fmt), data))
_write_dispatch[idx] = lambda self, *values: (
b"".join(self._pack(fmt, value) for value in values))
@ -417,7 +413,7 @@ class ImageFileDirectory(collections.MutableMapping):
@_register_loader(5, 8)
def load_rational(self, data):
vals = self._unpack("{}L".format(len(data) // 4), data)
vals = self._unpack("{0}L".format(len(data) // 4), data)
return tuple(num / denom for num, denom in zip(vals[::2], vals[1::2]))
@_register_writer(5)
@ -435,7 +431,7 @@ class ImageFileDirectory(collections.MutableMapping):
@_register_loader(10, 8)
def load_signed_rational(self, data):
vals = self._unpack("{}l".format(len(data) // 4), data)
vals = self._unpack("{0}l".format(len(data) // 4), data)
return tuple(num / denom for num, denom in zip(vals[::2], vals[1::2]))
@_register_writer(10)

View File

@ -130,6 +130,13 @@ TAGS = {
# FIXME add more tags here
34665: ("ExifIFD", 3, 1),
45056: ("MPFVersion", 7, 1),
45057: ("NumberOfImages", 4, 1),
45058: ("MPEntry", 7, 1),
45059: ("ImageUIDList", 7, 0),
45060: ("TotalFrames", 4, 1),
50741: ("MakerNoteSafety", 3, 1, {0: "Unsafe", 1: "Safe"}),
50780: ("BestQualityScale", 5, 1),
50838: ("ImageJMetaDataByteCounts", 4, 1),

View File

@ -4,7 +4,7 @@ from helper import unittest, PillowTestCase, hopper
from PIL import Image, TiffImagePlugin, TiffTags
tag_ids = {info.name: info.value for info in TiffTags.TAGS.values()}
tag_ids = dict((info.name, info.value) for info in TiffTags.TAGS.values())
class TestFileTiffMetadata(PillowTestCase):