README.md (1988B)
1 # WebP JavaScript decoder 2 3 ``` 4 __ __ ____ ____ ____ __ ____ 5 / \\/ \ _ \ _ \ _ \ (__)/ __\ 6 \ / __/ _ \ __/ _) \_ \ 7 \__\__/_____/____/_/ /____/____/ 8 ``` 9 10 This file describes the compilation of libwebp into a JavaScript decoder using 11 Emscripten and CMake. 12 13 - install the Emscripten SDK following the procedure described at: 14 https://emscripten.org/docs/getting_started/downloads.html#installation-instructions-using-the-emsdk-recommended 15 After installation, you should have some global variable positioned to the 16 location of the SDK. In particular, `$EMSDK` should point to the top-level 17 directory containing Emscripten tools. 18 19 - configure the project 'WEBP_JS' with CMake using: 20 21 ```shell 22 cd webp_js && \ 23 emcmake cmake -DWEBP_BUILD_WEBP_JS=ON ../ 24 ``` 25 26 - compile webp.js using `emmake make`. 27 28 - that's it! Upon completion, you should have the 'webp.js', 'webp.js.mem', 29 'webp_wasm.js' and 'webp_wasm.wasm' files generated. 30 31 The callable JavaScript function is `WebPToSDL()`, which decodes a raw WebP 32 bitstream into a canvas. See webp_js/index.html for a simple usage sample (see 33 below for instructions). 34 35 ## Demo HTML page 36 37 The HTML page webp_js/index.html requires the built files 'webp.js' and 38 'webp.js.mem' to be copied to webp_js/. An HTTP server to serve the WebP image 39 example is also needed. With Python, just run: 40 41 ```shell 42 cd webp_js && python3 -m http.server 8080 43 ``` 44 45 and then navigate to http://localhost:8080 in your favorite browser. 46 47 ## Web-Assembly (WASM) version: 48 49 CMakeLists.txt is configured to build the WASM version when using the option 50 WEBP_BUILD_WEBP_JS=ON. The compilation step will assemble the files 51 'webp_wasm.js' and 'webp_wasm.wasm' that you then need to copy to the webp_js/ 52 directory. 53 54 See webp_js/index_wasm.html for a simple demo page using the WASM version of the 55 library. 56 57 ## Caveats 58 59 - First decoding using the library is usually slower, due to just-in-time 60 compilation.