Skip to content

Commit

Permalink
Merge branch 'aous72:master' into feature/add-32bit-tif-support
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeldsmith authored Feb 7, 2025
2 parents 39e5d15 + c062d93 commit e53fdbe
Show file tree
Hide file tree
Showing 28 changed files with 706 additions and 426 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/emcc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Build with EMCC

on:
push:
pull_request:
types: [opened, reopened]

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Configure emcc
uses: mymindstorm/setup-emsdk@v14
with:
actions-cache-folder: 'emsdk-cache'

- name: Build non-SIMD and Debug
run: |
cd build
emcmake cmake .. --fresh -DOJPH_DISABLE_SIMD=ON -DCMAKE_BUILD_TYPE=Debug
cmake --build . --config Debug --clean-first
cd ..
- name: Build non-SIMD and Release
run: |
cd build
emcmake cmake .. --fresh -DOJPH_DISABLE_SIMD=ON -DCMAKE_BUILD_TYPE=Release
cmake --build . --config Release --clean-first
cd ..
- name: Build SIMD and Debug
run: |
cd build
emcmake cmake .. --fresh -DOJPH_DISABLE_SIMD=OFF -DCMAKE_BUILD_TYPE=Debug
cmake --build . --config Debug --clean-first
cd ..
- name: Build SIMD and Release
run: |
cd build
emcmake cmake .. --fresh -DOJPH_DISABLE_SIMD=OFF -DCMAKE_BUILD_TYPE=Release
cmake --build . --config Release --clean-first
cd ..
49 changes: 35 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,26 @@ if (DEFINED OJPH_ENABLE_INTEL_AVX512)
endif()

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

# This is related to how the timestamp is set for URL downloaded files.
Expand Down Expand Up @@ -106,6 +116,12 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
-Wunused-parameter
)
endif()
if (EMSCRIPTEN)
add_compile_options(-fexceptions)
if(OJPH_ENABLE_WASM_SIMD)
add_compile_options(-DOJPH_ENABLE_WASM_SIMD -msimd128)
endif()
endif()

## Enhanced instruction options
if (OJPH_DISABLE_SIMD)
Expand Down Expand Up @@ -148,15 +164,10 @@ endif()
################################################################################################

include(GNUInstallDirs)
install(TARGETS openjph
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})

install(DIRECTORY src/core/common/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/openjph
FILES_MATCHING
PATTERN "*.h")
install(EXPORT openjph-config
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/openjph
)

install(FILES "${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
Expand All @@ -179,6 +190,16 @@ configure_file(
@ONLY
)

include(CMakePackageConfigHelpers)
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/openjph-config-version.cmake
COMPATIBILITY SameMinorVersion)

install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/openjph-config-version.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/openjph
)


################################################################################################
# Testing (OJPH_BUILD_TESTS)
################################################################################################
Expand Down
15 changes: 10 additions & 5 deletions src/apps/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@

# Add tiff library
############################################################
if( OJPH_ENABLE_TIFF_SUPPORT )
if( OJPH_ENABLE_TIFF_SUPPORT AND (NOT EMSCRIPTEN))

FIND_PACKAGE( TIFF )

if( TIFF_FOUND )
set(USE_TIFF TRUE CACHE BOOL "Add TIFF support")
include_directories( ${TIFF_INCLUDE_DIR} )
add_definitions(-DOJPH_ENABLE_TIFF_SUPPORT)
elseif(MSVC)
message(STATUS "TIFF support has been enabled by no path to the TIFF library "
else()
message(WARNING "TIFF support has been requested but no path to the TIFF library "
"has been specified; please configure with -DCMAKE_PREFIX_PATH=<TIFF library directory>, "
"or disable TIFF support using -DOJPH_ENABLE_TIFF_SUPPORT=OFF.")
endif( TIFF_FOUND )

endif()
############################################################

if (EMSCRIPTEN)
add_link_options(-sWASM=1 -sASSERTIONS=1 -sALLOW_MEMORY_GROWTH=1 -sNODERAWFS=1 -sENVIRONMENT=node -sEXIT_RUNTIME=1 -sEXCEPTION_CATCHING_ALLOWED=['fake'])
endif()

## Build executables
add_subdirectory(ojph_expand)
add_subdirectory(ojph_compress)
add_subdirectory(ojph_stream_expand)
if (OJPH_BUILD_STREAM_EXPAND)
add_subdirectory(ojph_stream_expand)
endif()
36 changes: 13 additions & 23 deletions src/apps/ojph_compress/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
## building ojph_compress
#########################

include_directories(../common)
include_directories(../../core/common)

file(GLOB OJPH_COMPRESS "ojph_compress.cpp")
file(GLOB OJPH_IMG_IO "../others/ojph_img_io.cpp")
file(GLOB OJPH_IMG_IO_SSE4 "../others/ojph_img_io_sse41.cpp")
Expand All @@ -17,17 +14,11 @@ source_group("others" FILES ${OJPH_IMG_IO})
source_group("common" FILES ${OJPH_IMG_IO_H})

if(EMSCRIPTEN)
add_compile_options(-std=c++11 -O3 -fexceptions)
add_link_options(-sWASM=1 -sASSERTIONS=1 -sALLOW_MEMORY_GROWTH=1 -sNODERAWFS=1 -sENVIRONMENT=node -sEXIT_RUNTIME=1 -sEXCEPTION_CATCHING_ALLOWED=['fake'])
add_executable(ojph_compress ${SOURCES})
add_executable(ojph_compress_simd ${SOURCES} ${OJPH_IMG_IO_SSE4})
target_compile_options(ojph_compress_simd PRIVATE -DOJPH_ENABLE_WASM_SIMD -msimd128 -msse4.1)
source_group("others" FILES ${OJPH_IMG_IO_SSE4})

target_link_libraries(ojph_compress PRIVATE openjph)
install(TARGETS ojph_compress DESTINATION bin)
target_link_libraries(ojph_compress_simd PRIVATE openjphsimd)
install(TARGETS ojph_compress_simd DESTINATION bin)
if (OJPH_ENABLE_WASM_SIMD)
list(APPEND SOURCES ${OJPH_IMG_IO_SSE4})
source_group("others" FILES ${OJPH_IMG_IO_SSE4})
set_source_files_properties(${OJPH_IMG_IO_SSE4} PROPERTIES COMPILE_FLAGS -msse4.1)
endif()
else()
if (NOT OJPH_DISABLE_SIMD)
if (("${OJPH_TARGET_ARCH}" MATCHES "OJPH_ARCH_X86_64") OR ("${OJPH_TARGET_ARCH}" MATCHES "OJPH_ARCH_I386"))
Expand All @@ -48,18 +39,17 @@ else()
set_source_files_properties(${OJPH_IMG_IO_AVX2} PROPERTIES COMPILE_FLAGS -mavx2)
endif()
elseif ("${OJPH_TARGET_ARCH}" MATCHES "OJPH_ARCH_ARM")

endif()

endif()

add_executable(ojph_compress ${SOURCES})
endif()

if( USE_TIFF )
target_link_libraries(ojph_compress PUBLIC openjph ${TIFF_LIBRARIES})
else()
target_link_libraries(ojph_compress PUBLIC openjph)
endif()
add_executable(ojph_compress ${SOURCES})
target_include_directories(ojph_compress PRIVATE ../common)
target_link_libraries(ojph_compress PRIVATE openjph $<TARGET_NAME_IF_EXISTS:TIFF::TIFF>)

install(TARGETS ojph_compress DESTINATION bin)
endif()
install(TARGETS ojph_compress
EXPORT openjph-config
)
73 changes: 32 additions & 41 deletions src/apps/ojph_compress/ojph_compress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -777,33 +777,20 @@ int main(int argc, char * argv[]) {
if (num_bit_depths < num_comps) // but if not enough, repeat
for (ojph::ui32 c = num_bit_depths; c < num_comps; ++c)
bit_depth[c] = bit_depth[num_bit_depths - 1];
if (is_signed[0] != -1) // one was set
if (num_is_signed < num_comps) // but if not enough, repeat
for (ojph::ui32 c = num_is_signed; c < num_comps; ++c)
is_signed[c] = is_signed[num_is_signed - 1];

bool all_the_same = true;
if (num_comps == 3)
{
all_the_same = all_the_same
&& bit_depth[0] == bit_depth[1]
&& bit_depth[1] == bit_depth[2];
all_the_same = all_the_same
&& is_signed[0] == is_signed[1]
&& is_signed[1] == is_signed[2];
}

pfm.configure(bit_depth);
ojph::point ds(1, 1);
for (ojph::ui32 c = 0; c < num_comps; ++c) {
ojph::ui32 bd = 32;
if (bit_depth[c] != 0)
bd = bit_depth[c];
bool is = true;
if (is_signed[c] != -1)
is = is_signed[c] != 0;
siz.set_component(c, ds, bd, is);
if (bit_depth[c] == 0)
bit_depth[c] = 32;
siz.set_component(c, ojph::point(1,1), bit_depth[c], true);
}
pfm.configure(bit_depth);

siz.set_image_offset(image_offset);
siz.set_tile_size(tile_size);
siz.set_tile_offset(tile_offset);
Expand All @@ -817,7 +804,7 @@ int main(int argc, char * argv[]) {
if (num_comps == 1)
{
if (employ_color_transform != -1)
OJPH_WARN(0x01000092,
OJPH_WARN(0x01000091,
"-colour_trans option is not needed and was not used; "
"this is because the image has one component only\n");
}
Expand All @@ -829,29 +816,30 @@ int main(int argc, char * argv[]) {
cod.set_color_transform(employ_color_transform == 1);
}
cod.set_reversible(reversible);
if (!reversible && quantization_step != -1.0f)
if (!reversible) {
const float min_step = 1.0f / 16384.0f;
if (quantization_step == -1.0f)
quantization_step = min_step;
else
quantization_step = ojph_max(quantization_step, min_step);
codestream.access_qcd().set_irrev_quant(quantization_step);
}

// Note: Even if only ALL_COMPS is set to
// OJPH_NLT_BINARY_COMPLEMENT_NLT, the library can decide if
// one ALL_COMPS NLT marker segment is needed, or multiple
// per component NLT marker segments are needed (when the components
// have different bit depths or signedness).
// Of course for .pfm images all components should have the same
// bit depth and signedness.
ojph::param_nlt nlt = codestream.access_nlt();
if (reversible) {
// Note: Even if only ALL_COMPS is set to
// OJPH_NLT_BINARY_COMPLEMENT_NLT, the library can decide if
// one ALL_COMPS NLT marker segment is needed, or multiple
// per component NLT marker segments are needed (when the components
// have different bit depths or signedness).
// Of course for .pfm images all components should have the same
// bit depth and signedness.
if (all_the_same)
nlt.set_nonlinear_transform(ojph::param_nlt::ALL_COMPS,
ojph::param_nlt::OJPH_NLT_BINARY_COMPLEMENT_NLT);
else
for (ojph::ui32 c = 0; c < num_comps; ++c)
nlt.set_nonlinear_transform(c,
ojph::param_nlt::OJPH_NLT_BINARY_COMPLEMENT_NLT);
}
if (all_the_same)
nlt.set_nonlinear_transform(ojph::param_nlt::ALL_COMPS,
ojph::param_nlt::OJPH_NLT_BINARY_COMPLEMENT_NLT);
else
OJPH_ERROR(0x01000093, "We currently support lossless only for "
"pfm images; this may change in the future.");
for (ojph::ui32 c = 0; c < num_comps; ++c)
nlt.set_nonlinear_transform(c,
ojph::param_nlt::OJPH_NLT_BINARY_COMPLEMENT_NLT);

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

if (dims.w != 0 || dims.h != 0)
OJPH_WARN(0x01000094,
OJPH_WARN(0x01000092,
"-dims option is not needed and was not used\n");
if (num_components != 0)
OJPH_WARN(0x01000095,
OJPH_WARN(0x01000093,
"-num_comps is not needed and was not used\n");
if (is_signed[0] != -1)
OJPH_WARN(0x01000094,
"-signed is not needed and was not used\n");
if (comp_downsampling[0].x != 0 || comp_downsampling[0].y != 0)
OJPH_WARN(0x01000096,
OJPH_WARN(0x01000095,
"-downsamp is not needed and was not used\n");

base = &pfm;
Expand Down
34 changes: 12 additions & 22 deletions src/apps/ojph_expand/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
## building ojph_expand
#######################

include_directories(../common)
include_directories(../../core/common)

file(GLOB OJPH_EXPAND "ojph_expand.cpp")
file(GLOB OJPH_IMG_IO "../others/ojph_img_io.cpp")
file(GLOB OJPH_IMG_IO_SSE4 "../others/ojph_img_io_sse41.cpp")
Expand All @@ -17,17 +14,11 @@ source_group("others" FILES ${OJPH_IMG_IO})
source_group("common" FILES ${OJPH_IMG_IO_H})

if(EMSCRIPTEN)
add_compile_options(-std=c++11 -O3 -fexceptions)
add_link_options(-sWASM=1 -sASSERTIONS=1 -sALLOW_MEMORY_GROWTH=1 -sNODERAWFS=1 -sENVIRONMENT=node -sEXIT_RUNTIME=1 -sEXCEPTION_CATCHING_ALLOWED=['fake'])
add_executable(ojph_expand ${SOURCES})
add_executable(ojph_expand_simd ${SOURCES} ${OJPH_IMG_IO_SSE4})
target_compile_options(ojph_expand_simd PRIVATE -DOJPH_ENABLE_WASM_SIMD -msimd128 -msse4.1)
source_group("others" FILES ${OJPH_IMG_IO_SSE4})

target_link_libraries(ojph_expand PRIVATE openjph)
install(TARGETS ojph_expand DESTINATION bin)
target_link_libraries(ojph_expand_simd PRIVATE openjphsimd)
install(TARGETS ojph_expand_simd DESTINATION bin)
if (OJPH_ENABLE_WASM_SIMD)
list(APPEND SOURCES ${OJPH_IMG_IO_SSE4})
source_group("others" FILES ${OJPH_IMG_IO_SSE4})
set_source_files_properties(${OJPH_IMG_IO_SSE4} PROPERTIES COMPILE_FLAGS -msse4.1)
endif()
else()
if (NOT OJPH_DISABLE_SIMD)
if (("${OJPH_TARGET_ARCH}" MATCHES "OJPH_ARCH_X86_64") OR ("${OJPH_TARGET_ARCH}" MATCHES "OJPH_ARCH_I386"))
Expand All @@ -53,13 +44,12 @@ else()

endif()

add_executable(ojph_expand ${SOURCES})
endif()

if( USE_TIFF )
target_link_libraries(ojph_expand PUBLIC openjph ${TIFF_LIBRARIES})
else()
target_link_libraries(ojph_expand PUBLIC openjph)
endif()
add_executable(ojph_expand ${SOURCES})
target_include_directories(ojph_expand PRIVATE ../common)
target_link_libraries(ojph_expand PRIVATE openjph $<TARGET_NAME_IF_EXISTS:TIFF::TIFF>)

install(TARGETS ojph_expand DESTINATION bin)
endif()
install(TARGETS ojph_expand
EXPORT openjph-config
)
Loading

0 comments on commit e53fdbe

Please sign in to comment.