Skip to content
Draft
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 @@ -191,7 +191,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.23.1
echo "OPENEXR_PATH=$OPENEXR_PATH:$PROGRAM_FILES/openjph/bin:$PROGRAM_FILES/openjph/lib" >> $GITHUB_ENV
shell: bash

Expand Down
4 changes: 2 additions & 2 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ archive_override(
"//bazel:openjph_add_build_file.patch",
"//bazel:openjph_module_dot_bazel.patch",
],
strip_prefix = "OpenJPH-0.21.5",
urls = ["https://github.com/aous72/OpenJPH/archive/refs/tags/0.21.5.zip"],
strip_prefix = "OpenJPH-0.23.1",
urls = ["https://github.com/aous72/OpenJPH/archive/refs/tags/0.23.1.zip"],
)
2 changes: 1 addition & 1 deletion bazel/openjph_module_dot_bazel.patch
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
@@ -0,0 +1,8 @@
+module(
+ name = "openjph",
+ version = "0.21.5",
+ version = "0.23.1",
+ compatibility_level = 1,
+)
+
Expand Down
8 changes: 4 additions & 4 deletions cmake/OpenEXRSetup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ set(OPENEXR_OPENJPH_TAG "master" CACHE STRING "OpenJPH git repo tag")
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.23.0")
message(FATAL_ERROR "OpenJPH >= 0.23.0 required, but found ${openjph_VERSION}")
endif()
message(STATUS "Using OpenJPH ${openjph_VERSION} from ${openjph_DIR}")
set(EXR_OPENJPH_LIB openjph)
Expand All @@ -272,7 +272,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.23)
if(openjph_FOUND)
set(EXR_OPENJPH_LIB PkgConfig::openjph)
message(STATUS "Using OpenJPH from ${openjph_LINK_LIBRARIES}")
Expand Down Expand Up @@ -328,7 +328,7 @@ if (NOT EXR_OPENJPH_LIB)
message(ERROR "Failed to find OpenJPH")
endif()

set(EXR_OPENJPH_PKGCONFIG_REQUIRES "openjph >= 0.21.0")
set(EXR_OPENJPH_PKGCONFIG_REQUIRES "openjph >= 0.23.0")

#######################################
# Find or install Imath
Expand Down
28 changes: 28 additions & 0 deletions src/lib/OpenEXRCore/compression.c
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,34 @@ decompress_data (
return rv;
}

exr_result_t
exr_init_decompressor (exr_decode_pipeline_t* decode)
{
exr_result_t rv = EXR_ERR_SUCCESS;

switch (decode->chunk.compression)
{
case EXR_COMPRESSION_HTJ2K256:
case EXR_COMPRESSION_HTJ2K32:
rv = internal_exr_decompressor_init_ht (decode);
break;
}

return rv;
}

void
exr_destroy_compressor (exr_decode_pipeline_t* decode)
{
switch (decode->chunk.compression)
{
case EXR_COMPRESSION_HTJ2K256:
case EXR_COMPRESSION_HTJ2K32:
internal_exr_decompressor_destroy_ht (decode);
break;
}
}

exr_result_t
exr_uncompress_chunk (exr_decode_pipeline_t* decode)
{
Expand Down
18 changes: 18 additions & 0 deletions src/lib/OpenEXRCore/decoding.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,15 @@ exr_decoding_initialize (
decode->context = ctxt;
decode->chunk = *cinfo;
}

if (rv == EXR_ERR_SUCCESS)
{
if (decode->decompress_init_fn)
rv = decode->decompress_init_fn (decode);
else
rv = exr_init_decompressor (decode);
}

return rv;
}

Expand Down Expand Up @@ -476,6 +485,10 @@ exr_decoding_choose_default_routines (
if (part->comp_type != EXR_COMPRESSION_NONE)
decode->decompress_fn = &exr_uncompress_chunk;

decode->decompress_init_fn = &exr_init_decompressor;

decode->decompress_destroy_fn = &exr_destroy_compressor;

decode->unpack_and_convert_fn = internal_exr_match_decode (
decode,
isdeep,
Expand Down Expand Up @@ -680,6 +693,11 @@ exr_decoding_destroy (exr_const_context_t ctxt, exr_decode_pipeline_t* decode)
if (decode)
{
exr_decode_pipeline_t nil = {0};
if (decode->decompress_destroy_fn)
decode->decompress_destroy_fn(decode);
else
exr_destroy_compressor(decode);

if (decode->channels != decode->_quick_chan_store)
ctxt->free_fn (decode->channels);

Expand Down
4 changes: 4 additions & 0 deletions src/lib/OpenEXRCore/internal_decompress.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ exr_result_t internal_exr_undo_ht (
uint64_t comp_buf_size,
void* uncompressed_data,
uint64_t uncompressed_size);

exr_result_t internal_exr_decompressor_init_ht (exr_decode_pipeline_t* decode);

void internal_exr_decompressor_destroy_ht (exr_decode_pipeline_t* decode);
#ifdef __cplusplus
}
#endif
Expand Down
40 changes: 32 additions & 8 deletions src/lib/OpenEXRCore/internal_ht.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,14 @@ ht_undo_impl (
reinterpret_cast<const ojph::ui8*> (compressed_data) + header_sz,
comp_buf_size - header_sz);

ojph::codestream cs;
cs.read_headers (&infile);
if (decode->decompress_priv_data == NULL)
return EXR_ERR_MISSING_CONTEXT_ARG;

ojph::param_siz siz = cs.access_siz ();
ojph::codestream* cs = (ojph::codestream*) decode->decompress_priv_data;
cs->restart();
cs->read_headers (&infile);

ojph::param_siz siz = cs->access_siz ();

ojph::ui32 image_height =
siz.get_image_extent ().y - siz.get_image_offset ().y;
Expand All @@ -213,19 +217,19 @@ ht_undo_impl (
decode->channels[c].y_samples > 1)
{ is_planar = true; }
}
cs.set_planar (is_planar);
cs->set_planar (is_planar);

assert (decode->chunk.width == siz.get_image_extent ().x - siz.get_image_offset ().x);
assert (decode->chunk.height == image_height);
assert (decode->channel_count == siz.get_num_components ());

cs.create ();
cs->create ();

assert (sizeof (uint16_t) == 2);
assert (sizeof (uint32_t) == 4);
ojph::ui32 next_comp = 0;
ojph::line_buf* cur_line;
if (cs.is_planar ())
if (cs->is_planar ())
{
for (int16_t c = 0; c < decode->channel_count; c++)
{
Expand All @@ -249,7 +253,7 @@ ht_undo_impl (

if (line_c == static_cast<ojph::ui32>(file_c))
{
cur_line = cs.pull (next_comp);
cur_line = cs->pull (next_comp);
assert (next_comp == c);

if (decode->channels[file_c].data_type ==
Expand Down Expand Up @@ -292,7 +296,7 @@ ht_undo_impl (
for (int16_t c = 0; c < decode->channel_count; c++)
{
int file_c = cs_to_file_ch[c].file_index;
cur_line = cs.pull (next_comp);
cur_line = cs->pull (next_comp);
assert (next_comp == c);
if (decode->channels[file_c].data_type == EXR_PIXEL_HALF)
{
Expand Down Expand Up @@ -525,6 +529,26 @@ ht_apply_impl (exr_encode_pipeline_t* encode)
return rv;
}

extern "C" exr_result_t
internal_exr_decompressor_init_ht (exr_decode_pipeline_t* decode)
{
decode->decompress_priv_data = new ojph::codestream;

return EXR_ERR_SUCCESS;
}

extern "C" void
internal_exr_decompressor_destroy_ht (exr_decode_pipeline_t* decode)
{
if (decode->decompress_priv_data)
{
ojph::codestream* cs = (ojph::codestream*) decode->decompress_priv_data;
delete cs;
decode->decompress_priv_data = NULL;
}
}


extern "C" exr_result_t
internal_exr_apply_ht (exr_encode_pipeline_t* encode)
{
Expand Down
6 changes: 6 additions & 0 deletions src/lib/OpenEXRCore/openexr_compression.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ exr_result_t exr_compress_chunk (exr_encode_pipeline_t *encode_state);
EXR_EXPORT
exr_result_t exr_uncompress_chunk (exr_decode_pipeline_t *decode_state);

EXR_EXPORT
exr_result_t exr_init_decompressor (exr_decode_pipeline_t* decode);

EXR_EXPORT
void exr_destroy_compressor (exr_decode_pipeline_t* decode);

#ifdef __cplusplus
} /* extern "C" */
#endif
Expand Down
19 changes: 19 additions & 0 deletions src/lib/OpenEXRCore/openexr_decode.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ typedef struct _exr_decode_pipeline
int32_t* sample_count_table;
size_t sample_count_alloc_size;

/** Decompressor private data (optionally allocated through decompress_init_fn()
* and deallocated through decompress_destroy_fn())
*/
void* decompress_priv_data;

/** A scratch buffer of unpacked_size for intermediate results.
*
* If `NULL`, will be allocated during the run of the pipeline when
Expand Down Expand Up @@ -222,6 +227,20 @@ typedef struct _exr_decode_pipeline
*/
exr_result_t (*read_fn) (struct _exr_decode_pipeline* pipeline);

/** Function called when exr_decoding_initialize() is called.
*
* This allows the decompressor to initialize resources across calls
* to exr_decoding_run().
*/
exr_result_t (*decompress_init_fn) (struct _exr_decode_pipeline* pipeline);

/** Function called when exr_decoding_destroy() is called.
*
* This allows the decompressor to release resources previously allocated in
* decompress_init_fn().
*/
void (*decompress_destroy_fn) (struct _exr_decode_pipeline* pipeline);

/** Function chosen based on the compression type of the part to
* decompress data.
*
Expand Down
Loading