Merge pull request #6101 from radarhere/mpo

Reset size when seeking away from "Large Thumbnail" MPO frame
This commit is contained in:
Hugo van Kemenade 2022-03-02 08:08:20 +02:00 committed by GitHub
commit 2355001797
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 0 deletions

View File

@ -85,6 +85,9 @@ def test_frame_size():
im.seek(1) im.seek(1)
assert im.size == (680, 480) assert im.size == (680, 480)
im.seek(0)
assert im.size == (640, 480)
def test_ignore_frame_size(): def test_ignore_frame_size():
# Ignore the different size of the second frame # Ignore the different size of the second frame

View File

@ -46,6 +46,7 @@ class MpoImageFile(JpegImagePlugin.JpegImageFile):
self._after_jpeg_open() self._after_jpeg_open()
def _after_jpeg_open(self, mpheader=None): def _after_jpeg_open(self, mpheader=None):
self._initial_size = self.size
self.mpinfo = mpheader if mpheader is not None else self._getmp() self.mpinfo = mpheader if mpheader is not None else self._getmp()
self.n_frames = self.mpinfo[0xB001] self.n_frames = self.mpinfo[0xB001]
self.__mpoffsets = [ self.__mpoffsets = [
@ -77,6 +78,7 @@ class MpoImageFile(JpegImagePlugin.JpegImageFile):
segment = self.fp.read(2) segment = self.fp.read(2)
if not segment: if not segment:
raise ValueError("No data found for frame") raise ValueError("No data found for frame")
self._size = self._initial_size
if i16(segment) == 0xFFE1: # APP1 if i16(segment) == 0xFFE1: # APP1
n = i16(self.fp.read(2)) - 2 n = i16(self.fp.read(2)) - 2
self.info["exif"] = ImageFile._safe_read(self.fp, n) self.info["exif"] = ImageFile._safe_read(self.fp, n)