Skip to content

Commit fd8815e

Browse files
committed
Add support for OpenJPH restarts
1 parent e8e0b99 commit fd8815e

File tree

2 files changed

+39
-12
lines changed

2 files changed

+39
-12
lines changed

cmake/OpenEXRSetup.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ endif()
257257

258258
option(OPENEXR_FORCE_INTERNAL_OPENJPH "Force downloading OpenJPH from a git repo" OFF)
259259
set(OPENEXR_OPENJPH_REPO "https://github.com/aous72/OpenJPH.git" CACHE STRING "OpenJPH git repo URI")
260-
set(OPENEXR_OPENJPH_TAG "0.21.5" CACHE STRING "OpenJPH git repo tag")
260+
set(OPENEXR_OPENJPH_TAG "restart" CACHE STRING "OpenJPH git repo tag")
261261

262262
if (NOT OPENEXR_FORCE_INTERNAL_OPENJPH)
263263
find_package(openjph 0.21 CONFIG QUIET)

src/lib/OpenEXRCore/internal_ht.cpp

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@
1414
#include <ojph_codestream.h>
1515
#include <ojph_message.h>
1616

17+
#ifdef __cplusplus
18+
extern "C" {
19+
#endif
20+
#include "internal_memory.h"
21+
#ifdef __cplusplus
22+
}
23+
#endif
24+
1725
#include "openexr_decode.h"
1826
#include "openexr_encode.h"
1927
#include "internal_ht_common.h"
@@ -157,6 +165,17 @@ class staticmem_outfile : public ojph::outfile_base
157165
ojph::ui8 *cur_ptr;
158166
};
159167

168+
void* alloc_fn (exr_transcoding_pipeline_buffer_id_t buf, size_t sz) {
169+
return internal_exr_alloc(sz);
170+
}
171+
172+
void
173+
free_fn (exr_transcoding_pipeline_buffer_id_t id, void* buf)
174+
{
175+
if (id == EXR_TRANSCODE_BUFFER_SCRATCH1) { delete (ojph::codestream*) buf; }
176+
else { internal_exr_free (buf); }
177+
}
178+
160179
extern "C" exr_result_t
161180
internal_exr_undo_ht (
162181
exr_decode_pipeline_t* decode,
@@ -196,11 +215,19 @@ internal_exr_undo_ht (
196215
reinterpret_cast<const ojph::ui8*> (compressed_data) + header_sz,
197216
comp_buf_size - header_sz);
198217

199-
ojph::codestream cs;
200-
cs.read_headers (&infile);
218+
if (decode->scratch_buffer_1 == NULL) {
219+
decode->alloc_fn = alloc_fn;
220+
decode->free_fn = free_fn;
221+
decode->scratch_buffer_1 = new ojph::codestream();
222+
} else {
223+
((ojph::codestream*) decode->scratch_buffer_1)->restart();
224+
}
225+
ojph::codestream* cs = (ojph::codestream*)decode->scratch_buffer_1;
201226

202-
ojph::param_siz siz = cs.access_siz ();
203-
ojph::param_nlt nlt = cs.access_nlt ();
227+
cs->read_headers (&infile);
228+
229+
ojph::param_siz siz = cs->access_siz ();
230+
ojph::param_nlt nlt = cs->access_nlt ();
204231

205232
ojph::ui32 image_width =
206233
siz.get_image_extent ().x - siz.get_image_offset ().x;
@@ -217,19 +244,19 @@ internal_exr_undo_ht (
217244
decode->channels[c].y_samples > 1)
218245
{ is_planar = true; }
219246
}
220-
cs.set_planar (is_planar);
247+
cs->set_planar (is_planar);
221248

222249
assert (decode->chunk.width == image_width);
223250
assert (decode->chunk.height == image_height);
224251
assert (decode->channel_count == siz.get_num_components ());
225252

226-
cs.create ();
253+
cs->create ();
227254

228255
assert (sizeof (uint16_t) == 2);
229256
assert (sizeof (uint32_t) == 4);
230257
ojph::ui32 next_comp = 0;
231258
ojph::line_buf* cur_line;
232-
if (cs.is_planar ())
259+
if (cs->is_planar ())
233260
{
234261
for (uint32_t c = 0; c < decode->channel_count; c++)
235262
{
@@ -253,7 +280,7 @@ internal_exr_undo_ht (
253280

254281
if (line_c == file_c)
255282
{
256-
cur_line = cs.pull (next_comp);
283+
cur_line = cs->pull (next_comp);
257284
assert (next_comp == c);
258285

259286
if (decode->channels[file_c].data_type ==
@@ -296,7 +323,7 @@ internal_exr_undo_ht (
296323
for (uint32_t c = 0; c < decode->channel_count; c++)
297324
{
298325
int file_c = cs_to_file_ch[c].file_index;
299-
cur_line = cs.pull (next_comp);
326+
cur_line = cs->pull (next_comp);
300327
assert (next_comp == c);
301328
if (decode->channels[file_c].data_type == EXR_PIXEL_HALF)
302329
{
@@ -380,8 +407,8 @@ internal_exr_apply_ht (exr_encode_pipeline_t* encode)
380407

381408
cod.set_color_transform (isRGB && !isPlanar);
382409
cod.set_reversible (true);
383-
cod.set_block_dims (128, 32);
384-
cod.set_num_decomposition (5);
410+
cod.set_block_dims (256, 16);
411+
cod.set_num_decomposition (4);
385412

386413
try
387414
{

0 commit comments

Comments
 (0)