Skip to content

Commit f4f2453

Browse files
committed
Only use aom codec
1 parent 9f654ff commit f4f2453

File tree

13 files changed

+26
-289
lines changed

13 files changed

+26
-289
lines changed

.github/workflows/macos-install.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ if [[ "$ImageOS" == "macos13" ]]; then
77
fi
88
brew install \
99
aom \
10-
dav1d \
1110
freetype \
1211
ghostscript \
1312
jpeg-turbo \
@@ -16,8 +15,6 @@ brew install \
1615
libtiff \
1716
little-cms2 \
1817
openjpeg \
19-
rav1e \
20-
svt-av1 \
2118
webp
2219
export PKG_CONFIG_PATH="/usr/local/opt/openblas/lib/pkgconfig"
2320

.github/workflows/wheels-dependencies.sh

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,6 @@ function build_libavif {
122122
build_simple nasm 2.16.03 https://www.nasm.us/pub/nasm/releasebuilds/2.16.03
123123
fi
124124

125-
# For rav1e
126-
curl https://sh.rustup.rs -sSf | sh -s -- -y
127-
. "$HOME/.cargo/env"
128-
if [ -z "$IS_ALPINE" ] && [ -z "$SANITIZER" ] && [ -z "$IS_MACOS" ]; then
129-
yum install -y perl
130-
if [[ "$MB_ML_VER" == 2014 ]]; then
131-
yum install -y perl-IPC-Cmd
132-
fi
133-
fi
134-
135125
local out_dir=$(fetch_unpack https://github.com/AOMediaCodec/libavif/archive/refs/tags/v$LIBAVIF_VERSION.tar.gz libavif-$LIBAVIF_VERSION.tar.gz)
136126
(cd $out_dir \
137127
&& CMAKE_POLICY_VERSION_MINIMUM=3.5 cmake \
@@ -142,9 +132,6 @@ function build_libavif {
142132
-DAVIF_LIBSHARPYUV=LOCAL \
143133
-DAVIF_LIBYUV=LOCAL \
144134
-DAVIF_CODEC_AOM=LOCAL \
145-
-DAVIF_CODEC_DAV1D=LOCAL \
146-
-DAVIF_CODEC_RAV1E=LOCAL \
147-
-DAVIF_CODEC_SVT=LOCAL \
148135
-DENABLE_NASM=ON \
149136
-DCMAKE_MODULE_PATH=/tmp/cmake/Modules \
150137
. \

.github/workflows/wheels.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,6 @@ 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-
168163
- name: Build wheels
169164
run: |
170165
setlocal EnableDelayedExpansion

Tests/test_file_avif.py

Lines changed: 13 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,6 @@ def roundtrip(im: ImageFile.ImageFile, **options: Any) -> ImageFile.ImageFile:
5151
return Image.open(out)
5252

5353

54-
def skip_unless_avif_decoder(codec_name: str) -> pytest.MarkDecorator:
55-
reason = f"{codec_name} decode not available"
56-
return pytest.mark.skipif(
57-
not HAVE_AVIF or not _avif.decoder_codec_available(codec_name), reason=reason
58-
)
59-
60-
61-
def skip_unless_avif_encoder(codec_name: str) -> pytest.MarkDecorator:
62-
reason = f"{codec_name} encode not available"
63-
return pytest.mark.skipif(
64-
not HAVE_AVIF or not _avif.encoder_codec_available(codec_name), reason=reason
65-
)
66-
67-
6854
def is_docker_qemu() -> bool:
6955
try:
7056
init_proc_exe = os.readlink("/proc/1/exe")
@@ -99,15 +85,12 @@ def test_version(self) -> None:
9985
def test_codec_version(self) -> None:
10086
assert AvifImagePlugin.get_codec_version("unknown") is None
10187

102-
for codec_name in ("aom", "dav1d", "rav1e", "svt"):
103-
codec_version = AvifImagePlugin.get_codec_version(codec_name)
104-
if _avif.decoder_codec_available(
105-
codec_name
106-
) or _avif.encoder_codec_available(codec_name):
107-
assert codec_version is not None
108-
assert re.search(r"^v?\d+\.\d+\.\d+(-([a-z\d])+)*$", codec_version)
109-
else:
110-
assert codec_version is None
88+
codec_version = AvifImagePlugin.get_codec_version("aom")
89+
if _avif.decoder_codec_available() or _avif.encoder_codec_available():
90+
assert codec_version is not None
91+
assert re.search(r"^v?\d+\.\d+\.\d+(-([a-z\d])+)*$", codec_version)
92+
else:
93+
assert codec_version is None
11194

11295
def test_read(self) -> None:
11396
"""
@@ -181,6 +164,10 @@ def test_encoder_finish_none_error(
181164
"""Save should raise an OSError if AvifEncoder.finish returns None"""
182165

183166
class _mock_avif:
167+
@classmethod
168+
def encoder_codec_available(cls) -> bool:
169+
return True
170+
184171
class AvifEncoder:
185172
def __init__(self, *args: Any) -> None:
186173
pass
@@ -434,26 +421,6 @@ def test_encoder_range_invalid(self, tmp_path: Path) -> None:
434421
with pytest.raises(ValueError):
435422
im.save(test_file, range="foo")
436423

437-
@skip_unless_avif_encoder("aom")
438-
def test_encoder_codec_param(self, tmp_path: Path) -> None:
439-
with Image.open(TEST_AVIF_FILE) as im:
440-
test_file = tmp_path / "temp.avif"
441-
im.save(test_file, codec="aom")
442-
443-
def test_encoder_codec_invalid(self, tmp_path: Path) -> None:
444-
with Image.open(TEST_AVIF_FILE) as im:
445-
test_file = tmp_path / "temp.avif"
446-
with pytest.raises(ValueError):
447-
im.save(test_file, codec="foo")
448-
449-
@skip_unless_avif_decoder("dav1d")
450-
def test_decoder_codec_cannot_encode(self, tmp_path: Path) -> None:
451-
with Image.open(TEST_AVIF_FILE) as im:
452-
test_file = tmp_path / "temp.avif"
453-
with pytest.raises(ValueError):
454-
im.save(test_file, codec="dav1d")
455-
456-
@skip_unless_avif_encoder("aom")
457424
@pytest.mark.parametrize(
458425
"advanced",
459426
[
@@ -470,86 +437,30 @@ def test_encoder_advanced_codec_options(
470437
) -> None:
471438
with Image.open(TEST_AVIF_FILE) as im:
472439
ctrl_buf = BytesIO()
473-
im.save(ctrl_buf, "AVIF", codec="aom")
440+
im.save(ctrl_buf, "AVIF")
474441
test_buf = BytesIO()
475442
im.save(
476443
test_buf,
477444
"AVIF",
478-
codec="aom",
479445
advanced=advanced,
480446
)
481447
assert ctrl_buf.getvalue() != test_buf.getvalue()
482448

483-
@skip_unless_avif_encoder("aom")
484449
@pytest.mark.parametrize("advanced", [{"foo": "bar"}, {"foo": 1234}, 1234])
485450
def test_encoder_advanced_codec_options_invalid(
486451
self, tmp_path: Path, advanced: dict[str, str] | int
487452
) -> None:
488453
with Image.open(TEST_AVIF_FILE) as im:
489454
test_file = tmp_path / "temp.avif"
490455
with pytest.raises(ValueError):
491-
im.save(test_file, codec="aom", advanced=advanced)
492-
493-
@skip_unless_avif_decoder("aom")
494-
def test_decoder_codec_param(self, monkeypatch: pytest.MonkeyPatch) -> None:
495-
monkeypatch.setattr(AvifImagePlugin, "DECODE_CODEC_CHOICE", "aom")
496-
497-
with Image.open(TEST_AVIF_FILE) as im:
498-
assert im.size == (128, 128)
499-
500-
@skip_unless_avif_encoder("rav1e")
501-
def test_encoder_codec_cannot_decode(
502-
self, monkeypatch: pytest.MonkeyPatch, tmp_path: Path
503-
) -> None:
504-
monkeypatch.setattr(AvifImagePlugin, "DECODE_CODEC_CHOICE", "rav1e")
505-
506-
with pytest.raises(ValueError):
507-
with Image.open(TEST_AVIF_FILE):
508-
pass
509-
510-
def test_decoder_codec_invalid(self, monkeypatch: pytest.MonkeyPatch) -> None:
511-
monkeypatch.setattr(AvifImagePlugin, "DECODE_CODEC_CHOICE", "foo")
512-
513-
with pytest.raises(ValueError):
514-
with Image.open(TEST_AVIF_FILE):
515-
pass
516-
517-
@skip_unless_avif_encoder("aom")
518-
def test_encoder_codec_available(self) -> None:
519-
assert _avif.encoder_codec_available("aom") is True
520-
521-
def test_encoder_codec_available_bad_params(self) -> None:
522-
with pytest.raises(TypeError):
523-
_avif.encoder_codec_available()
524-
525-
@skip_unless_avif_decoder("dav1d")
526-
def test_encoder_codec_available_cannot_decode(self) -> None:
527-
assert _avif.encoder_codec_available("dav1d") is False
528-
529-
def test_encoder_codec_available_invalid(self) -> None:
530-
assert _avif.encoder_codec_available("foo") is False
456+
im.save(test_file, advanced=advanced)
531457

532458
def test_encoder_quality_valueerror(self, tmp_path: Path) -> None:
533459
with Image.open(TEST_AVIF_FILE) as im:
534460
test_file = tmp_path / "temp.avif"
535461
with pytest.raises(ValueError):
536462
im.save(test_file, quality="invalid")
537463

538-
@skip_unless_avif_decoder("aom")
539-
def test_decoder_codec_available(self) -> None:
540-
assert _avif.decoder_codec_available("aom") is True
541-
542-
def test_decoder_codec_available_bad_params(self) -> None:
543-
with pytest.raises(TypeError):
544-
_avif.decoder_codec_available()
545-
546-
@skip_unless_avif_encoder("rav1e")
547-
def test_decoder_codec_available_cannot_decode(self) -> None:
548-
assert _avif.decoder_codec_available("rav1e") is False
549-
550-
def test_decoder_codec_available_invalid(self) -> None:
551-
assert _avif.decoder_codec_available("foo") is False
552-
553464
def test_p_mode_transparency(self, tmp_path: Path) -> None:
554465
im = Image.new("P", size=(64, 64))
555466
draw = ImageDraw.Draw(im)
@@ -570,16 +481,10 @@ def test_decoder_strict_flags(self) -> None:
570481
with Image.open("Tests/images/avif/hopper-missing-pixi.avif") as im:
571482
assert im.size == (128, 128)
572483

573-
@skip_unless_avif_encoder("aom")
574484
@pytest.mark.parametrize("speed", [-1, 1, 11])
575485
def test_aom_optimizations(self, tmp_path: Path, speed: int) -> None:
576486
test_file = tmp_path / "temp.avif"
577-
hopper().save(test_file, codec="aom", speed=speed)
578-
579-
@skip_unless_avif_encoder("svt")
580-
def test_svt_optimizations(self, tmp_path: Path) -> None:
581-
test_file = tmp_path / "temp.avif"
582-
hopper().save(test_file, codec="svt", speed=1)
487+
hopper().save(test_file, speed=speed)
583488

584489

585490
@skip_unless_feature("avif")

depends/install_libavif.sh

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,6 @@ if $PKGCONFIG --exists aom; then
2525
HAS_DECODER=1
2626
fi
2727

28-
if $PKGCONFIG --exists dav1d; then
29-
LIBAVIF_CMAKE_FLAGS+=(-DAVIF_CODEC_DAV1D=SYSTEM)
30-
HAS_DECODER=1
31-
fi
32-
33-
if $PKGCONFIG --exists libgav1; then
34-
LIBAVIF_CMAKE_FLAGS+=(-DAVIF_CODEC_LIBGAV1=SYSTEM)
35-
HAS_DECODER=1
36-
fi
37-
38-
if $PKGCONFIG --exists rav1e; then
39-
LIBAVIF_CMAKE_FLAGS+=(-DAVIF_CODEC_RAV1E=SYSTEM)
40-
HAS_ENCODER=1
41-
fi
42-
43-
if $PKGCONFIG --exists SvtAv1Enc; then
44-
LIBAVIF_CMAKE_FLAGS+=(-DAVIF_CODEC_SVT=SYSTEM)
45-
HAS_ENCODER=1
46-
fi
47-
4828
if [ "$HAS_ENCODER" != 1 ] || [ "$HAS_DECODER" != 1 ]; then
4929
LIBAVIF_CMAKE_FLAGS+=(-DAVIF_CODEC_AOM=LOCAL)
5030
fi

docs/handbook/image-file-formats.rst

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,11 @@ The :py:meth:`~PIL.Image.Image.save` method supports the following options:
5050
Quality/speed trade-off (0=slower/better, 10=fastest). Defaults to 6.
5151

5252
**max_threads**
53-
Limit the number of active threads used. By default, there is no limit. If the aom
54-
codec is used, there is a maximum of 64.
53+
Limit the number of active threads used. There is a maximum of 64.
5554

5655
**range**
5756
YUV range, either "full" or "limited". Defaults to "full".
5857

59-
**codec**
60-
AV1 codec to use for encoding. Specific values are "aom", "rav1e", and
61-
"svt", presuming the chosen codec is available. Defaults to "auto", which
62-
will choose the first available codec in the order of the preceding list.
63-
6458
**tile_rows** / **tile_cols**
6559
For tile encoding, the (log 2) number of tile rows and columns to use.
6660
Valid values are 0-6, default 0. Ignored if "autotiling" is set to true.

docs/installation/building-from-source.rst

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,9 @@ Many of Pillow's features require external libraries:
9292
* **libavif** provides support for the AVIF format.
9393

9494
* Pillow requires libavif version **1.0.0** or greater.
95-
* libavif is merely an API that wraps AVIF codecs. If you are compiling
96-
libavif from source, you will also need to install both an AVIF encoder
97-
and decoder, such as rav1e and dav1d, or libaom, which both encodes and
98-
decodes AVIF images.
95+
* libavif is merely an API that wraps AVIF codecs. If you are compiling libavif from
96+
source, you will also need to install libaom, which both encodes and decodes AVIF
97+
images.
9998

10099
.. tab:: Linux
101100

@@ -164,14 +163,6 @@ Many of Pillow's features require external libraries:
164163

165164
brew install libavif libjpeg libraqm libtiff little-cms2 openjpeg webp
166165

167-
If you would like to use libavif with more codecs than just aom, then
168-
instead of installing libavif through Homebrew directly, you can use
169-
Homebrew to install libavif's build dependencies::
170-
171-
brew install aom dav1d rav1e svt-av1
172-
173-
Then see ``depends/install_libavif.sh`` to install libavif.
174-
175166
.. tab:: Windows
176167

177168
We recommend you use prebuilt wheels from PyPI.

src/PIL/AvifImagePlugin.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
except ImportError:
1414
SUPPORTED = False
1515

16-
# Decoder options as module globals, until there is a way to pass parameters
17-
# to Image.open (see https://github.com/python-pillow/Pillow/issues/569)
18-
DECODE_CODEC_CHOICE = "auto"
1916
# Decoding is only affected by this for libavif **0.8.4** or greater.
2017
DEFAULT_MAX_THREADS = 0
2118

@@ -73,14 +70,11 @@ def _open(self) -> None:
7370
msg = "image file could not be opened because AVIF support not installed"
7471
raise SyntaxError(msg)
7572

76-
if DECODE_CODEC_CHOICE != "auto" and not _avif.decoder_codec_available(
77-
DECODE_CODEC_CHOICE
78-
):
79-
msg = "Invalid opening codec"
73+
if not _avif.decoder_codec_available():
74+
msg = "Codec not available"
8075
raise ValueError(msg)
8176
self._decoder = _avif.AvifDecoder(
8277
self.fp.read(),
83-
DECODE_CODEC_CHOICE,
8478
_get_default_max_threads(),
8579
)
8680

@@ -165,9 +159,8 @@ def _save(
165159
subsampling = info.get("subsampling", "4:2:0")
166160
speed = info.get("speed", 6)
167161
max_threads = info.get("max_threads", _get_default_max_threads())
168-
codec = info.get("codec", "auto")
169-
if codec != "auto" and not _avif.encoder_codec_available(codec):
170-
msg = "Invalid saving codec"
162+
if not _avif.encoder_codec_available():
163+
msg = "Codec not available"
171164
raise ValueError(msg)
172165
range_ = info.get("range", "full")
173166
tile_rows_log2 = info.get("tile_rows", 0)
@@ -218,7 +211,6 @@ def _save(
218211
quality,
219212
speed,
220213
max_threads,
221-
codec,
222214
range_,
223215
tile_rows_log2,
224216
tile_cols_log2,

0 commit comments

Comments
 (0)