• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1     __   __ ____ ____ ____     __  ____
2    /  \\/  \  _ \  _ \  _ \   (__)/  __\
3    \       /  __/ _  \  __/   _)  \_   \
4     \__\__/_____/____/_/     /____/____/
5
6Description:
7============
8
9This file describes the compilation of libwebp into a JavaScript decoder
10using Emscripten and CMake.
11
12 - install the Emscripten SDK following the procedure described at:
13   https://kripken.github.io/emscripten-site/docs/getting_started/downloads.html
14   After installation, you should have some global variable positioned to the
15   location of the SDK. In particular, $EMSCRIPTEN should point to the
16   top-level directory containing Emscripten tools.
17
18 - make sure the file $EMSCRIPTEN/cmake/Modules/Platform/Emscripten.cmake is
19   accessible. This is the toolchain file used by CMake to invoke Emscripten.
20   If $EMSCRIPTEN is unset search for Emscripten.cmake under $EMSDK and set
21   $EMSCRIPTEN accordingly, for example:
22   unix-like environments: export EMSCRIPTEN=$EMSDK/fastcomp/emscripten
23   windows: set EMSCRIPTEN=%EMSDK%\fastcomp\emscripten
24
25 - configure the project 'WEBP_JS' with CMake using:
26
27 cd webp_js && \
28 cmake -DWEBP_BUILD_WEBP_JS=ON \
29       -DEMSCRIPTEN_GENERATE_BITCODE_STATIC_LIBRARIES=1 \
30       -DCMAKE_TOOLCHAIN_FILE=$EMSCRIPTEN/cmake/Modules/Platform/Emscripten.cmake \
31       ../
32
33 - compile webp.js using 'make'.
34
35 - that's it! Upon completion, you should have the webp.js and
36   webp.js.mem files generated.
37
38The callable JavaScript function is WebPToSDL(), which decodes a raw WebP
39bitstream into a canvas. See webp_js/index.html for a simple usage sample
40(see below for instructions).
41
42Demo HTML page:
43===============
44
45   The HTML page webp_js/index.html requires an HTTP server to serve the WebP
46   image example. It's easy to just use Python for that.
47
48cd webp_js && python -m SimpleHTTPServer 8080
49
50and then navigate to http://localhost:8080 in your favorite browser.
51
52
53Web-Assembly (WASM) version:
54============================
55
56  CMakeLists.txt is configured to build the WASM version when using
57  the option WEBP_BUILD_WEBP_JS=ON. The compilation step will assemble
58  the files 'webp_wasm.js', 'webp_wasm.wasm' in the webp_js/ directory.
59  See webp_js/index_wasm.html for a simple demo page using the WASM version
60  of the library.
61
62  You will need a fairly recent version of Emscripten (at least 1.37.8) and of
63  your WASM-enabled browser to run this version. Consider it very experimental!
64
65Caveat:
66=======
67
68  - First decoding using the library is usually slower, due to just-in-time
69    compilation.
70
71  - Some versions of llvm produce the following compile error when SSE2 is
72    enabled.
73
74"Unsupported:   %516 = bitcast <8 x i16> %481 to i128
75 LLVM ERROR: BitCast Instruction not yet supported for integer types larger than 64 bits"
76
77    The corresponding Emscripten bug is at:
78    https://github.com/kripken/emscripten/issues/3788
79
80    Therefore, SSE2 optimization is currently disabled in CMakeLists.txt.
81