fix MPO parsing issue

This commit is contained in:
Nick Adams 2015-05-31 13:10:29 -07:00
parent e58a773c29
commit dd1a6f1f13

View File

@ -467,7 +467,7 @@ def _getmp(self):
try: try:
quant = mp[0xB001] quant = mp[0xB001]
except KeyError: except KeyError:
raise SyntaxError("malformed MP Index (no number of images)") raise TypeError("malformed MP Index (no number of images)")
# get MP entries # get MP entries
try: try:
mpentries = [] mpentries = []
@ -491,7 +491,7 @@ def _getmp(self):
if mpentryattr['ImageDataFormat'] == 0: if mpentryattr['ImageDataFormat'] == 0:
mpentryattr['ImageDataFormat'] = 'JPEG' mpentryattr['ImageDataFormat'] = 'JPEG'
else: else:
raise SyntaxError("unsupported picture format in MPO") raise TypeError("unsupported picture format in MPO")
mptypemap = { mptypemap = {
0x000000: 'Undefined', 0x000000: 'Undefined',
0x010001: 'Large Thumbnail (VGA Equivalent)', 0x010001: 'Large Thumbnail (VGA Equivalent)',
@ -507,7 +507,7 @@ def _getmp(self):
mpentries.append(mpentry) mpentries.append(mpentry)
mp[0xB002] = mpentries mp[0xB002] = mpentries
except KeyError: except KeyError:
raise SyntaxError("malformed MP Index (bad MP Entry)") raise TypeError("malformed MP Index (bad MP Entry)")
# Next we should try and parse the individual image unique ID list; # Next we should try and parse the individual image unique ID list;
# we don't because I've never seen this actually used in a real MPO # we don't because I've never seen this actually used in a real MPO
# file and so can't test it. # file and so can't test it.
@ -713,8 +713,8 @@ def _save_cjpeg(im, fp, filename):
# Factory for making JPEG and MPO instances # Factory for making JPEG and MPO instances
def jpeg_factory(fp=None, filename=None): def jpeg_factory(fp=None, filename=None):
im = JpegImageFile(fp, filename) im = JpegImageFile(fp, filename)
mpheader = im._getmp()
try: try:
mpheader = im._getmp()
if mpheader[45057] > 1: if mpheader[45057] > 1:
# It's actually an MPO # It's actually an MPO
from .MpoImagePlugin import MpoImageFile from .MpoImagePlugin import MpoImageFile