From 762235cd56072cf76c0ceae52d6b854a097cc96b Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 6 Dec 2025 21:21:43 +1100 Subject: [PATCH] Simplified code --- Tests/test_file_jxl_alpha.py | 2 +- Tests/test_file_jxl_animated.py | 6 ++---- Tests/test_file_jxl_metadata.py | 8 ++++---- src/PIL/JpegXlImagePlugin.py | 11 ++++------- 4 files changed, 11 insertions(+), 16 deletions(-) diff --git a/Tests/test_file_jxl_alpha.py b/Tests/test_file_jxl_alpha.py index b7cb1998f..a5fa15019 100644 --- a/Tests/test_file_jxl_alpha.py +++ b/Tests/test_file_jxl_alpha.py @@ -4,7 +4,7 @@ from PIL import Image from .helper import assert_image_similar_tofile, skip_unless_feature -pytestmark = [skip_unless_feature("jpegxl")] +pytestmark = skip_unless_feature("jpegxl") def test_read_rgba() -> None: diff --git a/Tests/test_file_jxl_animated.py b/Tests/test_file_jxl_animated.py index cd502b30a..54bcae41e 100644 --- a/Tests/test_file_jxl_animated.py +++ b/Tests/test_file_jxl_animated.py @@ -6,7 +6,7 @@ from PIL import Image from .helper import assert_image_equal, skip_unless_feature -pytestmark = [skip_unless_feature("jpegxl")] +pytestmark = skip_unless_feature("jpegxl") def test_n_frames() -> None: @@ -27,7 +27,7 @@ def test_float_duration() -> None: assert im.info["duration"] == 70 -def test_seeking() -> None: +def test_seek() -> None: """ Open an animated jxl file, and then try seeking through frames in reverse-order, verifying the durations are correct. @@ -42,9 +42,7 @@ def test_seeking() -> None: total_dur = 0 for frame in reversed(range(im1.n_frames)): im1.seek(frame) - im1.load() im2.seek(frame) - im2.load() assert_image_equal(im1.convert("RGB"), im2.convert("RGB")) diff --git a/Tests/test_file_jxl_metadata.py b/Tests/test_file_jxl_metadata.py index eb996fb41..267ea7a12 100644 --- a/Tests/test_file_jxl_metadata.py +++ b/Tests/test_file_jxl_metadata.py @@ -8,7 +8,7 @@ from PIL import Image, JpegXlImagePlugin from .helper import skip_unless_feature -pytestmark = [skip_unless_feature("jpegxl")] +pytestmark = skip_unless_feature("jpegxl") ElementTree: ModuleType | None try: @@ -33,8 +33,8 @@ def test_read_exif_metadata() -> None: exif = im.getexif() - # Camera make - assert exif[271] == "Canon" + # Camera make + assert exif[271] == "Canon" with Image.open("Tests/images/flower.jpg") as im_jpeg: expected_exif = im_jpeg.info["exif"] @@ -49,7 +49,7 @@ def test_read_exif_metadata_without_prefix() -> None: assert im.info["exif"][:6] != b"Exif\x00\x00" exif = im.getexif() - assert exif[305] == "Adobe Photoshop CS6 (Macintosh)" + assert exif[305] == "Adobe Photoshop CS6 (Macintosh)" def test_read_icc_profile() -> None: diff --git a/src/PIL/JpegXlImagePlugin.py b/src/PIL/JpegXlImagePlugin.py index 7a6cc274c..d824449ea 100644 --- a/src/PIL/JpegXlImagePlugin.py +++ b/src/PIL/JpegXlImagePlugin.py @@ -14,7 +14,7 @@ except ImportError: ## Future idea: -## it's not known how many frames does animated image have +## it's not known how many frames an animated image has ## by default, _jxl_decoder_new will iterate over all frames without decoding them ## then libjxl decoder is rewinded and we're ready to decode frame by frame ## if OPEN_COUNTS_FRAMES is False, n_frames will be None until the last frame is decoded @@ -74,8 +74,7 @@ class JpegXlImageFile(ImageFile.ImageFile): self._rewind() - def _get_next(self) -> tuple[bytes, float, float, bool]: - + def _get_next(self) -> tuple[bytes, float, float]: # Get next frame next_frame = self._decoder.get_next() self.__physical_frame += 1 @@ -95,7 +94,7 @@ class JpegXlImageFile(ImageFile.ImageFile): timestamp = self.__timestamp self.__timestamp += duration - return data, timestamp, duration, is_last + return data, timestamp, duration def _rewind(self, hard: bool = False) -> None: if hard: @@ -125,9 +124,7 @@ class JpegXlImageFile(ImageFile.ImageFile): if self.__loaded != self.__logical_frame: self._seek(self.__logical_frame) - data, timestamp, duration, is_last = self._get_next() - self.info["timestamp"] = timestamp - self.info["duration"] = duration + data, self.info["timestamp"], self.info["duration"] = self._get_next() self.__loaded = self.__logical_frame # Set tile