mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-02-04 05:34:36 +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 struct
|
||||||
import io
|
import io
|
||||||
import warnings
|
import warnings
|
||||||
from struct import unpack
|
from struct import unpack_from
|
||||||
from PIL import Image, ImageFile, TiffImagePlugin, _binary
|
from PIL import Image, ImageFile, TiffImagePlugin, _binary
|
||||||
from PIL.JpegPresets import presets
|
from PIL.JpegPresets import presets
|
||||||
from PIL._util import isStringType
|
from PIL._util import isStringType
|
||||||
|
@ -462,11 +462,12 @@ def _getmp(self):
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise SyntaxError("malformed MP Index (no number of images)")
|
raise SyntaxError("malformed MP Index (no number of images)")
|
||||||
# get MP entries
|
# get MP entries
|
||||||
try:
|
|
||||||
mpentries = []
|
mpentries = []
|
||||||
|
try:
|
||||||
|
rawmpentries = mp[0xB002]
|
||||||
for entrynum in range(0, quant):
|
for entrynum in range(0, quant):
|
||||||
rawmpentry = mp[0xB002][entrynum * 16:(entrynum + 1) * 16]
|
unpackedentry = unpack_from(
|
||||||
unpackedentry = unpack('{0}LLLHH'.format(endianness), rawmpentry)
|
'{0}LLLHH'.format(endianness), rawmpentries, entrynum * 16)
|
||||||
labels = ('Attribute', 'Size', 'DataOffset', 'EntryNo1',
|
labels = ('Attribute', 'Size', 'DataOffset', 'EntryNo1',
|
||||||
'EntryNo2')
|
'EntryNo2')
|
||||||
mpentry = dict(zip(labels, unpackedentry))
|
mpentry = dict(zip(labels, unpackedentry))
|
||||||
|
|
|
@ -279,10 +279,6 @@ class ImageFileDirectory(collections.MutableMapping):
|
||||||
prefix = property(lambda self: self._prefix)
|
prefix = property(lambda self: self._prefix)
|
||||||
offset = property(lambda self: self._offset)
|
offset = property(lambda self: self._offset)
|
||||||
|
|
||||||
@property
|
|
||||||
def offset(self):
|
|
||||||
return self._offset
|
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
self._tags = {}
|
self._tags = {}
|
||||||
self._tagdata = {}
|
self._tagdata = {}
|
||||||
|
@ -302,8 +298,8 @@ class ImageFileDirectory(collections.MutableMapping):
|
||||||
"""
|
"""
|
||||||
Returns the complete tag dictionary, with named tags where possible.
|
Returns the complete tag dictionary, with named tags where possible.
|
||||||
"""
|
"""
|
||||||
return {TAGS.get(code, TagInfo()).name: value
|
return dict((TAGS.get(code, TagInfo()).name, value)
|
||||||
for code, value in self.items()}
|
for code, value in self.items())
|
||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
return len(self._tagdata) + len(self._tags)
|
return len(self._tagdata) + len(self._tags)
|
||||||
|
@ -397,7 +393,7 @@ class ImageFileDirectory(collections.MutableMapping):
|
||||||
TYPES[idx] = name
|
TYPES[idx] = name
|
||||||
size = struct.calcsize("=" + fmt)
|
size = struct.calcsize("=" + fmt)
|
||||||
_load_dispatch[idx] = size, lambda self, data: (
|
_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: (
|
_write_dispatch[idx] = lambda self, *values: (
|
||||||
b"".join(self._pack(fmt, value) for value in values))
|
b"".join(self._pack(fmt, value) for value in values))
|
||||||
|
|
||||||
|
@ -421,7 +417,7 @@ class ImageFileDirectory(collections.MutableMapping):
|
||||||
|
|
||||||
@_register_loader(5, 8)
|
@_register_loader(5, 8)
|
||||||
def load_rational(self, data):
|
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]))
|
return tuple(num / denom for num, denom in zip(vals[::2], vals[1::2]))
|
||||||
|
|
||||||
@_register_writer(5)
|
@_register_writer(5)
|
||||||
|
@ -439,7 +435,7 @@ class ImageFileDirectory(collections.MutableMapping):
|
||||||
|
|
||||||
@_register_loader(10, 8)
|
@_register_loader(10, 8)
|
||||||
def load_signed_rational(self, data):
|
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]))
|
return tuple(num / denom for num, denom in zip(vals[::2], vals[1::2]))
|
||||||
|
|
||||||
@_register_writer(10)
|
@_register_writer(10)
|
||||||
|
|
|
@ -130,6 +130,13 @@ TAGS = {
|
||||||
|
|
||||||
# FIXME add more tags here
|
# FIXME add more tags here
|
||||||
34665: ("ExifIFD", 3, 1),
|
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"}),
|
50741: ("MakerNoteSafety", 3, 1, {0: "Unsafe", 1: "Safe"}),
|
||||||
50780: ("BestQualityScale", 5, 1),
|
50780: ("BestQualityScale", 5, 1),
|
||||||
50838: ("ImageJMetaDataByteCounts", 4, 1),
|
50838: ("ImageJMetaDataByteCounts", 4, 1),
|
||||||
|
|
|
@ -4,7 +4,7 @@ from helper import unittest, PillowTestCase, hopper
|
||||||
|
|
||||||
from PIL import Image, TiffImagePlugin, TiffTags
|
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):
|
class TestFileTiffMetadata(PillowTestCase):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user