mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-02-03 21:24:31 +03:00
Fix MPO support, and Python2.6 support.
This commit is contained in:
parent
56a3f0f2ab
commit
d5b46dce96
|
@ -36,7 +36,7 @@ import array
|
|||
import struct
|
||||
import io
|
||||
import warnings
|
||||
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
|
||||
|
@ -462,11 +462,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))
|
||||
|
|
|
@ -279,10 +279,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 = {}
|
||||
|
@ -302,8 +298,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)
|
||||
|
@ -397,7 +393,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))
|
||||
|
||||
|
@ -421,7 +417,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)
|
||||
|
@ -439,7 +435,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)
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue
Block a user