Skip to content

Commit

Permalink
Update README.md, and removed unnecessary -s in the CMakeLists.txt fi…
Browse files Browse the repository at this point in the history
…le for javascript compilation
  • Loading branch information
aous72 committed Oct 27, 2019
1 parent ad62f76 commit 9cce6ed
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
30 changes: 27 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ The provided command line tools ojph\_compress and ojph\_expand accepts and gene

The code employs the *cmake* tool to generate a variety of build enviroments.

** For Linux **
**For Linux**

cd build
cmake ../
make

The generated library and executables will be in the bin folder.

** For Windows **
**For Windows**

cd build
cmake ../ -G "Visual Studio 14 2015 Win64"

cmake support other visual studio versions. This command generates a solution in the build folder, which can be build using visual studio

** For macOS **
**For macOS**

You can use the "For Linux" approach above. Alternatively, you can use the Xcode project in src/apps/apps.xcodeproj, which I use. Another approach is to use cmake to generate an xcode project, in the build folder, using

Expand All @@ -43,6 +43,25 @@ You can use the "For Linux" approach above. Alternatively, you can use the Xcod

The generated library and executables will be in the bin folder.

# Compiling to javascript/wasm #

The library can now be compiled to javascript/wasm. For this purpose, a small wrapper file (ojph_wrapper.cpp) has been written to interface between javascript and C++; the wrapper currently supports decoding only. A small demo page demonstrating the script can be accessed [here](https://openjph.org/javascript/demo.html).

Compilation needs the [emscripten](https://emscripten.org/) tools. The tools are activated using
```bash
emsdk_env.sh
```
Then, the javascript decoder can be compiled using
```bash
cd subprojects/js/build
emmake cmake ..
make
```
This creates libopenjph.js and libopenjph.wasm in subprojects/js/html folder. That html folder also has the demo webpage index.html and a compressed image test.j2c which the script in index.html decodes. To run the demo webpage on your machine, you need a webserver running on the machine -- Due to security reasons, javascript engines running in a browser cannot access local files on the machine. A simple python webserver can be run
```python
python -m SimpleHTTPServer 8000
```
from inside the html folder. Here, 8000 is the port number at which the webserver will be listening. The webpage can then be accessed by open 127.0.0.1:8000 in you browser. Any browser supporting webassembly can be used to view this webpage; examples include Firefox, Chrome, Safari, and Edge, on a desktop, mobile, or tablet.

# Usage Example #

Expand All @@ -54,4 +73,9 @@ The generated library and executables will be in the bin folder.
ojph_expand -i input_file.j2c -o output_file.ppm
ojph_expand -i input_file.j2c -o output_file.yuv

# Related #

The standard is available [here](https://www.itu.int/rec/T-REC-T.814/en). It is currently free of charge; I do not know if this is temporary or permanent.

The associate site [openjph.org](https://openjph.org) serves as a blog. It currently host the [javascript](https://openjph.org/javascript/demo.html) demo of the decoder; the webpage demonstrates that the library can be compiled to javascript, and can run inside a web-browser. Any browser supporting webassembly can be used to view this webpage; examples include Firefox, Chrome, Safari, and Edge, on a desktop, mobile, or tablet.

Binary file not shown.
2 changes: 1 addition & 1 deletion subprojects/js/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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,_pull_j2c_line,_release_j2c_data,_free,_malloc] -s EXTRA_EXPORTED_RUNTIME_METHODS=[ccall,cwrap] -s NO_EXIT_RUNTIME=1 -s -s ALLOW_MEMORY_GROWTH=1")
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,_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")
endif()

0 comments on commit 9cce6ed

Please sign in to comment.