README.webp_js 2.9 KB

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