1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
|
/*
* This file is part of RawTherapee.
*
* Copyright (c) 2004-2010 Gabor Horvath <hgabor@rawtherapee.com>
*
* RawTherapee is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* RawTherapee is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with RawTherapee. If not, see <https://www.gnu.org/licenses/>.
*/
#include "batchqueueentry.h"
#include <cstring>
#include "guiutils.h"
#include "threadutils.h"
#include "rtsurface.h"
#include "multilangmgr.h"
#include "thumbbrowserbase.h"
#include "thumbnail.h"
#include "rtsurface.h"
#include "rtengine/procparams.h"
#include "rtengine/rtengine.h"
bool BatchQueueEntry::iconsLoaded(false);
std::shared_ptr<RTSurface> BatchQueueEntry::savedAsIcon(std::shared_ptr<RTSurface>(nullptr));
BatchQueueEntry::BatchQueueEntry (rtengine::ProcessingJob* pjob, const rtengine::procparams::ProcParams& pparams, Glib::ustring fname, int prevw, int prevh, Thumbnail* thm, bool overwrite) :
ThumbBrowserEntryBase(fname, thm),
opreview(nullptr),
origpw(prevw),
origph(prevh),
opreviewDone(false),
job(pjob),
params(new rtengine::procparams::ProcParams(pparams)),
progress(0),
sequence(0),
forceFormatOpts(false),
fast_pipeline(job->fastPipeline()),
overwriteFile(overwrite)
{
thumbnail = thm;
#if 1 //ndef _WIN32
// The BatchQueueEntryIdleHelper tracks if an entry has been deleted while it was sitting waiting for "idle"
bqih = new BatchQueueEntryIdleHelper;
bqih->bqentry = this;
bqih->destroyed = false;
bqih->pending = 0;
#endif
if (!iconsLoaded) {
savedAsIcon = std::shared_ptr<RTSurface>(new RTSurface("save-small", Gtk::ICON_SIZE_SMALL_TOOLBAR));
iconsLoaded = true;
}
if (thumbnail) {
thumbnail->increaseRef ();
}
}
BatchQueueEntry::~BatchQueueEntry ()
{
batchQueueEntryUpdater.removeJobs (this);
if (opreview) {
delete [] opreview;
}
opreview = nullptr;
if (thumbnail) {
thumbnail->decreaseRef ();
}
if (bqih->pending) {
bqih->destroyed = true;
} else {
delete bqih;
}
}
void BatchQueueEntry::refreshThumbnailImage ()
{
if (!opreviewDone) {
// creating the image buffer first
//if (!opreview) opreview = new guint8[(origpw+1) * origph * 3];
// this will asynchronously compute the original preview and land at this.updateImage
batchQueueEntryUpdater.process (nullptr, origpw, origph, preh, this, params.get(), thumbnail);
} else {
// this will asynchronously land at this.updateImage
batchQueueEntryUpdater.process (opreview, origpw, origph, preh, this);
}
}
void BatchQueueEntry::calcThumbnailSize ()
{
prew = preh * origpw / origph;
const auto& options = App::get().options();
if (prew > options.maxThumbnailWidth) {
const float s = static_cast<float>(options.maxThumbnailWidth) / prew;
prew = options.maxThumbnailWidth;
preh = std::max<int>(preh * s, 1);
}
}
void BatchQueueEntry::drawProgressBar (Glib::RefPtr<Gdk::Window> win, const Gdk::RGBA& foregr, const Gdk::RGBA& backgr, int x, int w, int y, int h)
{
if (processing) {
Cairo::RefPtr<Cairo::Context> cr = win->create_cairo_context();
cr->set_antialias (Cairo::ANTIALIAS_SUBPIXEL);
double px = x + w / 6.0;
double pw = w * 2.0 / 3.0;
double py = y + h / 4.0;
double ph = h / 2.0;
cr->move_to (px, py);
cr->line_to (px + pw, py);
cr->set_line_width (ph);
cr->set_line_cap (Cairo::LINE_CAP_ROUND);
cr->set_source_rgb (foregr.get_red(), foregr.get_green(), foregr.get_blue());
cr->stroke ();
cr->move_to (px, py);
cr->line_to (px + pw, py);
cr->set_line_width (ph * 3.0 / 4.0);
cr->set_source_rgb (backgr.get_red(), backgr.get_green(), backgr.get_blue());
cr->stroke ();
cr->move_to (px, py);
cr->line_to (px + pw * progress, py);
cr->set_line_width (ph / 2.0);
cr->set_source_rgb (foregr.get_red(), foregr.get_green(), foregr.get_blue());
cr->stroke ();
}
}
void BatchQueueEntry::removeButtonSet ()
{
delete buttonSet;
buttonSet = nullptr;
}
std::vector<std::shared_ptr<RTSurface>> BatchQueueEntry::getIconsOnImageArea ()
{
std::vector<std::shared_ptr<RTSurface>> ret;
if (!outFileName.empty()) {
ret.push_back (savedAsIcon);
}
return ret;
}
void BatchQueueEntry::getIconSize (int& w, int& h) const
{
w = savedAsIcon->getWidth ();
h = savedAsIcon->getHeight ();
}
std::tuple<Glib::ustring, bool> BatchQueueEntry::getToolTip (int x, int y) const
{
// get the parent class' tooltip first
Glib::ustring tooltip;
bool useMarkup;
std::tie(tooltip, useMarkup) = ThumbBrowserEntryBase::getToolTip(x, y);
// add the saving param options
if (!outFileName.empty()) {
tooltip += Glib::ustring::compose("\n\n%1: %2", M("BATCHQUEUE_DESTFILENAME"), outFileName);
if (forceFormatOpts) {
tooltip += Glib::ustring::compose("\n\n%1: %2 (%3-bits%4)", M("SAVEDLG_FILEFORMAT"), saveFormat.format,
saveFormat.format == "png" ? saveFormat.pngBits :
saveFormat.format == "tif" ? saveFormat.tiffBits : 8,
saveFormat.format == "tif" && saveFormat.tiffFloat ? M("SAVEDLG_FILEFORMAT_FLOAT") : "");
if (saveFormat.format == "jpg") {
tooltip += Glib::ustring::compose("\n%1: %2\n%3: %4",
M("SAVEDLG_JPEGQUAL"), saveFormat.jpegQuality,
M("SAVEDLG_SUBSAMP"),
saveFormat.jpegSubSamp == 1 ? M("SAVEDLG_SUBSAMP_1") :
saveFormat.jpegSubSamp == 2 ? M("SAVEDLG_SUBSAMP_2") :
M("SAVEDLG_SUBSAMP_3"));
} else if (saveFormat.format == "tif") {
if (saveFormat.tiffUncompressed) {
tooltip += Glib::ustring::compose("\n%1", M("SAVEDLG_TIFFUNCOMPRESSED"));
}
if (saveFormat.bigTiff) {
tooltip += Glib::ustring::compose("\n%1", M("SAVEDLG_BIGTIFF"));
}
}
}
}
return std::make_tuple(std::move(tooltip), useMarkup);
}
struct BQUpdateParam {
BatchQueueEntryIdleHelper* bqih;
guint8* img;
int w, h;
};
int updateImageUIThread (void* data)
{
BQUpdateParam* params = static_cast<BQUpdateParam*>(data);
BatchQueueEntryIdleHelper* bqih = params->bqih;
GThreadLock tLock; // Acquire the GUI
// If the BQEntry was destroyed meanwhile, remove all the IdleHelper if all entries came through
if (bqih->destroyed) {
if (bqih->pending == 1) {
delete bqih;
} else {
bqih->pending--;
}
delete [] params->img;
delete params;
return 0;
}
bqih->bqentry->_updateImage (params->img, params->w, params->h);
bqih->pending--;
delete params;
return 0;
}
// Starts a copy of img->preview via GTK thread
void BatchQueueEntry::updateImage (guint8* img, int w, int h, int origw, int origh, guint8* newOPreview)
{
// since the update itself is already called in an async thread and there are problem with accessing opreview in thumbbrowserbase,
// it's safer to do this synchronously
{
GThreadLock lock;
_updateImage(img, w, h);
}
}
void BatchQueueEntry::_updateImage (guint8* img, int w, int h)
{
if (preh == h) {
MYWRITERLOCK(l, lockRW);
prew = w;
preview.resize(prew * preh * 3);
std::copy(img, img + preview.size(), preview.begin());
if (parent) {
parent->redrawNeeded (this);
}
}
delete [] img;
}
|