Merge branch 'master' of https://github.com/AlericInglewood/SingularityViewer.git into testpit
Conflicts: indra/newview/lldrawpoolavatar.cpp indra/newview/llviewertexturelist.cpp indra/newview/llworldmap.cpp indra/newview/pipeline.cpp
This commit is contained in:
@@ -1053,54 +1053,78 @@ void LLViewerTextureList::decodeAllImages(F32 max_time)
|
||||
BOOL LLViewerTextureList::createUploadFile(const std::string& filename,
|
||||
const std::string& out_filename,
|
||||
const U8 codec)
|
||||
{
|
||||
{
|
||||
// Load the image
|
||||
LLPointer<LLImageFormatted> image = LLImageFormatted::createFromType(codec);
|
||||
if (image.isNull())
|
||||
{
|
||||
image->setLastError("Couldn't open the image to be uploaded.");
|
||||
LLImage::setLastError("Couldn't open the image to be uploaded.");
|
||||
return FALSE;
|
||||
}
|
||||
if (!image->load(filename))
|
||||
{
|
||||
image->setLastError("Couldn't load the image to be uploaded.");
|
||||
LLImage::setLastError("Couldn't load the image to be uploaded.");
|
||||
return FALSE;
|
||||
}
|
||||
// Decompress or expand it in a raw image structure
|
||||
LLPointer<LLImageRaw> raw_image = new LLImageRaw;
|
||||
if (!image->decode(raw_image, 0.0f))
|
||||
{
|
||||
image->setLastError("Couldn't decode the image to be uploaded.");
|
||||
LLImage::setLastError("Couldn't decode the image to be uploaded.");
|
||||
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.");
|
||||
LLImage::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.isNull())
|
||||
{
|
||||
image->setLastError("Couldn't convert the image to jpeg2000.");
|
||||
LLImage::setLastError("Couldn't convert the image to jpeg2000.");
|
||||
llinfos << "Couldn't convert to j2c, file : " << filename << llendl;
|
||||
return FALSE;
|
||||
}
|
||||
if (!compressedImage->save(out_filename))
|
||||
{
|
||||
image->setLastError("Couldn't create the jpeg2000 image for upload.");
|
||||
LLImage::setLastError("Couldn't create the jpeg2000 image for upload.");
|
||||
llinfos << "Couldn't create output file : " << out_filename << llendl;
|
||||
return FALSE;
|
||||
}
|
||||
return verifyUploadFile(out_filename, codec);
|
||||
}
|
||||
|
||||
static bool positive_power_of_two(int dim)
|
||||
{
|
||||
return dim > 0 && !(dim & (dim - 1));
|
||||
}
|
||||
|
||||
BOOL LLViewerTextureList::verifyUploadFile(const std::string& out_filename, const U8 codec)
|
||||
{
|
||||
// Test to see if the encode and save worked
|
||||
LLPointer<LLImageJ2C> integrity_test = new LLImageJ2C;
|
||||
if (!integrity_test->loadAndValidate( out_filename ))
|
||||
{
|
||||
image->setLastError("The created jpeg2000 image is corrupt.");
|
||||
LLImage::setLastError(std::string("The ") + ((codec == IMG_CODEC_J2C) ? "" : "created ") + "jpeg2000 image is corrupt: " + LLImage::getLastError());
|
||||
llinfos << "Image file : " << out_filename << " is corrupt" << llendl;
|
||||
return FALSE;
|
||||
}
|
||||
if (codec == IMG_CODEC_J2C)
|
||||
{
|
||||
if (integrity_test->getComponents() < 3 || integrity_test->getComponents() > 4)
|
||||
{
|
||||
LLImage::setLastError("Image files with less than 3 or more than 4 components are not supported.");
|
||||
return FALSE;
|
||||
}
|
||||
else if (!positive_power_of_two(integrity_test->getWidth()) ||
|
||||
!positive_power_of_two(integrity_test->getHeight()))
|
||||
{
|
||||
LLImage::setLastError("The width or height is not a (positive) power of two.");
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user