Skip to content

Commit 0e08a4a

Browse files
committed
Bump OpenJPH
Add support for compressor init/destroy
1 parent b893bda commit 0e08a4a

File tree

9 files changed

+114
-15
lines changed

9 files changed

+114
-15
lines changed

MODULE.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ archive_override(
3939
"//bazel:openjph_add_build_file.patch",
4040
"//bazel:openjph_module_dot_bazel.patch",
4141
],
42-
strip_prefix = "OpenJPH-0.21.5",
43-
urls = ["https://github.com/aous72/OpenJPH/archive/refs/tags/0.21.5.zip"],
42+
strip_prefix = "OpenJPH-0.23.1",
43+
urls = ["https://github.com/aous72/OpenJPH/archive/refs/tags/0.23.1.zip"],
4444
)

bazel/openjph_module_dot_bazel.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
@@ -0,0 +1,8 @@
44
+module(
55
+ name = "openjph",
6-
+ version = "0.21.5",
6+
+ version = "0.23.1",
77
+ compatibility_level = 1,
88
+)
99
+

cmake/OpenEXRSetup.cmake

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,8 @@ set(OPENEXR_OPENJPH_TAG "master" CACHE STRING "OpenJPH git repo tag")
262262
if (NOT OPENEXR_FORCE_INTERNAL_OPENJPH)
263263
find_package(openjph CONFIG QUIET)
264264
if(openjph_FOUND)
265-
if(openjph_VERSION VERSION_LESS "0.21.0")
266-
message(FATAL_ERROR "OpenJPH >= 0.21.0 required, but found ${openjph_VERSION}")
265+
if(openjph_VERSION VERSION_LESS "0.23.0")
266+
message(FATAL_ERROR "OpenJPH >= 0.23.0 required, but found ${openjph_VERSION}")
267267
endif()
268268
message(STATUS "Using OpenJPH ${openjph_VERSION} from ${openjph_DIR}")
269269
set(EXR_OPENJPH_LIB openjph)
@@ -272,7 +272,7 @@ if (NOT OPENEXR_FORCE_INTERNAL_OPENJPH)
272272
find_package(PkgConfig)
273273
if(PKG_CONFIG_FOUND)
274274
include(FindPkgConfig)
275-
pkg_check_modules(openjph IMPORTED_TARGET GLOBAL QUIET openjph=0.21)
275+
pkg_check_modules(openjph IMPORTED_TARGET GLOBAL QUIET openjph=0.23)
276276
if(openjph_FOUND)
277277
set(EXR_OPENJPH_LIB PkgConfig::openjph)
278278
message(STATUS "Using OpenJPH from ${openjph_LINK_LIBRARIES}")
@@ -328,7 +328,7 @@ if (NOT EXR_OPENJPH_LIB)
328328
message(ERROR "Failed to find OpenJPH")
329329
endif()
330330

331-
set(EXR_OPENJPH_PKGCONFIG_REQUIRES "openjph >= 0.21.0")
331+
set(EXR_OPENJPH_PKGCONFIG_REQUIRES "openjph >= 0.23.0")
332332

333333
#######################################
334334
# Find or install Imath

src/lib/OpenEXRCore/compression.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,34 @@ decompress_data (
474474
return rv;
475475
}
476476

477+
exr_result_t
478+
exr_init_decompressor (exr_decode_pipeline_t* decode)
479+
{
480+
exr_result_t rv = EXR_ERR_SUCCESS;
481+
482+
switch (decode->chunk.compression)
483+
{
484+
case EXR_COMPRESSION_HTJ2K256:
485+
case EXR_COMPRESSION_HTJ2K32:
486+
rv = internal_exr_decompressor_init_ht (decode);
487+
break;
488+
}
489+
490+
return rv;
491+
}
492+
493+
void
494+
exr_destroy_compressor (exr_decode_pipeline_t* decode)
495+
{
496+
switch (decode->chunk.compression)
497+
{
498+
case EXR_COMPRESSION_HTJ2K256:
499+
case EXR_COMPRESSION_HTJ2K32:
500+
internal_exr_decompressor_destroy_ht (decode);
501+
break;
502+
}
503+
}
504+
477505
exr_result_t
478506
exr_uncompress_chunk (exr_decode_pipeline_t* decode)
479507
{

src/lib/OpenEXRCore/decoding.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,15 @@ exr_decoding_initialize (
334334
decode->context = ctxt;
335335
decode->chunk = *cinfo;
336336
}
337+
338+
if (rv == EXR_ERR_SUCCESS)
339+
{
340+
if (decode->decompress_init_fn)
341+
rv = decode->decompress_init_fn (decode);
342+
else
343+
rv = exr_init_decompressor (decode);
344+
}
345+
337346
return rv;
338347
}
339348

@@ -476,6 +485,10 @@ exr_decoding_choose_default_routines (
476485
if (part->comp_type != EXR_COMPRESSION_NONE)
477486
decode->decompress_fn = &exr_uncompress_chunk;
478487

488+
decode->decompress_init_fn = &exr_init_decompressor;
489+
490+
decode->decompress_destroy_fn = &exr_destroy_compressor;
491+
479492
decode->unpack_and_convert_fn = internal_exr_match_decode (
480493
decode,
481494
isdeep,
@@ -680,6 +693,11 @@ exr_decoding_destroy (exr_const_context_t ctxt, exr_decode_pipeline_t* decode)
680693
if (decode)
681694
{
682695
exr_decode_pipeline_t nil = {0};
696+
if (decode->decompress_destroy_fn)
697+
decode->decompress_destroy_fn(decode);
698+
else
699+
exr_destroy_compressor(decode);
700+
683701
if (decode->channels != decode->_quick_chan_store)
684702
ctxt->free_fn (decode->channels);
685703

src/lib/OpenEXRCore/internal_decompress.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ exr_result_t internal_exr_undo_ht (
8282
uint64_t comp_buf_size,
8383
void* uncompressed_data,
8484
uint64_t uncompressed_size);
85+
86+
exr_result_t internal_exr_decompressor_init_ht (exr_decode_pipeline_t* decode);
87+
88+
void internal_exr_decompressor_destroy_ht (exr_decode_pipeline_t* decode);
8589
#ifdef __cplusplus
8690
}
8791
#endif

src/lib/OpenEXRCore/internal_ht.cpp

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,14 @@ ht_undo_impl (
195195
reinterpret_cast<const ojph::ui8*> (compressed_data) + header_sz,
196196
comp_buf_size - header_sz);
197197

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

201-
ojph::param_siz siz = cs.access_siz ();
201+
ojph::codestream* cs = (ojph::codestream*) decode->decompress_priv_data;
202+
cs->restart();
203+
cs->read_headers (&infile);
204+
205+
ojph::param_siz siz = cs->access_siz ();
202206

203207
ojph::ui32 image_height =
204208
siz.get_image_extent ().y - siz.get_image_offset ().y;
@@ -213,19 +217,19 @@ ht_undo_impl (
213217
decode->channels[c].y_samples > 1)
214218
{ is_planar = true; }
215219
}
216-
cs.set_planar (is_planar);
220+
cs->set_planar (is_planar);
217221

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

222-
cs.create ();
226+
cs->create ();
223227

224228
assert (sizeof (uint16_t) == 2);
225229
assert (sizeof (uint32_t) == 4);
226230
ojph::ui32 next_comp = 0;
227231
ojph::line_buf* cur_line;
228-
if (cs.is_planar ())
232+
if (cs->is_planar ())
229233
{
230234
for (int16_t c = 0; c < decode->channel_count; c++)
231235
{
@@ -249,7 +253,7 @@ ht_undo_impl (
249253

250254
if (line_c == static_cast<ojph::ui32>(file_c))
251255
{
252-
cur_line = cs.pull (next_comp);
256+
cur_line = cs->pull (next_comp);
253257
assert (next_comp == c);
254258

255259
if (decode->channels[file_c].data_type ==
@@ -292,7 +296,7 @@ ht_undo_impl (
292296
for (int16_t c = 0; c < decode->channel_count; c++)
293297
{
294298
int file_c = cs_to_file_ch[c].file_index;
295-
cur_line = cs.pull (next_comp);
299+
cur_line = cs->pull (next_comp);
296300
assert (next_comp == c);
297301
if (decode->channels[file_c].data_type == EXR_PIXEL_HALF)
298302
{
@@ -525,6 +529,26 @@ ht_apply_impl (exr_encode_pipeline_t* encode)
525529
return rv;
526530
}
527531

532+
extern "C" exr_result_t
533+
internal_exr_decompressor_init_ht (exr_decode_pipeline_t* decode)
534+
{
535+
decode->decompress_priv_data = new ojph::codestream;
536+
537+
return EXR_ERR_SUCCESS;
538+
}
539+
540+
extern "C" void
541+
internal_exr_decompressor_destroy_ht (exr_decode_pipeline_t* decode)
542+
{
543+
if (decode->decompress_priv_data)
544+
{
545+
ojph::codestream* cs = (ojph::codestream*) decode->decompress_priv_data;
546+
delete cs;
547+
decode->decompress_priv_data = NULL;
548+
}
549+
}
550+
551+
528552
extern "C" exr_result_t
529553
internal_exr_apply_ht (exr_encode_pipeline_t* encode)
530554
{

src/lib/OpenEXRCore/openexr_compression.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ exr_result_t exr_compress_chunk (exr_encode_pipeline_t *encode_state);
104104
EXR_EXPORT
105105
exr_result_t exr_uncompress_chunk (exr_decode_pipeline_t *decode_state);
106106

107+
EXR_EXPORT
108+
exr_result_t exr_init_decompressor (exr_decode_pipeline_t* decode);
109+
110+
EXR_EXPORT
111+
void exr_destroy_compressor (exr_decode_pipeline_t* decode);
112+
107113
#ifdef __cplusplus
108114
} /* extern "C" */
109115
#endif

src/lib/OpenEXRCore/openexr_decode.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ typedef struct _exr_decode_pipeline
162162
int32_t* sample_count_table;
163163
size_t sample_count_alloc_size;
164164

165+
/** Decompressor private data (optionally allocated through decompress_init_fn()
166+
* and deallocated through decompress_destroy_fn())
167+
*/
168+
void* decompress_priv_data;
169+
165170
/** A scratch buffer of unpacked_size for intermediate results.
166171
*
167172
* If `NULL`, will be allocated during the run of the pipeline when
@@ -222,6 +227,20 @@ typedef struct _exr_decode_pipeline
222227
*/
223228
exr_result_t (*read_fn) (struct _exr_decode_pipeline* pipeline);
224229

230+
/** Function called when exr_decoding_initialize() is called.
231+
*
232+
* This allows the decompressor to initialize resources across calls
233+
* to exr_decoding_run().
234+
*/
235+
exr_result_t (*decompress_init_fn) (struct _exr_decode_pipeline* pipeline);
236+
237+
/** Function called when exr_decoding_destroy() is called.
238+
*
239+
* This allows the decompressor to release resources previously allocated in
240+
* decompress_init_fn().
241+
*/
242+
void (*decompress_destroy_fn) (struct _exr_decode_pipeline* pipeline);
243+
225244
/** Function chosen based on the compression type of the part to
226245
* decompress data.
227246
*

0 commit comments

Comments
 (0)