Skip to content

Commit

Permalink
Allow unsupported warning to be returned when identifying container b…
Browse files Browse the repository at this point in the history
…rands
  • Loading branch information
radarhere committed Nov 13, 2024
1 parent 49f3680 commit 2783098
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/PIL/AvifImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,26 @@
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
# before moving on to the next plugin that accepts the file.
#
# 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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2783098

Please sign in to comment.