From b08fb04daefd7a04bb9bbbc26a9a82e862525bfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fl=C3=B6ssie?= Date: Tue, 1 Jan 2019 15:53:39 +0100 Subject: [PATCH] Convert almost all `IdleRegister::add()` calls to `add(std::function<>)` --- rtgui/batchqueue.cc | 63 +++++------ rtgui/batchqueuepanel.cc | 12 +- rtgui/blackwhite.cc | 11 +- rtgui/colortoning.cc | 17 ++- rtgui/crop.cc | 236 ++++++++++++++++++++++++++------------- rtgui/crophandler.cc | 105 +++++++++-------- rtgui/dirpyrdenoise.cc | 58 +++++----- rtgui/editorpanel.cc | 102 +++++++---------- rtgui/filebrowser.cc | 16 +-- rtgui/filebrowser.h | 1 - rtgui/filecatalog.cc | 65 +++++------ rtgui/filecatalog.h | 2 +- rtgui/filepanel.cc | 11 +- rtgui/histogrampanel.cc | 33 +++--- rtgui/mydiagonalcurve.cc | 17 ++- rtgui/previewhandler.cc | 102 ++++++----------- rtgui/resize.cc | 61 +++++----- rtgui/retinex.cc | 24 ++-- rtgui/retinex.h | 1 - rtgui/tonecurve.cc | 151 +++++++++++-------------- rtgui/tonecurve.h | 4 +- rtgui/toolpanelcoord.cc | 92 +++++++-------- 22 files changed, 574 insertions(+), 610 deletions(-) diff --git a/rtgui/batchqueue.cc b/rtgui/batchqueue.cc index b0feeabb0..a995797f3 100644 --- a/rtgui/batchqueue.cc +++ b/rtgui/batchqueue.cc @@ -39,25 +39,6 @@ using namespace std; using namespace rtengine; -namespace -{ - -struct NLParams { - BatchQueueListener* listener; - int qsize; - bool queueRunning; - bool queueError; - Glib::ustring queueErrorMessage; -}; - -bool bqnotifylistenerUI(NLParams* params) -{ - params->listener->queueSizeChanged (params->qsize, params->queueRunning, params->queueError, params->queueErrorMessage); - return false; -} - -} - BatchQueue::BatchQueue (FileCatalog* aFileCatalog) : processing(nullptr), fileCatalog(aFileCatalog), sequence(0), listener(nullptr) { @@ -606,14 +587,13 @@ void BatchQueue::setProgress(double p) } // No need to acquire the GUI, setProgressUI will do it - const auto func = - [](BatchQueue* bq) -> bool + idle_register.add( + [this]() -> bool { - bq->redraw(); + redraw(); return false; - }; - - idle_register.add(func, this, false); + } + ); } void BatchQueue::setProgressStr(const Glib::ustring& str) @@ -638,12 +618,15 @@ void BatchQueue::error(const Glib::ustring& descr) } if (listener) { - NLParams* params = new NLParams; - params->listener = listener; - params->queueRunning = false; - params->queueError = true; - params->queueErrorMessage = descr; - idle_register.add(bqnotifylistenerUI, params, true); + BatchQueueListener* const bql = listener; + + idle_register.add( + [bql, descr]() -> bool + { + bql->queueSizeChanged(0, false, true, descr); + return false; + } + ); } } @@ -974,15 +957,21 @@ void BatchQueue::notifyListener () { const bool queueRunning = processing; if (listener) { - NLParams* params = new NLParams; - params->listener = listener; + BatchQueueListener* const bql = listener; + + int qsize = 0; { MYREADERLOCK(l, entryRW); - params->qsize = fd.size(); + qsize = fd.size(); } - params->queueRunning = queueRunning; - params->queueError = false; - idle_register.add(bqnotifylistenerUI, params, true); + + idle_register.add( + [bql, qsize, queueRunning]() -> bool + { + bql->queueSizeChanged(qsize, queueRunning, false, {}); + return false; + } + ); } } diff --git a/rtgui/batchqueuepanel.cc b/rtgui/batchqueuepanel.cc index 4c21feebf..55aea5f4f 100644 --- a/rtgui/batchqueuepanel.cc +++ b/rtgui/batchqueuepanel.cc @@ -172,14 +172,14 @@ BatchQueuePanel::BatchQueuePanel (FileCatalog* aFileCatalog) : parent(nullptr) show_all (); if (batchQueue->loadBatchQueue()) { - const auto func = - [](BatchQueue* bq) -> bool + idle_register.add( + [this]() -> bool { - bq->resizeLoadedQueue(); + batchQueue->resizeLoadedQueue(); return false; - }; - - idle_register.add(func, batchQueue, false, G_PRIORITY_LOW); + }, + G_PRIORITY_LOW + ); } } diff --git a/rtgui/blackwhite.cc b/rtgui/blackwhite.cc index 359207115..dcc5c7e01 100644 --- a/rtgui/blackwhite.cc +++ b/rtgui/blackwhite.cc @@ -375,14 +375,13 @@ void BlackWhite::BWChanged (double redbw, double greenbw, double bluebw) nextgreenbw = greenbw; nextbluebw = bluebw; - const auto func = - [](BlackWhite* self) -> bool + idle_register.add( + [this]() -> bool { - self->BWComputed_(); + BWComputed_(); return false; - }; - - idle_register.add(func, this, false); + } + ); } bool BlackWhite::BWComputed_ () diff --git a/rtgui/colortoning.cc b/rtgui/colortoning.cc index edff26ba5..025acb55f 100644 --- a/rtgui/colortoning.cc +++ b/rtgui/colortoning.cc @@ -891,17 +891,16 @@ void ColorToning::autoColorTonChanged(int bwct, int satthres, int satprot) nextsatth = satthres; nextsatpr = satprot; - const auto func = - [](ColorToning* self) -> bool + idle_register.add( + [this]() -> bool { - self->disableListener(); - self->saturatedOpacity->setValue(self->nextsatpr); - self->satProtectionThreshold->setValue(self->nextsatth); - self->enableListener(); + disableListener(); + saturatedOpacity->setValue(nextsatpr); + satProtectionThreshold->setValue(nextsatth); + enableListener(); return false; - }; - - idle_register.add(func, this, false); + } + ); } void ColorToning::adjusterChanged (ThresholdAdjuster* a, double newBottom, double newTop) diff --git a/rtgui/crop.cc b/rtgui/crop.cc index 52318fb79..1cd87b80a 100644 --- a/rtgui/crop.cc +++ b/rtgui/crop.cc @@ -28,29 +28,6 @@ extern Options options; namespace { -class RefreshSpinHelper -{ - -public: - Crop* crop; - bool notify; - RefreshSpinHelper (Crop* _crop, bool _notify) - : crop(_crop), notify(_notify) {} -}; - -bool refreshSpinsUI(RefreshSpinHelper* rsh) -{ - rsh->crop->refreshSpins(rsh->notify); - return false; -} - -bool notifyListenerUI(Crop* self) -{ - self->notifyListener(); - return false; -} - - inline void get_custom_ratio(int w, int h, double &rw, double &rh) { if (w < h) { @@ -120,28 +97,28 @@ Crop::Crop(): Gtk::Label* xlab = Gtk::manage (new Gtk::Label (M("TP_CROP_X") + ":")); setExpandAlignProperties(xlab, false, false, Gtk::ALIGN_START, Gtk::ALIGN_CENTER); - + x = Gtk::manage (new MySpinButton ()); setExpandAlignProperties(x, true, false, Gtk::ALIGN_END, Gtk::ALIGN_CENTER); x->set_width_chars(6); Gtk::Label* ylab = Gtk::manage (new Gtk::Label (M("TP_CROP_Y") + ":")); setExpandAlignProperties(ylab, false, false, Gtk::ALIGN_START, Gtk::ALIGN_CENTER); - + y = Gtk::manage (new MySpinButton ()); setExpandAlignProperties(y, true, false, Gtk::ALIGN_END, Gtk::ALIGN_CENTER); y->set_width_chars(6); - + Gtk::Label* wlab = Gtk::manage (new Gtk::Label (M("TP_CROP_W") + ":")); setExpandAlignProperties(wlab, false, false, Gtk::ALIGN_START, Gtk::ALIGN_CENTER); - + w = Gtk::manage (new MySpinButton ()); setExpandAlignProperties(w, true, false, Gtk::ALIGN_END, Gtk::ALIGN_CENTER); w->set_width_chars(6); Gtk::Label* hlab = Gtk::manage (new Gtk::Label (M("TP_CROP_H") + ":")); setExpandAlignProperties(hlab, false, false, Gtk::ALIGN_START, Gtk::ALIGN_CENTER); - + h = Gtk::manage (new MySpinButton ()); setExpandAlignProperties(h, true, false, Gtk::ALIGN_END, Gtk::ALIGN_CENTER); h->set_width_chars(6); @@ -155,7 +132,7 @@ Crop::Crop(): setExpandAlignProperties(resetCrop, true, false, Gtk::ALIGN_FILL, Gtk::ALIGN_CENTER); resetCrop->get_style_context()->add_class("independent"); resetCrop->set_image (*Gtk::manage (new RTImage ("undo-small.png"))); - + methodgrid->attach (*xlab, 0, 0, 1, 1); methodgrid->attach (*x, 1, 0, 1, 1); methodgrid->attach (*ylab, 2, 0, 1, 1); @@ -167,7 +144,7 @@ Crop::Crop(): methodgrid->attach (*selectCrop, 0, 2, 2, 1); methodgrid->attach (*resetCrop, 2, 2, 2, 1); pack_start (*methodgrid, Gtk::PACK_EXPAND_WIDGET, 0 ); - + Gtk::HSeparator* methodseparator = Gtk::manage (new Gtk::HSeparator()); methodseparator->get_style_context()->add_class("grid-row-separator"); pack_start (*methodseparator, Gtk::PACK_SHRINK, 0); @@ -179,7 +156,7 @@ Crop::Crop(): fixr = Gtk::manage (new Gtk::CheckButton (M("TP_CROP_FIXRATIO"))); setExpandAlignProperties(fixr, false, false, Gtk::ALIGN_START, Gtk::ALIGN_CENTER); fixr->set_active (1); - + Gtk::Grid* ratiogrid = Gtk::manage(new Gtk::Grid()); ratiogrid->get_style_context()->add_class("grid-spacing"); setExpandAlignProperties(ratiogrid, true, false, Gtk::ALIGN_FILL, Gtk::ALIGN_CENTER); @@ -193,15 +170,15 @@ Crop::Crop(): customRatioLabel = Gtk::manage(new Gtk::Label("")); customRatioLabel->hide(); setExpandAlignProperties(customRatioLabel, false, false, Gtk::ALIGN_CENTER, Gtk::ALIGN_CENTER); - + ratiogrid->set_column_homogeneous (true); ratiogrid->attach (*ratio, 0, 0, 1, 1); ratiogrid->attach (*customRatioLabel, 1, 0, 1, 1); ratiogrid->attach (*orientation, 1, 0, 1, 1); - + Gtk::Label* guidelab = Gtk::manage (new Gtk::Label (M("TP_CROP_GUIDETYPE"))); setExpandAlignProperties(guidelab, false, false, Gtk::ALIGN_START, Gtk::ALIGN_CENTER); - + guide = Gtk::manage (new MyComboBoxText ()); setExpandAlignProperties(guide, true, false, Gtk::ALIGN_FILL, Gtk::ALIGN_CENTER); @@ -220,27 +197,27 @@ Crop::Crop(): Gtk::HSeparator* ppiseparator = Gtk::manage (new Gtk::HSeparator()); ppiseparator->get_style_context()->add_class("grid-row-separator"); - + Gtk::Grid* ppisubgrid = Gtk::manage(new Gtk::Grid()); ppisubgrid->get_style_context()->add_class("grid-spacing"); setExpandAlignProperties(ppisubgrid, true, false, Gtk::ALIGN_FILL, Gtk::ALIGN_CENTER); Gtk::Label* ppilab = Gtk::manage (new Gtk::Label (M("TP_CROP_PPI"))); setExpandAlignProperties(ppilab, false, false, Gtk::ALIGN_START, Gtk::ALIGN_CENTER); - + ppi = Gtk::manage (new MySpinButton ()); setExpandAlignProperties(ppi, true, false, Gtk::ALIGN_END, Gtk::ALIGN_CENTER); ppi->set_width_chars(6); - + ppisubgrid->attach (*ppilab, 0, 0, 1, 1); ppisubgrid->attach (*ppi, 1, 0, 1, 1); sizecm = Gtk::manage (new Gtk::Label (M("GENERAL_NA") + " cm x " + M("GENERAL_NA") + " cm")); setExpandAlignProperties(sizecm, false, false, Gtk::ALIGN_CENTER, Gtk::ALIGN_CENTER); - + sizein = Gtk::manage (new Gtk::Label (M("GENERAL_NA") + " in x " + M("GENERAL_NA") + " in")); setExpandAlignProperties(sizein, false, false, Gtk::ALIGN_CENTER, Gtk::ALIGN_CENTER); - + ppigrid->attach (*ppiseparator, 0, 0, 2, 1); ppigrid->attach (*sizecm, 1, 1, 1, 1); ppigrid->attach (*sizein, 1, 2, 1, 1); @@ -326,7 +303,7 @@ Crop::Crop(): ppisubgrid->set_column_spacing(4); #endif //GTK318 - + show_all (); } @@ -423,7 +400,7 @@ void Crop::read (const ProcParams* pp, const ParamsEdited* pedited) } else if (pp->crop.ratio == "Current") { ratio->set_active(1); updateCurrentRatio(); - customRatioLabel->show(); + customRatioLabel->show(); orientation->hide(); } else { ratio->set_active_text (pp->crop.ratio); @@ -589,7 +566,13 @@ void Crop::doresetCrop () int W = maxw; int H = maxh; cropResized (X, Y, W, H); - idle_register.add(notifyListenerUI, this, false); + idle_register.add( + [this]() -> bool + { + notifyListener(); + return false; + } + ); refreshSpins(); } @@ -628,13 +611,25 @@ void Crop::enabledChanged () void Crop::hFlipCrop () { nx = maxw - nx - nw; - idle_register.add(refreshSpinsUI, new RefreshSpinHelper(this, false), true); + idle_register.add( + [this]() -> bool + { + refreshSpins(false); + return false; + } + ); } void Crop::vFlipCrop () { ny = maxh - ny - nh; - idle_register.add(refreshSpinsUI, new RefreshSpinHelper(this, false), true); + idle_register.add( + [this]() -> bool + { + refreshSpins(false); + return false; + } + ); } void Crop::rotateCrop (int deg, bool hflip, bool vflip) @@ -674,7 +669,13 @@ void Crop::rotateCrop (int deg, bool hflip, bool vflip) } lastRotationDeg = deg; - idle_register.add(refreshSpinsUI, new RefreshSpinHelper(this, false), true); + idle_register.add( + [this]() -> bool + { + refreshSpins(false); + return false; + } + ); } void Crop::positionChanged () @@ -688,7 +689,13 @@ void Crop::positionChanged () int W = nw; int H = nh; cropMoved (X, Y, W, H); - idle_register.add(notifyListenerUI, this, false); + idle_register.add( + [this]() -> bool + { + notifyListener(); + return false; + } + ); } void Crop::widthChanged () @@ -701,7 +708,13 @@ void Crop::widthChanged () int W = (int)w->get_value (); int H = nh; cropWidth2Resized (X, Y, W, H); - idle_register.add(notifyListenerUI, this, false); + idle_register.add( + [this]() -> bool + { + notifyListener(); + return false; + } + ); } void Crop::heightChanged () @@ -714,7 +727,13 @@ void Crop::heightChanged () int W = nw; int H = (int)h->get_value (); cropHeight2Resized (X, Y, W, H); - idle_register.add(notifyListenerUI, this, false); + idle_register.add( + [this]() -> bool + { + notifyListener(); + return false; + } + ); } // Fixed ratio toggle button @@ -747,7 +766,7 @@ void Crop::ratioChanged () orientation->show(); customRatioLabel->hide(); } - + if (!fixr->get_active ()) { fixr->set_active(true); // will adjust ratio anyway } else { @@ -808,7 +827,13 @@ void Crop::adjustCropToRatio() } // This will save the options - idle_register.add(refreshSpinsUI, new RefreshSpinHelper(this, true), true); + idle_register.add( + [this]() -> bool + { + refreshSpins(true); + return false; + } + ); } void Crop::refreshSize () @@ -882,26 +907,13 @@ void Crop::setDimensions (int mw, int mh) void Crop::sizeChanged(int x, int y, int ow, int oh) { - struct Params { - Crop* crop; - int x; - int y; - }; - - Params* const params = new Params{ - this, - x, - y - }; - - const auto func = - [](Params* params) -> bool + idle_register.add( + [this, x, y]() -> bool { - params->crop->setDimensions(params->x, params->y); + setDimensions(x, y); return false; - }; - - idle_register.add(func, params, true); + } + ); } bool Crop::refreshSpins (bool notify) @@ -969,7 +981,13 @@ void Crop::cropMoved (int &X, int &Y, int &W, int &H) nw = W; nh = H; - idle_register.add(refreshSpinsUI, new RefreshSpinHelper(this, false), true); + idle_register.add( + [this]() -> bool + { + refreshSpins(false); + return false; + } + ); // Glib::signal_idle().connect (sigc::mem_fun(*this, &Crop::refreshSpins)); } @@ -1013,7 +1031,13 @@ void Crop::cropWidth1Resized (int &X, int &Y, int &W, int &H, float custom_ratio nw = W; nh = H; - idle_register.add(refreshSpinsUI, new RefreshSpinHelper(this, false), true); + idle_register.add( + [this]() -> bool + { + refreshSpins(false); + return false; + } + ); } void Crop::cropWidth2Resized (int &X, int &Y, int &W, int &H, float custom_ratio) @@ -1053,7 +1077,13 @@ void Crop::cropWidth2Resized (int &X, int &Y, int &W, int &H, float custom_ratio nw = W; nh = H; - idle_register.add(refreshSpinsUI, new RefreshSpinHelper(this, false), true); + idle_register.add( + [this]() -> bool + { + refreshSpins(false); + return false; + } + ); } void Crop::cropHeight1Resized (int &X, int &Y, int &W, int &H, float custom_ratio) @@ -1096,7 +1126,13 @@ void Crop::cropHeight1Resized (int &X, int &Y, int &W, int &H, float custom_rati nw = W; nh = H; - idle_register.add(refreshSpinsUI, new RefreshSpinHelper(this, false), true); + idle_register.add( + [this]() -> bool + { + refreshSpins(false); + return false; + } + ); } void Crop::cropHeight2Resized (int &X, int &Y, int &W, int &H, float custom_ratio) @@ -1136,7 +1172,13 @@ void Crop::cropHeight2Resized (int &X, int &Y, int &W, int &H, float custom_rati nw = W; nh = H; - idle_register.add(refreshSpinsUI, new RefreshSpinHelper(this, false), true); + idle_register.add( + [this]() -> bool + { + refreshSpins(false); + return false; + } + ); } void Crop::cropTopLeftResized (int &X, int &Y, int &W, int &H, float custom_ratio) @@ -1178,7 +1220,13 @@ void Crop::cropTopLeftResized (int &X, int &Y, int &W, int &H, float custom_rati nw = W; nh = H; - idle_register.add(refreshSpinsUI, new RefreshSpinHelper(this, false), true); + idle_register.add( + [this]() -> bool + { + refreshSpins(false); + return false; + } + ); } void Crop::cropTopRightResized (int &X, int &Y, int &W, int &H, float custom_ratio) @@ -1218,7 +1266,13 @@ void Crop::cropTopRightResized (int &X, int &Y, int &W, int &H, float custom_rat nw = W; nh = H; - idle_register.add(refreshSpinsUI, new RefreshSpinHelper(this, false), true); + idle_register.add( + [this]() -> bool + { + refreshSpins(false); + return false; + } + ); } void Crop::cropBottomLeftResized (int &X, int &Y, int &W, int &H, float custom_ratio) @@ -1258,7 +1312,13 @@ void Crop::cropBottomLeftResized (int &X, int &Y, int &W, int &H, float custom_r nw = W; nh = H; - idle_register.add(refreshSpinsUI, new RefreshSpinHelper(this, false), true); + idle_register.add( + [this]() -> bool + { + refreshSpins(false); + return false; + } + ); } void Crop::cropBottomRightResized (int &X, int &Y, int &W, int &H, float custom_ratio) @@ -1295,7 +1355,13 @@ void Crop::cropBottomRightResized (int &X, int &Y, int &W, int &H, float custom_ nw = W; nh = H; - idle_register.add(refreshSpinsUI, new RefreshSpinHelper(this, false), true); + idle_register.add( + [this]() -> bool + { + refreshSpins(false); + return false; + } + ); } void Crop::cropInit (int &x, int &y, int &w, int &h) @@ -1409,12 +1475,24 @@ void Crop::cropResized (int &x, int &y, int& x2, int& y2) nw = W; nh = H; - idle_register.add(refreshSpinsUI, new RefreshSpinHelper(this, false), true); + idle_register.add( + [this]() -> bool + { + refreshSpins(false); + return false; + } + ); } void Crop::cropManipReady () { - idle_register.add(notifyListenerUI, this, false); + idle_register.add( + [this]() -> bool + { + notifyListener(); + return false; + } + ); } double Crop::getRatio () const diff --git a/rtgui/crophandler.cc b/rtgui/crophandler.cc index 579d9af5b..fdb920269 100644 --- a/rtgui/crophandler.cc +++ b/rtgui/crophandler.cc @@ -338,70 +338,69 @@ void CropHandler::setDetailedCrop( bool expected = false; if (redraw_needed.compare_exchange_strong(expected, true)) { - const auto func = - [](CropHandler* self) -> bool + idle_register.add( + [this]() -> bool { - self->cimg.lock (); + cimg.lock (); - if (self->redraw_needed.exchange(false)) { - self->cropPixbuf.clear (); + if (redraw_needed.exchange(false)) { + cropPixbuf.clear (); - if (!self->enabled) { - self->cropimg.clear(); - self->cropimgtrue.clear(); - self->cimg.unlock (); - return false; - } - - if (!self->cropimg.empty()) { - if (self->cix == self->cropX && self->ciy == self->cropY && self->ciw == self->cropW && self->cih == self->cropH && self->cis == (self->zoom >= 1000 ? 1 : self->zoom / 10)) { - // calculate final image size - float czoom = self->zoom >= 1000 ? - self->zoom / 1000.f : - float((self->zoom/10) * 10) / float(self->zoom); - int imw = self->cropimg_width * czoom; - int imh = self->cropimg_height * czoom; - - if (imw > self->ww) { - imw = self->ww; - } - - if (imh > self->wh) { - imh = self->wh; - } - - Glib::RefPtr tmpPixbuf = Gdk::Pixbuf::create_from_data (self->cropimg.data(), Gdk::COLORSPACE_RGB, false, 8, self->cropimg_width, self->cropimg_height, 3 * self->cropimg_width); - self->cropPixbuf = Gdk::Pixbuf::create (Gdk::COLORSPACE_RGB, false, 8, imw, imh); - tmpPixbuf->scale (self->cropPixbuf, 0, 0, imw, imh, 0, 0, czoom, czoom, Gdk::INTERP_TILES); - tmpPixbuf.clear (); - - Glib::RefPtr tmpPixbuftrue = Gdk::Pixbuf::create_from_data (self->cropimgtrue.data(), Gdk::COLORSPACE_RGB, false, 8, self->cropimg_width, self->cropimg_height, 3 * self->cropimg_width); - self->cropPixbuftrue = Gdk::Pixbuf::create (Gdk::COLORSPACE_RGB, false, 8, imw, imh); - tmpPixbuftrue->scale (self->cropPixbuftrue, 0, 0, imw, imh, 0, 0, czoom, czoom, Gdk::INTERP_TILES); - tmpPixbuftrue.clear (); + if (!enabled) { + cropimg.clear(); + cropimgtrue.clear(); + cimg.unlock (); + return false; } - self->cropimg.clear(); - self->cropimgtrue.clear(); - } + if (!cropimg.empty()) { + if (cix == cropX && ciy == cropY && ciw == cropW && cih == cropH && cis == (zoom >= 1000 ? 1 : zoom / 10)) { + // calculate final image size + float czoom = zoom >= 1000 ? + zoom / 1000.f : + float((zoom/10) * 10) / float(zoom); + int imw = cropimg_width * czoom; + int imh = cropimg_height * czoom; - self->cimg.unlock (); + if (imw > ww) { + imw = ww; + } - if (self->displayHandler) { - self->displayHandler->cropImageUpdated (); + if (imh > wh) { + imh = wh; + } - if (self->initial.exchange(false)) { - self->displayHandler->initialImageArrived (); + Glib::RefPtr tmpPixbuf = Gdk::Pixbuf::create_from_data (cropimg.data(), Gdk::COLORSPACE_RGB, false, 8, cropimg_width, cropimg_height, 3 * cropimg_width); + cropPixbuf = Gdk::Pixbuf::create (Gdk::COLORSPACE_RGB, false, 8, imw, imh); + tmpPixbuf->scale (cropPixbuf, 0, 0, imw, imh, 0, 0, czoom, czoom, Gdk::INTERP_TILES); + tmpPixbuf.clear (); + + Glib::RefPtr tmpPixbuftrue = Gdk::Pixbuf::create_from_data (cropimgtrue.data(), Gdk::COLORSPACE_RGB, false, 8, cropimg_width, cropimg_height, 3 * cropimg_width); + cropPixbuftrue = Gdk::Pixbuf::create (Gdk::COLORSPACE_RGB, false, 8, imw, imh); + tmpPixbuftrue->scale (cropPixbuftrue, 0, 0, imw, imh, 0, 0, czoom, czoom, Gdk::INTERP_TILES); + tmpPixbuftrue.clear (); + } + + cropimg.clear(); + cropimgtrue.clear(); } + + cimg.unlock (); + + if (displayHandler) { + displayHandler->cropImageUpdated (); + + if (initial.exchange(false)) { + displayHandler->initialImageArrived (); + } + } + } else { + cimg.unlock(); } - } else { - self->cimg.unlock(); + + return false; } - - return false; - }; - - idle_register.add(func, this, false); + ); } } diff --git a/rtgui/dirpyrdenoise.cc b/rtgui/dirpyrdenoise.cc index 2e77bbaa9..613dc8d44 100644 --- a/rtgui/dirpyrdenoise.cc +++ b/rtgui/dirpyrdenoise.cc @@ -289,19 +289,18 @@ void DirPyrDenoise::chromaChanged (double autchroma, double autred, double autbl nextred = autred; nextblue = autblue; - const auto func = - [](DirPyrDenoise* self) -> bool + idle_register.add( + [this]() -> bool { - self->disableListener(); - self->chroma->setValue(self->nextchroma); - self->redchro->setValue(self->nextred); - self->bluechro->setValue(self->nextblue); - self->enableListener(); - self->updateNoiseLabel(); + disableListener(); + chroma->setValue(nextchroma); + redchro->setValue(nextred); + bluechro->setValue(nextblue); + enableListener(); + updateNoiseLabel(); return false; - }; - - idle_register.add(func, this, false); + } + ); } void DirPyrDenoise::noiseTilePrev (int tileX, int tileY, int prevX, int prevY, int sizeT, int sizeP) @@ -313,17 +312,16 @@ void DirPyrDenoise::noiseTilePrev (int tileX, int tileY, int prevX, int prevY, i nextsizeT = sizeT; nextsizeP = sizeP; - const auto func = - [](DirPyrDenoise* self) -> bool + idle_register.add( + [this]() -> bool { - self->disableListener(); - self->enableListener(); - self->updateTileLabel(); - self->updatePrevLabel(); + disableListener(); + enableListener(); + updateTileLabel(); + updatePrevLabel(); return false; - }; - - idle_register.add(func, this, false); + } + ); } void DirPyrDenoise::updateTileLabel () @@ -361,16 +359,18 @@ void DirPyrDenoise::updatePrevLabel () void DirPyrDenoise::noiseChanged (double nresid, double highresid) { - const auto func = - [](DirPyrDenoise* self) -> bool - { - self->disableListener(); - self->enableListener(); - self->updateNoiseLabel(); - return false; - }; + nextnresid = nresid; + nexthighresid = highresid; - idle_register.add(func, this, false); + idle_register.add( + [this]() -> bool + { + disableListener(); + enableListener(); + updateNoiseLabel(); + return false; + } + ); } void DirPyrDenoise::updateNoiseLabel() diff --git a/rtgui/editorpanel.cc b/rtgui/editorpanel.cc index 84890bf87..b0e945ce1 100644 --- a/rtgui/editorpanel.cc +++ b/rtgui/editorpanel.cc @@ -38,34 +38,15 @@ using namespace rtengine::procparams; namespace { -struct spparams { - double val; - Glib::ustring str; - MyProgressBar *pProgress; - Glib::RefPtr cssProvider; -}; - -bool setprogressStrUI(spparams* s) +void setprogressStrUI(double val, const Glib::ustring str, MyProgressBar* pProgress) { - if ( ! s->str.empty() ) { - s->pProgress->set_text ( M (s->str) ); + if (!str.empty()) { + pProgress->set_text(M(str)); } - if ( s->val >= 0 ) { - s->pProgress->set_fraction ( s->val ); - - if (s->cssProvider) { - if ( s->val < 1.0 ) { - s->cssProvider->load_from_data ("ProgressBar { background-color: red }"); - } else { - s->cssProvider->load_from_data ("ProgressBar { background-color: grey }"); - } - - s->pProgress->get_style_context()->set_background (s->pProgress->get_window()); - } + if (val >= 0.0) { + pProgress->set_fraction(val); } - - return false; } @@ -1186,19 +1167,28 @@ void EditorPanel::clearParamChanges() void EditorPanel::setProgress(double p) { - spparams *s = new spparams; - s->val = p; - s->pProgress = progressLabel; - idle_register.add(setprogressStrUI, s, true); + MyProgressBar* const pl = progressLabel; + + idle_register.add( + [p, pl]() -> bool + { + setprogressStrUI(p, {}, pl); + return false; + } + ); } void EditorPanel::setProgressStr(const Glib::ustring& str) { - spparams *s = new spparams; - s->str = str; - s->val = -1; - s->pProgress = progressLabel; - idle_register.add(setprogressStrUI, s, true); + MyProgressBar* const pl = progressLabel; + + idle_register.add( + [str, pl]() -> bool + { + setprogressStrUI(-1.0, str, pl); + return false; + } + ); } void EditorPanel::setProgressState(bool inProcessing) @@ -1243,39 +1233,27 @@ void EditorPanel::error(const Glib::ustring& descr) void EditorPanel::error(const Glib::ustring& title, const Glib::ustring& descr) { - struct errparams { - Glib::ustring descr; - Glib::ustring title; - EditorPanelIdleHelper* epih; - }; - epih->pending++; - errparams* const p = new errparams; - p->descr = descr; - p->title = title; - p->epih = epih; - const auto func = - [](errparams* p) -> bool + idle_register.add( + [this, descr, title]() -> bool { - if (p->epih->destroyed) - { - if (p->epih->pending == 1) { - delete p->epih; + if (epih->destroyed) { + if (epih->pending == 1) { + delete epih; } else { - p->epih->pending--; + --epih->pending; } return false; } - p->epih->epanel->displayError (p->title, p->descr); - p->epih->pending--; + epih->epanel->displayError(title, descr); + --epih->pending; return false; - }; - - idle_register.add(func, p, true); + } + ); } void EditorPanel::displayError(const Glib::ustring& title, const Glib::ustring& descr) @@ -1296,16 +1274,16 @@ void EditorPanel::displayError(const Glib::ustring& title, const Glib::ustring& // This is only called from the ThreadUI, so within the gtk thread void EditorPanel::refreshProcessingState (bool inProcessingP) { - spparams *s = new spparams; - s->pProgress = progressLabel; + double val; + Glib::ustring str; if (inProcessingP) { if (processingStartedTime == 0) { processingStartedTime = ::time (nullptr); } - s->str = "PROGRESSBAR_PROCESSING"; - s->val = 1.0; + val = 1.0; + str = "PROGRESSBAR_PROCESSING"; } else { // Set proc params of thumbnail. It saves it into the cache and updates the file browser. if (ipc && openThm && tpc->getChangedState()) { @@ -1326,8 +1304,8 @@ void EditorPanel::refreshProcessingState (bool inProcessingP) } // Set progress bar "done" - s->str = "PROGRESSBAR_READY"; - s->val = 0.0; + val = 0.0; + str = "PROGRESSBAR_READY"; #ifdef WIN32 @@ -1342,7 +1320,7 @@ void EditorPanel::refreshProcessingState (bool inProcessingP) isProcessing = inProcessingP; - setprogressStrUI (s); + setprogressStrUI(val, str, progressLabel); } void EditorPanel::info_toggled () diff --git a/rtgui/filebrowser.cc b/rtgui/filebrowser.cc index d6362036a..20cb3350f 100644 --- a/rtgui/filebrowser.cc +++ b/rtgui/filebrowser.cc @@ -1925,21 +1925,15 @@ void FileBrowser::openNextPreviousEditorImage (Glib::ustring fname, eRTNav nextP } } -void FileBrowser::_thumbRearrangementNeeded () -{ - refreshThumbImages (); // arrangeFiles is NOT enough -} - void FileBrowser::thumbRearrangementNeeded () { - const auto func = - [](FileBrowser* self) -> bool + idle_register.add( + [this]() -> bool { - self->_thumbRearrangementNeeded(); + refreshThumbImages();// arrangeFiles is NOT enough return false; - }; - - idle_register.add(func, this, false); + } + ); } void FileBrowser::selectionChanged () diff --git a/rtgui/filebrowser.h b/rtgui/filebrowser.h index f15c7c5e8..209399135 100644 --- a/rtgui/filebrowser.h +++ b/rtgui/filebrowser.h @@ -192,7 +192,6 @@ public: #endif void thumbRearrangementNeeded () override; - void _thumbRearrangementNeeded (); void selectionChanged () override; diff --git a/rtgui/filecatalog.cc b/rtgui/filecatalog.cc index 66f76bb61..aebd0f990 100644 --- a/rtgui/filecatalog.cc +++ b/rtgui/filecatalog.cc @@ -855,14 +855,13 @@ void FileCatalog::previewsFinished (int dir_id) currentEFS = dirEFS; } - const auto func = - [](FileCatalog* self) -> bool + idle_register.add( + [this]() -> bool { - self->previewsFinishedUI(); + previewsFinishedUI(); return false; - }; - - idle_register.add(func, this, false); + } + ); } void FileCatalog::setEnabled (bool e) @@ -901,10 +900,9 @@ void FileCatalog::refreshHeight () set_size_request(0, newHeight + 2); // HOMBRE: yeah, +2, there's always 2 pixels missing... sorry for this dirty hack O:) } -void FileCatalog::_openImage (std::vector tmb) +void FileCatalog::_openImage(const std::vector& tmb) { - - if (enabled && listener != nullptr) { + if (enabled && listener) { bool continueToLoad = true; for (size_t i = 0; i < tmb.size() && continueToLoad; i++) { @@ -919,40 +917,30 @@ void FileCatalog::_openImage (std::vector tmb) } } -struct FCOIParams { - FileCatalog* catalog; - std::vector tmb; -}; - -bool openRequestedUI(FCOIParams* params) -{ - params->catalog->_openImage (params->tmb); - return false; -} - void FileCatalog::filterApplied() { - const auto func = - [](FileCatalog* self) -> bool + idle_register.add( + [this]() -> bool { - self->_refreshProgressBar(); + _refreshProgressBar(); return false; - }; - - idle_register.add(func, this, false); + } + ); } void FileCatalog::openRequested(const std::vector& tmb) { - FCOIParams* params = new FCOIParams; - params->catalog = this; - params->tmb = tmb; - - for (size_t i = 0; i < tmb.size(); i++) { - tmb[i]->increaseRef (); + for (auto thumb : tmb) { + thumb->increaseRef(); } - idle_register.add(openRequestedUI, params, true); + idle_register.add( + [this, tmb]() -> bool + { + _openImage(tmb); + return false; + } + ); } void FileCatalog::deleteRequested(const std::vector& tbe, bool inclBatchProcessed) @@ -1821,11 +1809,14 @@ void FileCatalog::addAndOpenFile (const Glib::ustring& fname) FileBrowserEntry* entry = new FileBrowserEntry (tmb, file->get_parse_name ()); previewReady (selectedDirectoryId, entry); // open the file - FCOIParams* params = new FCOIParams; - params->catalog = this; - params->tmb.push_back (tmb); tmb->increaseRef (); - idle_register.add(openRequestedUI, params, true); + idle_register.add( + [this, tmb]() -> bool + { + _openImage({tmb}); + return false; + } + ); } catch(Gio::Error&) {} } diff --git a/rtgui/filecatalog.h b/rtgui/filecatalog.h index 7e613a2b4..8b5b14ed2 100644 --- a/rtgui/filecatalog.h +++ b/rtgui/filecatalog.h @@ -239,7 +239,7 @@ public: void on_realize() override; void reparseDirectory (); - void _openImage (std::vector tmb); + void _openImage (const std::vector& tmb); void zoomIn (); void zoomOut (); diff --git a/rtgui/filepanel.cc b/rtgui/filepanel.cc index 3df10d9df..5a344c8ba 100644 --- a/rtgui/filepanel.cc +++ b/rtgui/filepanel.cc @@ -139,14 +139,13 @@ FilePanel::FilePanel () : parent(nullptr), error(0) fileCatalog->setFileSelectionListener (this); - const auto func = - [](FilePanel* self) -> bool + idle_register.add( + [this]() -> bool { - self->init(); + init(); return false; - }; - - idle_register.add(func, this, false); + } + ); show_all (); } diff --git a/rtgui/histogrampanel.cc b/rtgui/histogrampanel.cc index 007e1187d..b6756a59c 100644 --- a/rtgui/histogrampanel.cc +++ b/rtgui/histogrampanel.cc @@ -562,14 +562,14 @@ void HistogramRGBArea::update (int valh, int rh, int gh, int bh) harih->pending++; - const auto func = - [](HistogramRGBAreaIdleHelper* harih) -> bool + idle_register.add( + [this]() -> bool { if (harih->destroyed) { if (harih->pending == 1) { delete harih; } else { - harih->pending--; + --harih->pending; } return false; @@ -578,12 +578,11 @@ void HistogramRGBArea::update (int valh, int rh, int gh, int bh) harih->harea->updateBackBuffer(-1, -1, -1); harih->harea->queue_draw (); - harih->pending--; + --harih->pending; return false; - }; - - idle_register.add(func, harih, false); + } + ); } void HistogramRGBArea::updateOptions (bool r, bool g, bool b, bool l, bool c, bool raw, bool bar) @@ -760,30 +759,30 @@ void HistogramArea::update( } haih->pending++; + // Can be done outside of the GUI thread - const auto func = - [](HistogramAreaIdleHelper* haih) -> bool + idle_register.add( + [this]() -> bool { if (haih->destroyed) { if (haih->pending == 1) { delete haih; } else { - haih->pending--; + --haih->pending; } return false; } - haih->harea->setDirty (true); - haih->harea->updateBackBuffer (); - haih->harea->queue_draw (); + haih->harea->setDirty(true); + haih->harea->updateBackBuffer(); + haih->harea->queue_draw(); - haih->pending--; + --haih->pending; return false; - }; - - idle_register.add(func, haih, false); + } + ); } void HistogramArea::updateBackBuffer () diff --git a/rtgui/mydiagonalcurve.cc b/rtgui/mydiagonalcurve.cc index 8a2e08d1a..4980f9bd9 100644 --- a/rtgui/mydiagonalcurve.cc +++ b/rtgui/mydiagonalcurve.cc @@ -1518,28 +1518,27 @@ void MyDiagonalCurve::updateBackgroundHistogram (LUTu & hist) mcih->pending++; - const auto func = - [](MyCurveIdleHelper* mcih) -> bool + idle_register.add( + [this]() -> bool { if (mcih->destroyed) { if (mcih->pending == 1) { delete mcih; } else { - mcih->pending--; + --mcih->pending; } return false; } - mcih->clearPixmap (); - mcih->myCurve->queue_draw (); + mcih->clearPixmap(); + mcih->myCurve->queue_draw(); - mcih->pending--; + --mcih->pending; return false; - }; - - idle_register.add(func, mcih, false); + } + ); } void MyDiagonalCurve::reset(const std::vector &resetCurve, double identityValue) diff --git a/rtgui/previewhandler.cc b/rtgui/previewhandler.cc index 5029397a0..2315b8c91 100644 --- a/rtgui/previewhandler.cc +++ b/rtgui/previewhandler.cc @@ -23,18 +23,6 @@ using namespace rtengine; using namespace rtengine::procparams; -namespace -{ - -struct iaimgpar { - IImage8* image; - PreviewHandlerIdleHelper* pih; - double scale; - CropParams cp; -}; - -} - PreviewHandler::PreviewHandler () : image(nullptr), previewScale(1.) { @@ -61,22 +49,14 @@ void PreviewHandler::setImage(rtengine::IImage8* i, double scale, const rtengine { pih->pending++; - iaimgpar* iap = new iaimgpar; - iap->image = i; - iap->pih = pih; - iap->scale = scale; - iap->cp = cp; - - const auto func = - [](iaimgpar* iap) -> bool + idle_register.add( + [this, i, scale, cp]() -> bool { - PreviewHandlerIdleHelper* const pih = iap->pih; - if (pih->destroyed) { if (pih->pending == 1) { delete pih; } else { - pih->pending--; + --pih->pending; } return false; @@ -84,21 +64,21 @@ void PreviewHandler::setImage(rtengine::IImage8* i, double scale, const rtengine if (pih->phandler->image) { IImage8* const oldImg = pih->phandler->image; - oldImg->getMutex().lock (); - pih->phandler->image = iap->image; - oldImg->getMutex().unlock (); + + oldImg->getMutex().lock(); + pih->phandler->image = i; + oldImg->getMutex().unlock(); } else { - pih->phandler->image = iap->image; + pih->phandler->image = i; } - pih->phandler->cropParams = iap->cp; - pih->phandler->previewScale = iap->scale; - pih->pending--; + pih->phandler->cropParams = cp; + pih->phandler->previewScale = scale; + --pih->pending; return false; - }; - - idle_register.add(func, iap, true); + } + ); } @@ -106,20 +86,14 @@ void PreviewHandler::delImage(IImage8* i) { pih->pending++; - iaimgpar* iap = new iaimgpar; - iap->image = i; - iap->pih = pih; - - const auto func = - [](iaimgpar* iap) -> bool + idle_register.add( + [this, i]() -> bool { - PreviewHandlerIdleHelper* const pih = iap->pih; - if (pih->destroyed) { if (pih->pending == 1) { delete pih; } else { - pih->pending--; + --pih->pending; } return false; @@ -127,57 +101,51 @@ void PreviewHandler::delImage(IImage8* i) if (pih->phandler->image) { IImage8* oldImg = pih->phandler->image; - oldImg->getMutex().lock (); + oldImg->getMutex().lock(); pih->phandler->image = nullptr; - oldImg->getMutex().unlock (); + oldImg->getMutex().unlock(); } - iap->image->free (); - pih->phandler->previewImgMutex.lock (); - pih->phandler->previewImg.clear (); - pih->phandler->previewImgMutex.unlock (); + i->free(); + pih->phandler->previewImgMutex.lock(); + pih->phandler->previewImg.clear(); + pih->phandler->previewImgMutex.unlock(); - pih->pending--; + --pih->pending; return false; - }; - - idle_register.add(func, iap, true); + } + ); } void PreviewHandler::imageReady(const rtengine::procparams::CropParams& cp) { pih->pending++; - iaimgpar* iap = new iaimgpar; - iap->pih = pih; - iap->cp = cp; - const auto func = - [](iaimgpar* iap) -> bool + idle_register.add( + [this, cp]() -> bool { - PreviewHandlerIdleHelper* const pih = iap->pih; - if (pih->destroyed) { if (pih->pending == 1) { delete pih; } else { - pih->pending--; + --pih->pending; } return false; } - pih->phandler->previewImgMutex.lock (); - pih->phandler->previewImg = Gdk::Pixbuf::create_from_data (pih->phandler->image->getData(), Gdk::COLORSPACE_RGB, false, 8, pih->phandler->image->getWidth(), pih->phandler->image->getHeight(), 3 * pih->phandler->image->getWidth()); + pih->phandler->previewImgMutex.lock(); + pih->phandler->previewImg = Gdk::Pixbuf::create_from_data(pih->phandler->image->getData(), Gdk::COLORSPACE_RGB, false, 8, pih->phandler->image->getWidth(), pih->phandler->image->getHeight(), 3 * pih->phandler->image->getWidth()); pih->phandler->previewImgMutex.unlock (); - pih->phandler->cropParams = iap->cp; + + pih->phandler->cropParams = cp; pih->phandler->previewImageChanged (); - pih->pending--; + --pih->pending; return false; - }; - - idle_register.add(func, iap, true); + } + ); } Glib::RefPtr PreviewHandler::getRoughImage (int x, int y, int w, int h, double zoom) diff --git a/rtgui/resize.cc b/rtgui/resize.cc index c57ff236a..fc0f51191 100644 --- a/rtgui/resize.cc +++ b/rtgui/resize.cc @@ -366,60 +366,60 @@ void Resize::sizeChanged(int mw, int mh, int ow, int oh) void Resize::setDimensions () { - const auto func = - [](Resize* self) -> bool + idle_register.add( + [this]() -> bool { - self->wconn.block(true); - self->hconn.block(true); - self->scale->block(true); + wconn.block(true); + hconn.block(true); + scale->block(true); int refw, refh; - if (self->appliesTo->get_active_row_number() == 0 && self->cropw) { + if (appliesTo->get_active_row_number() == 0 && cropw) { // Applies to Cropped area - refw = self->cropw; - refh = self->croph; + refw = cropw; + refh = croph; } else { // Applies to Full image or crop is disabled - refw = self->maxw; - refh = self->maxh; + refw = maxw; + refh = maxh; } - self->w->set_range(32, MAX_SCALE * refw); - self->h->set_range(32, MAX_SCALE * refh); + w->set_range(32, MAX_SCALE * refw); + h->set_range(32, MAX_SCALE * refh); - switch (self->spec->get_active_row_number()) { + switch (spec->get_active_row_number()) { case 0: { // Scale mode - self->w->set_value(static_cast(static_cast(static_cast(refw) * self->scale->getValue() + 0.5))); - self->h->set_value(static_cast(static_cast(static_cast(refh) * self->scale->getValue() + 0.5))); + w->set_value(static_cast(static_cast(static_cast(refw) * scale->getValue() + 0.5))); + h->set_value(static_cast(static_cast(static_cast(refh) * scale->getValue() + 0.5))); break; } case 1: { // Width mode - const double tmp_scale = self->w->get_value() / static_cast(refw); - self->scale->setValue(tmp_scale); - self->h->set_value(static_cast(static_cast(static_cast(refh) * tmp_scale + 0.5))); + const double tmp_scale = w->get_value() / static_cast(refw); + scale->setValue(tmp_scale); + h->set_value(static_cast(static_cast(static_cast(refh) * tmp_scale + 0.5))); break; } case 2: { // Height mode - const double tmp_scale = self->h->get_value() / static_cast(refh); - self->scale->setValue(tmp_scale); - self->w->set_value(static_cast(static_cast(static_cast(refw) * tmp_scale + 0.5))); + const double tmp_scale = h->get_value() / static_cast(refh); + scale->setValue(tmp_scale); + w->set_value(static_cast(static_cast(static_cast(refw) * tmp_scale + 0.5))); break; } case 3: { // Bounding box mode const double tmp_scale = - self->w->get_value() / self->h->get_value() < static_cast(refw) / static_cast(refh) - ? self->w->get_value() / static_cast(refw) - : self->h->get_value() / static_cast(refh); + w->get_value() / h->get_value() < static_cast(refw) / static_cast(refh) + ? w->get_value() / static_cast(refw) + : h->get_value() / static_cast(refh); - self->scale->setValue(tmp_scale); + scale->setValue(tmp_scale); break; } @@ -428,14 +428,13 @@ void Resize::setDimensions () } } - self->scale->block(false); - self->wconn.block(false); - self->hconn.block(false); + scale->block(false); + wconn.block(false); + hconn.block(false); return false; - }; - - idle_register.add(func, this, false); + } + ); } void Resize::fitBoxScale() diff --git a/rtgui/retinex.cc b/rtgui/retinex.cc index c74f977c8..544ace535 100644 --- a/rtgui/retinex.cc +++ b/rtgui/retinex.cc @@ -672,28 +672,20 @@ void Retinex::minmaxChanged (double cdma, double cdmin, double mini, double maxi nextminT = Tmin; nextmaxT = Tmax; - const auto func = - [](Retinex* self) -> bool + idle_register.add( + [this]() -> bool { GThreadLock lock; // All GUI access from idle_add callbacks or separate thread HAVE to be protected // FIXME: The above can't be true?! - self->minmaxComputed_(); + disableListener(); + enableListener(); + updateLabel(); + updateTrans(); return false; - }; - - idle_register.add(func, this, false); + } + ); } -bool Retinex::minmaxComputed_ () -{ - - disableListener (); - enableListener (); - updateLabel (); - updateTrans (); - return false; - -} void Retinex::updateLabel () { if (!batchMode) { diff --git a/rtgui/retinex.h b/rtgui/retinex.h index b9ed3c927..8703ec607 100644 --- a/rtgui/retinex.h +++ b/rtgui/retinex.h @@ -108,7 +108,6 @@ public: void autoOpenCurve () override; void medianmapChanged (); void minmaxChanged (double cdma, double cdmin, double mini, double maxi, double Tmean, double Tsigma, double Tmin, double Tmax) override; - bool minmaxComputed_ (); void updateLabel (); void updateTrans (); void neutral_pressed (); diff --git a/rtgui/tonecurve.cc b/rtgui/tonecurve.cc index 5769386ef..b4157e58a 100644 --- a/rtgui/tonecurve.cc +++ b/rtgui/tonecurve.cc @@ -832,41 +832,6 @@ void ToneCurve::enableAll () histmatching->set_sensitive(true); } -bool ToneCurve::autoExpComputed_ () -{ - - GThreadLock lock; // All GUI access from idle_add callbacks or separate thread HAVE to be protected - disableListener (); - enableAll (); - expcomp->setValue (nextExpcomp); - brightness->setValue (nextBrightness); - contrast->setValue (nextContrast); - black->setValue (nextBlack); - hlcompr->setValue (nextHlcompr); - hlcomprthresh->setValue (nextHlcomprthresh); - enaconn.block (true); - hrenabled->set_active (nextHLRecons); - enaconn.block (false); - - if (nextHLRecons) { - hlrbox->show(); - } else if (!batchMode) { - hlrbox->hide(); - } - - if (!black->getAddMode() && !batchMode) { - shcompr->set_sensitive(!((int)black->getValue () == 0)); //at black=0 shcompr value has no effect - } - - if (!hlcompr->getAddMode() && !batchMode) { - hlcomprthresh->set_sensitive(!((int)hlcompr->getValue () == 0)); //at hlcompr=0 hlcomprthresh value has no effect - } - - enableListener (); - - return false; -} - void ToneCurve::setBatchMode (bool batchMode) { ToolPanel::setBatchMode (batchMode); @@ -967,42 +932,6 @@ void ToneCurve::histmatchingToggled() } } -bool ToneCurve::histmatchingComputed() -{ - GThreadLock lock; - disableListener(); - enableAll(); - brightness->setValue(0); - contrast->setValue(0); - black->setValue(0); - - if (!black->getAddMode() && !batchMode) { - shcompr->set_sensitive(!((int)black->getValue() == 0)); - } - - if (!hlcompr->getAddMode() && !batchMode) { - hlcomprthresh->set_sensitive(!((int)hlcompr->getValue () == 0)); //at hlcompr=0 hlcomprthresh value has no effect - } - - if (autolevels->get_active() ) { - expcomp->setValue(0); - autoconn.block(true); - autolevels->set_active(false); - autoconn.block(false); - autolevels->set_inconsistent(false); - } - - toneCurveMode->set_active(rtengine::toUnderlying(nextToneCurveMode)); - shape->setCurve(nextToneCurve); - shape2->setCurve({ DCT_Linear }); - shape->openIfNonlinear(); - - enableListener(); - fromHistMatching = true; - - return false; -} - void ToneCurve::autoExpChanged(double expcomp, int bright, int contr, int black, int hlcompr, int hlcomprthresh, bool hlrecons) { nextBlack = black; @@ -1013,14 +942,41 @@ void ToneCurve::autoExpChanged(double expcomp, int bright, int contr, int black, nextHlcomprthresh = hlcomprthresh; nextHLRecons = hlrecons; - const auto func = - [](ToneCurve* self) -> bool + idle_register.add( + [this]() -> bool { - self->autoExpComputed_(); - return false; - }; + GThreadLock lock; // All GUI access from idle_add callbacks or separate thread HAVE to be protected + // FIXME: We don't need the GThreadLock, don't we? + disableListener(); + enableAll(); + this->expcomp->setValue(nextExpcomp); + brightness->setValue(nextBrightness); + contrast->setValue(nextContrast); + this->black->setValue(nextBlack); + this->hlcompr->setValue(nextHlcompr); + this->hlcomprthresh->setValue(nextHlcomprthresh); + enaconn.block(true); + hrenabled->set_active(nextHLRecons); + enaconn.block(false); - idle_register.add(func, this, false); + if (nextHLRecons) { + hlrbox->show(); + } else if (!batchMode) { + hlrbox->hide(); + } + + if (!this->black->getAddMode() && !batchMode) { + shcompr->set_sensitive(static_cast(this->black->getValue())); //at black=0 shcompr value has no effect + } + + if (!this->hlcompr->getAddMode() && !batchMode) { + this->hlcomprthresh->set_sensitive(static_cast(this->hlcompr->getValue())); //at hlcompr=0 hlcomprthresh value has no effect + } + + enableListener(); + return false; + } + ); } void ToneCurve::autoMatchedToneCurveChanged(rtengine::procparams::ToneCurveParams::TcMode curveMode, const std::vector& curve) @@ -1028,12 +984,41 @@ void ToneCurve::autoMatchedToneCurveChanged(rtengine::procparams::ToneCurveParam nextToneCurveMode = curveMode; nextToneCurve = curve; - const auto func = - [](ToneCurve* self) -> bool + idle_register.add( + [this]() -> bool { - self->histmatchingComputed(); - return false; - }; + GThreadLock lock; // FIXME: Obsolete + disableListener(); + enableAll(); + brightness->setValue(0); + contrast->setValue(0); + black->setValue(0); - idle_register.add(func, this, false); + if (!black->getAddMode() && !batchMode) { + shcompr->set_sensitive(static_cast(black->getValue())); + } + + if (!hlcompr->getAddMode() && !batchMode) { + hlcomprthresh->set_sensitive(static_cast(hlcompr->getValue())); //at hlcompr=0 hlcomprthresh value has no effect + } + + if (autolevels->get_active() ) { + expcomp->setValue(0); + autoconn.block(true); + autolevels->set_active(false); + autoconn.block(false); + autolevels->set_inconsistent(false); + } + + toneCurveMode->set_active(rtengine::toUnderlying(nextToneCurveMode)); + shape->setCurve(nextToneCurve); + shape2->setCurve({DCT_Linear}); + shape->openIfNonlinear(); + + enableListener(); + fromHistMatching = true; + + return false; + } + ); } diff --git a/rtgui/tonecurve.h b/rtgui/tonecurve.h index d95049d1c..2cf7b9d12 100644 --- a/rtgui/tonecurve.h +++ b/rtgui/tonecurve.h @@ -72,7 +72,7 @@ protected: rtengine::ProcEvent EvHistMatching; rtengine::ProcEvent EvHistMatchingBatch; rtengine::ProcEvent EvClampOOG; - + // used temporarily in eventing double nextExpcomp; int nextBrightness; @@ -108,7 +108,6 @@ public: void clip_changed (); bool clip_changed_ (); void waitForAutoExp (); - bool autoExpComputed_ (); void enableAll (); void curveChanged (CurveEditor* ce) override; void curveMode1Changed (); @@ -131,7 +130,6 @@ public: ); void histmatchingToggled(); - bool histmatchingComputed(); void autoExpChanged(double expcomp, int bright, int contr, int black, int hlcompr, int hlcomprthresh, bool hlrecons) override; void autoMatchedToneCurveChanged(rtengine::procparams::ToneCurveParams::TcMode curveMode, const std::vector& curve) override; diff --git a/rtgui/toolpanelcoord.cc b/rtgui/toolpanelcoord.cc index 00a220c89..dce59dbce 100644 --- a/rtgui/toolpanelcoord.cc +++ b/rtgui/toolpanelcoord.cc @@ -297,74 +297,74 @@ void ToolPanelCoordinator::imageTypeChanged (bool isRaw, bool isBayer, bool isXt { if (isRaw) { if (isBayer) { - const auto func = - [](ToolPanelCoordinator* self) -> bool + idle_register.add( + [this]() -> bool { - self->rawPanelSW->set_sensitive (true); - self->sensorxtrans->FoldableToolPanel::hide(); - self->sensorbayer->FoldableToolPanel::show(); - self->preprocess->FoldableToolPanel::show(); - self->flatfield->FoldableToolPanel::show(); - self->retinex->FoldableToolPanel::setGrayedOut(false); + rawPanelSW->set_sensitive(true); + sensorxtrans->FoldableToolPanel::hide(); + sensorbayer->FoldableToolPanel::show(); + preprocess->FoldableToolPanel::show(); + flatfield->FoldableToolPanel::show(); + retinex->FoldableToolPanel::setGrayedOut(false); return false; - }; - idle_register.add(func, this, false); + } + ); } else if (isXtrans) { - const auto func = - [](ToolPanelCoordinator* self) -> bool + idle_register.add( + [this]() -> bool { - self->rawPanelSW->set_sensitive (true); - self->sensorxtrans->FoldableToolPanel::show(); - self->sensorbayer->FoldableToolPanel::hide(); - self->preprocess->FoldableToolPanel::show(); - self->flatfield->FoldableToolPanel::show(); - self->retinex->FoldableToolPanel::setGrayedOut(false); + rawPanelSW->set_sensitive(true); + sensorxtrans->FoldableToolPanel::show(); + sensorbayer->FoldableToolPanel::hide(); + preprocess->FoldableToolPanel::show(); + flatfield->FoldableToolPanel::show(); + retinex->FoldableToolPanel::setGrayedOut(false); return false; - }; - idle_register.add(func, this, false); + } + ); } else if (isMono) { - const auto func = - [](ToolPanelCoordinator* self) -> bool + idle_register.add( + [this]() -> bool { - self->rawPanelSW->set_sensitive (true); - self->sensorbayer->FoldableToolPanel::hide(); - self->sensorxtrans->FoldableToolPanel::hide(); - self->preprocess->FoldableToolPanel::hide(); - self->flatfield->FoldableToolPanel::show(); - self->retinex->FoldableToolPanel::setGrayedOut(false); + rawPanelSW->set_sensitive(true); + sensorbayer->FoldableToolPanel::hide(); + sensorxtrans->FoldableToolPanel::hide(); + preprocess->FoldableToolPanel::hide(); + flatfield->FoldableToolPanel::show(); + retinex->FoldableToolPanel::setGrayedOut(false); return false; - }; - idle_register.add(func, this, false); + } + ); } else { - const auto func = - [](ToolPanelCoordinator* self) -> bool + idle_register.add( + [this]() -> bool { - self->rawPanelSW->set_sensitive (true); - self->sensorbayer->FoldableToolPanel::hide(); - self->sensorxtrans->FoldableToolPanel::hide(); - self->preprocess->FoldableToolPanel::hide(); - self->flatfield->FoldableToolPanel::hide(); - self->retinex->FoldableToolPanel::setGrayedOut(false); + rawPanelSW->set_sensitive(true); + sensorbayer->FoldableToolPanel::hide(); + sensorxtrans->FoldableToolPanel::hide(); + preprocess->FoldableToolPanel::hide(); + flatfield->FoldableToolPanel::hide(); + retinex->FoldableToolPanel::setGrayedOut(false); return false; - }; - idle_register.add(func, this, false); + } + ); } } else { - const auto func = - [](ToolPanelCoordinator* self) -> bool + idle_register.add( + [this]() -> bool { - self->rawPanelSW->set_sensitive (false); - self->retinex->FoldableToolPanel::setGrayedOut(true); + rawPanelSW->set_sensitive(false); + retinex->FoldableToolPanel::setGrayedOut(true); return false; - }; - idle_register.add(func, this, false); + } + ); } }