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; }