Skip to content

Commit 3d261a2

Browse files
fdintinoradarherehugovk
authored
Add AVIF to wheels using only aomenc and dav1d AVIF codecs for reduced size (#8858)
Co-authored-by: Andrew Murray <[email protected]> Co-authored-by: Hugo van Kemenade <[email protected]>
1 parent 46d9691 commit 3d261a2

File tree

9 files changed

+542
-7
lines changed

9 files changed

+542
-7
lines changed

.github/workflows/wheels-dependencies.sh

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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.3.0
5455

5556
function build_pkg_config {
5657
if [ -e pkg-config-stamp ]; then return; fi
@@ -98,6 +99,59 @@ function build_harfbuzz {
9899
touch harfbuzz-stamp
99100
}
100101

102+
function build_libavif {
103+
if [ -e libavif-stamp ]; then return; fi
104+
105+
python3 -m pip install meson ninja
106+
107+
if [[ "$PLAT" == "x86_64" ]] || [ -n "$SANITIZER" ]; then
108+
build_simple nasm 2.16.03 https://www.nasm.us/pub/nasm/releasebuilds/2.16.03
109+
fi
110+
111+
local build_type=MinSizeRel
112+
local lto=ON
113+
114+
local libavif_cmake_flags
115+
116+
if [ -n "$IS_MACOS" ]; then
117+
lto=OFF
118+
libavif_cmake_flags=(
119+
-DCMAKE_C_FLAGS_MINSIZEREL="-Oz -DNDEBUG -flto" \
120+
-DCMAKE_CXX_FLAGS_MINSIZEREL="-Oz -DNDEBUG -flto" \
121+
-DCMAKE_SHARED_LINKER_FLAGS_INIT="-Wl,-S,-x,-dead_strip_dylibs" \
122+
)
123+
else
124+
if [[ "$MB_ML_VER" == 2014 ]] && [[ "$PLAT" == "x86_64" ]]; then
125+
build_type=Release
126+
fi
127+
libavif_cmake_flags=(-DCMAKE_SHARED_LINKER_FLAGS_INIT="-Wl,--strip-all,-z,relro,-z,now")
128+
fi
129+
130+
local out_dir=$(fetch_unpack https://github.com/AOMediaCodec/libavif/archive/refs/tags/v$LIBAVIF_VERSION.tar.gz libavif-$LIBAVIF_VERSION.tar.gz)
131+
# CONFIG_AV1_HIGHBITDEPTH=0 is a flag for libaom (included as a subproject
132+
# of libavif) that disables support for encoding high bit depth images.
133+
(cd $out_dir \
134+
&& cmake \
135+
-DCMAKE_INSTALL_PREFIX=$BUILD_PREFIX \
136+
-DCMAKE_INSTALL_LIBDIR=$BUILD_PREFIX/lib \
137+
-DCMAKE_INSTALL_NAME_DIR=$BUILD_PREFIX/lib \
138+
-DBUILD_SHARED_LIBS=ON \
139+
-DAVIF_LIBSHARPYUV=LOCAL \
140+
-DAVIF_LIBYUV=LOCAL \
141+
-DAVIF_CODEC_AOM=LOCAL \
142+
-DCONFIG_AV1_HIGHBITDEPTH=0 \
143+
-DAVIF_CODEC_AOM_DECODE=OFF \
144+
-DAVIF_CODEC_DAV1D=LOCAL \
145+
-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=$lto \
146+
-DCMAKE_C_VISIBILITY_PRESET=hidden \
147+
-DCMAKE_CXX_VISIBILITY_PRESET=hidden \
148+
-DCMAKE_BUILD_TYPE=$build_type \
149+
"${libavif_cmake_flags[@]}" \
150+
. \
151+
&& make install)
152+
touch libavif-stamp
153+
}
154+
101155
function build {
102156
build_xz
103157
if [ -z "$IS_ALPINE" ] && [ -z "$SANITIZER" ] && [ -z "$IS_MACOS" ]; then
@@ -132,6 +186,7 @@ function build {
132186
build_tiff
133187
fi
134188

189+
build_libavif
135190
build_libpng
136191
build_lcms2
137192
build_openjpeg

.github/workflows/wheels.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ jobs:
159159
# Install extra test images
160160
xcopy /S /Y Tests\test-images\* Tests\images
161161
162-
& python.exe winbuild\build_prepare.py -v --no-imagequant --no-avif --architecture=${{ matrix.cibw_arch }}
162+
& python.exe winbuild\build_prepare.py -v --no-imagequant --architecture=${{ matrix.cibw_arch }}
163163
shell: pwsh
164164

165165
- name: Build wheels

Tests/check_wheel.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

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

1414
if sys.platform == "win32":
1515
# tkinter is not available in cibuildwheel installed CPython on Windows
@@ -20,6 +20,10 @@ def test_wheel_modules() -> None:
2020
except ImportError:
2121
expected_modules.remove("tkinter")
2222

23+
# libavif is not available on Windows for ARM64 architectures
24+
if platform.machine() == "ARM64":
25+
expected_modules.remove("avif")
26+
2327
assert set(features.get_supported_modules()) == expected_modules
2428

2529

docs/releasenotes/11.3.0.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ Pillow only supports libavif 1.0.0 or later. In order to prevent errors when bui
8080
from source, if a user happens to have an earlier libavif on their system, Pillow will
8181
now ignore it.
8282

83+
AVIF support in wheels
84+
^^^^^^^^^^^^^^^^^^^^^^
85+
86+
Support for reading and writing AVIF images is now included in Pillow's wheels, except
87+
for Windows ARM64. libaom is available as an encoder and dav1d as a decoder.
88+
8389
Python 3.14 beta
8490
^^^^^^^^^^^^^^^^
8591

wheels/dependency_licenses/AOM.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Copyright (c) 2016, Alliance for Open Media. All rights reserved.
2+
3+
Redistribution and use in source and binary forms, with or without
4+
modification, are permitted provided that the following conditions
5+
are met:
6+
7+
1. Redistributions of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer.
9+
10+
2. Redistributions in binary form must reproduce the above copyright
11+
notice, this list of conditions and the following disclaimer in
12+
the documentation and/or other materials provided with the
13+
distribution.
14+
15+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18+
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19+
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
25+
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26+
POSSIBILITY OF SUCH DAMAGE.

wheels/dependency_licenses/DAV1D.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Copyright © 2018-2019, VideoLAN and dav1d authors
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are met:
6+
7+
1. Redistributions of source code must retain the above copyright notice, this
8+
list of conditions and the following disclaimer.
9+
10+
2. Redistributions in binary form must reproduce the above copyright notice,
11+
this list of conditions and the following disclaimer in the documentation
12+
and/or other materials provided with the distribution.
13+
14+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
18+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

0 commit comments

Comments
 (0)