Do not create core image in TIFF seek() by radarhere · Pull Request #8392 · python-pillow/Pillow

Conversation

@radarhere

def seek(self, frame: int) -> None:
"""Select a given frame as current image"""
if not self._seek_check(frame):
return
self._seek(frame)
# Create a new core image object on second and
# subsequent frames in the image. Image may be
# different size/mode.
Image._decompression_bomb_check(self._tile_size)
self.im = Image.core.new(self.mode, self._tile_size)

The core image instance does not need to be created here. It can be set to None instead, and the initialisation can delayed until load() (or more specifically, load_prepare()).

def load_prepare(self) -> None:
if self._im is None:
self.im = Image.core.new(self.mode, self._tile_size)

@radarhere radarhere changed the title Do not create core image in TiffImagePlugin seek(), when load() might not run Do not create core image in TIFF seek(), when load() might not run

Sep 18, 2024

@radarhere radarhere changed the title Do not create core image in TIFF seek(), when load() might not run Do not create core image in TIFF seek()

Sep 18, 2024

Labels

2 participants

@radarhere @hugovk