Clear C image when MPO frame image size changes

This commit is contained in:
Andrew Murray 2025-09-15 22:28:30 +10:00
parent abfdbdd6ce
commit 9ba1029d51
2 changed files with 4 additions and 0 deletions

View File

@ -108,9 +108,11 @@ def test_frame_size() -> None:
# in the SOF marker of the second frame # in the SOF marker of the second frame
with Image.open("Tests/images/sugarshack_frame_size.mpo") as im: with Image.open("Tests/images/sugarshack_frame_size.mpo") as im:
assert im.size == (640, 480) assert im.size == (640, 480)
im.load()
im.seek(1) im.seek(1)
assert im.size == (680, 480) assert im.size == (680, 480)
im.load()
im.seek(0) im.seek(0)
assert im.size == (640, 480) assert im.size == (640, 480)

View File

@ -193,6 +193,8 @@ def SOF(self: JpegImageFile, marker: int) -> None:
n = i16(self.fp.read(2)) - 2 n = i16(self.fp.read(2)) - 2
s = ImageFile._safe_read(self.fp, n) s = ImageFile._safe_read(self.fp, n)
self._size = i16(s, 3), i16(s, 1) self._size = i16(s, 3), i16(s, 1)
if self._im is not None and self.size != self.im.size:
self._im = None
self.bits = s[0] self.bits = s[0]
if self.bits != 8: if self.bits != 8: