Skip to content

Commit

Permalink
Another small, but important, update to the javascript subproject.
Browse files Browse the repository at this point in the history
It turns out that wasm does not support exception for the time being.
Emscripten provides a workaround, but the flag -fexceptions must be used.  So CMakeLists.txt has been updated.
Also the ojph_wrapper.cpp has been update. Now it include enable_resilience. Now, it also uses EMSCRIPTEN_KEEPALIVE preprocessor directive to expose functions rather than specifying them in the CMakeLists.txt.
  • Loading branch information
aous72 committed Feb 17, 2021
1 parent 11b19ab commit d0d4b1d
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 4 deletions.
4 changes: 2 additions & 2 deletions subprojects/js/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ endif()

project (openjph DESCRIPTION "Open source implementation of JPH" LANGUAGES CXX)

set(CMAKE_CXX_FLAGS "-std=c++11 -O3 -DOJPH_DISABLE_INTEL_SIMD")
set(CMAKE_CXX_FLAGS "-std=c++11 -O3 -fexceptions -DOJPH_DISABLE_INTEL_SIMD")

set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/../html)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/../html)
Expand All @@ -24,6 +24,6 @@ endif()

if (BUILD_TEST)
else()
set_target_properties(libopenjph PROPERTIES SUFFIX ".js" LINK_FLAGS "-s WASM=1 -s ENVIRONMENT=web -s EXPORTED_FUNCTIONS=[_create_j2c_data,_init_j2c_data,_get_j2c_width,_get_j2c_height,_get_j2c_bit_depth,_get_j2c_is_signed,_get_j2c_num_components,_get_j2c_downsampling_x,_get_j2c_downsampling_y,_parse_j2c_data,_restrict_input_resolution,_pull_j2c_line,_release_j2c_data,_free,_malloc] -s EXTRA_EXPORTED_RUNTIME_METHODS=[ccall,cwrap] -s NO_EXIT_RUNTIME=1 -s ALLOW_MEMORY_GROWTH=1")
set_target_properties(libopenjph PROPERTIES SUFFIX ".js" LINK_FLAGS "-s WASM=1 -s ENVIRONMENT=web -s EXPORTED_FUNCTIONS=[_free,_malloc] -s EXTRA_EXPORTED_RUNTIME_METHODS=[ccall,cwrap] -s NO_EXIT_RUNTIME=1 -s ALLOW_MEMORY_GROWTH=1")
endif()

4 changes: 3 additions & 1 deletion subprojects/js/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ <h1>HTJ2K progressive decoding to full resolution (downloaded once, decoded many
get_j2c_downsampling_y = Module.cwrap('get_j2c_downsampling_y', 'number', ['number', 'number']);
parse_j2c_data = Module.cwrap('parse_j2c_data', 'void', ['number']);
restrict_input_resolution = Module.cwrap('restrict_input_resolution', 'void', ['number', 'number', 'number']);
enable_resilience = Module.cwrap('enable_resilience', 'void', ['number']);
pull_j2c_line = Module.cwrap('pull_j2c_line', 'number', ['number']);
release_j2c_data = Module.cwrap('release_j2c_data', 'void', ['number']);

Expand All @@ -120,10 +121,11 @@ <h1>HTJ2K progressive decoding to full resolution (downloaded once, decoded many
var t0 = performance.now();

j2c = create_j2c_data();
const array = new Uint8Array(data);
const array = new Uint8Array(data, 0, data.byteLength);

var buffer = Module._malloc(array.length);
writeArrayToMemory(array, buffer);
enable_resilience(j2c);
init_j2c_data(j2c, buffer, array.length);
restrict_input_resolution(j2c, skip_res_for_data, skip_res_for_recon);
var width = get_j2c_width(j2c, 0) | 0; //component 0
Expand Down
Loading

0 comments on commit d0d4b1d

Please sign in to comment.