Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 36 additions & 33 deletions external/OpenJPH/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ option(OJPH_ENABLE_TIFF_SUPPORT "Enables input and output support for TIFF files
option(OJPH_BUILD_TESTS "Enables building test code" OFF)
option(OJPH_BUILD_EXECUTABLES "Enables building command line executables" ON)
option(OJPH_BUILD_STREAM_EXPAND "Enables building ojph_stream_expand executable" OFF)
option(OJPH_INSTALL "Install OpenJPH libraries, headers, and CMake config" ON)
option(OJPH_BUILD_FUZZER "Enables building oss-fuzzing target executable" OFF)

option(OJPH_DISABLE_SIMD "Disables the use of SIMD instructions -- agnostic to architectures" OFF)
Expand Down Expand Up @@ -104,7 +105,9 @@ if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.24.0")
endif()
endif()

## Added by Michael Smith
## Set build flags for AddressSanitizer (ASAN)
# these are used when the user sets -DCMAKE_BUILD_TYPE=asan i.e ("cmake .. -DCMAKE_BUILD_TYPE=asan")
# setting flags for specific build types is documented here: https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_FLAGS_CONFIG.html
set(CMAKE_CXX_FLAGS_ASAN
"-fsanitize=address -fno-optimize-sibling-calls -fsanitize-address-use-after-scope -fno-omit-frame-pointer -g -O1"
CACHE STRING "Flags used by the C++ compiler during AddressSanitizer builds."
Expand Down Expand Up @@ -190,46 +193,46 @@ endif()
################################################################################################

if (OJPH_INSTALL)
install(EXPORT openjph-targets
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/openjph
)
install(EXPORT openjph-targets
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/openjph
)

include(CMakePackageConfigHelpers)
include(CMakePackageConfigHelpers)

configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/src/openjph-config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/openjph-config.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/openjph
)
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/src/openjph-config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/openjph-config.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/openjph
)

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

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

if(IS_ABSOLUTE "${CMAKE_INSTALL_INCLUDEDIR}")
set(PKG_CONFIG_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}")
else()
set(PKG_CONFIG_INCLUDEDIR "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
endif()
if(IS_ABSOLUTE "${CMAKE_INSTALL_INCLUDEDIR}")
set(PKG_CONFIG_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}")
else()
set(PKG_CONFIG_INCLUDEDIR "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
endif()

if(IS_ABSOLUTE "${CMAKE_INSTALL_LIBDIR}")
set(PKG_CONFIG_LIBDIR "${CMAKE_INSTALL_LIBDIR}")
else()
set(PKG_CONFIG_LIBDIR "\${prefix}/${CMAKE_INSTALL_LIBDIR}")
endif()
if(IS_ABSOLUTE "${CMAKE_INSTALL_LIBDIR}")
set(PKG_CONFIG_LIBDIR "${CMAKE_INSTALL_LIBDIR}")
else()
set(PKG_CONFIG_LIBDIR "\${prefix}/${CMAKE_INSTALL_LIBDIR}")
endif()

configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/src/openjph.pc.in"
"${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc"
@ONLY
)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/src/openjph.pc.in"
"${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc"
@ONLY
)

install(FILES "${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
)
install(FILES "${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
)
endif()

################################################################################################
Expand Down
51 changes: 38 additions & 13 deletions external/OpenJPH/src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ file(GLOB CODESTREAM_SSE2 "codestream/*_sse2.cpp")
file(GLOB CODESTREAM_AVX "codestream/*_avx.cpp")
file(GLOB CODESTREAM_AVX2 "codestream/*_avx2.cpp")
file(GLOB CODESTREAM_WASM "codestream/*_wasm.cpp")
file(GLOB CODESTREAM_VSX "codestream/*_vsx.cpp")
file(GLOB CODING "coding/*.cpp" "coding/*.h")
file(GLOB CODING_SSSE3 "coding/*_ssse3.cpp")
file(GLOB CODING_WASM "coding/*_wasm.cpp")
file(GLOB CODING_AVX2 "coding/*_avx2.cpp")
file(GLOB CODING_AVX512 "coding/*_avx512.cpp")
file(GLOB CODING_VSX "coding/*_vsx.cpp")
file(GLOB COMMON "openjph/*.h")
file(GLOB OTHERS "others/*.cpp" "others/*.c")
file(GLOB TRANSFORM "transform/*.cpp" "transform/*.h")
Expand All @@ -19,10 +21,11 @@ file(GLOB TRANSFORM_AVX "transform/*_avx.cpp")
file(GLOB TRANSFORM_AVX2 "transform/*_avx2.cpp")
file(GLOB TRANSFORM_AVX512 "transform/*_avx512.cpp")
file(GLOB TRANSFORM_WASM "transform/*_wasm.cpp")
file(GLOB TRANSFORM_VSX "transform/*_vsx.cpp")

list(REMOVE_ITEM CODESTREAM ${CODESTREAM_SSE} ${CODESTREAM_SSE2} ${CODESTREAM_AVX} ${CODESTREAM_AVX2} ${CODESTREAM_WASM})
list(REMOVE_ITEM CODING ${CODING_SSSE3} ${CODING_WASM} ${CODING_AVX2} ${CODING_AVX512})
list(REMOVE_ITEM TRANSFORM ${TRANSFORM_SSE} ${TRANSFORM_SSE2} ${TRANSFORM_AVX} ${TRANSFORM_AVX2} ${TRANSFORM_AVX512} ${TRANSFORM_WASM})
list(REMOVE_ITEM CODESTREAM ${CODESTREAM_SSE} ${CODESTREAM_SSE2} ${CODESTREAM_AVX} ${CODESTREAM_AVX2} ${CODESTREAM_WASM} ${CODESTREAM_VSX})
list(REMOVE_ITEM CODING ${CODING_SSSE3} ${CODING_WASM} ${CODING_AVX2} ${CODING_AVX512} ${CODING_VSX})
list(REMOVE_ITEM TRANSFORM ${TRANSFORM_SSE} ${TRANSFORM_SSE2} ${TRANSFORM_AVX} ${TRANSFORM_AVX2} ${TRANSFORM_AVX512} ${TRANSFORM_WASM} ${TRANSFORM_VSX})
list(APPEND SOURCES ${CODESTREAM} ${CODING} ${COMMON} ${OTHERS} ${TRANSFORM})

source_group("codestream" FILES ${CODESTREAM})
Expand Down Expand Up @@ -112,6 +115,24 @@ else()

endif()

if (("${OJPH_TARGET_ARCH}" MATCHES "OJPH_ARCH_PPC64")
AND (CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64le|powerpc64le"))
if (NOT OJPH_DISABLE_SIMD)
# native 128-bit VSX kernels (see ojph_simd_vsx.h). Supported
# targets are POWER9 (ISA 3.0) and newer, little-endian only.
# The block decoder dispatch is selective; see
# ojph_codeblock_fun.cpp.
list(APPEND SOURCES ${CODESTREAM_VSX} ${CODING_VSX} ${TRANSFORM_VSX})
source_group("codestream" FILES ${CODESTREAM_VSX})
source_group("coding" FILES ${CODING_VSX})
source_group("transform" FILES ${TRANSFORM_VSX})
set_source_files_properties(codestream/ojph_codestream_vsx.cpp PROPERTIES COMPILE_FLAGS "-mcpu=power9")
set_source_files_properties(coding/ojph_block_decoder_vsx.cpp PROPERTIES COMPILE_FLAGS "-mcpu=power9")
set_source_files_properties(transform/ojph_transform_vsx.cpp PROPERTIES COMPILE_FLAGS "-mcpu=power9")
set_source_files_properties(transform/ojph_colour_vsx.cpp PROPERTIES COMPILE_FLAGS "-mcpu=power9")
endif()
endif()

endif()

endif()
Expand Down Expand Up @@ -140,7 +161,11 @@ endif()
## include library version/name
set_target_properties(openjph PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_compile_definitions(openjph PUBLIC _FILE_OFFSET_BITS=64)
target_include_directories(openjph PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/openjph> $<INSTALL_INTERFACE:include>)
target_include_directories(openjph PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/openjph>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/shared>
$<INSTALL_INTERFACE:include>
)

## This is to check if aligned_alloc or posix_memalign is available
# We want the code to compile for C11 and C++11.
Expand Down Expand Up @@ -173,13 +198,13 @@ else()
endif()

if (OJPH_INSTALL)
install(TARGETS openjph
EXPORT openjph-targets
)

install(DIRECTORY openjph/
DESTINATION include/openjph
FILES_MATCHING
PATTERN "*.h"
)
install(TARGETS openjph
EXPORT openjph-targets
)

install(DIRECTORY openjph/
DESTINATION include/openjph
FILES_MATCHING
PATTERN "*.h"
)
endif()
5 changes: 3 additions & 2 deletions external/OpenJPH/src/core/codestream/ojph_bitbuffer_read.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#define OJPH_BITBUFFER_READ_H

#include "ojph_defs.h"
#include "ojph_arch.h"
#include "ojph_file.h"

namespace ojph {
Expand Down Expand Up @@ -79,7 +80,7 @@ namespace ojph {
{
if (bbp->bytes_left > 0)
{
ui32 t = 0;
ui8 t = 0;
if (bbp->file->read(&t, 1) != 1)
throw "error reading from file";
bbp->tmp = t;
Expand Down Expand Up @@ -195,7 +196,7 @@ namespace ojph {
ui16 com_len;
if (bbp->file->read(&com_len, 2) != 2)
throw "error reading from file";
com_len = swap_byte(com_len);
com_len = swap_bytes_if_le(com_len);
if (com_len != 4)
throw "something is wrong with SOP length";
int result =
Expand Down
43 changes: 24 additions & 19 deletions external/OpenJPH/src/core/codestream/ojph_codeblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
// This software is released under the 2-Clause BSD license, included
// below.
//
// Copyright (c) 2019, Aous Naman
// Copyright (c) 2019, Aous Naman
// Copyright (c) 2019, Kakadu Software Pty Ltd, Australia
// Copyright (c) 2019, The University of New South Wales, Australia
//
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
Expand Down Expand Up @@ -53,15 +53,15 @@ namespace ojph {
{

//////////////////////////////////////////////////////////////////////////
void codeblock::pre_alloc(codestream *codestream, const size& nominal,
void codeblock::pre_alloc(codestream *codestream, const size& nominal,
ui32 precision)
{
mem_fixed_allocator* allocator = codestream->get_allocator();

assert(byte_alignment / sizeof(ui32) > 1);
const ui32 f = byte_alignment / sizeof(ui32) - 1;
ui32 stride = (nominal.w + f) & ~f; // a multiple of 8

if (precision <= 32)
allocator->pre_alloc_data<ui32>(nominal.h * (size_t)stride, 0);
else
Expand Down Expand Up @@ -114,23 +114,25 @@ namespace ojph {
//////////////////////////////////////////////////////////////////////////
void codeblock::push(line_buf *line)
{
// convert to sign and magnitude and keep max_val
// convert to sign and magnitude and keep max_val
if (precision == BUF32)
{
assert(line->flags & line_buf::LFT_32BIT);
const si32 *sp = line->i32 + line_offset;
const void *sp = (line->flags & line_buf::LFT_INTEGER)
? (const void*)(line->i32 + line_offset)
: (const void*)(line->f32 + line_offset);
ui32 *dp = buf32 + cur_line * stride;
this->codeblock_functions.tx_to_cb32(sp, dp, K_max, delta_inv,
this->codeblock_functions.tx_to_cb32(sp, dp, K_max, delta_inv,
cb_size.w, max_val32);
++cur_line;
}
else
else
{
assert(precision == BUF64);
assert(line->flags & line_buf::LFT_64BIT);
const si64 *sp = line->i64 + line_offset;
ui64 *dp = buf64 + cur_line * stride;
this->codeblock_functions.tx_to_cb64(sp, dp, K_max, delta_inv,
this->codeblock_functions.tx_to_cb64(sp, dp, K_max, delta_inv,
cb_size.w, max_val64);
++cur_line;
}
Expand All @@ -148,7 +150,7 @@ namespace ojph {
assert(coded_cb->missing_msbs > 0);
assert(coded_cb->missing_msbs < K_max);
coded_cb->num_passes = 1;

this->codeblock_functions.encode_cb32(buf32, K_max-1, 1,
cb_size.w, cb_size.h, stride, coded_cb->pass_length,
elastic, coded_cb->next_coded);
Expand All @@ -164,7 +166,7 @@ namespace ojph {
assert(coded_cb->missing_msbs > 0);
assert(coded_cb->missing_msbs < K_max);
coded_cb->num_passes = 1;

this->codeblock_functions.encode_cb64(buf64, K_max-1, 1,
cb_size.w, cb_size.h, stride, coded_cb->pass_length,
elastic, coded_cb->next_coded);
Expand Down Expand Up @@ -199,7 +201,7 @@ namespace ojph {
coded_cb->pass_length[0], coded_cb->pass_length[1],
cb_size.w, cb_size.h, stride, stripe_causal);
}
else
else
{
assert(precision == BUF64);
result = this->codeblock_functions.decode_cb64(
Expand Down Expand Up @@ -231,11 +233,13 @@ namespace ojph {
if (precision == BUF32)
{
assert(line->flags & line_buf::LFT_32BIT);
si32 *dp = line->i32 + line_offset;
void *dp = (line->flags & line_buf::LFT_INTEGER)
? (void*)(line->i32 + line_offset)
: (void*)(line->f32 + line_offset);
if (!zero_block)
{
const ui32 *sp = buf32 + cur_line * stride;
this->codeblock_functions.tx_from_cb32(sp, dp, K_max, delta,
this->codeblock_functions.tx_from_cb32(sp, dp, K_max, delta,
cb_size.w);
}
else
Expand All @@ -244,12 +248,13 @@ namespace ojph {
else
{
assert(precision == BUF64);
assert(line->flags & line_buf::LFT_64BIT);
assert((reversible && (line->flags & line_buf::LFT_64BIT))
|| (!reversible && (line->flags & line_buf::LFT_32BIT)));
si64 *dp = line->i64 + line_offset;
if (!zero_block)
{
const ui64 *sp = buf64 + cur_line * stride;
this->codeblock_functions.tx_from_cb64(sp, dp, K_max, delta,
this->codeblock_functions.tx_from_cb64(sp, dp, K_max, delta,
cb_size.w);
}
else
Expand Down
Loading
Loading