// static void LLPostCard::send(LLPointer<LLImageFormatted> image, const LLSD& postcard_data) { // <FS:ND> Crashfix; image can end up being 0 if( image.isNull() ) { llwarns << "Passed invalid image into LLPostcard::send() [0 pointer]" << llendl; return; } // </FS:ND> LLTransactionID transaction_id; LLAssetID asset_id; transaction_id.generate(); asset_id = transaction_id.makeAssetID(gAgent.getSecureSessionID()); LLVFile::writeFile(image->getData(), image->getDataSize(), gVFS, asset_id, LLAssetType::AT_IMAGE_JPEG); // upload the image std::string url = gAgent.getRegion()->getCapability("SendPostcard"); if (!url.empty()) { llinfos << "Sending postcard via capability" << llendl; // the capability already encodes: agent ID, region ID LL_DEBUGS("Snapshots") << "url: " << url << llendl; LL_DEBUGS("Snapshots") << "body: " << postcard_data << llendl; LL_DEBUGS("Snapshots") << "data size: " << image->getDataSize() << llendl; LLHTTPClient::post(url, postcard_data, new LLPostcardSendResponder(postcard_data, asset_id, LLAssetType::AT_IMAGE_JPEG)); } else { llinfos << "Sending postcard" << llendl; LLSD* data = new LLSD(postcard_data); (*data)["asset-id"] = asset_id; gAssetStorage->storeAssetData(transaction_id, LLAssetType::AT_IMAGE_JPEG, &postcard_upload_callback, (void *)data, FALSE); } }
// static void LLFloaterAuction::onClickSnapshot(void* data) { LLFloaterAuction* self = (LLFloaterAuction*)(data); LLPointer<LLImageRaw> raw = new LLImageRaw; gForceRenderLandFence = self->getChild<LLUICtrl>("fence_check")->getValue().asBoolean(); BOOL success = gViewerWindow->rawSnapshot(raw, gViewerWindow->getWindowWidthScaled(), gViewerWindow->getWindowHeightScaled(), TRUE, FALSE, FALSE, FALSE); gForceRenderLandFence = FALSE; if (success) { self->mTransactionID.generate(); self->mImageID = self->mTransactionID.makeAssetID(gAgent.getSecureSessionID()); // <FS:PP> FIRE-8190: Preview function for "UI Sounds" Panel // if(!gSavedSettings.getBOOL("QuietSnapshotsToDisk")) if(!gSavedSettings.getBOOL("PlayModeUISndSnapshot")) // </FS:PP> FIRE-8190: Preview function for "UI Sounds" Panel { gViewerWindow->playSnapshotAnimAndSound(); } llinfos << "Writing TGA..." << llendl; LLPointer<LLImageTGA> tga = new LLImageTGA; tga->encode(raw); LLVFile::writeFile(tga->getData(), tga->getDataSize(), gVFS, self->mImageID, LLAssetType::AT_IMAGE_TGA); raw->biasedScaleToPowerOfTwo(LLViewerTexture::MAX_IMAGE_SIZE_DEFAULT); llinfos << "Writing J2C..." << llendl; LLPointer<LLImageJ2C> j2c = new LLImageJ2C; j2c->encode(raw, 0.0f); LLVFile::writeFile(j2c->getData(), j2c->getDataSize(), gVFS, self->mImageID, LLAssetType::AT_TEXTURE); self->mImage = LLViewerTextureManager::getLocalTexture((LLImageRaw*)raw, FALSE); gGL.getTexUnit(0)->bind(self->mImage); self->mImage->setAddressMode(LLTexUnit::TAM_CLAMP); } else { llwarns << "Unable to take snapshot" << llendl; } }
// static void LLFloaterAuction::onClickSnapshot(void* data) { LLFloaterAuction* self = (LLFloaterAuction*)(data); LLPointer<LLImageRaw> raw = new LLImageRaw; gForceRenderLandFence = self->childGetValue("fence_check").asBoolean(); BOOL success = gViewerWindow->rawSnapshot(raw, gViewerWindow->getWindowWidth(), gViewerWindow->getWindowHeight(), TRUE, FALSE, FALSE, FALSE); gForceRenderLandFence = FALSE; if (success) { self->mTransactionID.generate(); self->mImageID = self->mTransactionID.makeAssetID(gAgent.getSecureSessionID()); if(!gSavedSettings.getBOOL("QuietSnapshotsToDisk")) { gViewerWindow->playSnapshotAnimAndSound(); } llinfos << "Writing TGA..." << llendl; LLPointer<LLImageTGA> tga = new LLImageTGA; tga->encode(raw); LLVFile::writeFile(tga->getData(), tga->getDataSize(), gVFS, self->mImageID, LLAssetType::AT_IMAGE_TGA); raw->biasedScaleToPowerOfTwo(LLViewerImage::MAX_IMAGE_SIZE_DEFAULT); llinfos << "Writing J2C..." << llendl; LLPointer<LLImageJ2C> j2c = new LLImageJ2C; j2c->encode(raw, 0.0f); LLVFile::writeFile(j2c->getData(), j2c->getDataSize(), gVFS, self->mImageID, LLAssetType::AT_TEXTURE); self->mImage = new LLImageGL((LLImageRaw*)raw, FALSE); self->mImage->bind(); self->mImage->setClamp(TRUE, TRUE); } else { llwarns << "Unable to take snapshot" << llendl; } }
// static void LLWebProfile::post(LLPointer<LLImageFormatted> image, const LLSD& config, const std::string& url) { if (dynamic_cast<LLImagePNG*>(image.get()) == 0) { llwarns << "Image to upload is not a PNG" << llendl; llassert(dynamic_cast<LLImagePNG*>(image.get()) != 0); return; } const std::string boundary = "----------------------------0123abcdefab"; LLSD headers = LLViewerMedia::getHeaders(); headers["Cookie"] = getAuthCookie(); headers["Content-Type"] = "multipart/form-data; boundary=" + boundary; std::ostringstream body; // *NOTE: The order seems to matter. body << "--" << boundary << "\r\n" << "Content-Disposition: form-data; name=\"key\"\r\n\r\n" << config["key"].asString() << "\r\n"; body << "--" << boundary << "\r\n" << "Content-Disposition: form-data; name=\"AWSAccessKeyId\"\r\n\r\n" << config["AWSAccessKeyId"].asString() << "\r\n"; body << "--" << boundary << "\r\n" << "Content-Disposition: form-data; name=\"acl\"\r\n\r\n" << config["acl"].asString() << "\r\n"; body << "--" << boundary << "\r\n" << "Content-Disposition: form-data; name=\"Content-Type\"\r\n\r\n" << config["Content-Type"].asString() << "\r\n"; body << "--" << boundary << "\r\n" << "Content-Disposition: form-data; name=\"policy\"\r\n\r\n" << config["policy"].asString() << "\r\n"; body << "--" << boundary << "\r\n" << "Content-Disposition: form-data; name=\"signature\"\r\n\r\n" << config["signature"].asString() << "\r\n"; body << "--" << boundary << "\r\n" << "Content-Disposition: form-data; name=\"success_action_redirect\"\r\n\r\n" << config["success_action_redirect"].asString() << "\r\n"; body << "--" << boundary << "\r\n" << "Content-Disposition: form-data; name=\"file\"; filename=\"snapshot.png\"\r\n" << "Content-Type: image/png\r\n\r\n"; // Insert the image data. // *FIX: Treating this as a string will probably screw it up ... U8* image_data = image->getData(); for (S32 i = 0; i < image->getDataSize(); ++i) { body << image_data[i]; } body << "\r\n--" << boundary << "--\r\n"; // postRaw() takes ownership of the buffer and releases it later. size_t size = body.str().size(); U8 *data = new U8[size]; memcpy(data, body.str().data(), size); // Send request, successful upload will trigger posting metadata. LLHTTPClient::postRaw(url, data, size, new LLWebProfileResponders::PostImageResponder(), headers); }
void output_image_stats(LLPointer<LLImageFormatted> image, const std::string &filename) { // Print out some statistical data on the image std::cout << "Image stats for : " << filename << ", extension : " << image->getExtension() << std::endl; std::cout << " with : " << (int)(image->getWidth()) << ", height : " << (int)(image->getHeight()) << std::endl; std::cout << " comp : " << (int)(image->getComponents()) << ", levels : " << (int)(image->getDiscardLevel()) << std::endl; std::cout << " head : " << (int)(image->calcHeaderSize()) << ", data : " << (int)(image->getDataSize()) << std::endl; return; }
// static void LLWebProfile::post(LLPointer<LLImageFormatted> image, const LLSD& config, const std::string& url) { if (dynamic_cast<LLImagePNG*>(image.get()) == 0) { LL_WARNS() << "Image to upload is not a PNG" << LL_ENDL; llassert(dynamic_cast<LLImagePNG*>(image.get()) != 0); return; } const std::string boundary = "----------------------------0123abcdefab"; AIHTTPHeaders headers; headers.addHeader("Accept", "*/*"); headers.addHeader("Cookie", LLWebProfile::getAuthCookie()); headers.addHeader("User-Agent", LLViewerMedia::getCurrentUserAgent()); headers.addHeader("Content-Type", "multipart/form-data; boundary=" + boundary); std::ostringstream body; // *NOTE: The order seems to matter. body << "--" << boundary << "\r\n" << "Content-Disposition: form-data; name=\"key\"\r\n\r\n" << config["key"].asString() << "\r\n"; body << "--" << boundary << "\r\n" << "Content-Disposition: form-data; name=\"AWSAccessKeyId\"\r\n\r\n" << config["AWSAccessKeyId"].asString() << "\r\n"; body << "--" << boundary << "\r\n" << "Content-Disposition: form-data; name=\"acl\"\r\n\r\n" << config["acl"].asString() << "\r\n"; body << "--" << boundary << "\r\n" << "Content-Disposition: form-data; name=\"Content-Type\"\r\n\r\n" << config["Content-Type"].asString() << "\r\n"; body << "--" << boundary << "\r\n" << "Content-Disposition: form-data; name=\"policy\"\r\n\r\n" << config["policy"].asString() << "\r\n"; body << "--" << boundary << "\r\n" << "Content-Disposition: form-data; name=\"signature\"\r\n\r\n" << config["signature"].asString() << "\r\n"; body << "--" << boundary << "\r\n" << "Content-Disposition: form-data; name=\"success_action_redirect\"\r\n\r\n" << config["success_action_redirect"].asString() << "\r\n"; body << "--" << boundary << "\r\n" << "Content-Disposition: form-data; name=\"file\"; filename=\"snapshot.png\"\r\n" << "Content-Type: image/png\r\n\r\n"; size_t const body_size = body.str().size(); std::ostringstream footer; footer << "\r\n--" << boundary << "--\r\n"; size_t const footer_size = footer.str().size(); size_t size = body_size + image->getDataSize() + footer_size; // postRaw() takes ownership of the buffer and releases it later. U8* data = new U8 [size]; memcpy(data, body.str().data(), body_size); // Insert the image data. memcpy(data + body_size, image->getData(), image->getDataSize()); memcpy(data + body_size + image->getDataSize(), footer.str().data(), footer_size); // Send request, successful upload will trigger posting metadata. LLHTTPClient::postRaw(url, data, size, new LLWebProfileResponders::PostImageResponder(), headers/*,*/ DEBUG_CURLIO_PARAM(debug_off), no_keep_alive); }
// Create the baked texture, send it out to the server, then wait for it to come // back so we can switch to using it. void LLViewerTexLayerSetBuffer::doUpload() { LLViewerTexLayerSet* layer_set = getViewerTexLayerSet(); LL_INFOS() << "Uploading baked " << layer_set->getBodyRegionName() << LL_ENDL; LLViewerStats::getInstance()->incStat(LLViewerStats::ST_TEX_BAKES); // Don't need caches since we're baked now. (note: we won't *really* be baked // until this image is sent to the server and the Avatar Appearance message is received.) layer_set->deleteCaches(); // Get the COLOR information from our texture U8* baked_color_data = new U8[ mFullWidth * mFullHeight * 4 ]; glReadPixels(mOrigin.mX, mOrigin.mY, mFullWidth, mFullHeight, GL_RGBA, GL_UNSIGNED_BYTE, baked_color_data ); stop_glerror(); // Get the MASK information from our texture LLGLSUIDefault gls_ui; LLPointer<LLImageRaw> baked_mask_image = new LLImageRaw(mFullWidth, mFullHeight, 1 ); U8* baked_mask_data = baked_mask_image->getData(); layer_set->gatherMorphMaskAlpha(baked_mask_data, mOrigin.mX, mOrigin.mY, mFullWidth, mFullHeight); // Create the baked image from our color and mask information const S32 baked_image_components = 5; // red green blue [bump] clothing LLPointer<LLImageRaw> baked_image = new LLImageRaw( mFullWidth, mFullHeight, baked_image_components ); U8* baked_image_data = baked_image->getData(); S32 i = 0; for (S32 u=0; u < mFullWidth; u++) { for (S32 v=0; v < mFullHeight; v++) { baked_image_data[5*i + 0] = baked_color_data[4*i + 0]; baked_image_data[5*i + 1] = baked_color_data[4*i + 1]; baked_image_data[5*i + 2] = baked_color_data[4*i + 2]; baked_image_data[5*i + 3] = baked_color_data[4*i + 3]; // alpha should be correct for eyelashes. baked_image_data[5*i + 4] = baked_mask_data[i]; i++; } } LLPointer<LLImageJ2C> compressedImage = new LLImageJ2C; const char* comment_text = LINDEN_J2C_COMMENT_PREFIX "RGBHM"; // writes into baked_color_data. 5 channels (rgb, heightfield/alpha, mask) if (compressedImage->encode(baked_image, comment_text)) { LLTransactionID tid; tid.generate(); const LLAssetID asset_id = tid.makeAssetID(gAgent.getSecureSessionID()); if (LLVFile::writeFile(compressedImage->getData(), compressedImage->getDataSize(), gVFS, asset_id, LLAssetType::AT_TEXTURE)) { // Read back the file and validate. BOOL valid = FALSE; LLPointer<LLImageJ2C> integrity_test = new LLImageJ2C; S32 file_size = 0; U8* data = LLVFile::readFile(gVFS, LLImageBase::getPrivatePool(), asset_id, LLAssetType::AT_TEXTURE, &file_size); if (data) { valid = integrity_test->validate(data, file_size); // integrity_test will delete 'data' } else { integrity_test->setLastError("Unable to read entire file"); } if (valid) { const bool highest_lod = layer_set->isLocalTextureDataFinal(); // Baked_upload_data is owned by the responder and deleted after the request completes. LLBakedUploadData* baked_upload_data = new LLBakedUploadData(gAgentAvatarp, layer_set, asset_id, highest_lod); // upload ID is used to avoid overlaps, e.g. when the user rapidly makes two changes outside of Face Edit. mUploadID = asset_id; // Upload the image const std::string url = gAgent.getRegion()->getCapability("UploadBakedTexture"); if(!url.empty() && !LLPipeline::sForceOldBakedUpload // toggle debug setting UploadBakedTexOld to change between the new caps method and old method && (mUploadFailCount < (BAKE_UPLOAD_ATTEMPTS - 1))) // Try last ditch attempt via asset store if cap upload is failing. { LLSD body = LLSD::emptyMap(); // The responder will call LLViewerTexLayerSetBuffer::onTextureUploadComplete() LLHTTPClient::post(url, body, new LLSendTexLayerResponder(body, mUploadID, LLAssetType::AT_TEXTURE, baked_upload_data)); LL_INFOS() << "Baked texture upload via capability of " << mUploadID << " to " << url << LL_ENDL; } else { gAssetStorage->storeAssetData(tid, LLAssetType::AT_TEXTURE, LLViewerTexLayerSetBuffer::onTextureUploadComplete, baked_upload_data, TRUE, // temp_file TRUE, // is_priority TRUE); // store_local LL_INFOS() << "Baked texture upload via Asset Store." << LL_ENDL; } if (highest_lod) { // Sending the final LOD for the baked texture. All done, pause // the upload timer so we know how long it took. mNeedsUpload = FALSE; mNeedsUploadTimer.pause(); } else { // Sending a lower level LOD for the baked texture. Restart the upload timer. mNumLowresUploads++; mNeedsUploadTimer.unpause(); mNeedsUploadTimer.reset(); } // Print out notification that we uploaded this texture. if (gSavedSettings.getBOOL("DebugAvatarRezTime")) { const std::string lod_str = highest_lod ? "HighRes" : "LowRes"; LLSD args; args["EXISTENCE"] = llformat("%d",(U32)layer_set->getAvatar()->debugGetExistenceTimeElapsedF32()); args["TIME"] = llformat("%d",(U32)mNeedsUploadTimer.getElapsedTimeF32()); args["BODYREGION"] = layer_set->getBodyRegionName(); args["RESOLUTION"] = lod_str; LLNotificationsUtil::add("AvatarRezSelfBakedTextureUploadNotification",args); LL_DEBUGS("Avatar") << self_av_string() << "Uploading [ name: " << layer_set->getBodyRegionName() << " res:" << lod_str << " time:" << (U32)mNeedsUploadTimer.getElapsedTimeF32() << " ]" << LL_ENDL; } } else { // The read back and validate operation failed. Remove the uploaded file. mUploadPending = FALSE; LLVFile file(gVFS, asset_id, LLAssetType::AT_TEXTURE, LLVFile::WRITE); file.remove(); LL_INFOS() << "Unable to create baked upload file (reason: corrupted)." << LL_ENDL; } } } else { // The VFS write file operation failed. mUploadPending = FALSE; LL_INFOS() << "Unable to create baked upload file (reason: failed to write file)" << LL_ENDL; } delete [] baked_color_data; }