diff --git a/CMakeLists.txt b/CMakeLists.txt index 977e7374..24cd207c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -247,6 +247,7 @@ if(WEBP_BUILD_IMG2WEBP) endif() if(WEBP_BUILD_WEBP_JS) + # JavaScript version add_executable(webp_js ${CMAKE_CURRENT_SOURCE_DIR}/extras/webp_to_sdl.c) target_link_libraries(webp_js webpdecoder SDL) @@ -254,6 +255,16 @@ if(WEBP_BUILD_WEBP_JS) "-s EXPORTED_FUNCTIONS='[\"_WebpToSDL\"]' -s INVOKE_RUN=0") set_target_properties(webp_js PROPERTIES OUTPUT_NAME webp) target_compile_definitions(webp_js PUBLIC EMSCRIPTEN WEBP_HAVE_SDL) + + # WASM version + add_executable(webp_wasm + ${CMAKE_CURRENT_SOURCE_DIR}/extras/webp_to_sdl.c) + target_link_libraries(webp_wasm webpdecoder SDL) + set_target_properties(webp_wasm PROPERTIES LINK_FLAGS + "-s WASM=1 -s 'BINARYEN_METHOD=\"native-wasm\"' \ + -s EXPORTED_FUNCTIONS='[\"_WebpToSDL\"]' -s INVOKE_RUN=0") + target_compile_definitions(webp_wasm PUBLIC EMSCRIPTEN WEBP_HAVE_SDL) + target_compile_definitions(webpdecoder PUBLIC EMSCRIPTEN) endif() diff --git a/README.webp_js b/README.webp_js index 74c4f4c3..04f4970b 100644 --- a/README.webp_js +++ b/README.webp_js @@ -45,6 +45,18 @@ cd webp_js && python -m SimpleHTTPServer 8080 and then navigate to http://localhost:8080 in your favorite browser. +Web-Assembly (WASM) version: +============================ + + CMakeLists.txt is configured to build the WASM version when using + the option WEBP_BUILD_WEBP_JS=ON. The compilation step will assemble + the files 'webp_wasm.js', 'webp_wasm.wasm' in the webp_js/ directory. + See webp_js/index_wasm.html for a simple demo page using the WASM version + of the library. + + You will need a fairly recent version of Emscripten (at least 1.37.8) and of + your WASM-enabled browser to run this version. Consider it very experimental! + Caveat: ======= diff --git a/webp_js/index_wasm.html b/webp_js/index_wasm.html new file mode 100644 index 00000000..21950632 --- /dev/null +++ b/webp_js/index_wasm.html @@ -0,0 +1,84 @@ + + + + + + simple Javascript WebP decoding demo, using Web-Assembly (WASM) + + + + + +

+ WebP demo using Web-Assembly - +

+

+ WASM version of the WebP decoder, using libwebp compiled with + Emscripten. +

+

+ +

+

Timing: N/A

+ Your browser does not support canvas + + diff --git a/webp_js/test_webp_js.webp b/webp_js/test_webp_js.webp index f41d3670..f798f556 100644 Binary files a/webp_js/test_webp_js.webp and b/webp_js/test_webp_js.webp differ diff --git a/webp_js/test_webp_wasm.webp b/webp_js/test_webp_wasm.webp new file mode 100644 index 00000000..f798f556 Binary files /dev/null and b/webp_js/test_webp_wasm.webp differ