Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/ci_steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ jobs:
if: inputs.OPENEXR_FORCE_INTERNAL_OPENJPH == 'OFF' && inputs.msystem == ''
run: |
set -x
share/ci/scripts/install_openjph.sh 0.22.0
share/ci/scripts/install_openjph.sh 0.27.3
echo "OPENEXR_PATH=$OPENEXR_PATH:$PROGRAM_FILES/openjph/bin:$PROGRAM_FILES/openjph/lib" >> $GITHUB_ENV
shell: bash

Expand Down
8 changes: 4 additions & 4 deletions cmake/OpenEXRSetup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ set(OPENEXR_USE_INTERNAL_OPENJPH 0 CACHE INTERNAL
if (NOT OPENEXR_FORCE_INTERNAL_OPENJPH)
find_package(openjph CONFIG QUIET)
if(openjph_FOUND)
if(openjph_VERSION VERSION_LESS "0.21.0")
message(FATAL_ERROR "OpenJPH >= 0.21.0 required, but found ${openjph_VERSION}")
if(openjph_VERSION VERSION_LESS "0.27.3")
message(FATAL_ERROR "OpenJPH >= 0.27.3 required, but found ${openjph_VERSION}")
endif()

message(STATUS "Using OpenJPH ${openjph_VERSION} from ${openjph_DIR}")
Expand All @@ -285,7 +285,7 @@ if (NOT OPENEXR_FORCE_INTERNAL_OPENJPH)
find_package(PkgConfig)
if(PKG_CONFIG_FOUND)
include(FindPkgConfig)
pkg_check_modules(openjph IMPORTED_TARGET GLOBAL QUIET openjph=0.21)
pkg_check_modules(openjph IMPORTED_TARGET GLOBAL QUIET openjph=0.27.3)
if(openjph_FOUND)
set(EXR_OPENJPH_LIB PkgConfig::openjph)
message(STATUS "Using OpenJPH ${openjph_VERSION} from ${openjph_LINK_LIBRARIES}")
Expand All @@ -297,7 +297,7 @@ endif()
if(EXR_OPENJPH_LIB)
# Using external library
# For OpenEXR.pc.in for static build
set(EXR_OPENJPH_PKGCONFIG_REQUIRES "openjph >= 0.21.0")
set(EXR_OPENJPH_PKGCONFIG_REQUIRES "openjph >= 0.27.3")
else()
# Using internal openjph
set(OPENEXR_USE_INTERNAL_OPENJPH 1 CACHE INTERNAL
Expand Down
13 changes: 11 additions & 2 deletions external/OpenJPH/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +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)
option(OJPH_DISABLE_SSE "Disables the use of SSE SIMD instructions and associated files" OFF)
Expand Down Expand Up @@ -233,10 +233,19 @@ if (OJPH_INSTALL)
endif()

################################################################################################
# Testing (OJPH_BUILD_TESTS)
# Testing and fuzzing (OJPH_BUILD_TESTS)
################################################################################################

if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND OJPH_BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif()

################################################################################################
# Testing and fuzzing (OJPH_BUILD_FUZZER)
################################################################################################

if(OJPH_BUILD_FUZZER)
add_subdirectory(fuzzing)
endif()

2 changes: 1 addition & 1 deletion external/OpenJPH/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ The standard is available free of charge from [ITU website](https://www.itu.int/
* [Usage Example](./docs/usage_examples.md)
* [Web-based Demos](./docs/web_demos.md)
* [Doxygen Documentation Style](./docs/doxygen_style.md)
* [OSS-Fuzzing](./docs/fuzzing.md)

# Repositories #
[![Packaging status](https://repology.org/badge/vertical-allrepos/openjph.svg)](https://repology.org/project/openjph/versions)

12 changes: 11 additions & 1 deletion external/OpenJPH/src/core/codestream/ojph_codestream_local.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,17 @@ namespace ojph {
ui32 num_comments)
{
//finalize
siz.check_validity(cod);
siz.set_cod(cod);
// set the tile size if it was not set by the user
size tile_size = siz.get_tile_size();
if (tile_size.h == 0 && tile_size.w == 0)
{
point img_offset = siz.get_image_offset();
point img_extent = siz.get_image_extent();
size t(img_extent.x + img_offset.x, img_extent.y + img_offset.y);
siz.set_tile_size(t);
}
siz.check_validity();
cod.check_validity(siz);
cod.update_atk(&atk);
qcd.check_validity(siz, cod);
Expand Down
122 changes: 88 additions & 34 deletions external/OpenJPH/src/core/codestream/ojph_params.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,29 +58,25 @@ namespace ojph {
////////////////////////////////////////////////////////////////////////////
void param_siz::set_image_extent(point dims)
{
state->Xsiz = dims.x;
state->Ysiz = dims.y;
state->set_image_extent(dims);
}

////////////////////////////////////////////////////////////////////////////
void param_siz::set_tile_size(size s)
{
state->XTsiz = s.w;
state->YTsiz = s.h;
state->set_tile_size(s);
}

////////////////////////////////////////////////////////////////////////////
void param_siz::set_image_offset(point offset)
{ // WARNING need to check if these are valid
state->XOsiz = offset.x;
state->YOsiz = offset.y;
{
state->set_image_offset(offset);
}

////////////////////////////////////////////////////////////////////////////
void param_siz::set_tile_offset(point offset)
{ // WARNING need to check if these are valid
state->XTOsiz = offset.x;
state->YTOsiz = offset.y;
{
state->set_tile_offset(offset);
}

////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -703,24 +699,24 @@ namespace ojph {
if (file->read(&Ysiz, 4) != 4)
OJPH_ERROR(0x00050046, "error reading SIZ marker");
Ysiz = swap_byte(Ysiz);
if (file->read(&XOsiz, 4) != 4)
ui32 t_XOsiz, t_YOsiz;
if (file->read(&t_XOsiz, 4) != 4)
OJPH_ERROR(0x00050047, "error reading SIZ marker");
XOsiz = swap_byte(XOsiz);
if (file->read(&YOsiz, 4) != 4)
if (file->read(&t_YOsiz, 4) != 4)
OJPH_ERROR(0x00050048, "error reading SIZ marker");
YOsiz = swap_byte(YOsiz);
if (file->read(&XTsiz, 4) != 4)
set_image_offset(point(swap_byte(t_XOsiz), swap_byte(t_YOsiz)));
ui32 t_XTsiz, t_YTsiz;
if (file->read(&t_XTsiz, 4) != 4)
OJPH_ERROR(0x00050049, "error reading SIZ marker");
XTsiz = swap_byte(XTsiz);
if (file->read(&YTsiz, 4) != 4)
if (file->read(&t_YTsiz, 4) != 4)
OJPH_ERROR(0x0005004A, "error reading SIZ marker");
YTsiz = swap_byte(YTsiz);
if (file->read(&XTOsiz, 4) != 4)
set_tile_size(size(swap_byte(t_XTsiz), swap_byte(t_YTsiz)));
ui32 t_XTOsiz, t_YTOsiz;
if (file->read(&t_XTOsiz, 4) != 4)
OJPH_ERROR(0x0005004B, "error reading SIZ marker");
XTOsiz = swap_byte(XTOsiz);
if (file->read(&YTOsiz, 4) != 4)
if (file->read(&t_YTOsiz, 4) != 4)
OJPH_ERROR(0x0005004C, "error reading SIZ marker");
YTOsiz = swap_byte(YTOsiz);
set_tile_offset(point(swap_byte(t_XTOsiz), swap_byte(t_YTOsiz)));
if (file->read(&Csiz, 2) != 2)
OJPH_ERROR(0x0005004D, "error reading SIZ marker");
Csiz = swap_byte(Csiz);
Expand All @@ -745,6 +741,8 @@ namespace ojph {

ws_kern_support_needed = (Rsiz & 0x20) != 0;
dfs_support_needed = (Rsiz & 0x80) != 0;

check_validity();
}

//////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -994,10 +992,21 @@ namespace ojph {
OJPH_ERROR(0x0005007E, "unsupported settings in a COD-SPcod parameter");

ui8 num_decompositions = get_num_decompositions();
if (Scod & 1)
for (int i = 0; i <= num_decompositions; ++i)
if (Scod & 1) {
for (int i = 0; i <= num_decompositions; ++i) {
if (file->read(&SPcod.precinct_size[i], 1) != 1)
OJPH_ERROR(0x0005007B, "error reading COD segment");
if (i)
if ((SPcod.precinct_size[i] & 0x0F) == 0 ||
(SPcod.precinct_size[i] >> 4) == 0)
OJPH_ERROR(0x0005007F,
"Precinct width or height for resolutions other than the"
" coarsest must be larger than 1; here, they are %d and %d,"
" respectively.",
1 << (SPcod.precinct_size[i] & 0x0F),
1 << (SPcod.precinct_size[i] >> 4));
}
}
if (Lcod != 12 + ((Scod & 1) ? 1 + SPcod.num_decomp : 0))
OJPH_ERROR(0x0005007C, "error in COD segment length");
}
Expand Down Expand Up @@ -1053,10 +1062,21 @@ namespace ojph {
OJPH_ERROR(0x0005012D, "unsupported settings in a COC-SPcoc parameter");

ui8 num_decompositions = get_num_decompositions();
if (Scod & 1)
for (int i = 0; i <= num_decompositions; ++i)
if (Scod & 1) {
for (int i = 0; i <= num_decompositions; ++i) {
if (file->read(&SPcod.precinct_size[i], 1) != 1)
OJPH_ERROR(0x0005012A, "error reading COC segment");
if (i)
if ((SPcod.precinct_size[i] & 0x0F) == 0 ||
(SPcod.precinct_size[i] >> 4) == 0)
OJPH_ERROR(0x0005012E,
"Precinct width or height for resolutions other than the"
" coarsest must be larger than 1; here, they are %d and %d,"
" respectively.",
1 << (SPcod.precinct_size[i] & 0x0F),
1 << (SPcod.precinct_size[i] >> 4));
}
}
ui32 t = 9;
t += num_comps < 257 ? 0 : 1;
t += (Scod & 1) ? 1 + num_decompositions : 0;
Expand Down Expand Up @@ -1196,8 +1216,10 @@ namespace ojph {
qcd_component < 3 ? employing_color_transform : false);
else if (qcd_wavelet_kern == param_cod::DWT_IRV97)
{
if (this->base_delta == -1.0f)
this->base_delta = 1.0f / (float)(1 << qcd_bit_depth);
if (this->base_delta == -1.0f) {
ui32 t = ojph_min(16, qcd_bit_depth);
this->base_delta = 1.0f / (float)(1 << t);
}
set_irrev_quant(qcd_num_decompositions);
}
else
Expand Down Expand Up @@ -1230,8 +1252,16 @@ namespace ojph {
c < 3 ? employing_color_transform : false);
else if (cp->get_wavelet_kern() == param_cod::DWT_IRV97)
{
if (qp->base_delta == -1.0f)
qp->base_delta = 1.0f / (float)(1 << bit_depth);
if (qp->base_delta == -1.0f) {
if (qcd_wavelet_kern == param_cod::DWT_IRV97) {
assert(this->base_delta != -1.0f);
qp->base_delta = this->base_delta;
}
else {
ui32 t = ojph_min(16, qcd_bit_depth);
qp->base_delta = 1.0f / (float)(1 << t);
}
}
qp->set_irrev_quant(num_decompositions);
}
else
Expand All @@ -1255,8 +1285,16 @@ namespace ojph {
c < 3 ? employing_color_transform : false);
else if (cp->get_wavelet_kern() == param_cod::DWT_IRV97)
{
if (qp->base_delta == -1.0f)
qp->base_delta = 1.0f / (float)(1 << bit_depth);
if (qp->base_delta == -1.0f) {
if (qcd_wavelet_kern == param_cod::DWT_IRV97) {
assert(this->base_delta != -1.0f);
qp->base_delta = this->base_delta;
}
else {
ui32 t = ojph_min(16, qcd_bit_depth);
qp->base_delta = 1.0f / (float)(1 << t);
}
}
qp->set_irrev_quant(num_decompositions);
}
else
Expand Down Expand Up @@ -1401,11 +1439,15 @@ namespace ojph {

//////////////////////////////////////////////////////////////////////////
float param_qcd::get_irrev_delta(const param_dfs* dfs,
ui32 num_decompositions,
ui32 num_decompositions, ui32 comp_num,
ui32 resolution, ui32 subband) const
{
float arr[] = { 1.0f, 2.0f, 2.0f, 4.0f };
assert((Sqcd & 0x1F) == 2);
if ((Sqcd & 0x1F) != 2)
OJPH_ERROR(0x00050101, "There is something wrong in the configuration "
"of the codestream; for component %d, the codestream defines an "
"irreversible transform, for which the codestream provides a "
"reversible (no quantization) step sizes in Sqcd/Sqcc.", comp_num);

ui32 idx;
if (dfs != NULL && dfs->exists())
Expand Down Expand Up @@ -1657,6 +1699,9 @@ namespace ojph {
if ((Sqcd & 0x1F) == 0)
{
num_subbands = (Lqcd - 3);
if (num_subbands == 0)
OJPH_ERROR(0x0005008A, "QCD marker segment that specifies no "
"quantization informtion");
if (num_subbands > 97 || Lqcd != 3 + num_subbands)
OJPH_ERROR(0x00050083, "wrong Lqcd value of %d in QCD marker", Lqcd);
for (ui32 i = 0; i < num_subbands; ++i)
Expand All @@ -1674,6 +1719,9 @@ namespace ojph {
else if ((Sqcd & 0x1F) == 2)
{
num_subbands = (Lqcd - 3) / 2;
if (num_subbands == 0)
OJPH_ERROR(0x0005008B, "QCD marker segment that specifies no "
"quantization informtion");
if (num_subbands > 97 || Lqcd != 3 + 2 * num_subbands)
OJPH_ERROR(0x00050086, "wrong Lqcd value of %d in QCD marker", Lqcd);
for (ui32 i = 0; i < num_subbands; ++i)
Expand Down Expand Up @@ -1712,6 +1760,9 @@ namespace ojph {
if ((Sqcd & 0x1F) == 0)
{
num_subbands = (Lqcd - offset);
if (num_subbands == 0)
OJPH_ERROR(0x000500AC, "QCC marker segment that specifies no "
"quantization informtion");
if (num_subbands > 97 || Lqcd != offset + num_subbands)
OJPH_ERROR(0x000500A5, "wrong Lqcd value of %d in QCC marker", Lqcd);
for (ui32 i = 0; i < num_subbands; ++i)
Expand All @@ -1729,6 +1780,9 @@ namespace ojph {
else if ((Sqcd & 0x1F) == 2)
{
num_subbands = (Lqcd - offset) / 2;
if (num_subbands == 0)
OJPH_ERROR(0x000500AD, "QCC marker segment that specifies no "
"quantization informtion");
if (num_subbands > 97 || Lqcd != offset + 2 * num_subbands)
OJPH_ERROR(0x000500A8, "wrong Lqcc value of %d in QCC marker", Lqcd);
for (ui32 i = 0; i < num_subbands; ++i)
Expand Down
32 changes: 23 additions & 9 deletions external/OpenJPH/src/core/codestream/ojph_params_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,21 +217,35 @@ namespace ojph {
cptr[comp_num].YRsiz = (ui8)downsampling.y;
}

void check_validity(const param_cod& cod)
void set_image_extent(point dims) { Xsiz = dims.x; Ysiz = dims.y; }
point get_image_extent() const { return point(Xsiz, Ysiz); }
void set_tile_size(size s) { XTsiz = s.w; YTsiz = s.h; }
size get_tile_size() const { return size(XTsiz, YTsiz); }
void set_image_offset(point offset)
{ XOsiz = offset.x; YOsiz = offset.y; }
point get_image_offset() const
{ return point(XOsiz, YOsiz); }
void set_tile_offset(point offset)
{ XTOsiz = offset.x; YTOsiz = offset.y; }
point get_tile_offset() const
{ return point(XTOsiz, YTOsiz); }

void set_cod(const param_cod& cod) { this->cod = &cod; }

void check_validity()
{
this->cod = &cod;

if (XTsiz == 0 && YTsiz == 0)
{ XTsiz = Xsiz + XOsiz; YTsiz = Ysiz + YOsiz; }
if (Xsiz == 0 || Ysiz == 0 || XTsiz == 0 || YTsiz == 0)
OJPH_ERROR(0x00040001,
"You cannot set image extent nor tile size to zero");
"Image extent and/or tile size cannot be zero");
if (XTOsiz > XOsiz || YTOsiz > YOsiz)
OJPH_ERROR(0x00040002,
"tile offset has to be smaller than image offset");
"Tile offset has to be smaller than the image offset");
if (XTsiz + XTOsiz <= XOsiz || YTsiz + YTOsiz <= YOsiz)
OJPH_ERROR(0x00040003,
"the top left tile must intersect with the image");
"The top left tile must intersect with the image");
if (Xsiz <= XOsiz || Ysiz <= YOsiz)
OJPH_ERROR(0x00040004,
"The image extent must be larger than the image offset");
}

ui16 get_num_components() const { return Csiz; }
Expand Down Expand Up @@ -701,7 +715,7 @@ namespace ojph {
ui32 resolution, ui32 subband) const;
ui32 propose_precision(const param_cod* cod) const;
float get_irrev_delta(const param_dfs* dfs,
ui32 num_decompositions,
ui32 num_decompositions, ui32 comp_num,
ui32 resolution, ui32 subband) const;
bool write(outfile_base *file);
bool write_qcc(outfile_base *file, ui32 num_comps);
Expand Down
Loading
Loading