summaryrefslogtreecommitdiff
path: root/indra/newview
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview')
-rw-r--r--indra/newview/llfloaterimagepreview.cpp119
-rw-r--r--indra/newview/llviewermenufile.cpp55
-rw-r--r--indra/newview/llviewertexturelist.cpp110
3 files changed, 56 insertions, 228 deletions
diff --git a/indra/newview/llfloaterimagepreview.cpp b/indra/newview/llfloaterimagepreview.cpp
index c7fbdd5745..d76e7885bc 100644
--- a/indra/newview/llfloaterimagepreview.cpp
+++ b/indra/newview/llfloaterimagepreview.cpp
@@ -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;
}
-
+ // Load the image
+ LLPointer<LLImageFormatted> image = LLImageFormatted::createFromType(codec);
+ if (image.isNull())
+ {
+ return false;
+ }
+ if (!image->load(src_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(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;
}
-
+ // 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;
diff --git a/indra/newview/llviewermenufile.cpp b/indra/newview/llviewermenufile.cpp
index fda291f3c1..2cf8dbec89 100644
--- a/indra/newview/llviewermenufile.cpp
+++ b/indra/newview/llviewermenufile.cpp
@@ -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
diff --git a/indra/newview/llviewertexturelist.cpp b/indra/newview/llviewertexturelist.cpp
index 06f6ff23c2..5afed721ac 100644
--- a/indra/newview/llviewertexturelist.cpp
+++ b/indra/newview/llviewertexturelist.cpp
@@ -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;
+ return FALSE;
}
-
- LLPointer<LLImageJ2C> compressedImage = convertToUploadFile(raw_image);
-
- if( !compressedImage->save(out_filename) )
+ // Check the image constraints
+ if ((image->getComponents() != 3) && (image->getComponents() != 4))
{
- llinfos << "Couldn't create output file " << out_filename << llendl;
+ image->setLastError("Image files with less than 3 or more than 4 components are not supported.");
return FALSE;
}
-
- // test to see if the encode and save worked.
+ // 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;
}