diff options
Diffstat (limited to 'indra/llimagej2coj/llimagej2coj.cpp')
| -rw-r--r-- | indra/llimagej2coj/llimagej2coj.cpp | 74 | 
1 files changed, 25 insertions, 49 deletions
diff --git a/indra/llimagej2coj/llimagej2coj.cpp b/indra/llimagej2coj/llimagej2coj.cpp index 431f5aa001..5fa53657a0 100644 --- a/indra/llimagej2coj/llimagej2coj.cpp +++ b/indra/llimagej2coj/llimagej2coj.cpp @@ -29,8 +29,6 @@  // this is defined so that we get static linking.  #include "openjpeg.h" -#include "event.h" -#include "cio.h"  // Factory function: see declaration in llimagej2c.cpp  LLImageJ2CImpl* fallbackCreateLLImageJ2CImpl() @@ -48,6 +46,7 @@ std::string LLImageJ2COJ::getEngineInfo() const  #endif  } +#if WANT_VERBOSE_OPJ_SPAM  // Return string from message, eliminating final \n if present  static std::string chomp(const char* msg)  { @@ -63,27 +62,34 @@ static std::string chomp(const char* msg)  }      return message;  } +#endif  /**  sample error callback expecting a LLFILE* client object  */  void error_callback(const char* msg, void*)  { -    LL_DEBUGS() << "LLImageJ2COJ: " << chomp(msg) << LL_ENDL; +#if WANT_VERBOSE_OPJ_SPAM +    LL_WARNS() << "LLImageJ2COJ: " << chomp(msg) << LL_ENDL; +#endif  }  /**  sample warning callback expecting a LLFILE* client object  */  void warning_callback(const char* msg, void*)  { -    LL_DEBUGS() << "LLImageJ2COJ: " << chomp(msg) << LL_ENDL; +#if WANT_VERBOSE_OPJ_SPAM +    LL_WARNS() << "LLImageJ2COJ: " << chomp(msg) << LL_ENDL; +#endif  }  /**  sample debug callback expecting no client object  */  void info_callback(const char* msg, void*)  { -    LL_DEBUGS() << "LLImageJ2COJ: " << chomp(msg) << LL_ENDL; +#if WANT_VERBOSE_OPJ_SPAM +    LL_INFOS() << "LLImageJ2COJ: " << chomp(msg) << LL_ENDL; +#endif  }  // Divide a by 2 to the power of b and round upwards @@ -95,39 +101,13 @@ int ceildivpow2(int a, int b)  class JPEG2KBase  {  public: -    JPEG2KBase() {} +    JPEG2KBase() = default;      U8*        buffer = nullptr;      OPJ_SIZE_T size = 0;      OPJ_OFF_T  offset = 0;  }; -#define WANT_VERBOSE_OPJ_SPAM LL_DEBUG - -static void opj_info(const char* msg, void* user_data) -{ -    llassert(user_data); -#if WANT_VERBOSE_OPJ_SPAM -    LL_INFOS("OpenJPEG") << msg << LL_ENDL; -#endif -} - -static void opj_warn(const char* msg, void* user_data) -{ -    llassert(user_data); -#if WANT_VERBOSE_OPJ_SPAM -    LL_WARNS("OpenJPEG") << msg << LL_ENDL; -#endif -} - -static void opj_error(const char* msg, void* user_data) -{ -    llassert(user_data); -#if WANT_VERBOSE_OPJ_SPAM -    LL_WARNS("OpenJPEG") << msg << LL_ENDL; -#endif -} -  static OPJ_SIZE_T opj_read(void * buffer, OPJ_SIZE_T bytes, void* user_data)  {      llassert(user_data && buffer); @@ -283,11 +263,7 @@ public:      JPEG2KDecode(S8 discardLevel)      { -        memset(&event_mgr, 0, sizeof(opj_event_mgr_t));          memset(¶meters, 0, sizeof(opj_dparameters_t)); -        event_mgr.error_handler = error_callback; -        event_mgr.warning_handler = warning_callback; -        event_mgr.info_handler = info_callback;          opj_set_default_decoder_parameters(¶meters);          parameters.cp_reduce = discardLevel;      } @@ -331,6 +307,11 @@ public:          decoder = opj_create_decompress(OPJ_CODEC_J2K); +        /* catch events using our callbacks and give a local context */ +        opj_set_error_handler(decoder, error_callback, nullptr); +        opj_set_warning_handler(decoder, warning_callback, nullptr); +        opj_set_info_handler(decoder, info_callback, nullptr); +          if (!opj_setup_decoder(decoder, ¶meters))          {              return false; @@ -401,9 +382,9 @@ public:          decoder = opj_create_decompress(OPJ_CODEC_J2K);          opj_setup_decoder(decoder, ¶meters); -        opj_set_info_handler(decoder, opj_info, this); -        opj_set_warning_handler(decoder, opj_warn, this); -        opj_set_error_handler(decoder, opj_error, this); +        opj_set_info_handler(decoder, info_callback, this); +        opj_set_warning_handler(decoder, warning_callback, this); +        opj_set_error_handler(decoder, error_callback, this);          if (stream)          { @@ -469,7 +450,6 @@ public:  private:      opj_dparameters_t         parameters; -    opj_event_mgr_t           event_mgr;      opj_image_t*              image = nullptr;      opj_codec_t*              decoder = nullptr;      opj_stream_t*             stream = nullptr; @@ -484,10 +464,6 @@ public:      JPEG2KEncode(const char* comment_text_in, bool reversible)      {          memset(¶meters, 0, sizeof(opj_cparameters_t)); -        memset(&event_mgr, 0, sizeof(opj_event_mgr_t)); -        event_mgr.error_handler = error_callback; -        event_mgr.warning_handler = warning_callback; -        event_mgr.info_handler = info_callback;          opj_set_default_encoder_parameters(¶meters);          parameters.cod_format = OPJ_CODEC_J2K; @@ -555,6 +531,11 @@ public:          encoder = opj_create_compress(OPJ_CODEC_J2K); +        /* catch events using our callbacks and give a local context */ +        opj_set_error_handler(encoder, error_callback, nullptr); +        opj_set_warning_handler(encoder, warning_callback, nullptr); +        opj_set_info_handler(encoder, info_callback, nullptr); +          parameters.tcp_mct = (image->numcomps >= 3) ? 1 : 0; // no color transform for RGBA images @@ -578,10 +559,6 @@ public:              return false;          } -        opj_set_info_handler(encoder, opj_info, this); -        opj_set_warning_handler(encoder, opj_warn, this); -        opj_set_error_handler(encoder, opj_error, this); -          U32 width_tiles = (rawImageIn.getWidth() >> 6);          U32 height_tiles = (rawImageIn.getHeight() >> 6); @@ -786,7 +763,6 @@ public:  private:      opj_cparameters_t   parameters; -    opj_event_mgr_t     event_mgr;      opj_image_t*        image = nullptr;      opj_codec_t*        encoder = nullptr;      opj_stream_t*       stream = nullptr;  | 
