Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

radarhere
Copy link
Member

@radarhere radarhere commented Oct 8, 2024

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
Copy link
Member

homm commented Oct 9, 2024

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

@@ -2633,10 +2633,16 @@ def seek(self, frame: int) -> None:
"""

# overridden by file handlers
if frame != 0:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make impossible to call super().seek() for plugins prior Pillow 11?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...yes, an external plugin would fail calling super().seek() if the user had Pillow < 11.

I could add a dedicated new method instead of using super().seek(), but any way you look at the idea of this PR, it is new functionality.

@radarhere
Copy link
Member Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants