Skip to content

Commit

Permalink
A few small modifications:
Browse files Browse the repository at this point in the history
Closes Issue #18: CMakeLists.txt allows disabling SIMD instruction for compilations targeting ARM and other platforms.
Closes Issue #21: Added some text in README.md to clarify the need to use an escape character before { and }.
Closes Issue #22: Added some text in README.md to clarify how the downsampling option -downsamp should be used for the case of 422 (Obviously more work on documentation is needed).
Closes Issue #23: It looks like some older versions of ffprobe is sensitive to the header of ppm, so I modified the header slightly to make it acceptable.  I think the new format should be supported by more applications.
  • Loading branch information
aous72 committed Feb 27, 2020
1 parent 41ff30c commit 99bb152
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 25 deletions.
17 changes: 16 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,21 @@ cmake_minimum_required(VERSION 3.10.0)

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

option(OJPH_DISABLE_INTEL_SIMD "Disables the use of SIMD instructions and associated files" OFF)

set(CMAKE_CXX_STANDARD 11)
if (MSVC)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /D \"_CRT_SECURE_NO_WARNINGS\"")
endif()

if (OJPH_DISABLE_INTEL_SIMD)
if (MSVC)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D \"OJPH_DISABLE_INTEL_SIMD\"")
else()
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DOJPH_DISABLE_INTEL_SIMD")
endif()
endif()

set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/../bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/../bin)

Expand All @@ -17,7 +27,12 @@ file(GLOB SSE_SOURCES "src/core/transform/*_sse.cpp")
file(GLOB SSE2_SOURCES "src/core/transform/*_sse2.cpp")
file(GLOB AVX_SOURCES "src/core/transform/*_avx.cpp")
file(GLOB AVX2_SOURCES "src/core/transform/*_avx2.cpp")
add_library(openjph SHARED ${SOURCES} ${SSE_SOURCES} ${SSE2_SOURCES} ${AVX_SOURCES} ${AVX2_SOURCES})

if (OJPH_DISABLE_INTEL_SIMD)
add_library(openjph SHARED ${SOURCES})
else()
add_library(openjph SHARED ${SOURCES} ${SSE_SOURCES} ${SSE2_SOURCES} ${AVX_SOURCES} ${AVX2_SOURCES})
endif()

if (MSVC)
set_source_files_properties(src/core/transform/ojph_colour_avx.cpp PROPERTIES COMPILE_FLAGS "/arch:AVX")
Expand Down
48 changes: 33 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,45 +50,63 @@ The generated library and executables will be in the bin folder.
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. One way of using these tools is to install them on your machine, and activate them using
```base
source emsdk_env.sh
```

source emsdk_env.sh

before compilation. Alternatively, if you are a docker user, the you can launch a docker session using script provided at ```subprojects/js/emscripten-docker.sh```; this script will download a third-party docker image that has the emscripten tools integrated in it -- Thanks to [Chris](https://github.com/chafey) for the suggesting and providing these tools.

The javascript decoder can be compiled using
```bash
cd subprojects/js/build
emmake cmake ..
make
```

cd subprojects/js/build
emmake cmake ..
make


The compilation 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. You can use the ```emrun``` command, provided with the emscripten
tools, by issuing the command
```base
emrun index.html
```

emrun index.html

from inside the html folder; the default port is 6931.
Alternatively, a simple python webserver can be run using
```python
python -m SimpleHTTPServer 8000
```

python -m SimpleHTTPServer 8000

also 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.

# Visual Studio Code Remote Containers #

Visual Studio Code Remote Containers are now available with OpenJPH. These scripts/configuration files are provided by [Chris](https://github.com/chafey) -- Thank you Chris, and I must say I am not familiar with them.
The scripts, in the ```.devcontainer``` folder, will build a docker image that can be used with visual studio code as a development environment.

# Compiling for ARM and other platforms #

To compile for platforms where x86_64 SIMD instructions are not supported, such as on ARM, we need to disable SIMD instructions; this can be achieved using

cd build
cmake -DCMAKE_BUILD_TYPE=Release -DOJPH_DISABLE_INTEL_SIMD=ON ../
make

As I do not have an ARM board, I tested this using QEMU for aarch64 architecture, targeting a Cortex-A57 CPU. The code worked without issues, but because the ARM platform is emulated, the whole process was slow.

# Usage Example #

**Note**: in Kakadu, pairs of data in command line arguments represent columns,rows. Here, a pair represents x,y information. On a different note, in reversible compression, quantization is not supported.
Here are some usage examples:

ojph_compress -i input_file.ppm -o output_file.j2c -num_decomps 5 -block_size {64,64} -precincts {128,128},{256,256} -prog_order CPRL -colour_trans true -qstep 0.05
ojph_compress -i input_file.yuv -o output_file.j2c -num_decomps 5 -reversible true -dims {3840,2160} -num_comps 3 -signed false -bit_depth 10 -downsamp {1,1},{2,2}

ojph_expand -i input_file.j2c -o output_file.ppm
ojph_expand -i input_file.j2c -o output_file.yuv

**Notes**:

* Issuing ojph\_compress or ojph\_expand without arguments prints a short usage statement.
* In reversible compression, quantization is not supported.
* On Linux and MacOS, but NOT Windows, { and } need to be escaped; i.e, we need to write \\\{ and \\\}. So, -block\_size {64,64} must be written as -block\_size \\\{64,64\\\}.
* When the source is a .yuv file, use -downsamp {1,1} for 4:4:4 sources. For 4:2:2 downsampling, specify -downsamp {1,1},{2,1}, and for 4:2:0 subsampling specify -downsamp {1,1},{2,2}. The source must have already been downsampled (i.e., OpenJPH does not downsample the source before compression, but can compress downsampled sources).
* In Kakadu, pairs of data in command line arguments represent columns,rows. Here, a pair represents x,y information.

# 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 -- **Update 25/12/2019**: it is no longer available free of charge.
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "-num_decomps 4"
isEnabled = "YES">
argument = "-num_decomps 6"
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "-num_decomps 2"
Expand Down Expand Up @@ -215,7 +215,7 @@
</CommandLineArgument>
<CommandLineArgument
argument = "-prog_order CPRL"
isEnabled = "YES">
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "-block_size \{4,1024\}"
Expand Down Expand Up @@ -263,7 +263,7 @@
</CommandLineArgument>
<CommandLineArgument
argument = "-reversible true"
isEnabled = "YES">
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "-colour_trans false"
Expand All @@ -275,18 +275,22 @@
</CommandLineArgument>
<CommandLineArgument
argument = "-profile IMF"
isEnabled = "YES">
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "-profile BROADCAST"
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "-tile_size \{1024,1024\}"
isEnabled = "YES">
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "-i ARRI_AlexaDrums_3840x2160p_24_8b_P3_444_00000.ppm -o test.j2c -block_size \{32,32\} -precincts \{128,128\},\{256,256\}"
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "-i ARRI_AlexaDrums_3840x2160p_24_10b_bt709_444_00162.ppm -o test.j2c -profile IMF -block_size \{32,32\} -precincts \{128,128\},\{256,256\} -prog_order CPRL -reversible true"
isEnabled = "YES">
</CommandLineArgument>
</CommandLineArguments>
Expand Down
4 changes: 2 additions & 2 deletions src/apps/others/ojph_img_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ namespace ojph {
OJPH_ERROR(0x030000021,
"unable to open file %s for writing", filename);

fprintf(fh, "P5 %d %d %d\n", width, height, (1 << bit_depth) - 1);
fprintf(fh, "P5\n%d %d\n%d\n", width, height, (1 << bit_depth) - 1);
buffer_size = width * bytes_per_sample;
buffer = (ui8*)malloc(buffer_size);
}
Expand All @@ -264,7 +264,7 @@ namespace ojph {
OJPH_ERROR(0x030000022,
"unable to open file %s for writing", filename);
int result = //the number of written characters
fprintf(fh, "P6 %d %d %d\n", width, height, (1 << bit_depth) - 1);
fprintf(fh, "P6\n%d %d\n%d\n", width, height, (1 << bit_depth) - 1);
if (result == 0)
OJPH_ERROR(0x030000023, "error writing to file %s", filename);
buffer_size = width * num_components * bytes_per_sample;
Expand Down
2 changes: 1 addition & 1 deletion src/core/common/ojph_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ typedef int64_t si64;
/////////////////////////////////////////////////////////////////////////////
#define OJPH_CORE_VER_MAJOR 0
#define OJPH_CORE_VER_MINOR 6
#define OJPH_CORE_VER_SUBMINOR 0
#define OJPH_CORE_VER_SUBMINOR 1

/////////////////////////////////////////////////////////////////////////////
#define OJPH_INT_STRINGIFY(I) #I
Expand Down

0 comments on commit 99bb152

Please sign in to comment.