Skip to content

Commit e53fdbe

Browse files
Merge branch 'aous72:master' into feature/add-32bit-tif-support
2 parents 39e5d15 + c062d93 commit e53fdbe

28 files changed

+706
-426
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
@@ -58,16 +58,26 @@ if (DEFINED OJPH_ENABLE_INTEL_AVX512)
5858
endif()
5959

6060
## Setting some of the options if EMSCRIPTEN is the compiler
61-
# WebAssembly SIMD is treated differently. The SIMD flags above have no effect on the
62-
# use of WASM SIMD. This is because, for WASM, both non-SIMD and SIMD are required,
63-
# and therefore two sets of binaries are generated. For CPUs, one binary can carry both
64-
# non-SIMD and SIMD, and the program, at run-time, can decide which path to follow,
65-
# depending on what CPU instructions are available.
61+
# In previous releases, the cmake script used to produce both non-SIMD and
62+
# SIMD builds in one go. At the time of this writing, all interpreters and
63+
# compilers of WASM code, such as web-browser and node, support SIMD, therefore
64+
# it is time to make the SIMD build the default. In other words, this cmake
65+
# script builds only WASM SIMD code by default, if desired, a non-SIMD build
66+
# can be generated using the OJPH_DISABLE_SIMD option (in this case, the
67+
# WASM SIMD code is not generated).
68+
# It is worth remembering that the SIMD/non-SIMD issue arose because it is
69+
# NOT possible to have multiple execution paths in the code, one for non-SIMD
70+
# and one for SIMD, as we do for CPUs, letting the program select, at run-time,
71+
# the best path to follow.
6672
if(EMSCRIPTEN)
6773
set(BUILD_SHARED_LIBS OFF)
6874
set(OJPH_ENABLE_TIFF_SUPPORT OFF)
6975
set(OJPH_BUILD_STREAM_EXPAND OFF)
70-
set(OJPH_DISABLE_SIMD ON)
76+
if (OJPH_DISABLE_SIMD)
77+
set(OJPH_ENABLE_WASM_SIMD OFF)
78+
else()
79+
set(OJPH_ENABLE_WASM_SIMD ON)
80+
endif()
7181
endif()
7282

7383
# This is related to how the timestamp is set for URL downloaded files.
@@ -106,6 +116,12 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
106116
-Wunused-parameter
107117
)
108118
endif()
119+
if (EMSCRIPTEN)
120+
add_compile_options(-fexceptions)
121+
if(OJPH_ENABLE_WASM_SIMD)
122+
add_compile_options(-DOJPH_ENABLE_WASM_SIMD -msimd128)
123+
endif()
124+
endif()
109125

110126
## Enhanced instruction options
111127
if (OJPH_DISABLE_SIMD)
@@ -148,15 +164,10 @@ endif()
148164
################################################################################################
149165

150166
include(GNUInstallDirs)
151-
install(TARGETS openjph
152-
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
153-
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
154-
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
155167

156-
install(DIRECTORY src/core/common/
157-
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/openjph
158-
FILES_MATCHING
159-
PATTERN "*.h")
168+
install(EXPORT openjph-config
169+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/openjph
170+
)
160171

161172
install(FILES "${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc"
162173
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
@@ -179,6 +190,16 @@ configure_file(
179190
@ONLY
180191
)
181192

193+
include(CMakePackageConfigHelpers)
194+
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/openjph-config-version.cmake
195+
COMPATIBILITY SameMinorVersion)
196+
197+
install(
198+
FILES ${CMAKE_CURRENT_BINARY_DIR}/openjph-config-version.cmake
199+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/openjph
200+
)
201+
202+
182203
################################################################################################
183204
# Testing (OJPH_BUILD_TESTS)
184205
################################################################################################

src/apps/CMakeLists.txt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
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(MSVC)
13-
message(STATUS "TIFF support has been enabled by 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 )
1716

1817
endif()
1918
############################################################
2019

20+
if (EMSCRIPTEN)
21+
add_link_options(-sWASM=1 -sASSERTIONS=1 -sALLOW_MEMORY_GROWTH=1 -sNODERAWFS=1 -sENVIRONMENT=node -sEXIT_RUNTIME=1 -sEXCEPTION_CATCHING_ALLOWED=['fake'])
22+
endif()
23+
2124
## Build executables
2225
add_subdirectory(ojph_expand)
2326
add_subdirectory(ojph_compress)
24-
add_subdirectory(ojph_stream_expand)
27+
if (OJPH_BUILD_STREAM_EXPAND)
28+
add_subdirectory(ojph_stream_expand)
29+
endif()
Lines changed: 13 additions & 23 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,18 +39,17 @@ 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()
5546

56-
add_executable(ojph_compress ${SOURCES})
47+
endif()
5748

58-
if( USE_TIFF )
59-
target_link_libraries(ojph_compress PUBLIC openjph ${TIFF_LIBRARIES})
60-
else()
61-
target_link_libraries(ojph_compress PUBLIC openjph)
62-
endif()
49+
add_executable(ojph_compress ${SOURCES})
50+
target_include_directories(ojph_compress PRIVATE ../common)
51+
target_link_libraries(ojph_compress PRIVATE openjph $<TARGET_NAME_IF_EXISTS:TIFF::TIFF>)
6352

64-
install(TARGETS ojph_compress DESTINATION bin)
65-
endif()
53+
install(TARGETS ojph_compress
54+
EXPORT openjph-config
55+
)

src/apps/ojph_compress/ojph_compress.cpp

Lines changed: 32 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -777,33 +777,20 @@ int main(int argc, char * argv[]) {
777777
if (num_bit_depths < num_comps) // but if not enough, repeat
778778
for (ojph::ui32 c = num_bit_depths; c < num_comps; ++c)
779779
bit_depth[c] = bit_depth[num_bit_depths - 1];
780-
if (is_signed[0] != -1) // one was set
781-
if (num_is_signed < num_comps) // but if not enough, repeat
782-
for (ojph::ui32 c = num_is_signed; c < num_comps; ++c)
783-
is_signed[c] = is_signed[num_is_signed - 1];
784780

785781
bool all_the_same = true;
786782
if (num_comps == 3)
787-
{
788783
all_the_same = all_the_same
789784
&& bit_depth[0] == bit_depth[1]
790785
&& bit_depth[1] == bit_depth[2];
791-
all_the_same = all_the_same
792-
&& is_signed[0] == is_signed[1]
793-
&& is_signed[1] == is_signed[2];
794-
}
795786

796-
pfm.configure(bit_depth);
797-
ojph::point ds(1, 1);
798787
for (ojph::ui32 c = 0; c < num_comps; ++c) {
799-
ojph::ui32 bd = 32;
800-
if (bit_depth[c] != 0)
801-
bd = bit_depth[c];
802-
bool is = true;
803-
if (is_signed[c] != -1)
804-
is = is_signed[c] != 0;
805-
siz.set_component(c, ds, bd, is);
788+
if (bit_depth[c] == 0)
789+
bit_depth[c] = 32;
790+
siz.set_component(c, ojph::point(1,1), bit_depth[c], true);
806791
}
792+
pfm.configure(bit_depth);
793+
807794
siz.set_image_offset(image_offset);
808795
siz.set_tile_size(tile_size);
809796
siz.set_tile_offset(tile_offset);
@@ -817,7 +804,7 @@ int main(int argc, char * argv[]) {
817804
if (num_comps == 1)
818805
{
819806
if (employ_color_transform != -1)
820-
OJPH_WARN(0x01000092,
807+
OJPH_WARN(0x01000091,
821808
"-colour_trans option is not needed and was not used; "
822809
"this is because the image has one component only\n");
823810
}
@@ -829,29 +816,30 @@ int main(int argc, char * argv[]) {
829816
cod.set_color_transform(employ_color_transform == 1);
830817
}
831818
cod.set_reversible(reversible);
832-
if (!reversible && quantization_step != -1.0f)
819+
if (!reversible) {
820+
const float min_step = 1.0f / 16384.0f;
821+
if (quantization_step == -1.0f)
822+
quantization_step = min_step;
823+
else
824+
quantization_step = ojph_max(quantization_step, min_step);
833825
codestream.access_qcd().set_irrev_quant(quantization_step);
826+
}
834827

828+
// Note: Even if only ALL_COMPS is set to
829+
// OJPH_NLT_BINARY_COMPLEMENT_NLT, the library can decide if
830+
// one ALL_COMPS NLT marker segment is needed, or multiple
831+
// per component NLT marker segments are needed (when the components
832+
// have different bit depths or signedness).
833+
// Of course for .pfm images all components should have the same
834+
// bit depth and signedness.
835835
ojph::param_nlt nlt = codestream.access_nlt();
836-
if (reversible) {
837-
// Note: Even if only ALL_COMPS is set to
838-
// OJPH_NLT_BINARY_COMPLEMENT_NLT, the library can decide if
839-
// one ALL_COMPS NLT marker segment is needed, or multiple
840-
// per component NLT marker segments are needed (when the components
841-
// have different bit depths or signedness).
842-
// Of course for .pfm images all components should have the same
843-
// bit depth and signedness.
844-
if (all_the_same)
845-
nlt.set_nonlinear_transform(ojph::param_nlt::ALL_COMPS,
846-
ojph::param_nlt::OJPH_NLT_BINARY_COMPLEMENT_NLT);
847-
else
848-
for (ojph::ui32 c = 0; c < num_comps; ++c)
849-
nlt.set_nonlinear_transform(c,
850-
ojph::param_nlt::OJPH_NLT_BINARY_COMPLEMENT_NLT);
851-
}
836+
if (all_the_same)
837+
nlt.set_nonlinear_transform(ojph::param_nlt::ALL_COMPS,
838+
ojph::param_nlt::OJPH_NLT_BINARY_COMPLEMENT_NLT);
852839
else
853-
OJPH_ERROR(0x01000093, "We currently support lossless only for "
854-
"pfm images; this may change in the future.");
840+
for (ojph::ui32 c = 0; c < num_comps; ++c)
841+
nlt.set_nonlinear_transform(c,
842+
ojph::param_nlt::OJPH_NLT_BINARY_COMPLEMENT_NLT);
855843

856844
codestream.set_planar(false);
857845
if (profile_string[0] != '\0')
@@ -861,13 +849,16 @@ int main(int argc, char * argv[]) {
861849
codestream.request_tlm_marker(tlm_marker);
862850

863851
if (dims.w != 0 || dims.h != 0)
864-
OJPH_WARN(0x01000094,
852+
OJPH_WARN(0x01000092,
865853
"-dims option is not needed and was not used\n");
866854
if (num_components != 0)
867-
OJPH_WARN(0x01000095,
855+
OJPH_WARN(0x01000093,
868856
"-num_comps is not needed and was not used\n");
857+
if (is_signed[0] != -1)
858+
OJPH_WARN(0x01000094,
859+
"-signed is not needed and was not used\n");
869860
if (comp_downsampling[0].x != 0 || comp_downsampling[0].y != 0)
870-
OJPH_WARN(0x01000096,
861+
OJPH_WARN(0x01000095,
871862
"-downsamp is not needed and was not used\n");
872863

873864
base = &pfm;

src/apps/ojph_expand/CMakeLists.txt

Lines changed: 12 additions & 22 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"))
@@ -53,13 +44,12 @@ else()
5344

5445
endif()
5546

56-
add_executable(ojph_expand ${SOURCES})
47+
endif()
5748

58-
if( USE_TIFF )
59-
target_link_libraries(ojph_expand PUBLIC openjph ${TIFF_LIBRARIES})
60-
else()
61-
target_link_libraries(ojph_expand PUBLIC openjph)
62-
endif()
49+
add_executable(ojph_expand ${SOURCES})
50+
target_include_directories(ojph_expand PRIVATE ../common)
51+
target_link_libraries(ojph_expand PRIVATE openjph $<TARGET_NAME_IF_EXISTS:TIFF::TIFF>)
6352

64-
install(TARGETS ojph_expand DESTINATION bin)
65-
endif()
53+
install(TARGETS ojph_expand
54+
EXPORT openjph-config
55+
)

0 commit comments

Comments
 (0)