From f09a92f1f32179ae24f150670851bf63aad204c4 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Thu, 21 Jul 2016 14:29:29 -0400 Subject: DRTVWR-427: Remove engineInfoLLImageJ2CKDU(), createLLImageJ2CKDU(), destroyLLImageJ2CKDU(). These were apparently intended as simple C-style DLL entry points. But as nobody calls them, and as we decided against building the viewer from DLLs, they only clutter the code. --- indra/llkdu/llimagej2ckdu.cpp | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) (limited to 'indra/llkdu/llimagej2ckdu.cpp') diff --git a/indra/llkdu/llimagej2ckdu.cpp b/indra/llkdu/llimagej2ckdu.cpp index 282c859e9e..90b8d10ecc 100644 --- a/indra/llkdu/llimagej2ckdu.cpp +++ b/indra/llkdu/llimagej2ckdu.cpp @@ -72,23 +72,6 @@ private: // void set_default_colour_weights(kdu_params *siz); -const char* engineInfoLLImageJ2CKDU() -{ - static std::string version = llformat("KDU %s", KDU_CORE_VERSION); - return version.c_str(); -} - -LLImageJ2CKDU* createLLImageJ2CKDU() -{ - return new LLImageJ2CKDU(); -} - -void destroyLLImageJ2CKDU(LLImageJ2CKDU* kdu) -{ - delete kdu; - kdu = NULL; -} - LLImageJ2CImpl* fallbackCreateLLImageJ2CImpl() { return new LLImageJ2CKDU(); @@ -102,7 +85,8 @@ void fallbackDestroyLLImageJ2CImpl(LLImageJ2CImpl* impl) const char* fallbackEngineInfoLLImageJ2CImpl() { - return engineInfoLLImageJ2CKDU(); + static std::string version = llformat("KDU %s", KDU_CORE_VERSION); + return version.c_str(); } class LLKDUDecodeState -- cgit v1.2.3 From 71b593e88b1e601db84cd3c399865a0bfd8164cf Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Thu, 21 Jul 2016 16:49:02 -0400 Subject: MAINT-6584: Streamline static LLImageJ2C implementation API. Specifically, remove unused function pointer types CreateLLImageJ2CFunction, DestroyLLImageJ2CFunction and EngineInfoLLImageJ2CFunction. Also eliminate static fallbackDestroyLLImageJ2CImpl() and fallbackEngineInfoLLImageJ2CImpl(), leaving only static fallbackCreateLLImageJ2CImpl(). We do need a factory function to instantiate the appropriate LLImageJ2CImpl subclass, so leave the fallbackCreateLLImageJ2CImpl() link seam in place. However, given that every known LLImageJ2CImpl subclass is cheap to instantiate, make getEngineInfo() a pure virtual method on that subclass: the static LLImageJ2C::getEngineInfo() method can temporarily construct an instance to query. While we're at it, make getEngineInfo() return std::string like LLImageJ2C::getEngineInfo(). It's ridiculous that fallbackEngineInfoLLImageJ2CImpl() implementations constructed a static std::string and returned its c_str(), only to have LLImageJ2C::getEngineInfo() construct ANOTHER std::string from the returned const char*. fallbackDestroyLLImageJ2CImpl() never did anything useful: it merely deleted the passed LLImageJ2CImpl subclass pointer as the specific subclass type. But since LLImageJ2CImpl's destructor is virtual, LLImageJ2C's destructor could simply delete the stored LLImageJ2CImpl*. In fact, make mImpl a boost::scoped_ptr so we don't even have to delete it manually. --- indra/llkdu/llimagej2ckdu.cpp | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'indra/llkdu/llimagej2ckdu.cpp') diff --git a/indra/llkdu/llimagej2ckdu.cpp b/indra/llkdu/llimagej2ckdu.cpp index 90b8d10ecc..0906fc894e 100644 --- a/indra/llkdu/llimagej2ckdu.cpp +++ b/indra/llkdu/llimagej2ckdu.cpp @@ -72,21 +72,15 @@ private: // void set_default_colour_weights(kdu_params *siz); +// Factory function: see declaration in llimagej2c.cpp LLImageJ2CImpl* fallbackCreateLLImageJ2CImpl() { return new LLImageJ2CKDU(); } -void fallbackDestroyLLImageJ2CImpl(LLImageJ2CImpl* impl) +std::string LLImageJ2CKDU::getEngineInfo() const { - delete impl; - impl = NULL; -} - -const char* fallbackEngineInfoLLImageJ2CImpl() -{ - static std::string version = llformat("KDU %s", KDU_CORE_VERSION); - return version.c_str(); + return llformat("KDU %s", KDU_CORE_VERSION); } class LLKDUDecodeState -- cgit v1.2.3 From ab07b1a46150aaf04e7fd80c141bc9c95656b065 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Fri, 22 Jul 2016 10:32:53 -0400 Subject: MAINT-6584: Rationalize custom KDU error/warning message classes. Derive them both from a common base class that does the message logging, instead of having each handler class log redundantly -- especially since the put_text() override accepting const kdu_uint16* was simply streaming the kdu_uint16 pointer to the log file, which would log the hex value of the pointer. Although we want a static instance of each of these handler classes, pull it out rather than nesting the instance within the class itself. --- indra/llkdu/llimagej2ckdu.cpp | 93 +++++++++++++++++++++++-------------------- 1 file changed, 49 insertions(+), 44 deletions(-) (limited to 'indra/llkdu/llimagej2ckdu.cpp') diff --git a/indra/llkdu/llimagej2ckdu.cpp b/indra/llkdu/llimagej2ckdu.cpp index 0906fc894e..44dc9daabd 100644 --- a/indra/llkdu/llimagej2ckdu.cpp +++ b/indra/llkdu/llimagej2ckdu.cpp @@ -106,62 +106,67 @@ private: S32 mRowGap; }; -void ll_kdu_error( void ) -{ - // *FIX: This exception is bad, bad, bad. It gets thrown from a - // destructor which can lead to immediate program termination! - throw "ll_kdu_error() throwing an exception"; -} - // Stuff for new kdu error handling -class LLKDUMessageWarning : public kdu_message +class LLKDUMessage: public kdu_message { public: - /*virtual*/ void put_text(const char *s); - /*virtual*/ void put_text(const kdu_uint16 *s); + LLKDUMessage(const std::string& type): + mType(type) + {} - static LLKDUMessageWarning sDefaultMessage; -}; - -class LLKDUMessageError : public kdu_message -{ -public: - /*virtual*/ void put_text(const char *s); - /*virtual*/ void put_text(const kdu_uint16 *s); - /*virtual*/ void flush(bool end_of_message = false); - static LLKDUMessageError sDefaultMessage; -}; + virtual void put_text(const char *s) + { + LL_INFOS() << "KDU " << mType << ": " << s << LL_ENDL; + } -void LLKDUMessageWarning::put_text(const char *s) -{ - LL_INFOS() << "KDU Warning: " << s << LL_ENDL; -} + virtual void put_text(const kdu_uint16 *s) + { + // The previous implementation simply streamed 's' to the log. So + // either this put_text() override was never called -- or it produced + // some baffling log messages -- because I assert that streaming a + // const kdu_uint16* to a std::ostream will display only the hex value + // of the pointer. + LL_INFOS() << "KDU " << mType << ": " + << utf16str_to_utf8str(llutf16string(s)) << LL_ENDL; + } -void LLKDUMessageWarning::put_text(const kdu_uint16 *s) -{ - LL_INFOS() << "KDU Warning: " << s << LL_ENDL; -} +private: + std::string mType; +}; -void LLKDUMessageError::put_text(const char *s) +struct LLKDUMessageWarning : public LLKDUMessage { - LL_INFOS() << "KDU Error: " << s << LL_ENDL; -} + LLKDUMessageWarning(): + LLKDUMessage("Warning") + {} +}; +static LLKDUMessageWarning sWarningHandler; -void LLKDUMessageError::put_text(const kdu_uint16 *s) +struct LLKDUMessageError : public LLKDUMessage { - LL_INFOS() << "KDU Error: " << s << LL_ENDL; -} + LLKDUMessageError(): + LLKDUMessage("Error") + {} -void LLKDUMessageError::flush(bool end_of_message) -{ - if (end_of_message) + virtual void flush(bool end_of_message = false) { - throw "KDU throwing an exception"; + // According to the documentation nat found: + // http://pirlwww.lpl.arizona.edu/resources/guide/software/Kakadu/html_pages/globals__kdu$mize_errors.html + // "If a kdu_error object is destroyed, handler→flush will be called with + // an end_of_message argument equal to true and the process will + // subsequently be terminated through exit. The termination may be + // avoided, however, by throwing an exception from within the message + // terminating handler→flush call." + // So throwing an exception here isn't arbitrary: we MUST throw an + // exception if we want to recover from a KDU error. + if (end_of_message) + { + throw "KDU throwing an exception"; + } } -} +}; +static LLKDUMessageError sErrorHandler; -LLKDUMessageWarning LLKDUMessageWarning::sDefaultMessage; -LLKDUMessageError LLKDUMessageError::sDefaultMessage; static bool kdu_message_initialized = false; LLImageJ2CKDU::LLImageJ2CKDU() : LLImageJ2CImpl(), @@ -196,8 +201,8 @@ void LLImageJ2CKDU::setupCodeStream(LLImageJ2C &base, BOOL keep_codestream, ECod if (!kdu_message_initialized) { kdu_message_initialized = true; - kdu_customize_errors(&LLKDUMessageError::sDefaultMessage); - kdu_customize_warnings(&LLKDUMessageWarning::sDefaultMessage); + kdu_customize_errors(&sErrorHandler); + kdu_customize_warnings(&sWarningHandler); } if (mCodeStreamp) -- cgit v1.2.3 From acdb050ce5e672a6e5c83ef6e95257ce68934d1b Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Fri, 22 Jul 2016 11:35:23 -0400 Subject: MAINT-6584: Convert LLImage class hierarchy to standard 'bool' instead of legacy BOOL. --- indra/llkdu/llimagej2ckdu.cpp | 62 +++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 31 deletions(-) (limited to 'indra/llkdu/llimagej2ckdu.cpp') diff --git a/indra/llkdu/llimagej2ckdu.cpp b/indra/llkdu/llimagej2ckdu.cpp index 44dc9daabd..0b2ac03b9d 100644 --- a/indra/llkdu/llimagej2ckdu.cpp +++ b/indra/llkdu/llimagej2ckdu.cpp @@ -88,11 +88,11 @@ class LLKDUDecodeState public: LLKDUDecodeState(kdu_tile tile, kdu_byte *buf, S32 row_gap); ~LLKDUDecodeState(); - BOOL processTileDecode(F32 decode_time, BOOL limit_time = TRUE); + bool processTileDecode(F32 decode_time, bool limit_time = true); private: S32 mNumComponents; - BOOL mUseYCC; + bool mUseYCC; kdu_dims mDims; kdu_sample_allocator mAllocator; kdu_tile_comp mComps[4]; @@ -190,7 +190,7 @@ LLImageJ2CKDU::~LLImageJ2CKDU() // Stuff for new simple decode void transfer_bytes(kdu_byte *dest, kdu_line_buf &src, int gap, int precision); -void LLImageJ2CKDU::setupCodeStream(LLImageJ2C &base, BOOL keep_codestream, ECodeStreamMode mode) +void LLImageJ2CKDU::setupCodeStream(LLImageJ2C &base, bool keep_codestream, ECodeStreamMode mode) { S32 data_size = base.getDataSize(); S32 max_bytes = (base.getMaxBytes() ? base.getMaxBytes() : data_size); @@ -316,12 +316,12 @@ void LLImageJ2CKDU::cleanupCodeStream() mTileIndicesp = NULL; } -BOOL LLImageJ2CKDU::initDecode(LLImageJ2C &base, LLImageRaw &raw_image, int discard_level, int* region) +bool LLImageJ2CKDU::initDecode(LLImageJ2C &base, LLImageRaw &raw_image, int discard_level, int* region) { return initDecode(base,raw_image,0.0f,MODE_FAST,0,4,discard_level,region); } -BOOL LLImageJ2CKDU::initEncode(LLImageJ2C &base, LLImageRaw &raw_image, int blocks_size, int precincts_size, int levels) +bool LLImageJ2CKDU::initEncode(LLImageJ2C &base, LLImageRaw &raw_image, int blocks_size, int precincts_size, int levels) { mPrecinctsSize = precincts_size; if (mPrecinctsSize != -1) @@ -345,10 +345,10 @@ BOOL LLImageJ2CKDU::initEncode(LLImageJ2C &base, LLImageRaw &raw_image, int bloc mLevels = llclamp(mLevels,MIN_DECOMPOSITION_LEVELS,MAX_DECOMPOSITION_LEVELS); base.setLevels(mLevels); } - return TRUE; + return true; } -BOOL LLImageJ2CKDU::initDecode(LLImageJ2C &base, LLImageRaw &raw_image, F32 decode_time, ECodeStreamMode mode, S32 first_channel, S32 max_channel_count, int discard_level, int* region) +bool LLImageJ2CKDU::initDecode(LLImageJ2C &base, LLImageRaw &raw_image, F32 decode_time, ECodeStreamMode mode, S32 first_channel, S32 max_channel_count, int discard_level, int* region) { base.resetLastError(); @@ -360,7 +360,7 @@ BOOL LLImageJ2CKDU::initDecode(LLImageJ2C &base, LLImageRaw &raw_image, F32 deco //findDiscardLevelsBoundaries(base); base.updateRawDiscardLevel(); - setupCodeStream(base, TRUE, mode); + setupCodeStream(base, true, mode); mRawImagep = &raw_image; mCodeStreamp->change_appearance(false, true, false); @@ -408,20 +408,20 @@ BOOL LLImageJ2CKDU::initDecode(LLImageJ2C &base, LLImageRaw &raw_image, F32 deco catch (const char* msg) { base.setLastError(ll_safe_string(msg)); - return FALSE; + return false; } catch (...) { base.setLastError("Unknown J2C error"); - return FALSE; + return false; } - return TRUE; + return true; } -// Returns TRUE to mean done, whether successful or not. -BOOL LLImageJ2CKDU::decodeImpl(LLImageJ2C &base, LLImageRaw &raw_image, F32 decode_time, S32 first_channel, S32 max_channel_count) +// Returns true to mean done, whether successful or not. +bool LLImageJ2CKDU::decodeImpl(LLImageJ2C &base, LLImageRaw &raw_image, F32 decode_time, S32 first_channel, S32 max_channel_count) { ECodeStreamMode mode = MODE_FAST; @@ -433,7 +433,7 @@ BOOL LLImageJ2CKDU::decodeImpl(LLImageJ2C &base, LLImageRaw &raw_image, F32 deco { // Initializing the J2C decode failed, bail out. cleanupCodeStream(); - return TRUE; // done + return true; // done } } @@ -492,7 +492,7 @@ BOOL LLImageJ2CKDU::decodeImpl(LLImageJ2C &base, LLImageRaw &raw_image, F32 deco { // Not finished decoding yet. // setLastError("Ran out of time while decoding"); - return FALSE; + return false; } } catch (const char* msg) @@ -500,14 +500,14 @@ BOOL LLImageJ2CKDU::decodeImpl(LLImageJ2C &base, LLImageRaw &raw_image, F32 deco base.setLastError(ll_safe_string(msg)); base.decodeFailed(); cleanupCodeStream(); - return TRUE; // done + return true; // done } catch (...) { base.setLastError( "Unknown J2C error" ); base.decodeFailed(); cleanupCodeStream(); - return TRUE; // done + return true; // done } @@ -519,11 +519,11 @@ BOOL LLImageJ2CKDU::decodeImpl(LLImageJ2C &base, LLImageRaw &raw_image, F32 deco cleanupCodeStream(); - return TRUE; + return true; } -BOOL LLImageJ2CKDU::encodeImpl(LLImageJ2C &base, const LLImageRaw &raw_image, const char* comment_text, F32 encode_time, BOOL reversible) +bool LLImageJ2CKDU::encodeImpl(LLImageJ2C &base, const LLImageRaw &raw_image, const char* comment_text, F32 encode_time, bool reversible) { // Declare and set simple arguments bool transpose = false; @@ -691,36 +691,36 @@ BOOL LLImageJ2CKDU::encodeImpl(LLImageJ2C &base, const LLImageRaw &raw_image, co catch(const char* msg) { base.setLastError(ll_safe_string(msg)); - return FALSE; + return false; } catch( ... ) { base.setLastError( "Unknown J2C error" ); - return FALSE; + return false; } - return TRUE; + return true; } -BOOL LLImageJ2CKDU::getMetadata(LLImageJ2C &base) +bool LLImageJ2CKDU::getMetadata(LLImageJ2C &base) { // *FIX: kdu calls our callback function if there's an error, and // then bombs. To regain control, we throw an exception, and // catch it here. try { - setupCodeStream(base, FALSE, MODE_FAST); - return TRUE; + setupCodeStream(base, false, MODE_FAST); + return true; } catch (const char* msg) { base.setLastError(ll_safe_string(msg)); - return FALSE; + return false; } catch (...) { base.setLastError( "Unknown J2C error" ); - return FALSE; + return false; } } @@ -830,7 +830,7 @@ void LLImageJ2CKDU::findDiscardLevelsBoundaries(LLImageJ2C &base) { //std::cout << "Parsing discard level = " << discard_level << std::endl; // Create the input codestream object. - setupCodeStream(base, TRUE, MODE_FAST); + setupCodeStream(base, true, MODE_FAST); mCodeStreamp->apply_input_restrictions(0, 4, discard_level, 0, NULL); mCodeStreamp->set_max_bytes(KDU_LONG_MAX,true); siz_params *siz_in = mCodeStreamp->access_siz(); @@ -1189,7 +1189,7 @@ LLKDUDecodeState::~LLKDUDecodeState() mTile.close(); } -BOOL LLKDUDecodeState::processTileDecode(F32 decode_time, BOOL limit_time) +bool LLKDUDecodeState::processTileDecode(F32 decode_time, bool limit_time) /* Decompresses a tile, writing the data into the supplied byte buffer. The buffer contains interleaved image components, if there are any. Although you may think of the buffer as belonging entirely to this tile, @@ -1221,11 +1221,11 @@ separation between consecutive rows in the real buffer. */ { if (limit_time && decode_timer.getElapsedTimeF32() > decode_time) { - return FALSE; + return false; } } } - return TRUE; + return true; } // kdc_flow_control -- cgit v1.2.3 From 03bff896bd18b71c9a2d8e0b163647b1cd64b871 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Wed, 3 Aug 2016 20:40:03 -0400 Subject: MAINT-6584: Use RAII classes to manage helper object lifespans. Use boost::scoped_ptr instead of raw pointers to LLKDUMemSource, LLKDUDecodeState, kdu_coords and kdu_dims so cleanup is simpler, and automated on destruction of LLImageJ2CKDU. Replace pointer to kdu_codestream with a custom RAII class. kdu_codestream is itself an opaque handle, so we don't need to add another layer of indirection. Just wrap it to ensure its destroy() method is reliably called when needed. Make static instances of LLKDUMessageWarning and LLKDUMessageError self-register, eliminating the companion static bool and explicit checks in code. --- indra/llkdu/llimagej2ckdu.cpp | 98 +++++++++++++++++-------------------------- 1 file changed, 38 insertions(+), 60 deletions(-) (limited to 'indra/llkdu/llimagej2ckdu.cpp') diff --git a/indra/llkdu/llimagej2ckdu.cpp b/indra/llkdu/llimagej2ckdu.cpp index 0b2ac03b9d..0d37b123ec 100644 --- a/indra/llkdu/llimagej2ckdu.cpp +++ b/indra/llkdu/llimagej2ckdu.cpp @@ -138,15 +138,21 @@ struct LLKDUMessageWarning : public LLKDUMessage { LLKDUMessageWarning(): LLKDUMessage("Warning") - {} + { + kdu_customize_warnings(this); + } }; +// Instantiating LLKDUMessageWarning calls kdu_customize_warnings() with the +// new instance. Make it static so this only happens once. static LLKDUMessageWarning sWarningHandler; struct LLKDUMessageError : public LLKDUMessage { LLKDUMessageError(): LLKDUMessage("Error") - {} + { + kdu_customize_errors(this); + } virtual void flush(bool end_of_message = false) { @@ -165,20 +171,20 @@ struct LLKDUMessageError : public LLKDUMessage } } }; +// Instantiating LLKDUMessageError calls kdu_customize_errors() with the new +// instance. Make it static so this only happens once. static LLKDUMessageError sErrorHandler; -static bool kdu_message_initialized = false; - LLImageJ2CKDU::LLImageJ2CKDU() : LLImageJ2CImpl(), -mInputp(NULL), -mCodeStreamp(NULL), -mTPosp(NULL), -mTileIndicesp(NULL), -mRawImagep(NULL), -mDecodeState(NULL), -mBlocksSize(-1), -mPrecinctsSize(-1), -mLevels(0) + mInputp(), + mCodeStreamp(), + mTPosp(), + mTileIndicesp(), + mRawImagep(NULL), + mDecodeState(), + mBlocksSize(-1), + mPrecinctsSize(-1), + mLevels(0) { } @@ -198,38 +204,27 @@ void LLImageJ2CKDU::setupCodeStream(LLImageJ2C &base, bool keep_codestream, ECod // // Initialization // - if (!kdu_message_initialized) - { - kdu_message_initialized = true; - kdu_customize_errors(&sErrorHandler); - kdu_customize_warnings(&sWarningHandler); - } - - if (mCodeStreamp) - { - mCodeStreamp->destroy(); - delete mCodeStreamp; - mCodeStreamp = NULL; - } + mCodeStreamp.reset(); if (!mInputp && base.getData()) { // The compressed data has been loaded // Setup the source for the codestream - mInputp = new LLKDUMemSource(base.getData(), data_size); + mInputp.reset(new LLKDUMemSource(base.getData(), data_size)); } if (mInputp) { + // This is LLKDUMemSource::reset(), not boost::scoped_ptr::reset(). mInputp->reset(); } - mCodeStreamp = new kdu_codestream; - mCodeStreamp->create(mInputp); + mCodeStreamp->create(mInputp.get()); // Set the maximum number of bytes to use from the codestream - // *TODO: This seems to be wrong. The base class should have no idea of how j2c compression works so no - // good way of computing what's the byte range to be used. + // *TODO: This seems to be wrong. The base class should have no idea of + // how j2c compression works so no good way of computing what's the byte + // range to be used. mCodeStreamp->set_max_bytes(max_bytes,true); // If you want to flip or rotate the image for some reason, change @@ -286,34 +281,18 @@ void LLImageJ2CKDU::setupCodeStream(LLImageJ2C &base, bool keep_codestream, ECod if (!keep_codestream) { - mCodeStreamp->destroy(); - delete mCodeStreamp; - mCodeStreamp = NULL; - delete mInputp; - mInputp = NULL; + mCodeStreamp.reset(); + mInputp.reset(); } } void LLImageJ2CKDU::cleanupCodeStream() { - delete mInputp; - mInputp = NULL; - - delete mDecodeState; - mDecodeState = NULL; - - if (mCodeStreamp) - { - mCodeStreamp->destroy(); - delete mCodeStreamp; - mCodeStreamp = NULL; - } - - delete mTPosp; - mTPosp = NULL; - - delete mTileIndicesp; - mTileIndicesp = NULL; + mInputp.reset(); + mDecodeState.reset(); + mCodeStreamp.reset(); + mTPosp.reset(); + mTileIndicesp.reset(); } bool LLImageJ2CKDU::initDecode(LLImageJ2C &base, LLImageRaw &raw_image, int discard_level, int* region) @@ -395,12 +374,12 @@ bool LLImageJ2CKDU::initDecode(LLImageJ2C &base, LLImageRaw &raw_image, F32 deco if (!mTileIndicesp) { - mTileIndicesp = new kdu_dims; + mTileIndicesp.reset(new kdu_dims); } mCodeStreamp->get_valid_tiles(*mTileIndicesp); if (!mTPosp) { - mTPosp = new kdu_coords; + mTPosp.reset(new kdu_coords); mTPosp->y = 0; mTPosp->x = 0; } @@ -427,7 +406,7 @@ bool LLImageJ2CKDU::decodeImpl(LLImageJ2C &base, LLImageRaw &raw_image, F32 deco LLTimer decode_timer; - if (!mCodeStreamp) + if (!mCodeStreamp->exists()) { if (!initDecode(base, raw_image, decode_time, mode, first_channel, max_channel_count)) { @@ -478,15 +457,14 @@ bool LLImageJ2CKDU::decodeImpl(LLImageJ2C &base, LLImageRaw &raw_image, F32 deco kdu_coords offset = tile_dims.pos - dims.pos; int row_gap = channels*dims.size.x; // inter-row separation kdu_byte *buf = buffer + offset.y*row_gap + offset.x*channels; - mDecodeState = new LLKDUDecodeState(tile, buf, row_gap); + mDecodeState.reset(new LLKDUDecodeState(tile, buf, row_gap)); } // Do the actual processing F32 remaining_time = decode_time - decode_timer.getElapsedTimeF32(); // This is where we do the actual decode. If we run out of time, return false. if (mDecodeState->processTileDecode(remaining_time, (decode_time > 0.0f))) { - delete mDecodeState; - mDecodeState = NULL; + mDecodeState.reset(); } else { -- cgit v1.2.3 From 2339e759fc2d6f36a4b9425022a22a747ec55dad Mon Sep 17 00:00:00 2001 From: AndreyL ProductEngine Date: Wed, 27 Jul 2016 05:49:07 +0300 Subject: MAINT-4327/MAINT-6584 Supress the crash on memory allocation error when decoding J2C images --- indra/llkdu/llimagej2ckdu.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'indra/llkdu/llimagej2ckdu.cpp') diff --git a/indra/llkdu/llimagej2ckdu.cpp b/indra/llkdu/llimagej2ckdu.cpp index 0d37b123ec..0863240686 100644 --- a/indra/llkdu/llimagej2ckdu.cpp +++ b/indra/llkdu/llimagej2ckdu.cpp @@ -422,6 +422,13 @@ bool LLImageJ2CKDU::decodeImpl(LLImageJ2C &base, LLImageRaw &raw_image, F32 deco // Now we are ready to walk through the tiles processing them one-by-one. kdu_byte *buffer = raw_image.getData(); + if (!buffer) + { + base.setLastError("Memory error"); + base.decodeFailed(); + cleanupCodeStream(); + return true; // done + } while (mTPosp->y < mTileIndicesp->size.y) { -- cgit v1.2.3 From 2ce38c3c9890f6cf65238e125a78cdc57841f3bd Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Thu, 4 Aug 2016 16:20:39 -0400 Subject: MAINT-6584: Comment out completely unused LLImageJ2CKDU code. The only call to the findDiscardLevelsBoundaries() method was commented out inside initDecode(), with a comment: // Merov : Test!! DO NOT COMMIT!! This was the only caller of copy_tile(), which was the only caller of copy_block(). Commented out all three of these (biggish!) functions, since I have no idea what any of them were supposed to do or when it might be useful to call them. In other words, I can't yet rule out the possibility that I might have to uncomment them. --- indra/llkdu/llimagej2ckdu.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'indra/llkdu/llimagej2ckdu.cpp') diff --git a/indra/llkdu/llimagej2ckdu.cpp b/indra/llkdu/llimagej2ckdu.cpp index 0863240686..9347e51b85 100644 --- a/indra/llkdu/llimagej2ckdu.cpp +++ b/indra/llkdu/llimagej2ckdu.cpp @@ -713,6 +713,8 @@ bool LLImageJ2CKDU::getMetadata(LLImageJ2C &base) /* STATIC copy_block */ /*****************************************************************************/ +/*==========================================================================*| +// Only called by copy_tile(), which is itself commented out static void copy_block(kdu_block *in, kdu_block *out) { if (in->K_max_prime != out->K_max_prime) @@ -741,11 +743,14 @@ static void copy_block(kdu_block *in, kdu_block *out) out->set_max_bytes(num_bytes,false); memcpy(out->byte_buffer,in->byte_buffer,(size_t) num_bytes); } +|*==========================================================================*/ /*****************************************************************************/ /* STATIC copy_tile */ /*****************************************************************************/ +/*==========================================================================*| +// Only called by findDiscardLevelsBoundaries(), which is itself commented out static void copy_tile(kdu_tile tile_in, kdu_tile tile_out, int tnum_in, int tnum_out, kdu_params *siz_in, kdu_params *siz_out, int skip_components, @@ -802,10 +807,13 @@ copy_tile(kdu_tile tile_in, kdu_tile tile_out, int tnum_in, int tnum_out, } } } +|*==========================================================================*/ // Find the block boundary for each discard level in the input image. // We parse the input blocks and copy them in a temporary output stream. // For the moment, we do nothing more that parsing the raw list of blocks and outputing result. +/*==========================================================================*| +// See comments in header file for why this is commented out. void LLImageJ2CKDU::findDiscardLevelsBoundaries(LLImageJ2C &base) { // We need the number of levels in that image before starting. @@ -909,6 +917,7 @@ void LLImageJ2CKDU::findDiscardLevelsBoundaries(LLImageJ2C &base) } return; } +|*==========================================================================*/ void set_default_colour_weights(kdu_params *siz) { -- cgit v1.2.3