summaryrefslogtreecommitdiff
path: root/indra/newview/llfloaterimagepreview.cpp
diff options
context:
space:
mode:
authorNyx (Neal Orman) <nyx@lindenlab.com>2011-05-17 12:13:54 -0400
committerNyx (Neal Orman) <nyx@lindenlab.com>2011-05-17 12:13:54 -0400
commit8f94ff85f9b0318f959f066a138eac03770838cf (patch)
tree7b2885af863ae16281f197c61bbedff4f2895e2c /indra/newview/llfloaterimagepreview.cpp
parent2deea74cf6f08376e14e2f7e5333fc6959d2af19 (diff)
parenta2d8f0cb3308fed1cb2c8d5fa8fb74ec4cefa45b (diff)
merging up latest mesh-development to nyx-mesh-development
Diffstat (limited to 'indra/newview/llfloaterimagepreview.cpp')
-rw-r--r--indra/newview/llfloaterimagepreview.cpp119
1 files changed, 24 insertions, 95 deletions
diff --git a/indra/newview/llfloaterimagepreview.cpp b/indra/newview/llfloaterimagepreview.cpp
index d360d5db55..e4d8e3513d 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;