From 13022347613fdffbfaec2d298e47366c55d43ddf Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Wed, 13 Nov 2024 22:20:42 +1100 Subject: [PATCH] Allow unsupported warning to be returned when identifying container brands --- src/PIL/AvifImagePlugin.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/PIL/AvifImagePlugin.py b/src/PIL/AvifImagePlugin.py index de770cfd6f0..41172e27ad7 100644 --- a/src/PIL/AvifImagePlugin.py +++ b/src/PIL/AvifImagePlugin.py @@ -24,17 +24,11 @@ def _accept(prefix: bytes) -> bool | str: if prefix[4:8] != b"ftyp": return False - coding_brands = (b"avif", b"avis") - container_brands = (b"mif1", b"msf1") major_brand = prefix[8:12] - if major_brand in coding_brands: - if not SUPPORTED: - return ( - "image file could not be identified because AVIF " - "support not installed" - ) - return True - if major_brand in container_brands: + if major_brand in ( + # coding brands + b"avif", + b"avis", # We accept files with AVIF container brands; we can't yet know if # the ftyp box has the correct compatible brands, but if it doesn't # then the plugin will raise a SyntaxError which Pillow will catch @@ -42,6 +36,14 @@ def _accept(prefix: bytes) -> bool | str: # # Also, because this file might not actually be an AVIF file, we # don't raise an error if AVIF support isn't properly compiled. + b"mif1", + b"msf1", + ): + if not SUPPORTED: + return ( + "image file could not be identified because AVIF " + "support not installed" + ) return True return False @@ -104,10 +106,8 @@ def load(self) -> Image.core.PixelAccess | None: data, timescale, tsp_in_ts, dur_in_ts = self._decoder.get_frame( self.__frame ) - timestamp = round(1000 * (tsp_in_ts / timescale)) - duration = round(1000 * (dur_in_ts / timescale)) - self.info["timestamp"] = timestamp - self.info["duration"] = duration + self.info["timestamp"] = round(1000 * (tsp_in_ts / timescale)) + self.info["duration"] = round(1000 * (dur_in_ts / timescale)) self.__loaded = self.__frame # Set tile @@ -186,7 +186,7 @@ def _save( ) raise ValueError(msg) advanced = tuple( - [(str(k).encode("utf-8"), str(v).encode("utf-8")) for k, v in advanced] + (str(k).encode("utf-8"), str(v).encode("utf-8")) for k, v in advanced ) # Setup the AVIF encoder