Skip to content

Commit

Permalink
FEAT: Support for AVIF image format (#1048)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pandede committed Nov 6, 2023
1 parent b060cf7 commit d24944f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
9 changes: 8 additions & 1 deletion imageio/config/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1856,7 +1856,14 @@ def reset(self):
priority=["tifffile"],
),
FileExtension(
name="High Efficiency Image File Format", extension=".heic", priority=["pillow"]
name="High Efficiency Image File Format",
extension=".heic",
priority=["pillow"],
),
FileExtension(
name="AV1 Image File Format",
extension=".avif",
priority=["pillow"],
),
]
extension_list.sort(key=lambda x: x.extension)
Expand Down
8 changes: 8 additions & 0 deletions imageio/plugins/pillow.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ def __init__(self, request: Request) -> None:
else:
register_heif_opener()

# Register AVIF opener for Pillow
try:
from pillow_heif import register_avif_opener
except ImportError:
pass
else:
register_avif_opener()

self._image: Image = None
self.images_to_write = []

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
"swf": [],
"tifffile": ["tifffile"],
"pyav": ["av"],
"heif": ["pillow-heif"],
"pillow-heif": ["pillow-heif"],
}

cpython_only_plugins = {
Expand Down
7 changes: 7 additions & 0 deletions tests/test_pillow.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,3 +712,10 @@ def test_heif_remote():
url = "http://github.com/tigranbs/test-heic-images/raw/master/image4.heic"
im = iio.imread(url, plugin="pillow")
assert im.shape == (476, 700, 4)


@pytest.mark.needs_internet
def test_avif_remote():
url = "https://github.com/link-u/avif-sample-images/raw/master/fox.profile0.10bpc.yuv420.avif"
im = iio.imread(url, plugin="pillow")
assert im.shape == (800, 1204, 3)

0 comments on commit d24944f

Please sign in to comment.