Skip to content

Commit

Permalink
This improved wasm builds. It also removes all the warnings during wa…
Browse files Browse the repository at this point in the history
…sm builds.
  • Loading branch information
aous72 committed Dec 30, 2023
1 parent 1655c1b commit 0de48e2
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 68 deletions.
77 changes: 47 additions & 30 deletions src/apps/ojph_compress/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,38 +1,55 @@
## building ojph_compress
#########################

include_directories(../common)

file(GLOB OJPH_COMPRESS "ojph_compress.cpp")
file(GLOB OJPH_IMG_IO "../others/ojph_img_io*.cpp")
file(GLOB OJPH_IMG_IO_H "../common/ojph_img_io.h")

if(NOT OJPH_DISABLE_INTEL_SIMD)
list(REMOVE_ITEM OJPH_IMG_IO ${OJPH_IMG_IO_SSE41})
list(REMOVE_ITEM OJPH_IMG_IO ${OJPH_IMG_IO_AVX2})
endif()

source_group("main" FILES ${OJPH_COMPRESS})
source_group("others" FILES ${OJPH_IMG_IO})
source_group("common" FILES ${OJPH_IMG_IO_H})

if(OJPH_BUILD_EXECUTABLES)
add_executable(ojph_compress ${OJPH_COMPRESS} ${OJPH_IMG_IO} ${OJPH_IMG_IO_H})
endif()

if (MSVC)
set_source_files_properties(../others/ojph_img_io_avx2.cpp PROPERTIES COMPILE_FLAGS "/arch:AVX2")
else()
set_source_files_properties(../others/ojph_img_io_sse41.cpp PROPERTIES COMPILE_FLAGS -msse4.1)
set_source_files_properties(../others/ojph_img_io_avx2.cpp PROPERTIES COMPILE_FLAGS -mavx2)
endif()

if(OJPH_BUILD_EXECUTABLES)
if( USE_TIFF )
target_link_libraries(ojph_compress PUBLIC openjph ${TIFF_LIBRARIES})
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")
file(GLOB OJPH_IMG_IO_AVX2 "../others/ojph_img_io_avx2.cpp")
file(GLOB OJPH_IMG_IO_H "../common/ojph_img_io.h")

list(APPEND SOURCES ${OJPH_COMPRESS} ${OJPH_IMG_IO} ${OJPH_IMG_IO_H})

source_group("main" FILES ${OJPH_COMPRESS})
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 -DOJPH_DISABLE_INTEL_SIMD)
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)
else()
target_link_libraries(ojph_compress PUBLIC openjph)
if(NOT OJPH_DISABLE_INTEL_SIMD)
add_executable(ojph_compress ${SOURCES} ${OJPH_IMG_IO_SSE4} ${OJPH_IMG_IO_AVX2})

if (MSVC)
set_source_files_properties(${OJPH_IMG_IO_AVX2} PROPERTIES COMPILE_FLAGS "/arch:AVX2")
else()
set_source_files_properties(${OJPH_IMG_IO_SSE4} PROPERTIES COMPILE_FLAGS -msse4.1)
set_source_files_properties(${OJPH_IMG_IO_AVX2} PROPERTIES COMPILE_FLAGS -mavx2)
endif()
else()
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()

install(TARGETS ojph_compress DESTINATION bin)
endif()
endif()

install(TARGETS ojph_compress DESTINATION bin)
endif()
77 changes: 47 additions & 30 deletions src/apps/ojph_expand/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,38 +1,55 @@
## building ojph_expand
#######################

include_directories(../common)

file(GLOB OJPH_EXPAND "ojph_expand.cpp")
file(GLOB OJPH_IMG_IO "../others/ojph_img_io*.cpp")
file(GLOB OJPH_IMG_IO_H "../common/ojph_img_io.h")

if(NOT OJPH_DISABLE_INTEL_SIMD)
list(REMOVE_ITEM OJPH_IMG_IO ${OJPH_IMG_IO_SSE41})
list(REMOVE_ITEM OJPH_IMG_IO ${OJPH_IMG_IO_AVX2})
endif()

source_group("main" FILES ${OJPH_EXPAND})
source_group("others" FILES ${OJPH_IMG_IO})
source_group("common" FILES ${OJPH_IMG_IO_H})

if(OJPH_BUILD_EXECUTABLES)
add_executable(ojph_expand ${OJPH_EXPAND} ${OJPH_IMG_IO} ${OJPH_IMG_IO_H})
endif()

if (MSVC)
set_source_files_properties(../others/ojph_img_io_avx2.cpp PROPERTIES COMPILE_FLAGS "/arch:AVX2")
else()
set_source_files_properties(../others/ojph_img_io_sse41.cpp PROPERTIES COMPILE_FLAGS -msse4.1)
set_source_files_properties(../others/ojph_img_io_avx2.cpp PROPERTIES COMPILE_FLAGS -mavx2)
endif()

if(OJPH_BUILD_EXECUTABLES)
if( USE_TIFF )
target_link_libraries(ojph_expand PUBLIC openjph ${TIFF_LIBRARIES})
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")
file(GLOB OJPH_IMG_IO_AVX2 "../others/ojph_img_io_avx2.cpp")
file(GLOB OJPH_IMG_IO_H "../common/ojph_img_io.h")

list(APPEND SOURCES ${OJPH_EXPAND} ${OJPH_IMG_IO} ${OJPH_IMG_IO_H})

source_group("main" FILES ${OJPH_EXPAND})
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 -DOJPH_DISABLE_INTEL_SIMD)
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)
else()
target_link_libraries(ojph_expand PUBLIC openjph)
if(NOT OJPH_DISABLE_INTEL_SIMD)
add_executable(ojph_expand ${SOURCES} ${OJPH_IMG_IO_SSE4} ${OJPH_IMG_IO_AVX2})

if (MSVC)
set_source_files_properties(${OJPH_IMG_IO_AVX2} PROPERTIES COMPILE_FLAGS "/arch:AVX2")
else()
set_source_files_properties(${OJPH_IMG_IO_SSE4} PROPERTIES COMPILE_FLAGS -msse4.1)
set_source_files_properties(${OJPH_IMG_IO_AVX2} PROPERTIES COMPILE_FLAGS -mavx2)
endif()
else()
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()

install(TARGETS ojph_expand DESTINATION bin)
endif()
endif()

install(TARGETS ojph_expand DESTINATION bin)
endif()
2 changes: 1 addition & 1 deletion src/apps/others/ojph_img_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1650,7 +1650,7 @@ namespace ojph {
be2le(offset_to_data_for_image_element_1);

// set to starting point of image data
if (fseek(file_handle, offset_to_image_data_in_bytes, SEEK_SET) != 0)
if (fseek(file_handle, (long)offset_to_image_data_in_bytes, SEEK_SET) != 0)
{
close();
OJPH_ERROR(0x0300000E7, "Error reading file %s", filename);
Expand Down
4 changes: 2 additions & 2 deletions src/core/codestream/ojph_codestream_local.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ namespace ojph {
OJPH_ERROR(0x00030011, "number of tiles cannot exceed 65535");

//allocate tiles
allocator->pre_alloc_obj<tile>(num_tiles.area());
allocator->pre_alloc_obj<tile>((size_t)num_tiles.area());

ui32 num_tileparts = 0;
point index;
Expand Down Expand Up @@ -208,7 +208,7 @@ namespace ojph {
allocator->post_alloc_obj<ui8>(precinct_scratch_needed_bytes);

//get tiles
tiles = this->allocator->post_alloc_obj<tile>(num_tiles.area());
tiles = this->allocator->post_alloc_obj<tile>((size_t)num_tiles.area());

ui32 num_tileparts = 0;
point index;
Expand Down
5 changes: 3 additions & 2 deletions src/core/codestream/ojph_resolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ namespace ojph {
num_precincts.w -= trx0 >> log_PP.w;
num_precincts.h = (try1 + (1 << log_PP.h) - 1) >> log_PP.h;
num_precincts.h -= try0 >> log_PP.h;
allocator->pre_alloc_obj<precinct>(num_precincts.area());
allocator->pre_alloc_obj<precinct>((size_t)num_precincts.area());
}

//allocate lines
Expand Down Expand Up @@ -262,7 +262,8 @@ namespace ojph {
num_precincts.w -= trx0 >> log_PP.w;
num_precincts.h = (try1 + (1 << log_PP.h) - 1) >> log_PP.h;
num_precincts.h -= try0 >> log_PP.h;
precincts = allocator->post_alloc_obj<precinct>(num_precincts.area());
precincts =
allocator->post_alloc_obj<precinct>((size_t)num_precincts.area());
ui64 num = num_precincts.area();
for (ui64 i = 0; i < num; ++i)
precincts[i] = precinct();
Expand Down
6 changes: 3 additions & 3 deletions src/core/codestream/ojph_subband.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ namespace ojph {

allocator->pre_alloc_obj<codeblock>(num_blocks.w);
//allocate codeblock headers
allocator->pre_alloc_obj<coded_cb_header>(num_blocks.area());
allocator->pre_alloc_obj<coded_cb_header>((size_t)num_blocks.area());

for (ui32 i = 0; i < num_blocks.w; ++i)
codeblock::pre_alloc(codestream, nominal);
Expand Down Expand Up @@ -152,8 +152,8 @@ namespace ojph {
blocks = allocator->post_alloc_obj<codeblock>(num_blocks.w);
//allocate codeblock headers
coded_cb_header *cp = coded_cbs =
allocator->post_alloc_obj<coded_cb_header>(num_blocks.area());
memset(coded_cbs, 0, sizeof(coded_cb_header) * num_blocks.area());
allocator->post_alloc_obj<coded_cb_header>((size_t)num_blocks.area());
memset(coded_cbs, 0, sizeof(coded_cb_header) * (size_t)num_blocks.area());
for (int i = (int)num_blocks.area(); i > 0; --i, ++cp)
cp->Kmax = K_max;

Expand Down

0 comments on commit 0de48e2

Please sign in to comment.