Skip to content

Commit

Permalink
Update wasm instructions.
Browse files Browse the repository at this point in the history
  • Loading branch information
vrabaud committed Oct 4, 2022
1 parent e68765a commit cb90f76
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
12 changes: 6 additions & 6 deletions CMakeLists.txt
Expand Up @@ -631,9 +631,9 @@ if(WEBP_BUILD_WEBP_JS)
set(WEBP_HAVE_SDL 1)
set_target_properties(
webp_js
PROPERTIES LINK_FLAGS "-s WASM=0 \
-s EXPORTED_FUNCTIONS='[\"_WebpToSDL\"]' -s INVOKE_RUN=0 \
-s EXPORTED_RUNTIME_METHODS='[\"cwrap\"]'")
PROPERTIES LINK_FLAGS "-sWASM=0 \
-sEXPORTED_FUNCTIONS=_WebpToSDL -sINVOKE_RUN=0 \
-sEXPORTED_RUNTIME_METHODS=cwrap")
set_target_properties(webp_js PROPERTIES OUTPUT_NAME webp)
target_compile_definitions(webp_js PUBLIC EMSCRIPTEN WEBP_HAVE_SDL)
endif()
Expand All @@ -644,9 +644,9 @@ if(WEBP_BUILD_WEBP_JS)
target_include_directories(webp_wasm PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
set_target_properties(
webp_wasm
PROPERTIES LINK_FLAGS "-s WASM=1 \
-s EXPORTED_FUNCTIONS='[\"_WebpToSDL\"]' -s INVOKE_RUN=0 \
-s EXPORTED_RUNTIME_METHODS='[\"cwrap\"]'")
PROPERTIES LINK_FLAGS "-sWASM=1 \
-sEXPORTED_FUNCTIONS=_WebpToSDL -sINVOKE_RUN=0 \
-sEXPORTED_RUNTIME_METHODS=cwrap")
target_compile_definitions(webp_wasm PUBLIC EMSCRIPTEN WEBP_HAVE_SDL)

target_compile_definitions(webpdspdecode PUBLIC EMSCRIPTEN)
Expand Down
19 changes: 11 additions & 8 deletions webp_js/README.md
Expand Up @@ -26,20 +26,21 @@ Emscripten and CMake.

- compile webp.js using 'emmake make'.

- that's it! Upon completion, you should have the webp.js and webp.wasm files
generated.
- that's it! Upon completion, you should have the 'webp.js', 'webp.js.mem',
'webp_wasm.js' and 'webp_wasm.wasm' files generated.

The callable JavaScript function is WebPToSDL(), which decodes a raw WebP
bitstream into a canvas. See webp_js/index.html for a simple usage sample (see
below for instructions).

## Demo HTML page

The HTML page webp_js/index.html requires an HTTP server to serve the WebP image
example. It's easy to just use Python for that.
The HTML page webp_js/index.html requires the built files 'webp.js' and
'webp.js.mem' to be copied to webp_js/. An HTTP server to serve the WebP image
example is also needed. With Python, just run:

```shell
cd webp_js && python -m SimpleHTTPServer 8080
cd webp_js && python3 -m http.server 8080
```

and then navigate to http://localhost:8080 in your favorite browser.
Expand All @@ -48,9 +49,11 @@ and then navigate to http://localhost:8080 in your favorite browser.

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.
'webp_wasm.js' and 'webp_wasm.wasm' that you then need to copy to 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 2.0.18,
latest-upstream is recommended) and of your WASM-enabled browser to run this
Expand Down

0 comments on commit cb90f76

Please sign in to comment.