python-pillow / Pillow

Python Imaging Library (Fork)
https://python-pillow.org
Other
12.32k stars 2.23k forks source link

In Image.Image.seek(), clear core image if mode or size has changed #8450

Open radarhere opened 1 month ago

radarhere commented 1 month ago

Addresses #8439

8390 stopped load_prepare() from recreating the core image instance if the mode or size had changed, as might happen at the end of a seek() operation. After that PR, this was no longer needed for any of our internal plugins.

However, #8439 has pointed out that this would still be helpful for external plugins. Rather than reverting the change, this PR suggests that external plugins can call super().seek() at the end of their seek() methods. That will then clear the core image instance if the mode or size has changed, allowing load_prepare() to detect that a new core image is needed.

The advantage of this over a simple revert is that if a user calls seek() on an image, but not load(), then the core image instance is discarded.

homm commented 1 month ago

What about TiffImagePlugin? Can we call super().seek() there?

radarhere commented 1 month ago

What about TiffImagePlugin? Can we call super().seek() there?

No, because at the end of TiffImagePlugin's seek(), the normal size isn't used - self._tile_size is.