This is based on the openjpeg+js work in cornerstone, except upgraded for new openjpeg builds.
Software required:
- emscripten (installed via emsdk)
Ensure that you have activated an emscripten SDK. Afterwards, source the emsdk environment.
/emsdk/emsdk activate latest source /emsdk/emsdk_env.sh
Once the environment is set up, clone the OpenJPEG official repo and checkout the desired version.
git clone https://github.com/uclouvain/openjpeg.git
Apply the patch file openjpeg-js.patch
.
cd openjpeg/ git apply ../openjpeg-js.patch
After applying the patch, we will now build openjpeg into LLVM bitcode. The
second cmake invocation is to skip the error related to TestEndian from cmake.
Make sure you have sourced the emsdk_env.sh
as shown above.
mkdir openjpeg/build cd openjpeg/build cmake \ -DCMAKE_TOOLCHAIN_FILE=/path/to/emsdk/fastcomp/emscripten/cmake/Modules/Platform/Emscripten.cmake \ -DBUILD_CODEC=OFF \ -DBUILD_SHARED_LIBS=OFF \ -G'Unix Makefiles' \ -DCMAKE_BUILD_TYPE=Release \ .. cmake . make
The output will be in openjpeg/build/bin/libopenjp2.a
.
Once openjpeg has been compiled, it’s time to compile the wrapping. Edit
emcc-compile.sh
and update the OPENJPEG_ROOT
to the path of the openjpeg
repo from above. You may also adjust the emcc flags as you see fit.
Once edited, just compile! Be sure to have the emsdk_env.sh
sourced from
above.
./emcc-compile.sh
The resulting cross-compiled OpenJPEG will be found in out/
.