Some openjpeg optimizations and crash preventions from imprudence.

This commit is contained in:
phr0z3nt04st
2010-06-18 23:14:27 -05:00
parent 9f44d1d504
commit bf67293f7d
3 changed files with 23 additions and 11 deletions

View File

@@ -99,6 +99,7 @@ void info_callback(const char* msg, void*)
LLImageJ2COJ::LLImageJ2COJ() : LLImageJ2CImpl() LLImageJ2COJ::LLImageJ2COJ() : LLImageJ2CImpl()
{ {
mRawImagep=NULL;
} }
@@ -166,9 +167,17 @@ BOOL LLImageJ2COJ::decodeImpl(LLImageJ2C &base, LLImageRaw &raw_image, F32 decod
// The image decode failed if the return was NULL or the component // The image decode failed if the return was NULL or the component
// count was zero. The latter is just a sanity check before we // count was zero. The latter is just a sanity check before we
// dereference the array. // dereference the array.
if(!image || !image->numcomps) if(!image)
{ {
llwarns << "ERROR -> decodeImpl: failed to decode image!" << llendl; LL_DEBUGS("Openjpeg") << "ERROR -> decodeImpl: failed to decode image - no image" << LL_ENDL;
return TRUE; // done
}
S32 img_components = image->numcomps;
if( !img_components ) // < 1 ||img_components > 4 )
{
LL_DEBUGS("Openjpeg") << "ERROR -> decodeImpl: failed to decode image wrong number of components: " << img_components << LL_ENDL;
if (image) if (image)
{ {
opj_image_destroy(image); opj_image_destroy(image);
@@ -178,20 +187,21 @@ BOOL LLImageJ2COJ::decodeImpl(LLImageJ2C &base, LLImageRaw &raw_image, F32 decod
} }
// sometimes we get bad data out of the cache - check to see if the decode succeeded // sometimes we get bad data out of the cache - check to see if the decode succeeded
for (S32 i = 0; i < image->numcomps; i++) for (S32 i = 0; i < img_components; i++)
{ {
if (image->comps[i].factor != base.getRawDiscardLevel()) if (image->comps[i].factor != base.getRawDiscardLevel())
{ {
// if we didn't get the discard level we're expecting, fail // if we didn't get the discard level we're expecting, fail
opj_image_destroy(image); if (image) //anyway somthing odd with the image, better check than crash
opj_image_destroy(image);
base.mDecoding = FALSE; base.mDecoding = FALSE;
return TRUE; return TRUE;
} }
} }
if(image->numcomps <= first_channel) if(img_components <= first_channel)
{ {
llwarns << "trying to decode more channels than are present in image: numcomps: " << image->numcomps << " first_channel: " << first_channel << llendl; LL_DEBUGS("Openjpeg") << "trying to decode more channels than are present in image: numcomps: " << img_components << " first_channel: " << first_channel << LL_ENDL;
if (image) if (image)
{ {
opj_image_destroy(image); opj_image_destroy(image);
@@ -202,7 +212,6 @@ BOOL LLImageJ2COJ::decodeImpl(LLImageJ2C &base, LLImageRaw &raw_image, F32 decod
// Copy image data into our raw image format (instead of the separate channel format // Copy image data into our raw image format (instead of the separate channel format
S32 img_components = image->numcomps;
S32 channels = img_components - first_channel; S32 channels = img_components - first_channel;
if( channels > max_channel_count ) if( channels > max_channel_count )
channels = max_channel_count; channels = max_channel_count;
@@ -249,7 +258,10 @@ BOOL LLImageJ2COJ::decodeImpl(LLImageJ2C &base, LLImageRaw &raw_image, F32 decod
} }
/* free image data structure */ /* free image data structure */
opj_image_destroy(image); if (image)
{
opj_image_destroy(image);
}
return TRUE; // done return TRUE; // done
} }

View File

@@ -1016,8 +1016,7 @@ BOOL LLImageGL::createGLTexture(S32 discard_level, const LLImageRaw* imageraw, S
mFormatType = GL_UNSIGNED_BYTE; mFormatType = GL_UNSIGNED_BYTE;
break; break;
default: default:
//HACKY MCHACK HACK LL_DEBUGS("Openjpeg") << "Bad number of components for texture: " << (U32)getComponents() << LL_ENDL;
llinfos << "Bad number of components for texture: " << (U32)getComponents() << llendl;
to_create = false; to_create = false;
} }
} }

View File

@@ -40,7 +40,8 @@
</array> </array>
<key>tags</key> <key>tags</key>
<array> <array>
<string>ShaderLoading</string> <string>ShaderLoading</string>
<string>Openjpeg</string>
</array> </array>
</map> </map>
</array> </array>