Skip to content

Commit a729dab

Browse files
akirkbgrgicakbrandonpayton
authored
[PHP] Add support for AVIF in GD (#2814)
## Motivation for the change, related issues Adds AVIF support to PHP WebAssembly builds for PHP 8.1+. See #1953 ## Implementation details Added support for AVIF image processing by compiling and linking libaom (AV1 codec) and libavif libraries: **New library builds:** - `libaom/Dockerfile` - Compiles libaom v3.13.1 (AV1 video codec) to WebAssembly - `libavif/Dockerfile` - Compiles libavif v1.3.0 (AVIF encoder/decoder) to WebAssembly - Both libraries built for asyncify and JSPI runtime modes - Updated `Makefile` with build targets for both libraries **PHP integration:** - Modified `php/Dockerfile` to conditionally enable AVIF support: - PHP 8.1, 8.2, 8.3, 8.4: `--with-avif` flag enabled, libaom.a and libavif.a linked - PHP 7.2-7.4, 8.0: AVIF disabled (not supported by PHP) - Libraries copied for all versions but only configured/linked when GD and PHP version support it **Build artifacts:** - Added compiled WASM libraries to both `asyncify/dist/` and `jspi/dist/` directories ## Testing Instructions (or ideally a Blueprint) WIP --------- Co-authored-by: Bero <[email protected]> Co-authored-by: Brandon Payton <[email protected]>
1 parent 3bcb9b3 commit a729dab

File tree

114 files changed

+152770
-129234
lines changed

Some content is hidden

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

114 files changed

+152770
-129234
lines changed

packages/php-wasm/compile/Makefile

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,34 @@ libwebp/jspi/dist/root/lib/lib/libwebp.a: base-image libz_jspi
100100
docker cp $$(docker create playground-php-wasm:libpng):/root/lib/lib ./libwebp/jspi/dist/root/lib
101101
docker cp $$(docker create playground-php-wasm:libpng):/root/lib/include ./libwebp/jspi/dist/root/lib
102102

103+
libaom_asyncify: libaom/asyncify/dist/root/lib/lib/libaom.a
104+
libaom/asyncify/dist/root/lib/lib/libaom.a: base-image
105+
mkdir -p ./libaom/asyncify/dist/root/lib
106+
docker build -f ./libaom/Dockerfile -t playground-php-wasm:libaom .
107+
docker cp $$(docker create playground-php-wasm:libaom):/root/lib/lib ./libaom/asyncify/dist/root/lib
108+
docker cp $$(docker create playground-php-wasm:libaom):/root/lib/include ./libaom/asyncify/dist/root/lib
109+
110+
libaom_jspi: libaom/jspi/dist/root/lib/lib/libaom.a
111+
libaom/jspi/dist/root/lib/lib/libaom.a: base-image
112+
mkdir -p ./libaom/jspi/dist/root/lib
113+
docker build -f ./libaom/Dockerfile -t playground-php-wasm:libaom . --build-arg JSPI=1
114+
docker cp $$(docker create playground-php-wasm:libaom):/root/lib/lib ./libaom/jspi/dist/root/lib
115+
docker cp $$(docker create playground-php-wasm:libaom):/root/lib/include ./libaom/jspi/dist/root/lib
116+
117+
libavif_asyncify: libavif/asyncify/dist/root/lib/lib/libavif.a
118+
libavif/asyncify/dist/root/lib/lib/libavif.a: base-image
119+
mkdir -p ./libavif/asyncify/dist/root/lib
120+
docker build -f ./libavif/Dockerfile -t playground-php-wasm:libavif .
121+
docker cp $$(docker create playground-php-wasm:libavif):/root/lib/lib ./libavif/asyncify/dist/root/lib
122+
docker cp $$(docker create playground-php-wasm:libavif):/root/lib/include ./libavif/asyncify/dist/root/lib
123+
124+
libavif_jspi: libavif/jspi/dist/root/lib/lib/libavif.a
125+
libavif/jspi/dist/root/lib/lib/libavif.a: base-image
126+
mkdir -p ./libavif/jspi/dist/root/lib
127+
docker build -f ./libavif/Dockerfile -t playground-php-wasm:libavif . --build-arg JSPI=1
128+
docker cp $$(docker create playground-php-wasm:libavif):/root/lib/lib ./libavif/jspi/dist/root/lib
129+
docker cp $$(docker create playground-php-wasm:libavif):/root/lib/include ./libavif/jspi/dist/root/lib
130+
103131
libxml2_asyncify: libxml2/asyncify/dist/root/lib/lib/libxml2.a
104132
libxml2/asyncify/dist/root/lib/lib/libxml2.a: base-image libz_asyncify
105133
mkdir -p ./libxml2/asyncify/dist/root/lib
@@ -273,8 +301,8 @@ libintl/jspi/dist/root/lib/lib/libintl.a: base-image
273301
docker cp $$(docker create playground-php-wasm:libintl):/root/lib/data/. ./libintl/
274302

275303
all: all_jspi all_asyncify
276-
all_jspi: libz_jspi libzip_jspi libpng16_jspi libjpeg_jspi libwebp_jspi libxml2_jspi libopenssl_jspi libsqlite3_jspi libiconv_jspi bison2.7 oniguruma_jspi libcurl_jspi libintl_jspi
277-
all_asyncify: libz_asyncify libzip_asyncify libpng16_asyncify libjpeg_asyncify libwebp_asyncify libxml2_asyncify libopenssl_asyncify libsqlite3_asyncify libiconv_asyncify bison2.7 oniguruma_asyncify libcurl_asyncify libintl_asyncify
304+
all_jspi: libz_jspi libzip_jspi libpng16_jspi libjpeg_jspi libwebp_jspi libaom_jspi libavif_jspi libxml2_jspi libopenssl_jspi libsqlite3_jspi libiconv_jspi bison2.7 oniguruma_jspi libcurl_jspi libintl_jspi
305+
all_asyncify: libz_asyncify libzip_asyncify libpng16_asyncify libjpeg_asyncify libwebp_asyncify libaom_asyncify libavif_asyncify libxml2_asyncify libopenssl_asyncify libsqlite3_asyncify libiconv_asyncify bison2.7 oniguruma_asyncify libcurl_asyncify libintl_asyncify
278306

279307
clean:
280308
rm -rf ./libz/jspi/dist
@@ -287,6 +315,10 @@ clean:
287315
rm -rf ./libjpeg/asyncify/dist
288316
rm -rf ./libwebp/jspi/dist
289317
rm -rf ./libwebp/asyncify/dist
318+
rm -rf ./libaom/jspi/dist
319+
rm -rf ./libaom/asyncify/dist
320+
rm -rf ./libavif/jspi/dist
321+
rm -rf ./libavif/asyncify/dist
290322
rm -rf ./libxml2/jspi/dist
291323
rm -rf ./libxml2/asyncify/dist
292324
rm -rf ./libopenssl/jspi/dist
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
FROM playground-php-wasm:base
2+
3+
ARG JSPI
4+
5+
RUN wget https://aomedia.googlesource.com/aom/+archive/v3.13.1.tar.gz -O aom.tar.gz
6+
RUN mkdir -p /root/aom && tar -xzf aom.tar.gz -C /root/aom
7+
WORKDIR /root/aom
8+
9+
RUN mkdir -p build && cd build && \
10+
source /root/emsdk/emsdk_env.sh && \
11+
export JSPI_FLAGS=$(if [ "$JSPI" = "1" ]; then echo "-sSUPPORT_LONGJMP=wasm -fwasm-exceptions"; else echo ""; fi) && \
12+
emcmake cmake .. \
13+
-DCMAKE_BUILD_TYPE=Release \
14+
-DENABLE_CCACHE=1 \
15+
-DAOM_TARGET_CPU=generic \
16+
-DENABLE_DOCS=0 \
17+
-DENABLE_TESTS=0 \
18+
-DENABLE_TESTDATA=0 \
19+
-DENABLE_TOOLS=0 \
20+
-DENABLE_EXAMPLES=0 \
21+
-DCONFIG_ACCOUNTING=1 \
22+
-DCONFIG_INSPECTION=0 \
23+
-DCONFIG_MULTITHREAD=0 \
24+
-DCONFIG_RUNTIME_CPU_DETECT=0 \
25+
-DCONFIG_WEBM_IO=0 \
26+
-DCMAKE_C_FLAGS="-sSIDE_MODULE $JSPI_FLAGS" \
27+
-DCMAKE_INSTALL_PREFIX=/root/lib
28+
29+
RUN cd build && \
30+
source /root/emsdk/emsdk_env.sh && \
31+
emmake make
32+
33+
RUN cd build && \
34+
source /root/emsdk/emsdk_env.sh && \
35+
emmake make install
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/*
2+
* Copyright (c) 2016, Alliance for Open Media. All rights reserved.
3+
*
4+
* This source code is subject to the terms of the BSD 2 Clause License and
5+
* the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6+
* was not distributed with this source code in the LICENSE file, you can
7+
* obtain it at www.aomedia.org/license/software. If the Alliance for Open
8+
* Media Patent License 1.0 was not distributed with this source code in the
9+
* PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10+
*/
11+
12+
/*!\defgroup aom AOM
13+
* \ingroup codecs
14+
* AOM is aom's newest video compression algorithm that uses motion
15+
* compensated prediction, Discrete Cosine Transform (DCT) coding of the
16+
* prediction error signal and context dependent entropy coding techniques
17+
* based on arithmetic principles. It features:
18+
* - YUV 4:2:0 image format
19+
* - Macro-block based coding (16x16 luma plus two 8x8 chroma)
20+
* - 1/4 (1/8) pixel accuracy motion compensated prediction
21+
* - 4x4 DCT transform
22+
* - 128 level linear quantizer
23+
* - In loop deblocking filter
24+
* - Context-based entropy coding
25+
*
26+
* @{
27+
*/
28+
/*!\file
29+
* \brief Provides controls common to both the AOM encoder and decoder.
30+
*/
31+
#ifndef AOM_AOM_AOM_H_
32+
#define AOM_AOM_AOM_H_
33+
34+
#include "aom/aom_codec.h"
35+
#include "aom/aom_image.h"
36+
37+
#ifdef __cplusplus
38+
extern "C" {
39+
#endif
40+
41+
/*!\brief Control functions
42+
*
43+
* The set of macros define the control functions of AOM interface
44+
* The range for common control IDs is 230-255(max).
45+
*/
46+
enum aom_com_control_id {
47+
/*!\brief Codec control function to get a pointer to a reference frame
48+
*
49+
* av1_ref_frame_t* parameter
50+
*/
51+
AV1_GET_REFERENCE = 230,
52+
53+
/*!\brief Codec control function to write a frame into a reference buffer
54+
*
55+
* av1_ref_frame_t* parameter
56+
*/
57+
AV1_SET_REFERENCE = 231,
58+
59+
/*!\brief Codec control function to get a copy of reference frame from the
60+
* decoder
61+
*
62+
* av1_ref_frame_t* parameter
63+
*/
64+
AV1_COPY_REFERENCE = 232,
65+
66+
/*!\brief Codec control function to get a pointer to the new frame
67+
*
68+
* aom_image_t* parameter
69+
*/
70+
AV1_GET_NEW_FRAME_IMAGE = 233,
71+
72+
/*!\brief Codec control function to copy the new frame to an external buffer
73+
*
74+
* aom_image_t* parameter
75+
*/
76+
AV1_COPY_NEW_FRAME_IMAGE = 234,
77+
78+
/*!\brief Start point of control IDs for aom_dec_control_id.
79+
* Any new common control IDs should be added above.
80+
*/
81+
AOM_DECODER_CTRL_ID_START = 256
82+
// No common control IDs should be added after AOM_DECODER_CTRL_ID_START.
83+
};
84+
85+
/*!\brief AV1 specific reference frame data struct
86+
*
87+
* Define the data struct to access av1 reference frames.
88+
*/
89+
typedef struct av1_ref_frame {
90+
int idx; /**< frame index to get (input) */
91+
int use_external_ref; /**< Directly use external ref buffer(decoder only) */
92+
aom_image_t img; /**< img structure to populate (output) */
93+
} av1_ref_frame_t;
94+
95+
/*!\cond */
96+
/*!\brief aom decoder control function parameter type
97+
*
98+
* Defines the data type for each of AOM decoder control function requires.
99+
*
100+
* \note For each control ID "X", a macro-define of
101+
* AOM_CTRL_X is provided. It is used at compile time to determine
102+
* if the control ID is supported by the libaom library available,
103+
* when the libaom version cannot be controlled.
104+
*/
105+
AOM_CTRL_USE_TYPE(AV1_GET_REFERENCE, av1_ref_frame_t *)
106+
#define AOM_CTRL_AV1_GET_REFERENCE
107+
108+
AOM_CTRL_USE_TYPE(AV1_SET_REFERENCE, av1_ref_frame_t *)
109+
#define AOM_CTRL_AV1_SET_REFERENCE
110+
111+
AOM_CTRL_USE_TYPE(AV1_COPY_REFERENCE, av1_ref_frame_t *)
112+
#define AOM_CTRL_AV1_COPY_REFERENCE
113+
114+
AOM_CTRL_USE_TYPE(AV1_GET_NEW_FRAME_IMAGE, aom_image_t *)
115+
#define AOM_CTRL_AV1_GET_NEW_FRAME_IMAGE
116+
117+
AOM_CTRL_USE_TYPE(AV1_COPY_NEW_FRAME_IMAGE, aom_image_t *)
118+
#define AOM_CTRL_AV1_COPY_NEW_FRAME_IMAGE
119+
120+
/*!\endcond */
121+
/*! @} - end defgroup aom */
122+
123+
#ifdef __cplusplus
124+
} // extern "C"
125+
#endif
126+
127+
#endif // AOM_AOM_AOM_H_

0 commit comments

Comments
 (0)