//----------------------------------------------------------------------------- // loadImage() //----------------------------------------------------------------------------- bool LLFloaterImagePreview::loadImage(const std::string& src_filename) { std::string exten = gDirUtilp->getExtension(src_filename); U32 codec = LLImageBase::getCodecFromExtension(exten); LLImageDimensionsInfo image_info; if (!image_info.load(src_filename,codec)) { mImageLoadError = image_info.getLastError(); return false; } S32 max_width = gSavedSettings.getS32("max_texture_dimension_X"); S32 max_height = gSavedSettings.getS32("max_texture_dimension_Y"); 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_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; 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; return true; }
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; }
// 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; }
// 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; }