Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only read different sizes for "Large Thumbnail" MPO frames #5168

Merged
merged 2 commits into from Mar 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file added Tests/images/ignore_frame_size.mpo
Binary file not shown.
Binary file modified Tests/images/sugarshack_frame_size.mpo
Binary file not shown.
16 changes: 15 additions & 1 deletion Tests/test_file_mpo.py
Expand Up @@ -89,6 +89,20 @@ def test_frame_size():
assert im.size == (680, 480)


def test_ignore_frame_size():
# Ignore the different size of the second frame
# since this is not a "Large Thumbnail" image
with Image.open("Tests/images/ignore_frame_size.mpo") as im:
assert im.size == (64, 64)

im.seek(1)
assert (
im.mpinfo[0xB002][1]["Attribute"]["MPType"]
== "Multi-Frame Image: (Disparity)"
)
assert im.size == (64, 64)


def test_parallax():
# Nintendo
with Image.open("Tests/images/sugarshack.mpo") as im:
Expand Down Expand Up @@ -132,7 +146,7 @@ def test_mp_attribute():
with Image.open(test_file) as im:
mpinfo = im._getmp()
frameNumber = 0
for mpentry in mpinfo[45058]:
for mpentry in mpinfo[0xB002]:
mpattr = mpentry["Attribute"]
if frameNumber:
assert not mpattr["RepresentativeImageFlag"]
Expand Down
8 changes: 5 additions & 3 deletions src/PIL/MpoImagePlugin.py
Expand Up @@ -82,9 +82,11 @@ def seek(self, frame):
n = i16(self.fp.read(2)) - 2
self.info["exif"] = ImageFile._safe_read(self.fp, n)

exif = self.getexif()
if 40962 in exif and 40963 in exif:
self._size = (exif[40962], exif[40963])
mptype = self.mpinfo[0xB002][frame]["Attribute"]["MPType"]
if mptype.startswith("Large Thumbnail"):
exif = self.getexif()
if 40962 in exif and 40963 in exif:
self._size = (exif[40962], exif[40963])
elif "exif" in self.info:
del self.info["exif"]

Expand Down