Skip to content

Commit 867516f

Browse files
authored
Merge pull request #2 from mlocati/fix-heic-support
Install libheif only if libx265 is available
2 parents f0e428b + 93b1954 commit 867516f

File tree

3 files changed

+192
-24
lines changed

3 files changed

+192
-24
lines changed

.github/workflows/create-images.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,26 +93,50 @@ jobs:
9393
-
9494
name: Update apt packages
9595
run: docker exec -t imagine-${{ matrix.php-version }} apt-get upgrade -qy
96+
-
97+
name: Inspect container environment
98+
id: inspect
99+
run: |
100+
if docker exec -t imagine-${{ matrix.php-version }} /installer.sh support-avif; then
101+
echo 'AVIF is supported'
102+
AVIF_SUPPORT=yes
103+
else
104+
AVIF_SUPPORT=no
105+
fi
106+
if docker exec -t imagine-${{ matrix.php-version }} /installer.sh support-heic; then
107+
echo 'HEIC is supported'
108+
HEIC_SUPPORT=yes
109+
else
110+
HEIC_SUPPORT=no
111+
fi
112+
echo "::set-output name=avif-support::$AVIF_SUPPORT"
113+
echo "::set-output name=heic-support::$HEIC_SUPPORT"
96114
-
97115
name: Install git
98116
run: docker exec -t imagine-${{ matrix.php-version }} /installer.sh git $GIT_VERSION
99117
-
100118
name: Install libaom ${{ env.LIBAOM_VERSION }}
119+
if: ${{ steps.inspect.outputs.avif-support == 'yes' || steps.inspect.outputs.heic-support == 'yes' }}
101120
run: docker exec -t imagine-${{ matrix.php-version }} /installer.sh libaom $LIBAOM_VERSION
102121
-
103122
name: Install libdav1d ${{ env.LIBDAV1D_VERSION }}
123+
if: ${{ steps.inspect.outputs.avif-support == 'yes' }}
104124
run: docker exec -t imagine-${{ matrix.php-version }} /installer.sh libdav1d $LIBDAV1D_VERSION
105125
-
106126
name: Install libyuv
127+
if: ${{ steps.inspect.outputs.avif-support == 'yes' || steps.inspect.outputs.heic-support == 'yes' }}
107128
run: docker exec -t imagine-${{ matrix.php-version }} /installer.sh libyuv
108129
-
109130
name: Install libavif ${{ env.LIBAVIF_VERSION }}
131+
if: ${{ steps.inspect.outputs.avif-support == 'yes' }}
110132
run: docker exec -t imagine-${{ matrix.php-version }} /installer.sh libavif $LIBAVIF_VERSION
111133
-
112134
name: Install libde265 ${{ env.LIBDE265_VERSION }}
135+
if: ${{ steps.inspect.outputs.heic-support == 'yes' }}
113136
run: docker exec -t imagine-${{ matrix.php-version }} /installer.sh libde265 $LIBDE265_VERSION
114137
-
115138
name: Install libheif ${{ env.LIBHEIF_VERSION }}
139+
if: ${{ steps.inspect.outputs.heic-support == 'yes' }}
116140
run: docker exec -t imagine-${{ matrix.php-version }} /installer.sh libheif $LIBHEIF_VERSION
117141
-
118142
name: Install Composer

docker/installer.sh

Lines changed: 158 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,18 @@ installGit() {
3131
git version --build-options
3232
}
3333

34-
# Try to install libaom.
34+
# Install libaom.
3535
#
3636
# Arguments:
3737
# $1: the version to be installed
38+
#
39+
# Return:
40+
# 0 in case of success
41+
# 1 in case of errors
3842
installLibaom() {
39-
if ! isCMakeAtLeastVersion '3.6'; then
40-
echo 'libaom not installed because cmake is too old' >&2
41-
return
43+
if ! isAvifSupported 2>/dev/null && ! isHeicSupported 2>/dev/null; then
44+
echo 'libaom not installed because the system does not support neither AVIF nor HEIC' >&2
45+
return 1
4246
fi
4347
installAptPackages '' 'cmake ninja-build nasm'
4448
printf 'Downloading libaom v%s... ' "$1"
@@ -54,16 +58,21 @@ installLibaom() {
5458
ldconfig
5559
markPackagesAsInstalledByRegex '^(lib)?aom([0-9]|-dev)'
5660
pkg-config --list-all | grep -E '^(lib)?aom\s'
61+
return 0
5762
}
5863

59-
# Try to install libdav1d.
64+
# Install libdav1d.
6065
#
6166
# Arguments:
6267
# $1: the version to be installed
68+
#
69+
# Return:
70+
# 0 in case of success
71+
# 1 in case of errors
6372
installLibdav1d() {
64-
if ! isMesonAtLeastVersion '0.44'; then
65-
echo 'libdav1d not installed because meson is too old' >&2
66-
return
73+
if ! isAvifSupported 2>/dev/null; then
74+
echo 'libdav1d not installed because the system does not support AVIF' >&2
75+
return 1
6776
fi
6877
installAptPackages '' 'meson ninja-build nasm'
6978
printf 'Downloading libdav1d v%s... ' "$1"
@@ -82,16 +91,21 @@ installLibdav1d() {
8291
ldconfig
8392
markPackagesAsInstalledByRegex '^(lib)?dav1d([0-9]|-dev)'
8493
pkg-config --list-all | grep -E '^(lib)?dav1d\s'
94+
return 0
8595
}
8696

87-
# Try to install libyuv.
97+
# Install libyuv.
8898
#
8999
# Arguments:
90100
# $1: the version to be installed
101+
#
102+
# Return:
103+
# 0 in case of success
104+
# 1 in case of errors
91105
installLibyuv() {
92-
if ! isGccAtLeastVersion '4.9.3'; then
93-
echo 'libyuv not installed because gcc is too old' >&2
94-
return
106+
if ! isAvifSupported 2>/dev/null && ! isHeicSupported 2>/dev/null; then
107+
echo 'libyuv not installed because the system does not support neither AVIF nor HEIC' >&2
108+
return 1
95109
fi
96110
installAptPackages '^libjpeg[0-9]*-turbo' 'cmake ^libjpeg[0-9]*-turbo-dev'
97111
printf 'Downloading libyuv... '
@@ -100,27 +114,60 @@ installLibyuv() {
100114
printf 'done.\n'
101115
mkdir "$installLibyuv_dir/build"
102116
cd "$installLibyuv_dir/build"
117+
printf '\nconfigure_file(imaginepatch-libyuv.pc.in imaginepatch-libyuv.pc @ONLY)\n' >>../CMakeLists.txt
118+
cat <<'EOT' >../imaginepatch-libyuv.pc.in
119+
prefix=@CMAKE_INSTALL_PREFIX@
120+
exec_prefix=${prefix}
121+
includedir=${prefix}/include
122+
libdir=${prefix}/lib
123+
124+
Name: @CPACK_PACKAGE_NAME@
125+
Description: @CPACK_PACKAGE_DESCRIPTION@
126+
Version: @CPACK_PACKAGE_VERSION@
127+
Requires: @pc_req_public@
128+
Requires.private: @pc_req_private@
129+
Cflags: -I${includedir}
130+
Libs: -L${libdir} -llibyuv
131+
EOT
103132
cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr -B. ..
104133
make -j$(nproc) install
134+
ldconfig
135+
if ! pkg-config --exists libyuv && ! pkg-config --exists yuv; then
136+
cp imaginepatch-libyuv.pc /usr/lib/pkgconfig/libyuv.pc
137+
ldconfig
138+
fi
105139
cd - >/dev/null
106140
rm -rf "$installLibyuv_dir"
107141
ldconfig
108142
markPackagesAsInstalledByRegex '^(lib)?yuv([0-9]|-dev)'
109-
#pkg-config --list-all | grep -E '^(lib)?yuv\s'
143+
pkg-config --list-all | grep -E '^(lib)?yuv\s'
144+
return 0
110145
}
111146

112-
# Try to install libavif.
147+
# Install libavif.
113148
#
114149
# Arguments:
115150
# $1: the version to be installed
151+
#
152+
# Return:
153+
# 0 in case of success
154+
# 1 in case of errors
116155
installLibavif() {
156+
if ! isAvifSupported 2>/dev/null; then
157+
echo 'libavif not installed because the system does not support AVIF' >&2
158+
return 1
159+
fi
117160
if ! pkg-config --list-all | grep -E '^(lib)?aom\s' >/dev/null; then
118161
echo 'libavif not installed because libaom is not installed' >&2
119-
return
162+
return 1
120163
fi
121-
if ! isCMakeAtLeastVersion '3.5'; then
122-
echo 'libavif not installed because cmake is too old' >&2
123-
return
164+
if ! pkg-config --list-all | grep -E '^(lib)?dav1d\s' >/dev/null; then
165+
echo 'libavif not installed because libdav1d is not installed' >&2
166+
return 1
167+
fi
168+
if ! pkg-config --list-all | grep -E '^(lib)?yuv\s' >/dev/null; then
169+
echo 'libavif not installed because libyuv is not installed' >&2
170+
return 1
124171
fi
125172
installAptPackages '' 'cmake'
126173
printf 'Downloading libavif v%s... ' "$1"
@@ -136,17 +183,26 @@ installLibavif() {
136183
ldconfig
137184
markPackagesAsInstalledByRegex '^(lib)?avif([0-9]|-dev)'
138185
pkg-config --list-all | grep -E '^(lib)?avif\s'
186+
return 0
139187
}
140188

141189
# Install libde265.
142190
#
143191
# Arguments:
144192
# $1: the version to be installed
145193
#
194+
# Return:
195+
# 0 in case of success
196+
# 1 in case of errors
197+
#
146198
# @todo:
147199
# configure: WARNING: Did not find libvideogfx or libsdl, video output of dec265 will be disabled.
148200
# configure: WARNING: Did not find libvideogfx or libswscale, compilation of sherlock265 will be disabled.
149201
installLibde265() {
202+
if ! isHeicSupported 2>/dev/null; then
203+
echo 'libde265 not installed because the system does not support HEIC' >&2
204+
return 1
205+
fi
150206
installAptPackages '' 'automake libtool'
151207
printf 'Downloading libde265 v%s... ' "$1"
152208
installLibde265_dir="$(mktemp -d)"
@@ -161,14 +217,31 @@ installLibde265() {
161217
ldconfig
162218
markPackagesAsInstalledByRegex '^(lib)?de265'
163219
pkg-config --list-all | grep -E '^(lib)?de265\s'
220+
return 0
164221
}
165222

166223
# Install libheif.
167224
#
168225
# Arguments:
169226
# $1: the version to be installed
227+
#
228+
# Return:
229+
# 0 in case of success
230+
# 1 in case of errors
170231
installLibheif() {
171-
installAptPackages '^libjpeg[0-9]*-turbo ^libpng[0-9\-]*$' 'automake libtool ^libjpeg[0-9]*-turbo-dev libpng-dev'
232+
if ! isHeicSupported 2>/dev/null; then
233+
echo 'libheif not installed because the system does not support HEIC' >&2
234+
return 1
235+
fi
236+
if ! pkg-config --list-all | grep -E '^(lib)?aom\s' >/dev/null; then
237+
echo 'libheif not installed because libaom is not installed' >&2
238+
return 1
239+
fi
240+
if ! pkg-config --list-all | grep -E '^(lib)?de265\s' >/dev/null; then
241+
echo 'libheif not installed because libde265 is not installed' >&2
242+
return 1
243+
fi
244+
installAptPackages '^libjpeg[0-9]*-turbo ^libpng[0-9\-]*$ ^libx265(-[0-9\.\-]+)?$' 'automake libtool ^libjpeg[0-9]*-turbo-dev libpng-dev libx265-dev'
172245
printf 'Downloading libheif v%s... ' "$1"
173246
installLibheif_dir="$(mktemp -d)"
174247
curl -ksSLf -o - https://github.com/strukturag/libheif/releases/download/v$1/libheif-$1.tar.gz | tar xzm -C "$installLibheif_dir"
@@ -182,6 +255,59 @@ installLibheif() {
182255
ldconfig
183256
markPackagesAsInstalledByRegex '^libheif.*'
184257
pkg-config --list-all | grep -E '^(lib)?heif\s'
258+
return 0
259+
}
260+
261+
# Check if AVIF format is supported in this environment
262+
#
263+
# Output (stderr):
264+
# the reason (if any) why it's not supported
265+
#
266+
# Return:
267+
# 0: true
268+
# 1: false
269+
isAvifSupported() {
270+
if ! isCMakeAtLeastVersion '3.6'; then
271+
echo 'AVIF support not provided since compiling libaom requires a more recent cmake version' >&2
272+
return 1
273+
fi
274+
if ! isMesonAtLeastVersion '0.44'; then
275+
echo 'AVIF support not provided since compiling libdav1d requires a more recent meson version' >&2
276+
return 1
277+
fi
278+
if ! isGccAtLeastVersion '4.9.3'; then
279+
echo 'AVIF support not provided since compiling libyuv requires a more recent gcc version' >&2
280+
return 1
281+
fi
282+
if ! isCMakeAtLeastVersion '3.5'; then
283+
echo 'AVIF support not provided since compiling libavif requires a more recent cmake version' >&2
284+
return 1
285+
fi
286+
return 0
287+
}
288+
289+
# Check if HEIC format is supported in this environment
290+
#
291+
# Output (stderr):
292+
# the reason (if any) why it's not supported
293+
#
294+
# Return:
295+
# 0: true
296+
# 1: false
297+
isHeicSupported() {
298+
if ! isCMakeAtLeastVersion '3.6'; then
299+
echo 'HEIC support not provided since compiling libaom requires a more recent cmake version' >&2
300+
return 1
301+
fi
302+
if [ -z "$(getAptPackageAvailableVersion 'libx265(-[0-9\.\-]+)?$')" ]; then
303+
echo 'HEIC support not provided since libx265 is not available'
304+
return 1
305+
fi
306+
if ! isGccAtLeastVersion '4.9.3'; then
307+
echo 'HEIC support not provided since compiling libyuv requires a more recent gcc version' >&2
308+
return 1
309+
fi
310+
return 0
185311
}
186312

187313
# Install GraphicsMagick.
@@ -204,7 +330,7 @@ installGraphicsmagick() {
204330
curl -ksSLf -o - http://ftp.icm.edu.pl/pub/unix/graphics/GraphicsMagick/${1%.*}/GraphicsMagick-$1.tar.gz | tar xzm -C "$installGraphicsmagick_dir"
205331
printf 'done.\n'
206332
cd "$installGraphicsmagick_dir/GraphicsMagick-$1"
207-
CFLAGS='-Wno-misleading-indentation -Wno-unused-const-variable -Wno-pointer-compare -Wno-tautological-compare' ./configure --enable-shared
333+
CFLAGS='-Wno-misleading-indentation -Wno-unused-const-variable -Wno-pointer-compare -Wno-tautological-compare' ./configure --disable-static --enable-shared
208334
make V=0 -j$(nproc) install
209335
cd - >/dev/null
210336
rm -rf "$installGraphicsmagick_dir"
@@ -232,7 +358,7 @@ installImagemagick() {
232358
curl -ksSLf -o - https://www.imagemagick.org/download/releases/ImageMagick-$1.tar.xz | tar xJm -C "$installImagemagick_dir"
233359
printf 'done.\n'
234360
cd "$installImagemagick_dir/ImageMagick-$1"
235-
./configure --disable-docs
361+
./configure --disable-docs --disable-static --enable-shared
236362
make V=0 -j$(nproc) install
237363
cd - >/dev/null
238364
rm -rf "$installImagemagick_dir"
@@ -242,13 +368,23 @@ installImagemagick() {
242368

243369
if grep -Eq 'PRETTY_NAME.*jessie' /etc/os-release; then
244370
# https://bugs.launchpad.net/ubuntu/+source/apt/+bug/1332440
245-
ulimit -n 10000
371+
ulimit -n 10000 2>/dev/null || true
246372
fi
247373

248374
case "$1" in
249375
git)
250376
installGit "$2"
251377
;;
378+
support-avif)
379+
if ! isAvifSupported; then
380+
return 1
381+
fi
382+
;;
383+
support-heic)
384+
if ! isHeicSupported; then
385+
return 1
386+
fi
387+
;;
252388
libaom)
253389
installLibaom "$2"
254390
;;

docker/utilities.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ stringInList() {
3838
# 0: true
3939
# 1: false
4040
isAtLeastVersion() {
41+
if [ -z "$1" ]; then
42+
return 1
43+
fi
4144
isAtLeastVersion_actual=$(printf '%s' "$1" | cut -d. -f1)
4245
isAtLeastVersion_wanted=$(printf '%s' "$2" | cut -d. -f1)
4346
if [ $isAtLeastVersion_actual -lt $isAtLeastVersion_wanted ]; then
@@ -136,9 +139,14 @@ isGccAtLeastVersion() {
136139
# $1: the package name (regex, without leading '^' or trailing '$')
137140
#
138141
# Output:
139-
# the version (in format <mayor>.<minor>.<patch>)
142+
# the version (in format <mayor>.<minor>.<patch> or <mayor>.<minor>)
143+
# outputs nothing if the package can't be found
140144
getAptPackageAvailableVersion() {
141-
apt-cache show "^$1$" | grep -E '^Version: ' | head -n1 | sed -E 's/^.*[^0-9]([0-9]+\.[0-9]+\.[0-9]+).*$/\1/'
145+
getAptPackageAvailableVersion_found="$(apt-cache show "^$1$" 2>/dev/null || true)"
146+
if [ -z "$getAptPackageAvailableVersion_found" ]; then
147+
return
148+
fi
149+
printf '%s' "$getAptPackageAvailableVersion_found" | grep -E '^Version: ' | head -n1 | sed -E 's/^.*[^0-9\.]([0-9]+\.[0-9]+(\.[0-9]+)?).*$/\1/'
142150
}
143151

144152
# Check if the version of an apt package is at least the provided one.

0 commit comments

Comments
 (0)