EXP-669 : Refactor code to use correct LLImageFormatted methods to load images of all formats, reviewed by richard
parent
505e5e403d
commit
759d72a46c
|
|
@ -69,31 +69,8 @@ static bool sAllDone = false;
|
|||
// Create an empty formatted image instance of the correct type from the filename
|
||||
LLPointer<LLImageFormatted> create_image(const std::string &filename)
|
||||
{
|
||||
std::string exten = gDirUtilp->getExtension(filename);
|
||||
U32 codec = LLImageBase::getCodecFromExtension(exten);
|
||||
|
||||
LLPointer<LLImageFormatted> image;
|
||||
switch (codec)
|
||||
{
|
||||
case IMG_CODEC_BMP:
|
||||
image = new LLImageBMP();
|
||||
break;
|
||||
case IMG_CODEC_TGA:
|
||||
image = new LLImageTGA();
|
||||
break;
|
||||
case IMG_CODEC_JPEG:
|
||||
image = new LLImageJPEG();
|
||||
break;
|
||||
case IMG_CODEC_J2C:
|
||||
image = new LLImageJ2C();
|
||||
break;
|
||||
case IMG_CODEC_PNG:
|
||||
image = new LLImagePNG();
|
||||
break;
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
std::string exten = gDirUtilp->getExtension(filename);
|
||||
LLPointer<LLImageFormatted> image = LLImageFormatted::createFromExtension(exten);
|
||||
return image;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1254,28 +1254,7 @@ bool LLImageRaw::createFromFile(const std::string &filename, bool j2c_lowest_mip
|
|||
return false;
|
||||
}
|
||||
|
||||
LLPointer<LLImageFormatted> image;
|
||||
switch(codec)
|
||||
{
|
||||
//case IMG_CODEC_RGB:
|
||||
case IMG_CODEC_BMP:
|
||||
image = new LLImageBMP();
|
||||
break;
|
||||
case IMG_CODEC_TGA:
|
||||
image = new LLImageTGA();
|
||||
break;
|
||||
case IMG_CODEC_JPEG:
|
||||
image = new LLImageJPEG();
|
||||
break;
|
||||
case IMG_CODEC_J2C:
|
||||
image = new LLImageJ2C();
|
||||
break;
|
||||
case IMG_CODEC_DXT:
|
||||
image = new LLImageDXT();
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
LLPointer<LLImageFormatted> image = LLImageFormatted::createFromType(codec);
|
||||
llassert(image.notNull());
|
||||
|
||||
U8 *buffer = image->allocateData(length);
|
||||
|
|
|
|||
|
|
@ -325,122 +325,51 @@ void LLFloaterImagePreview::draw()
|
|||
bool LLFloaterImagePreview::loadImage(const std::string& src_filename)
|
||||
{
|
||||
std::string exten = gDirUtilp->getExtension(src_filename);
|
||||
|
||||
U32 codec = IMG_CODEC_INVALID;
|
||||
std::string temp_str;
|
||||
if( exten == "bmp")
|
||||
{
|
||||
codec = IMG_CODEC_BMP;
|
||||
}
|
||||
else if( exten == "tga")
|
||||
{
|
||||
codec = IMG_CODEC_TGA;
|
||||
}
|
||||
else if( exten == "jpg" || exten == "jpeg")
|
||||
{
|
||||
codec = IMG_CODEC_JPEG;
|
||||
}
|
||||
else if( exten == "png" )
|
||||
{
|
||||
codec = IMG_CODEC_PNG;
|
||||
}
|
||||
U32 codec = LLImageBase::getCodecFromExtension(exten);
|
||||
|
||||
LLImageDimensionsInfo image_info;
|
||||
if(!image_info.load(src_filename,codec))
|
||||
if (!image_info.load(src_filename,codec))
|
||||
{
|
||||
mImageLoadError = image_info.getLastError();
|
||||
return false;
|
||||
}
|
||||
|
||||
S32 max_width = gSavedSettings.getS32("max_texture_dimension_X");
|
||||
S32 max_heigh = gSavedSettings.getS32("max_texture_dimension_Y");
|
||||
S32 max_height = gSavedSettings.getS32("max_texture_dimension_Y");
|
||||
|
||||
if(image_info.getWidth() > max_width|| image_info.getHeight() > max_heigh)
|
||||
if ((image_info.getWidth() > max_width) || (image_info.getHeight() > max_height))
|
||||
{
|
||||
LLStringUtil::format_map_t args;
|
||||
args["WIDTH"] = llformat("%d", max_width);
|
||||
args["HEIGHT"] = llformat("%d", max_heigh);
|
||||
args["HEIGHT"] = llformat("%d", max_height);
|
||||
|
||||
mImageLoadError = LLTrans::getString("texture_load_dimensions_error", args);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
LLPointer<LLImageRaw> raw_image = new LLImageRaw;
|
||||
|
||||
switch (codec)
|
||||
// Load the image
|
||||
LLPointer<LLImageFormatted> image = LLImageFormatted::createFromType(codec);
|
||||
if (image.isNull())
|
||||
{
|
||||
case IMG_CODEC_BMP:
|
||||
{
|
||||
LLPointer<LLImageBMP> bmp_image = new LLImageBMP;
|
||||
|
||||
if (!bmp_image->load(src_filename))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!bmp_image->decode(raw_image, 0.0f))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case IMG_CODEC_TGA:
|
||||
{
|
||||
LLPointer<LLImageTGA> tga_image = new LLImageTGA;
|
||||
|
||||
if (!tga_image->load(src_filename))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!tga_image->decode(raw_image))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if( (tga_image->getComponents() != 3) &&
|
||||
(tga_image->getComponents() != 4) )
|
||||
{
|
||||
tga_image->setLastError( "Image files with less than 3 or more than 4 components are not supported." );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case IMG_CODEC_JPEG:
|
||||
{
|
||||
LLPointer<LLImageJPEG> jpeg_image = new LLImageJPEG;
|
||||
|
||||
if (!jpeg_image->load(src_filename))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!jpeg_image->decode(raw_image, 0.0f))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case IMG_CODEC_PNG:
|
||||
{
|
||||
LLPointer<LLImagePNG> png_image = new LLImagePNG;
|
||||
|
||||
if (!png_image->load(src_filename))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!png_image->decode(raw_image, 0.0f))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!image->load(src_filename))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// Decompress or expand it in a raw image structure
|
||||
LLPointer<LLImageRaw> raw_image = new LLImageRaw;
|
||||
if (!image->decode(raw_image, 0.0f))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// Check the image constraints
|
||||
if ((image->getComponents() != 3) && (image->getComponents() != 4))
|
||||
{
|
||||
image->setLastError("Image files with less than 3 or more than 4 components are not supported.");
|
||||
return false;
|
||||
}
|
||||
|
||||
raw_image->biasedScaleToPowerOfTwo(1024);
|
||||
mRawImagep = raw_image;
|
||||
|
||||
|
|
|
|||
|
|
@ -493,6 +493,7 @@ void upload_new_resource(const std::string& src_filename, std::string name,
|
|||
LLSD args;
|
||||
|
||||
std::string exten = gDirUtilp->getExtension(src_filename);
|
||||
U32 codec = LLImageBase::getCodecFromExtension(exten);
|
||||
LLAssetType::EType asset_type = LLAssetType::AT_NONE;
|
||||
std::string error_message;
|
||||
|
||||
|
|
@ -510,66 +511,20 @@ void upload_new_resource(const std::string& src_filename, std::string name,
|
|||
upload_error(error_message, "NoFileExtension", filename, args);
|
||||
return;
|
||||
}
|
||||
else if( exten == "bmp")
|
||||
else if (codec != IMG_CODEC_INVALID)
|
||||
{
|
||||
// It's an image file, the upload procedure is the same for all
|
||||
asset_type = LLAssetType::AT_TEXTURE;
|
||||
if (!LLViewerTextureList::createUploadFile(src_filename,
|
||||
filename,
|
||||
IMG_CODEC_BMP ))
|
||||
if (!LLViewerTextureList::createUploadFile(src_filename, filename, codec ))
|
||||
{
|
||||
error_message = llformat( "Problem with file %s:\n\n%s\n",
|
||||
src_filename.c_str(), LLImage::getLastError().c_str());
|
||||
src_filename.c_str(), LLImage::getLastError().c_str());
|
||||
args["FILE"] = src_filename;
|
||||
args["ERROR"] = LLImage::getLastError();
|
||||
upload_error(error_message, "ProblemWithFile", filename, args);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if( exten == "tga")
|
||||
{
|
||||
asset_type = LLAssetType::AT_TEXTURE;
|
||||
if (!LLViewerTextureList::createUploadFile(src_filename,
|
||||
filename,
|
||||
IMG_CODEC_TGA ))
|
||||
{
|
||||
error_message = llformat("Problem with file %s:\n\n%s\n",
|
||||
src_filename.c_str(), LLImage::getLastError().c_str());
|
||||
args["FILE"] = src_filename;
|
||||
args["ERROR"] = LLImage::getLastError();
|
||||
upload_error(error_message, "ProblemWithFile", filename, args);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if( exten == "jpg" || exten == "jpeg")
|
||||
{
|
||||
asset_type = LLAssetType::AT_TEXTURE;
|
||||
if (!LLViewerTextureList::createUploadFile(src_filename,
|
||||
filename,
|
||||
IMG_CODEC_JPEG ))
|
||||
{
|
||||
error_message = llformat("Problem with file %s:\n\n%s\n",
|
||||
src_filename.c_str(), LLImage::getLastError().c_str());
|
||||
args["FILE"] = src_filename;
|
||||
args["ERROR"] = LLImage::getLastError();
|
||||
upload_error(error_message, "ProblemWithFile", filename, args);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if( exten == "png")
|
||||
{
|
||||
asset_type = LLAssetType::AT_TEXTURE;
|
||||
if (!LLViewerTextureList::createUploadFile(src_filename,
|
||||
filename,
|
||||
IMG_CODEC_PNG ))
|
||||
{
|
||||
error_message = llformat("Problem with file %s:\n\n%s\n",
|
||||
src_filename.c_str(), LLImage::getLastError().c_str());
|
||||
args["FILE"] = src_filename;
|
||||
args["ERROR"] = LLImage::getLastError();
|
||||
upload_error(error_message, "ProblemWithFile", filename, args);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if(exten == "wav")
|
||||
{
|
||||
asset_type = LLAssetType::AT_SOUND; // tag it as audio
|
||||
|
|
|
|||
|
|
@ -927,99 +927,43 @@ void LLViewerTextureList::decodeAllImages(F32 max_time)
|
|||
BOOL LLViewerTextureList::createUploadFile(const std::string& filename,
|
||||
const std::string& out_filename,
|
||||
const U8 codec)
|
||||
{
|
||||
// First, load the image.
|
||||
{
|
||||
// Load the image
|
||||
LLPointer<LLImageFormatted> image = LLImageFormatted::createFromType(codec);
|
||||
if (image.isNull())
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
if (!image->load(filename))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
// Decompress or expand it in a raw image structure
|
||||
LLPointer<LLImageRaw> raw_image = new LLImageRaw;
|
||||
|
||||
switch (codec)
|
||||
if (!image->decode(raw_image, 0.0f))
|
||||
{
|
||||
case IMG_CODEC_BMP:
|
||||
{
|
||||
LLPointer<LLImageBMP> bmp_image = new LLImageBMP;
|
||||
|
||||
if (!bmp_image->load(filename))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!bmp_image->decode(raw_image, 0.0f))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case IMG_CODEC_TGA:
|
||||
{
|
||||
LLPointer<LLImageTGA> tga_image = new LLImageTGA;
|
||||
|
||||
if (!tga_image->load(filename))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!tga_image->decode(raw_image))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if( (tga_image->getComponents() != 3) &&
|
||||
(tga_image->getComponents() != 4) )
|
||||
{
|
||||
tga_image->setLastError( "Image files with less than 3 or more than 4 components are not supported." );
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case IMG_CODEC_JPEG:
|
||||
{
|
||||
LLPointer<LLImageJPEG> jpeg_image = new LLImageJPEG;
|
||||
|
||||
if (!jpeg_image->load(filename))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!jpeg_image->decode(raw_image, 0.0f))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case IMG_CODEC_PNG:
|
||||
{
|
||||
LLPointer<LLImagePNG> png_image = new LLImagePNG;
|
||||
|
||||
if (!png_image->load(filename))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!png_image->decode(raw_image, 0.0f))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
LLPointer<LLImageJ2C> compressedImage = convertToUploadFile(raw_image);
|
||||
|
||||
if( !compressedImage->save(out_filename) )
|
||||
{
|
||||
llinfos << "Couldn't create output file " << out_filename << llendl;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// test to see if the encode and save worked.
|
||||
// Check the image constraints
|
||||
if ((image->getComponents() != 3) && (image->getComponents() != 4))
|
||||
{
|
||||
image->setLastError("Image files with less than 3 or more than 4 components are not supported.");
|
||||
return FALSE;
|
||||
}
|
||||
// Convert to j2c (JPEG2000) and save the file locally
|
||||
LLPointer<LLImageJ2C> compressedImage = convertToUploadFile(raw_image);
|
||||
if (!compressedImage->save(out_filename))
|
||||
{
|
||||
llinfos << "Couldn't create output file : " << out_filename << llendl;
|
||||
return FALSE;
|
||||
}
|
||||
// Test to see if the encode and save worked
|
||||
LLPointer<LLImageJ2C> integrity_test = new LLImageJ2C;
|
||||
if( !integrity_test->loadAndValidate( out_filename ) )
|
||||
if (!integrity_test->loadAndValidate( out_filename ))
|
||||
{
|
||||
llinfos << "Image: " << out_filename << " is corrupt." << llendl;
|
||||
llinfos << "Image file : " << out_filename << " is corrupt" << llendl;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue