From ccfc2524b8bb6336877dc513f9ba77a187ad79e4 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 10 May 2025 20:56:56 +1000 Subject: [PATCH] Use n_frames and _seek_check --- Tests/test_file_ani.py | 8 ++++---- src/PIL/AniImagePlugin.py | 7 +++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Tests/test_file_ani.py b/Tests/test_file_ani.py index 807ef0b63..bcb9791dc 100644 --- a/Tests/test_file_ani.py +++ b/Tests/test_file_ani.py @@ -10,7 +10,7 @@ from PIL import Image def test_aero_busy() -> None: with Image.open("Tests/images/ani/aero_busy.ani") as im: assert im.size == (64, 64) - assert im.info["frames"] == 18 + assert im.n_frames == 18 with Image.open("Tests/images/ani/aero_busy_0.png") as png: assert png.tobytes() == im.tobytes() @@ -29,7 +29,7 @@ def test_aero_busy() -> None: def test_posy_busy() -> None: with Image.open("Tests/images/ani/posy_busy.ani") as im: assert im.size == (96, 96) - assert im.info["frames"] == 77 + assert im.n_frames == 77 with Image.open("Tests/images/ani/posy_busy_0.png") as png: assert png.tobytes() == im.tobytes() @@ -45,7 +45,7 @@ def test_posy_busy() -> None: def test_stopwtch() -> None: with Image.open("Tests/images/ani/stopwtch.ani") as im: assert im.size == (32, 32) - assert im.info["frames"] == 8 + assert im.n_frames == 8 assert im.info["seq"][0] == 0 assert im.info["seq"][2] == 0 @@ -132,7 +132,7 @@ def test_save() -> None: ) with Image.open(output, formats=["ANI"]) as im: - assert im.info["frames"] == 6 + assert im.n_frames == 6 assert im.info["seq"] == [0, 2, 4, 1, 3, 5, 0, 1, 0, 1] assert im.info["rate"] == [1, 2, 3, 1, 2, 3, 1, 2, 3, 4] assert im.size == (32, 32) diff --git a/src/PIL/AniImagePlugin.py b/src/PIL/AniImagePlugin.py index 5d78d3024..cf0ac2a39 100644 --- a/src/PIL/AniImagePlugin.py +++ b/src/PIL/AniImagePlugin.py @@ -407,7 +407,7 @@ class AniImageFile(ImageFile.ImageFile): self.info["rate"] = self.ani.rate assert self.ani.anih is not None - self.info["frames"] = self.ani.anih["nFrames"] + self.n_frames = self.ani.anih["nFrames"] self.frame = 0 self.seek(0) @@ -434,9 +434,8 @@ class AniImageFile(ImageFile.ImageFile): return Image.Image.load(self) def seek(self, frame: int) -> None: - if frame > self.info["frames"] - 1 or frame < 0: - msg = "Frame index out of animation bounds" - raise EOFError(msg) + if not self._seek_check(frame): + return self.frame = frame