Skip to content

Commit 19c65e1

Browse files
committed
Merge branch 'master' into feature/add-openexr-support
2 parents ae332c6 + c062d93 commit 19c65e1

28 files changed

+707
-409
lines changed

.github/workflows/emcc.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Build with EMCC
2+
3+
on:
4+
push:
5+
pull_request:
6+
types: [opened, reopened]
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v4
15+
16+
- name: Configure emcc
17+
uses: mymindstorm/setup-emsdk@v14
18+
with:
19+
actions-cache-folder: 'emsdk-cache'
20+
21+
- name: Build non-SIMD and Debug
22+
run: |
23+
cd build
24+
emcmake cmake .. --fresh -DOJPH_DISABLE_SIMD=ON -DCMAKE_BUILD_TYPE=Debug
25+
cmake --build . --config Debug --clean-first
26+
cd ..
27+
28+
- name: Build non-SIMD and Release
29+
run: |
30+
cd build
31+
emcmake cmake .. --fresh -DOJPH_DISABLE_SIMD=ON -DCMAKE_BUILD_TYPE=Release
32+
cmake --build . --config Release --clean-first
33+
cd ..
34+
35+
- name: Build SIMD and Debug
36+
run: |
37+
cd build
38+
emcmake cmake .. --fresh -DOJPH_DISABLE_SIMD=OFF -DCMAKE_BUILD_TYPE=Debug
39+
cmake --build . --config Debug --clean-first
40+
cd ..
41+
42+
- name: Build SIMD and Release
43+
run: |
44+
cd build
45+
emcmake cmake .. --fresh -DOJPH_DISABLE_SIMD=OFF -DCMAKE_BUILD_TYPE=Release
46+
cmake --build . --config Release --clean-first
47+
cd ..

CMakeLists.txt

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,27 @@ if (DEFINED OJPH_ENABLE_INTEL_AVX512)
6464
endif()
6565

6666
## Setting some of the options if EMSCRIPTEN is the compiler
67-
# WebAssembly SIMD is treated differently. The SIMD flags above have no effect on the
68-
# use of WASM SIMD. This is because, for WASM, both non-SIMD and SIMD are required,
69-
# and therefore two sets of binaries are generated. For CPUs, one binary can carry both
70-
# non-SIMD and SIMD, and the program, at run-time, can decide which path to follow,
71-
# depending on what CPU instructions are available.
67+
# In previous releases, the cmake script used to produce both non-SIMD and
68+
# SIMD builds in one go. At the time of this writing, all interpreters and
69+
# compilers of WASM code, such as web-browser and node, support SIMD, therefore
70+
# it is time to make the SIMD build the default. In other words, this cmake
71+
# script builds only WASM SIMD code by default, if desired, a non-SIMD build
72+
# can be generated using the OJPH_DISABLE_SIMD option (in this case, the
73+
# WASM SIMD code is not generated).
74+
# It is worth remembering that the SIMD/non-SIMD issue arose because it is
75+
# NOT possible to have multiple execution paths in the code, one for non-SIMD
76+
# and one for SIMD, as we do for CPUs, letting the program select, at run-time,
77+
# the best path to follow.
7278
if(EMSCRIPTEN)
7379
set(BUILD_SHARED_LIBS OFF)
7480
set(OJPH_ENABLE_TIFF_SUPPORT OFF)
7581
set(OJPH_ENABLE_OPENEXR_SUPPORT OFF)
7682
set(OJPH_BUILD_STREAM_EXPAND OFF)
77-
set(OJPH_DISABLE_SIMD ON)
83+
if (OJPH_DISABLE_SIMD)
84+
set(OJPH_ENABLE_WASM_SIMD OFF)
85+
else()
86+
set(OJPH_ENABLE_WASM_SIMD ON)
87+
endif()
7888
endif()
7989

8090
# This is related to how the timestamp is set for URL downloaded files.
@@ -113,6 +123,12 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
113123
-Wunused-parameter
114124
)
115125
endif()
126+
if (EMSCRIPTEN)
127+
add_compile_options(-fexceptions)
128+
if(OJPH_ENABLE_WASM_SIMD)
129+
add_compile_options(-DOJPH_ENABLE_WASM_SIMD -msimd128)
130+
endif()
131+
endif()
116132

117133
## Enhanced instruction options
118134
if (OJPH_DISABLE_SIMD)
@@ -155,15 +171,10 @@ endif()
155171
################################################################################################
156172

157173
include(GNUInstallDirs)
158-
install(TARGETS openjph
159-
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
160-
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
161-
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
162174

163-
install(DIRECTORY src/core/common/
164-
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/openjph
165-
FILES_MATCHING
166-
PATTERN "*.h")
175+
install(EXPORT openjph-config
176+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/openjph
177+
)
167178

168179
install(FILES "${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc"
169180
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
@@ -186,6 +197,16 @@ configure_file(
186197
@ONLY
187198
)
188199

200+
include(CMakePackageConfigHelpers)
201+
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/openjph-config-version.cmake
202+
COMPATIBILITY SameMinorVersion)
203+
204+
install(
205+
FILES ${CMAKE_CURRENT_BINARY_DIR}/openjph-config-version.cmake
206+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/openjph
207+
)
208+
209+
189210
################################################################################################
190211
# Testing (OJPH_BUILD_TESTS)
191212
################################################################################################

src/apps/CMakeLists.txt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11

22
# Add tiff library
33
############################################################
4-
if( OJPH_ENABLE_TIFF_SUPPORT )
4+
if( OJPH_ENABLE_TIFF_SUPPORT AND (NOT EMSCRIPTEN))
55

66
FIND_PACKAGE( TIFF )
77

88
if( TIFF_FOUND )
99
set(USE_TIFF TRUE CACHE BOOL "Add TIFF support")
10-
include_directories( ${TIFF_INCLUDE_DIR} )
1110
add_definitions(-DOJPH_ENABLE_TIFF_SUPPORT)
12-
elseif( TIFF_FOUND )
13-
message(STATUS "TIFF support has been enabled but no path to the TIFF library "
11+
else()
12+
message(WARNING "TIFF support has been requested but no path to the TIFF library "
1413
"has been specified; please configure with -DCMAKE_PREFIX_PATH=<TIFF library directory>, "
1514
"or disable TIFF support using -DOJPH_ENABLE_TIFF_SUPPORT=OFF.")
1615
endif( TIFF_FOUND )
@@ -80,7 +79,13 @@ if( OJPH_ENABLE_OPENEXR_SUPPORT )
8079
endif(OJPH_ENABLE_OPENEXR_SUPPORT)
8180
############################################################
8281

82+
if (EMSCRIPTEN)
83+
add_link_options(-sWASM=1 -sASSERTIONS=1 -sALLOW_MEMORY_GROWTH=1 -sNODERAWFS=1 -sENVIRONMENT=node -sEXIT_RUNTIME=1 -sEXCEPTION_CATCHING_ALLOWED=['fake'])
84+
endif()
85+
8386
## Build executables
8487
add_subdirectory(ojph_expand)
8588
add_subdirectory(ojph_compress)
86-
add_subdirectory(ojph_stream_expand)
89+
if (OJPH_BUILD_STREAM_EXPAND)
90+
add_subdirectory(ojph_stream_expand)
91+
endif()

src/apps/ojph_compress/CMakeLists.txt

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
## building ojph_compress
22
#########################
33

4-
include_directories(../common)
5-
include_directories(../../core/common)
6-
74
file(GLOB OJPH_COMPRESS "ojph_compress.cpp")
85
file(GLOB OJPH_IMG_IO "../others/ojph_img_io.cpp")
96
file(GLOB OJPH_IMG_IO_SSE4 "../others/ojph_img_io_sse41.cpp")
@@ -17,17 +14,11 @@ source_group("others" FILES ${OJPH_IMG_IO})
1714
source_group("common" FILES ${OJPH_IMG_IO_H})
1815

1916
if(EMSCRIPTEN)
20-
add_compile_options(-std=c++11 -O3 -fexceptions)
21-
add_link_options(-sWASM=1 -sASSERTIONS=1 -sALLOW_MEMORY_GROWTH=1 -sNODERAWFS=1 -sENVIRONMENT=node -sEXIT_RUNTIME=1 -sEXCEPTION_CATCHING_ALLOWED=['fake'])
22-
add_executable(ojph_compress ${SOURCES})
23-
add_executable(ojph_compress_simd ${SOURCES} ${OJPH_IMG_IO_SSE4})
24-
target_compile_options(ojph_compress_simd PRIVATE -DOJPH_ENABLE_WASM_SIMD -msimd128 -msse4.1)
25-
source_group("others" FILES ${OJPH_IMG_IO_SSE4})
26-
27-
target_link_libraries(ojph_compress PRIVATE openjph)
28-
install(TARGETS ojph_compress DESTINATION bin)
29-
target_link_libraries(ojph_compress_simd PRIVATE openjphsimd)
30-
install(TARGETS ojph_compress_simd DESTINATION bin)
17+
if (OJPH_ENABLE_WASM_SIMD)
18+
list(APPEND SOURCES ${OJPH_IMG_IO_SSE4})
19+
source_group("others" FILES ${OJPH_IMG_IO_SSE4})
20+
set_source_files_properties(${OJPH_IMG_IO_SSE4} PROPERTIES COMPILE_FLAGS -msse4.1)
21+
endif()
3122
else()
3223
if (NOT OJPH_DISABLE_SIMD)
3324
if (("${OJPH_TARGET_ARCH}" MATCHES "OJPH_ARCH_X86_64") OR ("${OJPH_TARGET_ARCH}" MATCHES "OJPH_ARCH_I386"))
@@ -48,7 +39,7 @@ else()
4839
set_source_files_properties(${OJPH_IMG_IO_AVX2} PROPERTIES COMPILE_FLAGS -mavx2)
4940
endif()
5041
elseif ("${OJPH_TARGET_ARCH}" MATCHES "OJPH_ARCH_ARM")
51-
42+
5243
endif()
5344

5445
endif()
@@ -95,3 +86,11 @@ else()
9586

9687
install(TARGETS ojph_compress DESTINATION bin)
9788
endif()
89+
90+
add_executable(ojph_compress ${SOURCES})
91+
target_include_directories(ojph_compress PRIVATE ../common)
92+
target_link_libraries(ojph_compress PRIVATE openjph $<TARGET_NAME_IF_EXISTS:TIFF::TIFF>)
93+
94+
install(TARGETS ojph_compress
95+
EXPORT openjph-config
96+
)

src/apps/ojph_compress/ojph_compress.cpp

Lines changed: 32 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -788,33 +788,20 @@ int main(int argc, char * argv[]) {
788788
if (num_bit_depths < num_comps) // but if not enough, repeat
789789
for (ojph::ui32 c = num_bit_depths; c < num_comps; ++c)
790790
bit_depth[c] = bit_depth[num_bit_depths - 1];
791-
if (is_signed[0] != -1) // one was set
792-
if (num_is_signed < num_comps) // but if not enough, repeat
793-
for (ojph::ui32 c = num_is_signed; c < num_comps; ++c)
794-
is_signed[c] = is_signed[num_is_signed - 1];
795791

796792
bool all_the_same = true;
797793
if (num_comps == 3)
798-
{
799794
all_the_same = all_the_same
800795
&& bit_depth[0] == bit_depth[1]
801796
&& bit_depth[1] == bit_depth[2];
802-
all_the_same = all_the_same
803-
&& is_signed[0] == is_signed[1]
804-
&& is_signed[1] == is_signed[2];
805-
}
806797

807-
pfm.configure(bit_depth);
808-
ojph::point ds(1, 1);
809798
for (ojph::ui32 c = 0; c < num_comps; ++c) {
810-
ojph::ui32 bd = 32;
811-
if (bit_depth[c] != 0)
812-
bd = bit_depth[c];
813-
bool is = true;
814-
if (is_signed[c] != -1)
815-
is = is_signed[c] != 0;
816-
siz.set_component(c, ds, bd, is);
799+
if (bit_depth[c] == 0)
800+
bit_depth[c] = 32;
801+
siz.set_component(c, ojph::point(1,1), bit_depth[c], true);
817802
}
803+
pfm.configure(bit_depth);
804+
818805
siz.set_image_offset(image_offset);
819806
siz.set_tile_size(tile_size);
820807
siz.set_tile_offset(tile_offset);
@@ -828,7 +815,7 @@ int main(int argc, char * argv[]) {
828815
if (num_comps == 1)
829816
{
830817
if (employ_color_transform != -1)
831-
OJPH_WARN(0x01000092,
818+
OJPH_WARN(0x01000091,
832819
"-colour_trans option is not needed and was not used; "
833820
"this is because the image has one component only\n");
834821
}
@@ -840,29 +827,30 @@ int main(int argc, char * argv[]) {
840827
cod.set_color_transform(employ_color_transform == 1);
841828
}
842829
cod.set_reversible(reversible);
843-
if (!reversible && quantization_step != -1.0f)
830+
if (!reversible) {
831+
const float min_step = 1.0f / 16384.0f;
832+
if (quantization_step == -1.0f)
833+
quantization_step = min_step;
834+
else
835+
quantization_step = ojph_max(quantization_step, min_step);
844836
codestream.access_qcd().set_irrev_quant(quantization_step);
837+
}
845838

839+
// Note: Even if only ALL_COMPS is set to
840+
// OJPH_NLT_BINARY_COMPLEMENT_NLT, the library can decide if
841+
// one ALL_COMPS NLT marker segment is needed, or multiple
842+
// per component NLT marker segments are needed (when the components
843+
// have different bit depths or signedness).
844+
// Of course for .pfm images all components should have the same
845+
// bit depth and signedness.
846846
ojph::param_nlt nlt = codestream.access_nlt();
847-
if (reversible) {
848-
// Note: Even if only ALL_COMPS is set to
849-
// OJPH_NLT_BINARY_COMPLEMENT_NLT, the library can decide if
850-
// one ALL_COMPS NLT marker segment is needed, or multiple
851-
// per component NLT marker segments are needed (when the components
852-
// have different bit depths or signedness).
853-
// Of course for .pfm images all components should have the same
854-
// bit depth and signedness.
855-
if (all_the_same)
856-
nlt.set_nonlinear_transform(ojph::param_nlt::ALL_COMPS,
857-
ojph::param_nlt::OJPH_NLT_BINARY_COMPLEMENT_NLT);
858-
else
859-
for (ojph::ui32 c = 0; c < num_comps; ++c)
860-
nlt.set_nonlinear_transform(c,
861-
ojph::param_nlt::OJPH_NLT_BINARY_COMPLEMENT_NLT);
862-
}
847+
if (all_the_same)
848+
nlt.set_nonlinear_transform(ojph::param_nlt::ALL_COMPS,
849+
ojph::param_nlt::OJPH_NLT_BINARY_COMPLEMENT_NLT);
863850
else
864-
OJPH_ERROR(0x01000093, "We currently support lossless only for "
865-
"pfm images; this may change in the future.");
851+
for (ojph::ui32 c = 0; c < num_comps; ++c)
852+
nlt.set_nonlinear_transform(c,
853+
ojph::param_nlt::OJPH_NLT_BINARY_COMPLEMENT_NLT);
866854

867855
codestream.set_planar(false);
868856
if (profile_string[0] != '\0')
@@ -872,13 +860,16 @@ int main(int argc, char * argv[]) {
872860
codestream.request_tlm_marker(tlm_marker);
873861

874862
if (dims.w != 0 || dims.h != 0)
875-
OJPH_WARN(0x01000094,
863+
OJPH_WARN(0x01000092,
876864
"-dims option is not needed and was not used\n");
877865
if (num_components != 0)
878-
OJPH_WARN(0x01000095,
866+
OJPH_WARN(0x01000093,
879867
"-num_comps is not needed and was not used\n");
868+
if (is_signed[0] != -1)
869+
OJPH_WARN(0x01000094,
870+
"-signed is not needed and was not used\n");
880871
if (comp_downsampling[0].x != 0 || comp_downsampling[0].y != 0)
881-
OJPH_WARN(0x01000096,
872+
OJPH_WARN(0x01000095,
882873
"-downsamp is not needed and was not used\n");
883874

884875
base = &pfm;

src/apps/ojph_expand/CMakeLists.txt

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
## building ojph_expand
22
#######################
33

4-
include_directories(../common)
5-
include_directories(../../core/common)
6-
74
file(GLOB OJPH_EXPAND "ojph_expand.cpp")
85
file(GLOB OJPH_IMG_IO "../others/ojph_img_io.cpp")
96
file(GLOB OJPH_IMG_IO_SSE4 "../others/ojph_img_io_sse41.cpp")
@@ -17,17 +14,11 @@ source_group("others" FILES ${OJPH_IMG_IO})
1714
source_group("common" FILES ${OJPH_IMG_IO_H})
1815

1916
if(EMSCRIPTEN)
20-
add_compile_options(-std=c++11 -O3 -fexceptions)
21-
add_link_options(-sWASM=1 -sASSERTIONS=1 -sALLOW_MEMORY_GROWTH=1 -sNODERAWFS=1 -sENVIRONMENT=node -sEXIT_RUNTIME=1 -sEXCEPTION_CATCHING_ALLOWED=['fake'])
22-
add_executable(ojph_expand ${SOURCES})
23-
add_executable(ojph_expand_simd ${SOURCES} ${OJPH_IMG_IO_SSE4})
24-
target_compile_options(ojph_expand_simd PRIVATE -DOJPH_ENABLE_WASM_SIMD -msimd128 -msse4.1)
25-
source_group("others" FILES ${OJPH_IMG_IO_SSE4})
26-
27-
target_link_libraries(ojph_expand PRIVATE openjph)
28-
install(TARGETS ojph_expand DESTINATION bin)
29-
target_link_libraries(ojph_expand_simd PRIVATE openjphsimd)
30-
install(TARGETS ojph_expand_simd DESTINATION bin)
17+
if (OJPH_ENABLE_WASM_SIMD)
18+
list(APPEND SOURCES ${OJPH_IMG_IO_SSE4})
19+
source_group("others" FILES ${OJPH_IMG_IO_SSE4})
20+
set_source_files_properties(${OJPH_IMG_IO_SSE4} PROPERTIES COMPILE_FLAGS -msse4.1)
21+
endif()
3122
else()
3223
if (NOT OJPH_DISABLE_SIMD)
3324
if (("${OJPH_TARGET_ARCH}" MATCHES "OJPH_ARCH_X86_64") OR ("${OJPH_TARGET_ARCH}" MATCHES "OJPH_ARCH_I386"))
@@ -95,3 +86,11 @@ else()
9586

9687
install(TARGETS ojph_expand DESTINATION bin)
9788
endif()
89+
90+
add_executable(ojph_expand ${SOURCES})
91+
target_include_directories(ojph_expand PRIVATE ../common)
92+
target_link_libraries(ojph_expand PRIVATE openjph $<TARGET_NAME_IF_EXISTS:TIFF::TIFF>)
93+
94+
install(TARGETS ojph_expand
95+
EXPORT openjph-config
96+
)

0 commit comments

Comments
 (0)