1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# Maintainer: Smoolak <smoolak@gmail.com>
pkgname=python-pillow-avif-plugin
_pkgname=pillow-avif-plugin
pkgver=1.6.0
pkgrel=2
pkgdesc="A pillow plugin that adds avif support via libavif"
arch=('x86_64')
url="https://github.com/fdintino/pillow-avif-plugin"
license=('BSD-2-Clause')
depends=(
'python'
'python-pillow'
'libavif'
)
makedepends=(
'python-build'
'python-installer'
'python-setuptools'
'python-wheel'
)
checkdepends=(
'python-pytest'
)
options=('!strip')
source=(
"$pkgname-$pkgver.tar.gz::https://github.com/fdintino/${_pkgname}/archive/refs/tags/v${pkgver}.tar.gz"
'aom-3.14-test.patch'
)
sha256sums=(
'266eff6e8e6eae1ae976a5986b461e122d4fdc046fbc3fbe97c81817bad03c16'
'af823f1665fc5a4218885f9af15212e379b17029994f6775880c710cae6d36a2'
)
prepare() {
cd "$_pkgname-$pkgver"
# AOM 3.14 uses PSNR tuning by default, so upstream's control and
# `tune=psnr` encodings are identical. SSIM still exercises the same
# advanced-option passthrough while producing a distinct encoding.
patch -Np1 -i "$srcdir/aom-3.14-test.patch"
}
build() {
cd "$_pkgname-$pkgver"
python -m build --wheel --no-isolation
}
check() {
cd "$_pkgname-$pkgver"
local _site_packages
_site_packages="$(python -c 'import sysconfig; print(sysconfig.get_path("purelib").lstrip("/"))')"
rm -rf "$srcdir/test-install"
python -m installer --destdir="$srcdir/test-install" dist/*.whl
# Keep the project root available for its tests package, while importing
# pillow_avif exclusively from the staged wheel.
PYTHONPATH="$PWD:$srcdir/test-install/$_site_packages" \
python -P -m pytest --import-mode=importlib tests
# Exercise the staged plugin through Pillow's normal encode/decode API.
PYTHONPATH="$srcdir/test-install/$_site_packages" python -P - <<'PY'
from io import BytesIO
from pathlib import Path
import os
from PIL import Image
import pillow_avif
staged = Path(os.environ["PYTHONPATH"]).resolve()
assert Path(pillow_avif.__file__).resolve().is_relative_to(staged)
source = Image.new("RGB", (32, 20), (48, 132, 208))
encoded = BytesIO()
source.save(encoded, "AVIF", quality=100, subsampling="4:4:4")
assert encoded.tell() > 100
encoded.seek(0)
with Image.open(encoded) as decoded:
assert decoded.format == "AVIF"
assert decoded.size == source.size
assert decoded.mode == "RGB"
pixel = decoded.getpixel((16, 10))
assert max(abs(actual - expected) for actual, expected in zip(pixel, (48, 132, 208))) <= 12
PY
}
package() {
cd "$_pkgname-$pkgver"
python -m installer --destdir="$pkgdir" dist/*.whl
install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
install -Dm644 README.md "$pkgdir/usr/share/doc/$pkgname/README.md"
}
|