Skip to content

Commit 7d50816

Browse files
fdintinoradarherehugovk
authored
Add AVIF plugin (decoder + encoder using libavif) (#5201)
Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com> Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
1 parent 999d9a7 commit 7d50816

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+2807
-8
lines changed

.ci/install.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ if [[ $(uname) != CYGWIN* ]]; then
2323
sudo apt-get -qq install libfreetype6-dev liblcms2-dev libtiff-dev python3-tk\
2424
ghostscript libjpeg-turbo8-dev libopenjp2-7-dev\
2525
cmake meson imagemagick libharfbuzz-dev libfribidi-dev\
26-
sway wl-clipboard libopenblas-dev
26+
sway wl-clipboard libopenblas-dev nasm
2727
fi
2828

2929
python3 -m pip install --upgrade pip
@@ -62,6 +62,9 @@ if [[ $(uname) != CYGWIN* ]]; then
6262
# raqm
6363
pushd depends && ./install_raqm.sh && popd
6464

65+
# libavif
66+
pushd depends && CMAKE_POLICY_VERSION_MINIMUM=3.5 ./install_libavif.sh && popd
67+
6568
# extra test images
6669
pushd depends && ./install_extra_test_images.sh && popd
6770
else

.github/workflows/macos-install.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ if [[ "$ImageOS" == "macos13" ]]; then
66
brew uninstall gradle maven
77
fi
88
brew install \
9+
aom \
10+
dav1d \
911
freetype \
1012
ghostscript \
1113
jpeg-turbo \
@@ -14,6 +16,8 @@ brew install \
1416
libtiff \
1517
little-cms2 \
1618
openjpeg \
19+
rav1e \
20+
svt-av1 \
1721
webp
1822
export PKG_CONFIG_PATH="/usr/local/opt/openblas/lib/pkgconfig"
1923

@@ -27,5 +31,8 @@ python3 -m pip install -U pytest-timeout
2731
python3 -m pip install pyroma
2832
python3 -m pip install numpy
2933

34+
# libavif
35+
pushd depends && ./install_libavif.sh && popd
36+
3037
# extra test images
3138
pushd depends && ./install_extra_test_images.sh && popd

.github/workflows/test-mingw.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ jobs:
6060
mingw-w64-x86_64-gcc \
6161
mingw-w64-x86_64-ghostscript \
6262
mingw-w64-x86_64-lcms2 \
63+
mingw-w64-x86_64-libavif \
6364
mingw-w64-x86_64-libimagequant \
6465
mingw-w64-x86_64-libjpeg-turbo \
6566
mingw-w64-x86_64-libraqm \

.github/workflows/test-windows.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
# Test the oldest Python on 32-bit
4343
- { python-version: "3.9", architecture: "x86", os: "windows-2019" }
4444

45-
timeout-minutes: 30
45+
timeout-minutes: 45
4646

4747
name: Python ${{ matrix.python-version }} (${{ matrix.architecture }})
4848

@@ -145,6 +145,10 @@ jobs:
145145
if: steps.build-cache.outputs.cache-hit != 'true'
146146
run: "& winbuild\\build\\build_dep_libpng.cmd"
147147

148+
- name: Build dependencies / libavif
149+
if: steps.build-cache.outputs.cache-hit != 'true' && matrix.architecture == 'x64'
150+
run: "& winbuild\\build\\build_dep_libavif.cmd"
151+
148152
# for FreeType WOFF2 font support
149153
- name: Build dependencies / brotli
150154
if: steps.build-cache.outputs.cache-hit != 'true'

.github/workflows/wheels-dependencies.sh

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ else
2525
MB_ML_LIBC=${AUDITWHEEL_POLICY::9}
2626
MB_ML_VER=${AUDITWHEEL_POLICY:9}
2727
fi
28-
PLAT=$CIBW_ARCHS
28+
PLAT="${CIBW_ARCHS:-$AUDITWHEEL_ARCH}"
2929

3030
# Define custom utilities
3131
source wheels/multibuild/common_utils.sh
@@ -51,6 +51,7 @@ LIBWEBP_VERSION=1.5.0
5151
BZIP2_VERSION=1.0.8
5252
LIBXCB_VERSION=1.17.0
5353
BROTLI_VERSION=1.1.0
54+
LIBAVIF_VERSION=1.2.1
5455

5556
if [[ $MB_ML_VER == 2014 ]]; then
5657
function build_xz {
@@ -116,6 +117,45 @@ function build_harfbuzz {
116117
touch harfbuzz-stamp
117118
}
118119

120+
function build_libavif {
121+
if [ -e libavif-stamp ]; then return; fi
122+
123+
python3 -m pip install meson ninja
124+
125+
if [[ "$PLAT" == "x86_64" ]] || [ -n "$SANITIZER" ]; then
126+
build_simple nasm 2.16.03 https://www.nasm.us/pub/nasm/releasebuilds/2.16.03
127+
fi
128+
129+
# For rav1e
130+
curl https://sh.rustup.rs -sSf | sh -s -- -y
131+
. "$HOME/.cargo/env"
132+
if [ -z "$IS_ALPINE" ] && [ -z "$SANITIZER" ] && [ -z "$IS_MACOS" ]; then
133+
yum install -y perl
134+
if [[ "$MB_ML_VER" == 2014 ]]; then
135+
yum install -y perl-IPC-Cmd
136+
fi
137+
fi
138+
139+
local out_dir=$(fetch_unpack https://github.com/AOMediaCodec/libavif/archive/refs/tags/v$LIBAVIF_VERSION.tar.gz libavif-$LIBAVIF_VERSION.tar.gz)
140+
(cd $out_dir \
141+
&& CMAKE_POLICY_VERSION_MINIMUM=3.5 cmake \
142+
-DCMAKE_INSTALL_PREFIX=$BUILD_PREFIX \
143+
-DCMAKE_INSTALL_LIBDIR=$BUILD_PREFIX/lib \
144+
-DCMAKE_BUILD_TYPE=Release \
145+
-DBUILD_SHARED_LIBS=OFF \
146+
-DAVIF_LIBSHARPYUV=LOCAL \
147+
-DAVIF_LIBYUV=LOCAL \
148+
-DAVIF_CODEC_AOM=LOCAL \
149+
-DAVIF_CODEC_DAV1D=LOCAL \
150+
-DAVIF_CODEC_RAV1E=LOCAL \
151+
-DAVIF_CODEC_SVT=LOCAL \
152+
-DENABLE_NASM=ON \
153+
-DCMAKE_MODULE_PATH=/tmp/cmake/Modules \
154+
. \
155+
&& make install)
156+
touch libavif-stamp
157+
}
158+
119159
function build {
120160
build_xz
121161
if [ -z "$IS_ALPINE" ] && [ -z "$SANITIZER" ] && [ -z "$IS_MACOS" ]; then
@@ -150,6 +190,7 @@ function build {
150190
build_tiff
151191
fi
152192

193+
build_libavif
153194
build_libpng
154195
build_lcms2
155196
build_openjpeg

.github/workflows/wheels.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ jobs:
160160
& python.exe winbuild\build_prepare.py -v --no-imagequant --architecture=${{ matrix.cibw_arch }}
161161
shell: pwsh
162162

163+
- name: Update rust
164+
if: matrix.cibw_arch == 'AMD64'
165+
run: |
166+
rustup update
167+
163168
- name: Build wheels
164169
run: |
165170
setlocal EnableDelayedExpansion

Tests/check_wheel.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import platform
4+
import struct
45
import sys
56

67
from PIL import features
@@ -9,7 +10,7 @@
910

1011

1112
def test_wheel_modules() -> None:
12-
expected_modules = {"pil", "tkinter", "freetype2", "littlecms2", "webp"}
13+
expected_modules = {"pil", "tkinter", "freetype2", "littlecms2", "webp", "avif"}
1314

1415
# tkinter is not available in cibuildwheel installed CPython on Windows
1516
try:
@@ -19,6 +20,11 @@ def test_wheel_modules() -> None:
1920
except ImportError:
2021
expected_modules.remove("tkinter")
2122

23+
# libavif is not available on Windows for x86 and ARM64 architectures
24+
if sys.platform == "win32":
25+
if platform.machine() == "ARM64" or struct.calcsize("P") == 4:
26+
expected_modules.remove("avif")
27+
2228
assert set(features.get_supported_modules()) == expected_modules
2329

2430

Tests/images/avif/exif.avif

15.7 KB
Binary file not shown.
5.31 KB
Binary file not shown.

Tests/images/avif/hopper.avif

3 KB
Binary file not shown.

Tests/images/avif/hopper.heif

3.47 KB
Binary file not shown.
29.6 KB
Loading

Tests/images/avif/icc_profile.avif

6.31 KB
Binary file not shown.
3.23 KB
Binary file not shown.

Tests/images/avif/rot0mir0.avif

16 KB
Binary file not shown.

Tests/images/avif/rot0mir1.avif

16.8 KB
Binary file not shown.

Tests/images/avif/rot1mir0.avif

16.8 KB
Binary file not shown.

Tests/images/avif/rot1mir1.avif

16.2 KB
Binary file not shown.

Tests/images/avif/rot2mir0.avif

16.6 KB
Binary file not shown.

Tests/images/avif/rot2mir1.avif

16 KB
Binary file not shown.

Tests/images/avif/rot3mir0.avif

16.2 KB
Binary file not shown.

Tests/images/avif/rot3mir1.avif

16.9 KB
Binary file not shown.

Tests/images/avif/star.avifs

29 KB
Binary file not shown.

Tests/images/avif/star.gif

2.83 KB
Loading

Tests/images/avif/star.png

3.75 KB
Loading

Tests/images/avif/transparency.avif

6.29 KB
Binary file not shown.
6.53 KB
Binary file not shown.

0 commit comments

Comments
 (0)