Apply missing changes to OpenJPEG 2 decoder implementation
parent
120cd904c1
commit
7cda0ae26c
|
|
@ -33,6 +33,7 @@
|
|||
#include "lltimer.h"
|
||||
//#include "llmemory.h"
|
||||
|
||||
#define OPENJPEG_VERSION "2.1" // This actually needs to be in openjpeg.h
|
||||
|
||||
struct ndUserdata
|
||||
{
|
||||
|
|
@ -126,23 +127,16 @@ OPJ_BOOL nd_opj_stream_seek_fn(OPJ_OFF_T p_nb_bytes, void * p_user_data)
|
|||
return OPJ_TRUE;
|
||||
}
|
||||
|
||||
const char* fallbackEngineInfoLLImageJ2CImpl()
|
||||
{
|
||||
static std::string version_string =
|
||||
std::string("OpenJPEG: 2.1, Runtime: ")
|
||||
+ opj_version();
|
||||
return version_string.c_str();
|
||||
}
|
||||
|
||||
// Factory function: see declaration in llimagej2c.cpp
|
||||
LLImageJ2CImpl* fallbackCreateLLImageJ2CImpl()
|
||||
{
|
||||
return new LLImageJ2COJ();
|
||||
}
|
||||
|
||||
void fallbackDestroyLLImageJ2CImpl(LLImageJ2CImpl* impl)
|
||||
std::string LLImageJ2COJ::getEngineInfo() const
|
||||
{
|
||||
delete impl;
|
||||
impl = NULL;
|
||||
return std::string("OpenJPEG: " OPENJPEG_VERSION ", Runtime: ")
|
||||
+ opj_version();
|
||||
}
|
||||
|
||||
// Return string from message, eliminating final \n if present
|
||||
|
|
@ -200,19 +194,19 @@ LLImageJ2COJ::~LLImageJ2COJ()
|
|||
{
|
||||
}
|
||||
|
||||
BOOL LLImageJ2COJ::initDecode(LLImageJ2C &base, LLImageRaw &raw_image, int discard_level, int* region)
|
||||
bool LLImageJ2COJ::initDecode(LLImageJ2C &base, LLImageRaw &raw_image, int discard_level, int* region)
|
||||
{
|
||||
// No specific implementation for this method in the OpenJpeg case
|
||||
return FALSE;
|
||||
return false;
|
||||
}
|
||||
|
||||
BOOL LLImageJ2COJ::initEncode(LLImageJ2C &base, LLImageRaw &raw_image, int blocks_size, int precincts_size, int levels)
|
||||
bool LLImageJ2COJ::initEncode(LLImageJ2C &base, LLImageRaw &raw_image, int blocks_size, int precincts_size, int levels)
|
||||
{
|
||||
// No specific implementation for this method in the OpenJpeg case
|
||||
return FALSE;
|
||||
return false;
|
||||
}
|
||||
|
||||
BOOL LLImageJ2COJ::decodeImpl(LLImageJ2C &base, LLImageRaw &raw_image, F32 decode_time, S32 first_channel, S32 max_channel_count)
|
||||
bool LLImageJ2COJ::decodeImpl(LLImageJ2C &base, LLImageRaw &raw_image, F32 decode_time, S32 first_channel, S32 max_channel_count)
|
||||
{
|
||||
// <FS:Techwolf Lupindo> texture comment metadata reader
|
||||
U8* c_data = base.getData();
|
||||
|
|
@ -304,7 +298,7 @@ BOOL LLImageJ2COJ::decodeImpl(LLImageJ2C &base, LLImageRaw &raw_image, F32 decod
|
|||
opj_image_destroy(image);
|
||||
}
|
||||
|
||||
return TRUE; // done
|
||||
return true; // done
|
||||
}
|
||||
|
||||
// sometimes we get bad data out of the cache - check to see if the decode succeeded
|
||||
|
|
@ -314,8 +308,8 @@ BOOL LLImageJ2COJ::decodeImpl(LLImageJ2C &base, LLImageRaw &raw_image, F32 decod
|
|||
{
|
||||
// if we didn't get the discard level we're expecting, fail
|
||||
opj_image_destroy(image);
|
||||
base.mDecoding = FALSE;
|
||||
return TRUE;
|
||||
base.mDecoding = false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -327,7 +321,7 @@ BOOL LLImageJ2COJ::decodeImpl(LLImageJ2C &base, LLImageRaw &raw_image, F32 decod
|
|||
opj_image_destroy(image);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Copy image data into our raw image format (instead of the separate channel format
|
||||
|
|
@ -351,6 +345,16 @@ BOOL LLImageJ2COJ::decodeImpl(LLImageJ2C &base, LLImageRaw &raw_image, F32 decod
|
|||
raw_image.resize(width, height, channels);
|
||||
U8 *rawp = raw_image.getData();
|
||||
|
||||
// <FS:Ansariel> Port fix for MAINT-4327/MAINT-6584 to OpenJPEG decoder
|
||||
if (!rawp)
|
||||
{
|
||||
base.setLastError("Memory error");
|
||||
base.decodeFailed();
|
||||
opj_image_destroy(image);
|
||||
return true; // done
|
||||
}
|
||||
// <FS:Ansariel>
|
||||
|
||||
// first_channel is what channel to start copying from
|
||||
// dest is what channel to copy to. first_channel comes from the
|
||||
// argument, dest always starts writing at channel zero.
|
||||
|
|
@ -374,18 +378,18 @@ BOOL LLImageJ2COJ::decodeImpl(LLImageJ2C &base, LLImageRaw &raw_image, F32 decod
|
|||
LL_DEBUGS("Texture") << "ERROR -> decodeImpl: failed to decode image! (NULL comp data - OpenJPEG bug)" << LL_ENDL;
|
||||
opj_image_destroy(image);
|
||||
|
||||
return TRUE; // done
|
||||
return true; // done
|
||||
}
|
||||
}
|
||||
|
||||
/* free image data structure */
|
||||
opj_image_destroy(image);
|
||||
|
||||
return TRUE; // done
|
||||
return true; // done
|
||||
}
|
||||
|
||||
|
||||
BOOL LLImageJ2COJ::encodeImpl(LLImageJ2C &base, const LLImageRaw &raw_image, const char* comment_text, F32 encode_time, BOOL reversible)
|
||||
bool LLImageJ2COJ::encodeImpl(LLImageJ2C &base, const LLImageRaw &raw_image, const char* comment_text, F32 encode_time, bool reversible)
|
||||
{
|
||||
const S32 MAX_COMPS = 5;
|
||||
opj_cparameters_t parameters; /* compression parameters */
|
||||
|
|
@ -495,7 +499,7 @@ BOOL LLImageJ2COJ::encodeImpl(LLImageJ2C &base, const LLImageRaw &raw_image, con
|
|||
if (!bSuccess)
|
||||
{
|
||||
LL_DEBUGS("Texture") << "Failed to encode image." << LL_ENDL;
|
||||
return FALSE;
|
||||
return false;
|
||||
}
|
||||
|
||||
codestream_length = pStreamdata->mOutput.size();
|
||||
|
|
@ -513,7 +517,7 @@ BOOL LLImageJ2COJ::encodeImpl(LLImageJ2C &base, const LLImageRaw &raw_image, con
|
|||
|
||||
/* free image data */
|
||||
opj_image_destroy(image);
|
||||
return TRUE;
|
||||
return true;
|
||||
}
|
||||
|
||||
inline S32 extractLong4( U8 const *aBuffer, int nOffset )
|
||||
|
|
@ -573,7 +577,7 @@ bool getMetadataFast( LLImageJ2C &aImage, S32 &aW, S32 &aH, S32 &aComps )
|
|||
return true;
|
||||
}
|
||||
|
||||
BOOL LLImageJ2COJ::getMetadata(LLImageJ2C &base)
|
||||
bool LLImageJ2COJ::getMetadata(LLImageJ2C &base)
|
||||
{
|
||||
//
|
||||
// FIXME: We get metadata by decoding the ENTIRE image.
|
||||
|
|
@ -589,7 +593,7 @@ BOOL LLImageJ2COJ::getMetadata(LLImageJ2C &base)
|
|||
if ( getMetadataFast( base, width, height, img_components ) )
|
||||
{
|
||||
base.setSize(width, height, img_components);
|
||||
return TRUE;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Do it the old and slow way, decode the image with openjpeg
|
||||
|
|
@ -634,7 +638,7 @@ BOOL LLImageJ2COJ::getMetadata(LLImageJ2C &base)
|
|||
if(!image)
|
||||
{
|
||||
LL_WARNS() << "ERROR -> getMetadata: failed to decode image!" << LL_ENDL;
|
||||
return FALSE;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Copy image data into our raw image format (instead of the separate channel format
|
||||
|
|
@ -647,5 +651,5 @@ BOOL LLImageJ2COJ::getMetadata(LLImageJ2C &base)
|
|||
|
||||
/* free image data structure */
|
||||
opj_image_destroy(image);
|
||||
return TRUE;
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue