Skip to content

Commit 5cd941b

Browse files
author
Rye
committed
Fix internal openjpeg headers being used to set logging function
1 parent b242145 commit 5cd941b

File tree

1 file changed

+31
-48
lines changed

1 file changed

+31
-48
lines changed

indra/llimagej2coj/llimagej2coj.cpp

Lines changed: 31 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@
2929

3030
// this is defined so that we get static linking.
3131
#include "openjpeg.h"
32-
#include "event.h"
33-
#include "cio.h"
3432
#include "owning_ptr.h"
3533
#include <string>
3634

35+
36+
#define WANT_VERBOSE_OPJ_SPAM LL_DEBUG
37+
3738
#define MAX_ENCODED_DISCARD_LEVELS 5
3839

3940
// Factory function: see declaration in llimagej2c.cpp
@@ -52,6 +53,7 @@ std::string LLImageJ2COJ::getEngineInfo() const
5253
#endif
5354
}
5455

56+
#if WANT_VERBOSE_OPJ_SPAM
5557
// Return string from message, eliminating final \n if present
5658
static std::string chomp(const char* msg)
5759
{
@@ -67,27 +69,34 @@ static std::string chomp(const char* msg)
6769
}
6870
return message;
6971
}
72+
#endif
7073

7174
/**
7275
sample error callback expecting a LLFILE* client object
7376
*/
7477
void error_callback(const char* msg, void*)
7578
{
76-
LL_DEBUGS() << "LLImageJ2COJ: " << chomp(msg) << LL_ENDL;
79+
#if WANT_VERBOSE_OPJ_SPAM
80+
LL_WARNS() << "LLImageJ2COJ: " << chomp(msg) << LL_ENDL;
81+
#endif
7782
}
7883
/**
7984
sample warning callback expecting a LLFILE* client object
8085
*/
8186
void warning_callback(const char* msg, void*)
8287
{
83-
LL_DEBUGS() << "LLImageJ2COJ: " << chomp(msg) << LL_ENDL;
88+
#if WANT_VERBOSE_OPJ_SPAM
89+
LL_WARNS() << "LLImageJ2COJ: " << chomp(msg) << LL_ENDL;
90+
#endif
8491
}
8592
/**
8693
sample debug callback expecting no client object
8794
*/
8895
void info_callback(const char* msg, void*)
8996
{
90-
LL_DEBUGS() << "LLImageJ2COJ: " << chomp(msg) << LL_ENDL;
97+
#if WANT_VERBOSE_OPJ_SPAM
98+
LL_INFOS() << "LLImageJ2COJ: " << chomp(msg) << LL_ENDL;
99+
#endif
91100
}
92101

93102
// Divide a by 2 to the power of b and round upwards
@@ -99,39 +108,13 @@ int ceildivpow2(int a, int b)
99108
class JPEG2KBase
100109
{
101110
public:
102-
JPEG2KBase() {}
111+
JPEG2KBase() = default;
103112

104113
U8* buffer = nullptr;
105114
OPJ_SIZE_T size = 0;
106115
OPJ_OFF_T offset = 0;
107116
};
108117

109-
#define WANT_VERBOSE_OPJ_SPAM LL_DEBUG
110-
111-
static void opj_info(const char* msg, void* user_data)
112-
{
113-
llassert(user_data);
114-
#if WANT_VERBOSE_OPJ_SPAM
115-
LL_INFOS("OpenJPEG") << msg << LL_ENDL;
116-
#endif
117-
}
118-
119-
static void opj_warn(const char* msg, void* user_data)
120-
{
121-
llassert(user_data);
122-
#if WANT_VERBOSE_OPJ_SPAM
123-
LL_WARNS("OpenJPEG") << msg << LL_ENDL;
124-
#endif
125-
}
126-
127-
static void opj_error(const char* msg, void* user_data)
128-
{
129-
llassert(user_data);
130-
#if WANT_VERBOSE_OPJ_SPAM
131-
LL_WARNS("OpenJPEG") << msg << LL_ENDL;
132-
#endif
133-
}
134-
135118
static OPJ_SIZE_T opj_read(void * buffer, OPJ_SIZE_T bytes, void* user_data)
136119
{
137120
llassert(user_data);
@@ -224,11 +207,7 @@ class JPEG2KDecode : public JPEG2KBase
224207

225208
JPEG2KDecode(S8 discardLevel)
226209
{
227-
memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
228210
memset(&parameters, 0, sizeof(opj_dparameters_t));
229-
event_mgr.error_handler = error_callback;
230-
event_mgr.warning_handler = warning_callback;
231-
event_mgr.info_handler = info_callback;
232211
opj_set_default_decoder_parameters(&parameters);
233212
parameters.cp_reduce = discardLevel;
234213
}
@@ -245,6 +224,11 @@ class JPEG2KDecode : public JPEG2KBase
245224

246225
decoder = opj_create_decompress(OPJ_CODEC_J2K);
247226

227+
/* catch events using our callbacks and give a local context */
228+
opj_set_error_handler(decoder, error_callback, nullptr);
229+
opj_set_warning_handler(decoder, warning_callback, nullptr);
230+
opj_set_info_handler(decoder, info_callback, nullptr);
231+
248232
if (!opj_setup_decoder(decoder, &parameters))
249233
{
250234
return false;
@@ -311,9 +295,9 @@ class JPEG2KDecode : public JPEG2KBase
311295
decoder = opj_create_decompress(OPJ_CODEC_J2K);
312296
opj_setup_decoder(decoder, &parameters);
313297

314-
opj_set_info_handler(decoder, opj_info, this);
315-
opj_set_warning_handler(decoder, opj_warn, this);
316-
opj_set_error_handler(decoder, opj_error, this);
298+
opj_set_info_handler(decoder, info_callback, this);
299+
opj_set_warning_handler(decoder, warning_callback, this);
300+
opj_set_error_handler(decoder, error_callback, this);
317301

318302
stream = opj_stream_create(dataSize, true);
319303
if (!stream)
@@ -366,7 +350,6 @@ class JPEG2KDecode : public JPEG2KBase
366350

367351
private:
368352
opj_dparameters_t parameters;
369-
opj_event_mgr_t event_mgr;
370353
owning_ptr<opj_codestream_info_v2_t> codestream_info{
371354
nullptr,
372355
// opj_destroy_cstr_info(opj_codestream_info_v2_t**) requires a
@@ -389,10 +372,6 @@ class JPEG2KEncode : public JPEG2KBase
389372
JPEG2KEncode(const char* comment_text_in, bool reversible)
390373
{
391374
memset(&parameters, 0, sizeof(opj_cparameters_t));
392-
memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
393-
event_mgr.error_handler = error_callback;
394-
event_mgr.warning_handler = warning_callback;
395-
event_mgr.info_handler = info_callback;
396375

397376
opj_set_default_encoder_parameters(&parameters);
398377
parameters.cod_format = OPJ_CODEC_J2K;
@@ -435,6 +414,11 @@ class JPEG2KEncode : public JPEG2KBase
435414

436415
encoder = opj_create_compress(OPJ_CODEC_J2K);
437416

417+
/* catch events using our callbacks and give a local context */
418+
opj_set_error_handler(encoder, error_callback, nullptr);
419+
opj_set_warning_handler(encoder, warning_callback, nullptr);
420+
opj_set_info_handler(encoder, info_callback, nullptr);
421+
438422
parameters.tcp_mct = (image->numcomps >= 3) ? 1 : 0;
439423
parameters.cod_format = OPJ_CODEC_J2K;
440424
parameters.prog_order = OPJ_RLCP;
@@ -489,9 +473,9 @@ class JPEG2KEncode : public JPEG2KBase
489473
return false;
490474
}
491475

492-
opj_set_info_handler(encoder, opj_info, this);
493-
opj_set_warning_handler(encoder, opj_warn, this);
494-
opj_set_error_handler(encoder, opj_error, this);
476+
opj_set_info_handler(encoder, info_callback, this);
477+
opj_set_warning_handler(encoder, warning_callback, this);
478+
opj_set_error_handler(encoder, error_callback, this);
495479

496480
U32 tile_count = (rawImageIn.getWidth() >> 6) * (rawImageIn.getHeight() >> 6);
497481
U32 data_size_guess = tile_count * TILE_SIZE;
@@ -681,7 +665,6 @@ class JPEG2KEncode : public JPEG2KBase
681665
private:
682666
std::string comment_text;
683667
opj_cparameters_t parameters;
684-
opj_event_mgr_t event_mgr;
685668
owning_ptr<opj_stream_t> stream{ nullptr, opj_stream_destroy };
686669
owning_ptr<opj_image_t> image{ nullptr, opj_image_destroy };
687670
owning_ptr<opj_codec_t> encoder{ nullptr, opj_destroy_codec };

0 commit comments

Comments
 (0)