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

Test using _seek to skip frames #8804

Merged
merged 1 commit into from
Mar 6, 2025
Merged

Conversation

radarhere
Copy link
Member

Three formats - APNG, FLI and GIF raise an error if _seek is called to seek to frame that isn't the next one or the first one.

def seek(self, frame: int) -> None:
if not self._seek_check(frame):
return
if frame < self.__frame:
self._seek(0)
for f in range(self.__frame + 1, frame + 1):
self._seek(f)
def _seek(self, frame: int) -> None:
if frame == 0:
self.__frame = -1
self._fp.seek(self.__rewind)
self.__offset = 128
else:
# ensure that the previous frame was loaded
self.load()
if frame != self.__frame + 1:
msg = f"cannot seek to frame {frame}"
raise ValueError(msg)

_seek shouldn't be called by end users, but ensuring it is called in the correct way internally would guard against bugs.

@hugovk hugovk merged commit e946c7b into python-pillow:main Mar 6, 2025
53 of 54 checks passed
@radarhere radarhere deleted the seek branch March 6, 2025 20:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants