本文整理汇总了C++中LLPointer::decode方法的典型用法代码示例。如果您正苦于以下问题:C++ LLPointer::decode方法的具体用法?C++ LLPointer::decode怎么用?C++ LLPointer::decode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LLPointer
的用法示例。
在下文中一共展示了LLPointer::decode方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createUploadFile
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.");
return FALSE;
}
if (!image->load(filename))
{
image->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.");
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;
}
// 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.");
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.");
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 ))
{
image->setLastError("The created jpeg2000 image is corrupt.");
llinfos << "Image file : " << out_filename << " is corrupt" << llendl;
return FALSE;
}
return TRUE;
}
示例2:
// Load an image from file and return a raw (decompressed) instance of its data
LLPointer<LLImageRaw> load_image(const std::string &src_filename, int discard_level, int* region, bool output_stats)
{
LLPointer<LLImageFormatted> image = create_image(src_filename);
// This just loads the image file stream into a buffer. No decoding done.
if (!image->load(src_filename))
{
return NULL;
}
if( (image->getComponents() != 3) && (image->getComponents() != 4) )
{
std::cout << "Image files with less than 3 or more than 4 components are not supported\n";
return NULL;
}
if (output_stats)
{
output_image_stats(image, src_filename);
}
LLPointer<LLImageRaw> raw_image = new LLImageRaw;
// Set the image restriction on load in the case of a j2c image
if ((image->getCodec() == IMG_CODEC_J2C) && ((discard_level != -1) || (region != NULL)))
{
// That method doesn't exist (and likely, doesn't make sense) for any other image file format
// hence the required cryptic cast.
((LLImageJ2C*)(image.get()))->initDecode(*raw_image, discard_level, region);
}
if (!image->decode(raw_image, 0.0f))
{
return NULL;
}
return raw_image;
}
示例3: createFromFile
bool LLImageRaw::createFromFile(const std::string &filename, bool j2c_lowest_mip_only)
{
std::string name = filename;
size_t dotidx = name.rfind('.');
S8 codec = IMG_CODEC_INVALID;
std::string exten;
deleteData(); // delete any existing data
if (dotidx != std::string::npos)
{
exten = name.substr(dotidx+1);
LLStringUtil::toLower(exten);
codec = getCodecFromExtension(exten);
}
else
{
exten = find_file(name, &codec);
name = name + "." + exten;
}
if (codec == IMG_CODEC_INVALID)
{
return false; // format not recognized
}
llifstream ifs(name, llifstream::binary);
if (!ifs.is_open())
{
// SJB: changed from LL_INFOS() to LL_DEBUGS() to reduce spam
LL_DEBUGS() << "Unable to open image file: " << name << LL_ENDL;
return false;
}
ifs.seekg (0, std::ios::end);
int length = ifs.tellg();
if (j2c_lowest_mip_only && length > 2048)
{
length = 2048;
}
ifs.seekg (0, std::ios::beg);
if (!length)
{
LL_INFOS() << "Zero length file file: " << name << LL_ENDL;
return false;
}
LLPointer<LLImageFormatted> image = LLImageFormatted::createFromType(codec);
llassert(image.notNull());
U8 *buffer = image->allocateData(length);
ifs.read ((char*)buffer, length);
ifs.close();
BOOL success;
success = image->updateData();
if (success)
{
if (j2c_lowest_mip_only && codec == IMG_CODEC_J2C)
{
S32 width = image->getWidth();
S32 height = image->getHeight();
S32 discard_level = 0;
while (width > 1 && height > 1 && discard_level < MAX_DISCARD_LEVEL)
{
width >>= 1;
height >>= 1;
discard_level++;
}
((LLImageJ2C *)((LLImageFormatted*)image))->setDiscardLevel(discard_level);
}
success = image->decode(this, 100000.0f);
}
示例4:
// Load an image from file and return a raw (decompressed) instance of its data
LLPointer<LLImageRaw> load_image(const std::string &src_filename, int discard_level, int* region, int load_size, bool output_stats)
{
LLPointer<LLImageFormatted> image = create_image(src_filename);
// We support partial loading only for j2c images
if (image->getCodec() == IMG_CODEC_J2C)
{
// Load the header
if (!image->load(src_filename, 600))
{
return NULL;
}
S32 h = ((LLImageJ2C*)(image.get()))->calcHeaderSize();
S32 d = (load_size > 0 ? ((LLImageJ2C*)(image.get()))->calcDiscardLevelBytes(load_size) : 0);
S8 r = ((LLImageJ2C*)(image.get()))->getRawDiscardLevel();
std::cout << "Merov debug : header = " << h << ", load_size = " << load_size << ", discard level = " << d << ", raw discard level = " << r << std::endl;
for (d = 0; d < MAX_DISCARD_LEVEL; d++)
{
S32 data_size = ((LLImageJ2C*)(image.get()))->calcDataSize(d);
std::cout << "Merov debug : discard_level = " << d << ", data_size = " << data_size << std::endl;
}
if (load_size < 0)
{
load_size = (discard_level != -1 ? ((LLImageJ2C*)(image.get()))->calcDataSize(discard_level) : 0);
}
// Load the requested byte range
if (!image->load(src_filename, load_size))
{
return NULL;
}
}
else
{
// This just loads the image file stream into a buffer. No decoding done.
if (!image->load(src_filename))
{
return NULL;
}
}
if( (image->getComponents() != 3) && (image->getComponents() != 4) )
{
std::cout << "Image files with less than 3 or more than 4 components are not supported\n";
return NULL;
}
if (output_stats)
{
output_image_stats(image, src_filename);
}
LLPointer<LLImageRaw> raw_image = new LLImageRaw;
// Set the image restriction on load in the case of a j2c image
if ((image->getCodec() == IMG_CODEC_J2C) && ((discard_level != -1) || (region != NULL)))
{
// That method doesn't exist (and likely, doesn't make sense) for any other image file format
// hence the required cryptic cast.
((LLImageJ2C*)(image.get()))->initDecode(*raw_image, discard_level, region);
}
if (!image->decode(raw_image, 0.0f))
{
return NULL;
}
return raw_image;
}