bool GfxProc::savefa(string *localfilepath, GfxProc::meta_t type, string *localdstpath) { if (!isgfx(localfilepath) // (this assumes that the width of the largest dimension is max) || !readbitmap(NULL, localfilepath, dimensions[sizeof dimensions/sizeof dimensions[0]-1][0])) { return false; } string jpeg; bool success = resizebitmap(dimensions[type][0], dimensions[type][1], &jpeg); freebitmap(); if (!success) { return false; } FileAccess *f = client->fsaccess->newfileaccess(); client->fsaccess->unlinklocal(localdstpath); if (!f->fopen(localdstpath, false, true)) { delete f; return false; } if (!f->fwrite((const byte*)jpeg.data(), jpeg.size(), 0)) { delete f; return false; } delete f; return true; }
bool GfxProc::savefa(string *localfilepath, int width, int height, string *localdstpath) { if (!isgfx(localfilepath)) { return false; } mutex.lock(); if (!readbitmap(NULL, localfilepath, width > height ? width : height)) { mutex.unlock(); return false; } int w = width; int h = height; if (this->w < w && this->h < h) { LOG_debug << "Skipping upsizing of local preview"; w = this->w; h = this->h; } string jpeg; bool success = resizebitmap(w, h, &jpeg); freebitmap(); mutex.unlock(); if (!success) { return false; } FileAccess *f = client->fsaccess->newfileaccess(); client->fsaccess->unlinklocal(localdstpath); if (!f->fopen(localdstpath, false, true)) { delete f; return false; } if (!f->fwrite((const byte*)jpeg.data(), unsigned(jpeg.size()), 0)) { delete f; return false; } delete f; return true; }
// load bitmap image, generate all designated sizes, attach to specified upload/node handle // FIXME: move to a worker thread to keep the engine nonblocking int GfxProc::gendimensionsputfa(FileAccess* fa, string* localfilename, handle th, SymmCipher* key, int missing) { int numputs = 0; if (SimpleLogger::logCurrentLevel >= logDebug) { string utf8path; client->fsaccess->local2path(localfilename, &utf8path); LOG_debug << "Creating thumb/preview for " << utf8path; } // (this assumes that the width of the largest dimension is max) if (readbitmap(fa, localfilename, dimensions[sizeof dimensions/sizeof dimensions[0]-1][0])) { string* jpeg = NULL; // successively downscale the original image for (int i = sizeof dimensions/sizeof dimensions[0]; i--; ) { if (!jpeg) { jpeg = new string; } if (missing & (1 << i) && resizebitmap(dimensions[i][0], dimensions[i][1], jpeg)) { // store the file attribute data - it will be attached to the file // immediately if the upload has already completed; otherwise, once // the upload completes int creqtag = client->reqtag; client->reqtag = 0; client->putfa(th, (meta_t)i, key, jpeg); client->reqtag = creqtag; numputs++; jpeg = NULL; } } if (jpeg) { delete jpeg; } freebitmap(); } return numputs; }
// load bitmap image, generate all designated sizes, attach to specified upload/node handle // FIXME: move to a worker thread to keep the engine nonblocking int GfxProc::gendimensionsputfa(FileAccess* fa, string* localfilename, handle th, SymmCipher* key, int missing) { int numputs = 0; if (isgfx(localfilename)) { // (this assumes that the width of the largest dimension is max) if (readbitmap(fa, localfilename, dimensions[sizeof dimensions/sizeof dimensions[0]-1][0])) { string* jpeg = NULL; // successively downscale the original image for (int i = sizeof dimensions/sizeof dimensions[0]; i--; ) { if (!jpeg) { jpeg = new string; } if (missing & (1 << i) && resizebitmap(dimensions[i][0], dimensions[i][1], jpeg)) { // store the file attribute data - it will be attached to the file // immediately if the upload has already completed; otherwise, once // the upload completes client->putfa(th, (meta_t)i, key, jpeg); numputs++; jpeg = NULL; } } if (jpeg) { delete jpeg; } freebitmap(); } } return numputs; }
void GfxProc::loop() { GfxJob *job = NULL; while (!finished) { waiter.init(NEVER); waiter.wait(); while ((job = requests.pop())) { if (finished) { delete job; break; } mutex.lock(); LOG_debug << "Processing media file: " << job->h; // (this assumes that the width of the largest dimension is max) if (readbitmap(NULL, &job->localfilename, dimensions[sizeof dimensions/sizeof dimensions[0]-1][0])) { for (unsigned i = 0; i < job->imagetypes.size(); i++) { // successively downscale the original image string* jpeg = new string(); int w = dimensions[job->imagetypes[i]][0]; int h = dimensions[job->imagetypes[i]][1]; if (job->imagetypes[i] == PREVIEW && this->w < w && this->h < h ) { LOG_debug << "Skipping upsizing of preview"; w = this->w; h = this->h; } if (!resizebitmap(w, h, jpeg)) { delete jpeg; jpeg = NULL; } job->images.push_back(jpeg); } freebitmap(); } else { for (unsigned i = 0; i < job->imagetypes.size(); i++) { job->images.push_back(NULL); } } mutex.unlock(); responses.push(job); client->waiter->notify(); } } while ((job = requests.pop())) { delete job; } while ((job = responses.pop())) { for (unsigned i = 0; i < job->imagetypes.size(); i++) { delete job->images[i]; } delete job; } }