In seek(), create core image at size needed for loading

This commit is contained in:
Andrew Murray 2024-09-18 22:56:29 +10:00
parent a92dca66bd
commit 629f5be52e

View File

@ -1194,8 +1194,8 @@ class TiffImageFile(ImageFile.ImageFile):
# Create a new core image object on second and # Create a new core image object on second and
# subsequent frames in the image. Image may be # subsequent frames in the image. Image may be
# different size/mode. # different size/mode.
Image._decompression_bomb_check(self.size) Image._decompression_bomb_check(self._tile_size)
self.im = Image.core.new(self.mode, self.size) self.im = Image.core.new(self.mode, self._tile_size)
def _seek(self, frame: int) -> None: def _seek(self, frame: int) -> None:
self.fp = self._fp self.fp = self._fp
@ -1276,8 +1276,8 @@ class TiffImageFile(ImageFile.ImageFile):
return super().load() return super().load()
def load_prepare(self) -> None: def load_prepare(self) -> None:
if self._im is None and self._will_be_transposed: if self._im is None:
self.im = Image.core.new(self.mode, self.size[::-1]) self.im = Image.core.new(self.mode, self._tile_size)
ImageFile.ImageFile.load_prepare(self) ImageFile.ImageFile.load_prepare(self)
def load_end(self) -> None: def load_end(self) -> None:
@ -1421,9 +1421,9 @@ class TiffImageFile(ImageFile.ImageFile):
if not isinstance(xsize, int) or not isinstance(ysize, int): if not isinstance(xsize, int) or not isinstance(ysize, int):
msg = "Invalid dimensions" msg = "Invalid dimensions"
raise ValueError(msg) raise ValueError(msg)
self._tile_size = xsize, ysize
orientation = self.tag_v2.get(ExifTags.Base.Orientation) orientation = self.tag_v2.get(ExifTags.Base.Orientation)
self._will_be_transposed = orientation in (5, 6, 7, 8) if orientation in (5, 6, 7, 8):
if self._will_be_transposed:
self._size = ysize, xsize self._size = ysize, xsize
else: else:
self._size = xsize, ysize self._size = xsize, ysize