From ccc882dbcff710778c09724e7a044bfebbc0233a Mon Sep 17 00:00:00 2001 From: heckflosse Date: Wed, 24 Oct 2018 17:12:11 +0200 Subject: [PATCH 01/17] Review idle_register.add() calls: wavelets, ciecam02, colortoning --- rtengine/improccoordinator.cc | 4 +- rtengine/rtengine.h | 2 +- rtgui/colorappearance.cc | 87 +++++++++++++++-------------------- rtgui/colorappearance.h | 5 -- rtgui/colortoning.cc | 49 +++++++------------- rtgui/colortoning.h | 6 +-- rtgui/wavelet.cc | 44 +++++++----------- rtgui/wavelet.h | 2 - 8 files changed, 75 insertions(+), 124 deletions(-) diff --git a/rtengine/improccoordinator.cc b/rtengine/improccoordinator.cc index 5cc93d3c7..4a0072bea 100644 --- a/rtengine/improccoordinator.cc +++ b/rtengine/improccoordinator.cc @@ -611,7 +611,7 @@ void ImProcCoordinator::updatePreviewImage(int todo, bool panningRelatedChange) if (actListener && params.colorToning.enabled) { if (params.blackwhite.enabled && params.colorToning.autosat) { - actListener->autoColorTonChanged(0, satTH, satPR); //hide sliders only if autosat + actListener->autoColorTonChanged(satTH, satPR); //hide sliders only if autosat indi = 0; } else { if (params.colorToning.autosat) { @@ -656,7 +656,7 @@ void ImProcCoordinator::updatePreviewImage(int todo, bool panningRelatedChange) printf("ImProcCoordinator / Auto CT: indi=%d satH=%d satPR=%d\n", indi, (int)colourToningSatLimit, (int) colourToningSatLimitOpacity); } - actListener->autoColorTonChanged(indi, (int) colourToningSatLimit, (int)colourToningSatLimitOpacity); //change sliders autosat + actListener->autoColorTonChanged((int) colourToningSatLimit, (int)colourToningSatLimitOpacity); //change sliders autosat } // correct GUI black and white with value diff --git a/rtengine/rtengine.h b/rtengine/rtengine.h index bc8c12fec..b47620ee9 100644 --- a/rtengine/rtengine.h +++ b/rtengine/rtengine.h @@ -347,7 +347,7 @@ class AutoColorTonListener { public: virtual ~AutoColorTonListener() = default; - virtual void autoColorTonChanged(int bwct, int satthres, int satprot) = 0; + virtual void autoColorTonChanged(int satthres, int satprot) = 0; }; class AutoBWListener diff --git a/rtgui/colorappearance.cc b/rtgui/colorappearance.cc index 094c6fc5d..14e630f3c 100644 --- a/rtgui/colorappearance.cc +++ b/rtgui/colorappearance.cc @@ -1451,75 +1451,64 @@ void ColorAppearance::setDefaults (const ProcParams* defParams, const ParamsEdit void ColorAppearance::autoCamChanged (double ccam, double ccamout) { - nextCcam = ccam; - nextCcamout = ccamout; + struct Data { + ColorAppearance *me; + double ccam; + double ccamout; + }; - const auto func = [] (gpointer data) -> gboolean { - static_cast (data)->autoCamComputed_(); + const auto func = [](gpointer data) -> gboolean { + Data *d = static_cast(data); + ColorAppearance *me = d->me; + me->disableListener(); + me->degree->setValue(d->ccam); + me->degreeout->setValue(d->ccamout); + me->enableListener(); + delete d; return FALSE; }; - idle_register.add (func, this); -} - -bool ColorAppearance::autoCamComputed_ () -{ - - disableListener (); -// degree->setEnabled (true); - degree->setValue (nextCcam); - degreeout->setValue (nextCcamout); - enableListener (); - - return false; + idle_register.add(func, new Data { this, ccam, ccamout }); } void ColorAppearance::adapCamChanged (double cadap) { - nextCadap = cadap; + struct Data { + ColorAppearance *me; + double cadap; + }; - const auto func = [] (gpointer data) -> gboolean { - static_cast (data)->adapCamComputed_(); + const auto func = [](gpointer data) -> gboolean { + Data *d = static_cast(data); + ColorAppearance *me = d->me; + me->disableListener(); + me->adapscen->setValue(d->cadap); + me->enableListener(); + delete d; return FALSE; }; - idle_register.add (func, this); -} - -bool ColorAppearance::adapCamComputed_ () -{ - - disableListener (); -// degree->setEnabled (true); - adapscen->setValue (nextCadap); -// ybscen->setValue (nextYbscn); - enableListener (); - - return false; + idle_register.add(func, new Data { this, cadap }); } void ColorAppearance::ybCamChanged (int ybsc) { - nextYbscn = ybsc; + struct Data { + ColorAppearance *me; + int ybsc; + }; - const auto func = [] (gpointer data) -> gboolean { - static_cast (data)->ybCamComputed_(); + const auto func = [](gpointer data) -> gboolean { + Data *d = static_cast(data); + ColorAppearance *me = d->me; + me->disableListener(); + me->ybscen->setValue(d->ybsc); + me->enableListener(); + delete d; return FALSE; }; - idle_register.add (func, this); -} - -bool ColorAppearance::ybCamComputed_ () -{ - - disableListener (); -// degree->setEnabled (true); -// adapscen->setValue (nextCadap); - ybscen->setValue (nextYbscn); - enableListener (); - - return false; + idle_register.add(func, new Data { this, ybsc }); } void ColorAppearance::colorForValue (double valX, double valY, enum ColorCaller::ElemType elemType, int callerId, ColorCaller *caller) diff --git a/rtgui/colorappearance.h b/rtgui/colorappearance.h index 5dd8a2e82..98947b5a5 100644 --- a/rtgui/colorappearance.h +++ b/rtgui/colorappearance.h @@ -59,11 +59,8 @@ public: void tonecie_toggled (); // void sharpcie_toggled (); void autoCamChanged (double ccam, double ccamout); - bool autoCamComputed_ (); void adapCamChanged (double cadap); - bool adapCamComputed_ (); void ybCamChanged (int yb); - bool ybCamComputed_ (); void curveChanged (CurveEditor* ce); void curveMode1Changed (); @@ -160,8 +157,6 @@ private: DiagonalCurveEditor* shape; DiagonalCurveEditor* shape2; DiagonalCurveEditor* shape3; - double nextCcam, nextCcamout, nextCadap; - int nextYbscn; bool lastAutoDegree; bool lastAutoAdapscen; bool lastAutoDegreeout; diff --git a/rtgui/colortoning.cc b/rtgui/colortoning.cc index 8b357c3f9..2f32d9b0b 100644 --- a/rtgui/colortoning.cc +++ b/rtgui/colortoning.cc @@ -13,7 +13,6 @@ using namespace rtengine::procparams; ColorToning::ColorToning () : FoldableToolPanel(this, "colortoning", M("TP_COLORTONING_LABEL"), false, true) { - nextbw = 0; CurveListener::setMulti(true); //---------------method @@ -688,40 +687,26 @@ void ColorToning::setAdjusterBehavior (bool splitAdd, bool satThresholdAdd, bool } -void ColorToning::autoColorTonChanged(int bwct, int satthres, int satprot) +void ColorToning::autoColorTonChanged(int satthres, int satprot) { - nextbw = bwct; - nextsatth = satthres; - nextsatpr = satprot; + struct Data { + ColorToning *me; + int satthres; + int satprot; + }; - const auto func = [](gpointer data) -> gboolean { - static_cast(data)->CTComp_(); - return FALSE; - }; + const auto func = [](gpointer data) -> gboolean { + Data *d = static_cast(data); + ColorToning *me = d->me; + me->disableListener(); + me->satProtectionThreshold->setValue(d->satthres); + me->saturatedOpacity->setValue(d->satprot); + me->enableListener (); + delete d; + return FALSE; + }; - idle_register.add(func, this); -} - -bool ColorToning::CTComp_ () -{ - - disableListener (); - saturatedOpacity->setValue (nextsatpr); - satProtectionThreshold->setValue (nextsatth); - /* if(nextbw==1) { - saturatedOpacity->show(); - satProtectionThreshold->show(); - autosat->show(); - } - else { - saturatedOpacity->hide(); - satProtectionThreshold->hide(); - autosat->hide(); - } - */ - enableListener (); - - return false; + idle_register.add(func, new Data { this, satthres, satprot }); } void ColorToning::adjusterChanged (ThresholdAdjuster* a, double newBottom, double newTop) diff --git a/rtgui/colortoning.h b/rtgui/colortoning.h index cb021e242..5ee5d5ec9 100644 --- a/rtgui/colortoning.h +++ b/rtgui/colortoning.h @@ -36,8 +36,7 @@ public: void setAdjusterBehavior (bool splitAdd, bool satThresholdAdd, bool satOpacityAdd, bool strprotectAdd, bool balanceAdd); void neutral_pressed (); //void neutralCurves_pressed (); - void autoColorTonChanged (int bwct, int satthres, int satprot); - bool CTComp_ (); + void autoColorTonChanged (int satthres, int satprot); void adjusterChanged(ThresholdAdjuster* a, double newBottom, double newTop); void adjusterChanged(ThresholdAdjuster* a, double newBottomLeft, double newTopLeft, double newBottomRight, double newTopRight); @@ -99,9 +98,6 @@ private: Gtk::Button* neutral; Gtk::HBox* neutrHBox; - int nextbw; - int nextsatth; - int nextsatpr; Glib::ustring nextbalcolor; Glib::ustring balcolor; sigc::connection neutralconn, twocconn; //, neutralcurvesconn; diff --git a/rtgui/wavelet.cc b/rtgui/wavelet.cc index 81fc282ab..7aa03050a 100644 --- a/rtgui/wavelet.cc +++ b/rtgui/wavelet.cc @@ -144,7 +144,6 @@ Wavelet::Wavelet() : neutrHBox(Gtk::manage(new Gtk::HBox())) { CurveListener::setMulti(true); - nextnlevel = 7.; expsettings->signal_button_release_event().connect_notify( sigc::bind( sigc::mem_fun(this, &Wavelet::foldAllButMe), expsettings) ); @@ -886,36 +885,25 @@ Wavelet::~Wavelet () } void Wavelet::wavChanged (double nlevel) -{ - nextnlevel = nlevel; - - const auto func = [](gpointer data) -> gboolean { - GThreadLock lock; // All GUI access from idle_add callbacks or separate thread HAVE to be protected - static_cast(data)->wavComputed_(); - - return FALSE; - }; - - idle_register.add(func, this); -} - -bool Wavelet::wavComputed_ () -{ - disableListener (); - enableListener (); - updatewavLabel (); - return false; -} - -void Wavelet::updatewavLabel () { if (!batchMode) { - float lv; - lv = nextnlevel; - wavLabels->set_text( + struct Data { + Wavelet *me; + double nlevel; + }; + + const auto func = [](gpointer data) -> gboolean { + Data *d = static_cast(data); + Wavelet *me = d->me; + me->wavLabels->set_text( Glib::ustring::compose(M("TP_WAVELET_LEVLABEL"), - Glib::ustring::format(std::fixed, std::setprecision(0), lv)) - ); + Glib::ustring::format(std::fixed, std::setprecision(0), d->nlevel)) + ); + delete d; + return FALSE; + }; + + idle_register.add(func, new Data { this, nlevel }); } } diff --git a/rtgui/wavelet.h b/rtgui/wavelet.h index 5cbb5bfe3..4146fa17d 100644 --- a/rtgui/wavelet.h +++ b/rtgui/wavelet.h @@ -93,7 +93,6 @@ private: void neutral_pressed (); void neutralchPressed (); void tmrToggled (); - void updatewavLabel (); void wavChanged (double nlevel); void HSmethodUpdateUI(); @@ -252,7 +251,6 @@ private: sigc::connection neutralchPressedConn; bool lastmedian, lastmedianlev, lastlinkedg, lastavoid, lastlipst, lasttmr, lastcbenab; - int nextnlevel; IdleRegister idle_register; }; From 7038104a204a8ff355d51d748ea921af94621c0d Mon Sep 17 00:00:00 2001 From: heckflosse Date: Wed, 24 Oct 2018 23:56:25 +0200 Subject: [PATCH 02/17] Review idle_register.add() calls: denoise --- rtgui/dirpyrdenoise.cc | 207 ++++++++++++++--------------------------- rtgui/dirpyrdenoise.h | 68 +++++--------- 2 files changed, 92 insertions(+), 183 deletions(-) diff --git a/rtgui/dirpyrdenoise.cc b/rtgui/dirpyrdenoise.cc index c2fb31902..81d7cff9a 100644 --- a/rtgui/dirpyrdenoise.cc +++ b/rtgui/dirpyrdenoise.cc @@ -30,11 +30,6 @@ DirPyrDenoise::DirPyrDenoise () : FoldableToolPanel(this, "dirpyrdenoise", M("TP { std::vector milestones; CurveListener::setMulti(true); - nextnresid = 0.; - nexthighresid = 0.; - nextchroma = 15.; - nextred = 0.; - nextblue = 0.; std::vector defaultCurve; @@ -44,8 +39,6 @@ DirPyrDenoise::DirPyrDenoise () : FoldableToolPanel(this, "dirpyrdenoise", M("TP Gtk::VBox * lumaVBox = Gtk::manage ( new Gtk::VBox()); lumaVBox->set_spacing(2); - - ctboxL = Gtk::manage (new Gtk::HBox ()); Gtk::Label* labmL = Gtk::manage (new Gtk::Label (M("TP_DIRPYRDENOISE_LUMINANCE_CONTROL") + ":")); ctboxL->pack_start (*labmL, Gtk::PACK_SHRINK, 1); @@ -66,11 +59,10 @@ DirPyrDenoise::DirPyrDenoise () : FoldableToolPanel(this, "dirpyrdenoise", M("TP lshape->setIdentityValue(0.); lshape->setResetCurve(FlatCurveType(defaultCurve.at(0)), defaultCurve); - //lshape->setEditID(EUID_Lab_LCurve, BT_SINGLEPLANE_FLOAT); milestones.push_back( GradientMilestone(0., 0., 0., 0.) ); milestones.push_back( GradientMilestone(1., 1., 1., 1.) ); lshape->setBottomBarBgGradient(milestones); - //lshape->setLeftBarBgGradient(milestones); + milestones.push_back( GradientMilestone(0., 0., 0., 0.) ); milestones.push_back( GradientMilestone(1., 1., 1., 1.) ); NoiscurveEditorG->curveListComplete(); @@ -107,7 +99,6 @@ DirPyrDenoise::DirPyrDenoise () : FoldableToolPanel(this, "dirpyrdenoise", M("TP C2method->set_active(0); C2methodconn = C2method->signal_changed().connect ( sigc::mem_fun(*this, &DirPyrDenoise::C2methodChanged) ); - NoiseLabels = Gtk::manage(new Gtk::Label("---", Gtk::ALIGN_CENTER)); NoiseLabels->set_tooltip_text(M("TP_DIRPYRDENOISE_CHROMINANCE_PREVIEWRESIDUAL_INFO_TOOLTIP")); @@ -129,7 +120,6 @@ DirPyrDenoise::DirPyrDenoise () : FoldableToolPanel(this, "dirpyrdenoise", M("TP hb1->pack_end (*dmethod, Gtk::PACK_EXPAND_WIDGET, 1); pack_start(*hb1, Gtk::PACK_SHRINK, 1); - dmethodconn = dmethod->signal_changed().connect ( sigc::mem_fun(*this, &DirPyrDenoise::dmethodChanged) ); luma->setAdjusterListener (this); @@ -150,9 +140,6 @@ DirPyrDenoise::DirPyrDenoise () : FoldableToolPanel(this, "dirpyrdenoise", M("TP CCcurveEditorG->curveListComplete(); - - //----------------------------------------- - luma->hide(); Ldetail->show(); @@ -162,8 +149,6 @@ DirPyrDenoise::DirPyrDenoise () : FoldableToolPanel(this, "dirpyrdenoise", M("TP chroma->show(); redchro->show(); bluechro->show(); -// perform->show(); -// perform->set_active (true); // ---- Median FIltering ---- @@ -225,10 +210,7 @@ DirPyrDenoise::DirPyrDenoise () : FoldableToolPanel(this, "dirpyrdenoise", M("TP smethod = Gtk::manage (new MyComboBoxText ()); smethod->append (M("TP_DIRPYRDENOISE_MAIN_MODE_CONSERVATIVE")); -// smethod->append (M("TP_DIRPYRDENOISE_MAIN_MODE_SHBI")); smethod->append (M("TP_DIRPYRDENOISE_MAIN_MODE_AGGRESSIVE")); -// smethod->append (M("TP_DIRPYRDENOISE_MAIN_MODE_SHALAL")); -// smethod->append (M("TP_DIRPYRDENOISE_MAIN_MODE_SHBIBI")); smethod->set_active(1); hb11->pack_start (*smethod, Gtk::PACK_EXPAND_WIDGET, 1); pack_start( *hb11, Gtk::PACK_SHRINK, 1); @@ -272,17 +254,9 @@ DirPyrDenoise::DirPyrDenoise () : FoldableToolPanel(this, "dirpyrdenoise", M("TP chromaFrame->add(*chromaVBox); pack_start (*chromaFrame); -// pack_start( *hb11, Gtk::PACK_SHRINK, 4); - -// pack_start (*median); - ctboxm->pack_start (*methodmed); ctbox->pack_start (*medmethod); ctboxrgb->pack_start (*rgbmethod); -// pack_start (*ctboxm); -// pack_start (*ctbox); -// pack_start (*ctboxrgb); -// pack_start (*passes,Gtk::PACK_SHRINK, 1); medianVBox->pack_start (*ctboxm); medianVBox->pack_start (*ctbox); @@ -309,136 +283,97 @@ DirPyrDenoise::~DirPyrDenoise () void DirPyrDenoise::chromaChanged (double autchroma, double autred, double autblue) { - nextchroma = autchroma; - nextred = autred; - nextblue = autblue; - - const auto func = [](gpointer data) -> gboolean { - static_cast(data)->chromaComputed_(); - return false; + struct Data { + DirPyrDenoise *me; + double autchroma; + double autred; + double autblue; }; - idle_register.add(func, this); -} + const auto func = [](gpointer data) -> gboolean { + Data *d = static_cast(data); + DirPyrDenoise *me = d->me; + me->disableListener(); + me->chroma->setValue(d->autchroma); + me->redchro->setValue(d->autred); + me->bluechro->setValue(d->autblue); + me->enableListener(); + delete d; + return FALSE; + }; -bool DirPyrDenoise::chromaComputed_ () -{ - - disableListener (); - chroma->setValue (nextchroma); - redchro->setValue (nextred); - bluechro->setValue (nextblue); - enableListener (); - updateNoiseLabel (); - return false; + idle_register.add(func, new Data { this, autchroma, autred, autblue }); } void DirPyrDenoise::noiseTilePrev (int tileX, int tileY, int prevX, int prevY, int sizeT, int sizeP) -{ - nexttileX = tileX; - nexttileY = tileY; - nextprevX = prevX; - nextprevY = prevY; - nextsizeT = sizeT; - nextsizeP = sizeP; - - const auto func = [](gpointer data) -> gboolean { - static_cast(data)->TilePrevComputed_(); - return false; - }; - - idle_register.add(func, this); -} - -bool DirPyrDenoise::TilePrevComputed_ () -{ - - disableListener (); - enableListener (); - updateTileLabel (); - updatePrevLabel (); - return false; -} - -void DirPyrDenoise::updateTileLabel () { if (!batchMode) { - float sT; - float nX, nY; - sT = nextsizeT; - nX = nexttileX; - nY = nexttileY; - { - TileLabels->set_text( + struct Data { + DirPyrDenoise *me; + int tileX; + int tileY; + int prevX; + int prevY; + int sizeT; + int sizeP; + }; + + const auto func = [](gpointer data) -> gboolean { + Data *d = static_cast(data); + DirPyrDenoise *me = d->me; + me->TileLabels->set_text( Glib::ustring::compose(M("TP_DIRPYRDENOISE_CHROMINANCE_PREVIEW_TILEINFO"), - Glib::ustring::format(std::fixed, std::setprecision(0), sT), - Glib::ustring::format(std::fixed, std::setprecision(0), nX), - Glib::ustring::format(std::fixed, std::setprecision(0), nY)) + Glib::ustring::format(std::fixed, std::setprecision(0), d->sizeT), + Glib::ustring::format(std::fixed, std::setprecision(0), d->tileX), + Glib::ustring::format(std::fixed, std::setprecision(0), d->tileY)) ); - } - } -} -void DirPyrDenoise::updatePrevLabel () -{ - if (!batchMode) { - float sP; - float pX, pY; - sP = nextsizeP; - pX = nextprevX; - pY = nextprevY; - { - PrevLabels->set_text( + me->PrevLabels->set_text( Glib::ustring::compose(M("TP_DIRPYRDENOISE_CHROMINANCE_PREVIEW_INFO"), - Glib::ustring::format(std::fixed, std::setprecision(0), sP), - Glib::ustring::format(std::fixed, std::setprecision(0), pX), - Glib::ustring::format(std::fixed, std::setprecision(0), pY)) + Glib::ustring::format(std::fixed, std::setprecision(0), d->sizeP), + Glib::ustring::format(std::fixed, std::setprecision(0), d->prevX), + Glib::ustring::format(std::fixed, std::setprecision(0), d->prevY)) ); - } + delete d; + return FALSE; + }; + + idle_register.add(func, new Data { this, tileX, tileY, prevX, prevY, sizeT, sizeP }); } } void DirPyrDenoise::noiseChanged (double nresid, double highresid) -{ - nextnresid = nresid; - nexthighresid = highresid; - - const auto func = [](gpointer data) -> gboolean { - static_cast(data)->noiseComputed_(); - return false; - }; - - idle_register.add(func, this); -} - -bool DirPyrDenoise::noiseComputed_ () -{ - - disableListener (); - enableListener (); - updateNoiseLabel (); - return false; -} - -void DirPyrDenoise::updateNoiseLabel () { if (!batchMode) { - float nois, high; - nois = nextnresid; - high = nexthighresid; + struct Data { + DirPyrDenoise *me; + double nresid; + double highresid; + }; - if(nois == 0.f && high == 0.f) { - NoiseLabels->set_text(M("TP_DIRPYRDENOISE_CHROMINANCE_PREVIEW_NOISEINFO_EMPTY")); - } else { - NoiseLabels->set_text( - Glib::ustring::compose(M("TP_DIRPYRDENOISE_CHROMINANCE_PREVIEW_NOISEINFO"), - Glib::ustring::format(std::fixed, std::setprecision(0), nois), - Glib::ustring::format(std::fixed, std::setprecision(0), high)) - ); - } + const auto func = [](gpointer data) -> gboolean { + Data *d = static_cast(data); + DirPyrDenoise *me = d->me; + me->updateNoiseLabel(d->nresid, d->highresid); + delete d; + return FALSE; + }; + + idle_register.add(func, new Data { this, nresid, highresid }); } } - +void DirPyrDenoise::updateNoiseLabel (float nois, float high) +{ + if(nois == 0.f && high == 0.f) { + NoiseLabels->set_text(M("TP_DIRPYRDENOISE_CHROMINANCE_PREVIEW_NOISEINFO_EMPTY")); + } else { + NoiseLabels->set_text( + Glib::ustring::compose(M("TP_DIRPYRDENOISE_CHROMINANCE_PREVIEW_NOISEINFO"), + Glib::ustring::format(std::fixed, std::setprecision(0), nois), + Glib::ustring::format(std::fixed, std::setprecision(0), high)) + ); + } +} void DirPyrDenoise::read (const ProcParams* pp, const ParamsEdited* pedited) { @@ -647,7 +582,7 @@ void DirPyrDenoise::read (const ProcParams* pp, const ParamsEdited* pedited) medmethodconn.block(false); rgbmethodconn.block(false); methodmedconn.block(false); - updateNoiseLabel (); + updateNoiseLabel(); enableListener (); diff --git a/rtgui/dirpyrdenoise.h b/rtgui/dirpyrdenoise.h index 26a55ba20..767fb4a7a 100644 --- a/rtgui/dirpyrdenoise.h +++ b/rtgui/dirpyrdenoise.h @@ -40,43 +40,23 @@ public: DirPyrDenoise (); ~DirPyrDenoise (); - void read (const rtengine::procparams::ProcParams* pp, const ParamsEdited* pedited = nullptr); - void write (rtengine::procparams::ProcParams* pp, ParamsEdited* pedited = nullptr); - void setDefaults (const rtengine::procparams::ProcParams* defParams, const ParamsEdited* pedited = nullptr); - void setBatchMode (bool batchMode); - void curveChanged (CurveEditor* ce); - void setEditProvider (EditDataProvider *provider); - void autoOpenCurve (); - + void read (const rtengine::procparams::ProcParams* pp, const ParamsEdited* pedited = nullptr); + void write (rtengine::procparams::ProcParams* pp, ParamsEdited* pedited = nullptr); + void setDefaults (const rtengine::procparams::ProcParams* defParams, const ParamsEdited* pedited = nullptr); + void setBatchMode (bool batchMode); + void curveChanged (CurveEditor* ce); + void setEditProvider (EditDataProvider *provider); + void autoOpenCurve (); void adjusterChanged (Adjuster* a, double newval); void adjusterAutoToggled(Adjuster* a, bool newval); - void enabledChanged (); - void medianChanged (); + void enabledChanged (); void chromaChanged (double autchroma, double autred, double autblue); - bool chromaComputed_ (); void noiseChanged (double nresid, double highresid); - bool noiseComputed_ (); void noiseTilePrev (int tileX, int tileY, int prevX, int prevY, int sizeT, int sizeP); - bool TilePrevComputed_ (); - -// void perform_toggled (); - void updateNoiseLabel (); - void LmethodChanged (); - void CmethodChanged (); - void C2methodChanged (); - void updateTileLabel (); - void updatePrevLabel (); - - void dmethodChanged (); - void medmethodChanged (); - void methodmedChanged (); - void rgbmethodChanged (); - void smethodChanged (); + void updateNoiseLabel (float nois = 0.f, float high = 0.f); virtual void colorForValue (double valX, double valY, enum ColorCaller::ElemType elemType, int callerId, ColorCaller* caller); - void setAdjusterBehavior (bool lumaadd, bool lumdetadd, bool chromaadd, bool chromaredadd, bool chromablueadd, bool gammaadd, bool passesadd); - void trimValues (rtengine::procparams::ProcParams* pp); - Glib::ustring getSettingString (); + void trimValues (rtengine::procparams::ProcParams* pp); private: CurveEditorGroup* NoiscurveEditorG; @@ -90,17 +70,12 @@ private: Adjuster* passes; FlatCurveEditor* lshape; FlatCurveEditor* ccshape; - sigc::connection medianConn; Gtk::CheckButton* median; bool lastmedian; Gtk::Label* NoiseLabels; Gtk::Label* TileLabels; Gtk::Label* PrevLabels; - -// Gtk::CheckButton* perform; -// bool lastperform; -// sigc::connection perfconn; MyComboBoxText* dmethod; sigc::connection dmethodconn; MyComboBoxText* Lmethod; @@ -120,22 +95,21 @@ private: MyComboBoxText* rgbmethod; sigc::connection rgbmethodconn; Gtk::HBox* ctboxrgb; - double nextchroma; - double nextred; - double nextblue; - double nextnresid; - double nexthighresid; Gtk::HBox* ctboxL; Gtk::HBox* ctboxC; Gtk::HBox* ctboxC2; - int nexttileX; - int nexttileY; - int nextprevX; - int nextprevY; - int nextsizeT; - int nextsizeP; - IdleRegister idle_register; + + void LmethodChanged (); + void CmethodChanged (); + void C2methodChanged (); + void dmethodChanged (); + void medmethodChanged (); + void methodmedChanged (); + void rgbmethodChanged (); + void smethodChanged (); + void medianChanged (); + }; #endif From 5906329485d018c865d2d0eb96e7ceb581234d5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fl=C3=B6ssie?= Date: Sun, 28 Oct 2018 13:12:01 +0100 Subject: [PATCH 03/17] Review `IdleRegister` (#4892) This turns `IdleRegister::add()` into a template function to make the provided function pointers type safe. It also adds a `delete_data` parameter to manage the provided data pointer even in `destroy()`. --- rtgui/batchqueue.cc | 32 ++++---- rtgui/batchqueuepanel.cc | 13 ++-- rtgui/bayerprocess.cc | 72 +++++++++--------- rtgui/blackwhite.cc | 12 +-- rtgui/colorappearance.cc | 68 ++++++++--------- rtgui/colortoning.cc | 32 ++++---- rtgui/crop.cc | 66 ++++++++--------- rtgui/crophandler.cc | 12 +-- rtgui/dirpyrdenoise.cc | 84 ++++++++++----------- rtgui/editorpanel.cc | 99 +++++++++++-------------- rtgui/filebrowser.cc | 42 +++++------ rtgui/filebrowserentry.cc | 38 +++++----- rtgui/filecatalog.cc | 39 +++++----- rtgui/filepanel.cc | 12 +-- rtgui/flatfield.cc | 25 ++++--- rtgui/guiutils.cc | 35 ++------- rtgui/guiutils.h | 54 +++++++++++++- rtgui/histogrampanel.cc | 108 +++++++++++++-------------- rtgui/mydiagonalcurve.cc | 32 ++++---- rtgui/previewhandler.cc | 152 ++++++++++++++++++-------------------- rtgui/resize.cc | 126 +++++++++++++++---------------- rtgui/retinex.cc | 16 ++-- rtgui/tonecurve.cc | 44 +++++------ rtgui/toolpanelcoord.cc | 112 ++++++++++++++-------------- rtgui/wavelet.cc | 24 +++--- rtgui/whitebalance.cc | 33 +++++---- rtgui/xtransprocess.cc | 23 +++--- 27 files changed, 708 insertions(+), 697 deletions(-) diff --git a/rtgui/batchqueue.cc b/rtgui/batchqueue.cc index 1d52c96e6..de9864226 100644 --- a/rtgui/batchqueue.cc +++ b/rtgui/batchqueue.cc @@ -50,12 +50,10 @@ struct NLParams { Glib::ustring queueErrorMessage; }; -int bqnotifylistenerUI (void* data) +bool bqnotifylistenerUI(NLParams* params) { - NLParams* params = static_cast(data); params->listener->queueSizeChanged (params->qsize, params->queueEmptied, params->queueError, params->queueErrorMessage); - delete params; - return 0; + return false; } } @@ -438,16 +436,12 @@ void BatchQueue::cancelItems (const std::vector& items) if (entry->thumbnail) entry->thumbnail->imageRemovedFromQueue (); - const auto func = [](gpointer data) -> gboolean { - const BatchQueueEntry* const bqe = static_cast(data); - + const auto func = [](BatchQueueEntry* bqe) -> bool { ::g_remove(bqe->savedParamsFile.c_str()); - delete bqe; - - return FALSE; + return false; }; - idle_register.add(func, entry); + idle_register.add(func, entry, true); } for (const auto entry : fd) @@ -608,12 +602,14 @@ void BatchQueue::setProgress(double p) } // No need to acquire the GUI, setProgressUI will do it - const auto func = [](gpointer data) -> gboolean { - static_cast(data)->redraw(); - return FALSE; - }; + const auto func = + [](BatchQueue* bq) -> bool + { + bq->redraw(); + return false; + }; - idle_register.add(func, this); + idle_register.add(func, this, false); } void BatchQueue::setProgressStr(const Glib::ustring& str) @@ -643,7 +639,7 @@ void BatchQueue::error(const Glib::ustring& descr) params->queueEmptied = false; params->queueError = true; params->queueErrorMessage = descr; - idle_register.add(bqnotifylistenerUI, params); + idle_register.add(bqnotifylistenerUI, params, true); } } @@ -985,7 +981,7 @@ void BatchQueue::notifyListener (bool queueEmptied) } params->queueEmptied = queueEmptied; params->queueError = false; - idle_register.add(bqnotifylistenerUI, params); + idle_register.add(bqnotifylistenerUI, params, true); } } diff --git a/rtgui/batchqueuepanel.cc b/rtgui/batchqueuepanel.cc index bc03c2386..d718de677 100644 --- a/rtgui/batchqueuepanel.cc +++ b/rtgui/batchqueuepanel.cc @@ -170,13 +170,14 @@ BatchQueuePanel::BatchQueuePanel (FileCatalog* aFileCatalog) : parent(nullptr) show_all (); if (batchQueue->loadBatchQueue()) { - const auto func = [](gpointer data) -> gboolean { - static_cast(data)->resizeLoadedQueue(); + const auto func = + [](BatchQueue* bq) -> bool + { + bq->resizeLoadedQueue(); + return false; + }; - return FALSE; - }; - - idle_register.add(func, batchQueue, G_PRIORITY_LOW); + idle_register.add(func, batchQueue, false, G_PRIORITY_LOW); } } diff --git a/rtgui/bayerprocess.cc b/rtgui/bayerprocess.cc index 2a65a158e..ad9db9c2c 100644 --- a/rtgui/bayerprocess.cc +++ b/rtgui/bayerprocess.cc @@ -723,49 +723,51 @@ void BayerProcess::FrameCountChanged(int n, int frameNum) int n; int frameNum; }; - const auto func = [](gpointer data) -> gboolean { - Data *d = static_cast(data); - BayerProcess *me = d->me; - me->imageNumber->block (true); - int n = d->n; - int frameNum = d->frameNum; - me->imageNumber->remove_all(); - me->imageNumber->append("1"); - for(int i = 2; i <= std::min(n, 4); ++i) { - std::ostringstream entry; - entry << i; - me->imageNumber->append(entry.str()); - } - me->imageNumber->set_active(std::min(frameNum, n - 1)); - if(n == 1) { - me->imageNumberBox->hide(); - } else { - me->imageNumberBox->show(); - } - me->imageNumber->block (false); - delete d; - return FALSE; - }; + const auto func = + [](Data* d) -> bool + { + BayerProcess *me = d->me; + me->imageNumber->block (true); + int n = d->n; + int frameNum = d->frameNum; - idle_register.add(func, new Data { this, n, frameNum }); + me->imageNumber->remove_all(); + me->imageNumber->append("1"); + for(int i = 2; i <= std::min(n, 4); ++i) { + std::ostringstream entry; + entry << i; + me->imageNumber->append(entry.str()); + } + me->imageNumber->set_active(std::min(frameNum, n - 1)); + if(n == 1) { + me->imageNumberBox->hide(); + } else { + me->imageNumberBox->show(); + } + me->imageNumber->block (false); + return false; + }; + + idle_register.add(func, new Data{this, n, frameNum}, true); } void BayerProcess::autoContrastChanged (double autoContrast) { struct Data { - BayerProcess *me; + BayerProcess* self; double autoContrast; }; - const auto func = [](gpointer data) -> gboolean { - Data *d = static_cast(data); - BayerProcess *me = d->me; - me->disableListener(); - me->dualDemosaicContrast->setValue(d->autoContrast); - me->enableListener(); - delete d; - return FALSE; - }; - idle_register.add(func, new Data { this, autoContrast }); + const auto func = + [](Data* data) -> bool + { + BayerProcess* const self = data->self; + self->disableListener(); + self->dualDemosaicContrast->setValue(data->autoContrast); + self->enableListener(); + return false; + }; + + idle_register.add(func, new Data{this, autoContrast}, true); } diff --git a/rtgui/blackwhite.cc b/rtgui/blackwhite.cc index 47ab24f5e..359207115 100644 --- a/rtgui/blackwhite.cc +++ b/rtgui/blackwhite.cc @@ -375,12 +375,14 @@ void BlackWhite::BWChanged (double redbw, double greenbw, double bluebw) nextgreenbw = greenbw; nextbluebw = bluebw; - const auto func = [](gpointer data) -> gboolean { - static_cast(data)->BWComputed_(); - return FALSE; - }; + const auto func = + [](BlackWhite* self) -> bool + { + self->BWComputed_(); + return false; + }; - idle_register.add(func, this); + idle_register.add(func, this, false); } bool BlackWhite::BWComputed_ () diff --git a/rtgui/colorappearance.cc b/rtgui/colorappearance.cc index 14e630f3c..489b793da 100644 --- a/rtgui/colorappearance.cc +++ b/rtgui/colorappearance.cc @@ -1452,63 +1452,63 @@ void ColorAppearance::setDefaults (const ProcParams* defParams, const ParamsEdit void ColorAppearance::autoCamChanged (double ccam, double ccamout) { struct Data { - ColorAppearance *me; + ColorAppearance* me; double ccam; double ccamout; }; - const auto func = [](gpointer data) -> gboolean { - Data *d = static_cast(data); - ColorAppearance *me = d->me; - me->disableListener(); - me->degree->setValue(d->ccam); - me->degreeout->setValue(d->ccamout); - me->enableListener(); - delete d; - return FALSE; - }; + const auto func = + [](Data* data) -> bool + { + ColorAppearance* const self = data->me; + self->disableListener(); + self->degree->setValue(data->ccam); + self->degreeout->setValue(data->ccamout); + self->enableListener(); + return false; + }; - idle_register.add(func, new Data { this, ccam, ccamout }); + idle_register.add(func, new Data{this, ccam, ccamout}, true); } void ColorAppearance::adapCamChanged (double cadap) { struct Data { - ColorAppearance *me; + ColorAppearance* self; double cadap; }; - const auto func = [](gpointer data) -> gboolean { - Data *d = static_cast(data); - ColorAppearance *me = d->me; - me->disableListener(); - me->adapscen->setValue(d->cadap); - me->enableListener(); - delete d; - return FALSE; - }; + const auto func = + [](Data* data) -> bool + { + ColorAppearance* const self = data->self; + self->disableListener(); + self->adapscen->setValue(data->cadap); + self->enableListener(); + return false; + }; - idle_register.add(func, new Data { this, cadap }); + idle_register.add(func, new Data{this, cadap}, true); } void ColorAppearance::ybCamChanged (int ybsc) { struct Data { - ColorAppearance *me; + ColorAppearance* self; int ybsc; }; - const auto func = [](gpointer data) -> gboolean { - Data *d = static_cast(data); - ColorAppearance *me = d->me; - me->disableListener(); - me->ybscen->setValue(d->ybsc); - me->enableListener(); - delete d; - return FALSE; - }; + const auto func = + [](Data* data) -> bool + { + ColorAppearance* self = data->self; + self->disableListener(); + self->ybscen->setValue(data->ybsc); + self->enableListener(); + return false; + }; - idle_register.add(func, new Data { this, ybsc }); + idle_register.add(func, new Data{this, ybsc}, true); } void ColorAppearance::colorForValue (double valX, double valY, enum ColorCaller::ElemType elemType, int callerId, ColorCaller *caller) diff --git a/rtgui/colortoning.cc b/rtgui/colortoning.cc index 2f32d9b0b..f1e11a945 100644 --- a/rtgui/colortoning.cc +++ b/rtgui/colortoning.cc @@ -689,24 +689,24 @@ void ColorToning::setAdjusterBehavior (bool splitAdd, bool satThresholdAdd, bool void ColorToning::autoColorTonChanged(int satthres, int satprot) { - struct Data { - ColorToning *me; - int satthres; - int satprot; + struct Data { + ColorToning *self; + int satthres; + int satprot; + }; + + const auto func = + [](Data* data) -> bool + { + ColorToning* const self = data->self; + self->disableListener(); + self->satProtectionThreshold->setValue(data->satthres); + self->saturatedOpacity->setValue(data->satprot); + self->enableListener(); + return false; }; - const auto func = [](gpointer data) -> gboolean { - Data *d = static_cast(data); - ColorToning *me = d->me; - me->disableListener(); - me->satProtectionThreshold->setValue(d->satthres); - me->saturatedOpacity->setValue(d->satprot); - me->enableListener (); - delete d; - return FALSE; - }; - - idle_register.add(func, new Data { this, satthres, satprot }); + idle_register.add(func, new Data{this, satthres, satprot}, true); } void ColorToning::adjusterChanged (ThresholdAdjuster* a, double newBottom, double newTop) diff --git a/rtgui/crop.cc b/rtgui/crop.cc index d5b246107..edf76b6b1 100644 --- a/rtgui/crop.cc +++ b/rtgui/crop.cc @@ -38,18 +38,16 @@ public: : crop(_crop), notify(_notify) {} }; -int refreshSpinsUI (void* data) +bool refreshSpinsUI(RefreshSpinHelper* rsh) { - RefreshSpinHelper* rsh = static_cast(data); - rsh->crop->refreshSpins (rsh->notify); - delete rsh; - return 0; + rsh->crop->refreshSpins(rsh->notify); + return false; } -int notifyListenerUI (void* data) +bool notifyListenerUI(Crop* self) { - static_cast(data)->notifyListener(); - return 0; + self->notifyListener(); + return false; } } @@ -515,16 +513,14 @@ void Crop::enabledChanged () void Crop::hFlipCrop () { - nx = maxw - nx - nw; - idle_register.add(refreshSpinsUI, new RefreshSpinHelper(this, false)); + idle_register.add(refreshSpinsUI, new RefreshSpinHelper(this, false), true); } void Crop::vFlipCrop () { - ny = maxh - ny - nh; - idle_register.add(refreshSpinsUI, new RefreshSpinHelper(this, false)); + idle_register.add(refreshSpinsUI, new RefreshSpinHelper(this, false), true); } void Crop::rotateCrop (int deg, bool hflip, bool vflip) @@ -564,7 +560,7 @@ void Crop::rotateCrop (int deg, bool hflip, bool vflip) } lastRotationDeg = deg; - idle_register.add(refreshSpinsUI, new RefreshSpinHelper(this, false)); + idle_register.add(refreshSpinsUI, new RefreshSpinHelper(this, false), true); } void Crop::positionChanged () @@ -578,7 +574,7 @@ void Crop::positionChanged () int W = nw; int H = nh; cropMoved (X, Y, W, H); - idle_register.add(notifyListenerUI, this); + idle_register.add(notifyListenerUI, this, false); } void Crop::widthChanged () @@ -591,7 +587,7 @@ void Crop::widthChanged () int W = (int)w->get_value (); int H = nh; cropWidth2Resized (X, Y, W, H); - idle_register.add(notifyListenerUI, this); + idle_register.add(notifyListenerUI, this, false); } void Crop::heightChanged () @@ -604,7 +600,7 @@ void Crop::heightChanged () int W = nw; int H = (int)h->get_value (); cropHeight2Resized (X, Y, W, H); - idle_register.add(notifyListenerUI, this); + idle_register.add(notifyListenerUI, this, false); } // Fixed ratio toggle button @@ -656,7 +652,7 @@ void Crop::adjustCropToRatio() } // This will save the options - idle_register.add(refreshSpinsUI, new RefreshSpinHelper(this, true)); + idle_register.add(refreshSpinsUI, new RefreshSpinHelper(this, true), true); } void Crop::refreshSize () @@ -742,14 +738,14 @@ void Crop::sizeChanged(int x, int y, int ow, int oh) y }; - const auto func = [](gpointer data) -> gboolean { - Params* const params = static_cast(data); - params->crop->setDimensions(params->x, params->y); - delete params; - return FALSE; - }; + const auto func = + [](Params* params) -> bool + { + params->crop->setDimensions(params->x, params->y); + return false; + }; - idle_register.add(func, params); + idle_register.add(func, params, true); } bool Crop::refreshSpins (bool notify) @@ -813,7 +809,7 @@ void Crop::cropMoved (int &X, int &Y, int &W, int &H) nw = W; nh = H; - idle_register.add(refreshSpinsUI, new RefreshSpinHelper(this, false)); + idle_register.add(refreshSpinsUI, new RefreshSpinHelper(this, false), true); // Glib::signal_idle().connect (sigc::mem_fun(*this, &Crop::refreshSpins)); } @@ -857,7 +853,7 @@ 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)); + idle_register.add(refreshSpinsUI, new RefreshSpinHelper(this, false), true); } void Crop::cropWidth2Resized (int &X, int &Y, int &W, int &H, float custom_ratio) @@ -897,7 +893,7 @@ 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)); + idle_register.add(refreshSpinsUI, new RefreshSpinHelper(this, false), true); } void Crop::cropHeight1Resized (int &X, int &Y, int &W, int &H, float custom_ratio) @@ -940,7 +936,7 @@ 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)); + idle_register.add(refreshSpinsUI, new RefreshSpinHelper(this, false), true); } void Crop::cropHeight2Resized (int &X, int &Y, int &W, int &H, float custom_ratio) @@ -980,7 +976,7 @@ 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)); + idle_register.add(refreshSpinsUI, new RefreshSpinHelper(this, false), true); } void Crop::cropTopLeftResized (int &X, int &Y, int &W, int &H, float custom_ratio) @@ -1022,7 +1018,7 @@ 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)); + idle_register.add(refreshSpinsUI, new RefreshSpinHelper(this, false), true); } void Crop::cropTopRightResized (int &X, int &Y, int &W, int &H, float custom_ratio) @@ -1062,7 +1058,7 @@ 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)); + idle_register.add(refreshSpinsUI, new RefreshSpinHelper(this, false), true); } void Crop::cropBottomLeftResized (int &X, int &Y, int &W, int &H, float custom_ratio) @@ -1102,7 +1098,7 @@ 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)); + idle_register.add(refreshSpinsUI, new RefreshSpinHelper(this, false), true); } void Crop::cropBottomRightResized (int &X, int &Y, int &W, int &H, float custom_ratio) @@ -1139,7 +1135,7 @@ 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)); + idle_register.add(refreshSpinsUI, new RefreshSpinHelper(this, false), true); } void Crop::cropInit (int &x, int &y, int &w, int &h) @@ -1253,12 +1249,12 @@ void Crop::cropResized (int &x, int &y, int& x2, int& y2) nw = W; nh = H; - idle_register.add(refreshSpinsUI, new RefreshSpinHelper(this, false)); + idle_register.add(refreshSpinsUI, new RefreshSpinHelper(this, false), true); } void Crop::cropManipReady () { - idle_register.add(notifyListenerUI, this); + idle_register.add(notifyListenerUI, this, false); } double Crop::getRatio () const diff --git a/rtgui/crophandler.cc b/rtgui/crophandler.cc index c00cccf6c..579d9af5b 100644 --- a/rtgui/crophandler.cc +++ b/rtgui/crophandler.cc @@ -338,9 +338,9 @@ void CropHandler::setDetailedCrop( bool expected = false; if (redraw_needed.compare_exchange_strong(expected, true)) { - const auto func = [](gpointer data) -> gboolean { - CropHandler* const self = static_cast(data); - + const auto func = + [](CropHandler* self) -> bool + { self->cimg.lock (); if (self->redraw_needed.exchange(false)) { @@ -350,7 +350,7 @@ void CropHandler::setDetailedCrop( self->cropimg.clear(); self->cropimgtrue.clear(); self->cimg.unlock (); - return FALSE; + return false; } if (!self->cropimg.empty()) { @@ -398,10 +398,10 @@ void CropHandler::setDetailedCrop( self->cimg.unlock(); } - return FALSE; + return false; }; - idle_register.add(func, this/*, G_PRIORITY_HIGH_IDLE*/); + idle_register.add(func, this, false); } } diff --git a/rtgui/dirpyrdenoise.cc b/rtgui/dirpyrdenoise.cc index 81d7cff9a..72360b1de 100644 --- a/rtgui/dirpyrdenoise.cc +++ b/rtgui/dirpyrdenoise.cc @@ -284,32 +284,32 @@ DirPyrDenoise::~DirPyrDenoise () void DirPyrDenoise::chromaChanged (double autchroma, double autred, double autblue) { struct Data { - DirPyrDenoise *me; + DirPyrDenoise* self; double autchroma; double autred; double autblue; }; - const auto func = [](gpointer data) -> gboolean { - Data *d = static_cast(data); - DirPyrDenoise *me = d->me; - me->disableListener(); - me->chroma->setValue(d->autchroma); - me->redchro->setValue(d->autred); - me->bluechro->setValue(d->autblue); - me->enableListener(); - delete d; - return FALSE; - }; + const auto func = + [](Data* data) -> bool + { + DirPyrDenoise* const self = data->self; + self->disableListener(); + self->chroma->setValue(data->autchroma); + self->redchro->setValue(data->autred); + self->bluechro->setValue(data->autblue); + self->enableListener(); + return false; + }; - idle_register.add(func, new Data { this, autchroma, autred, autblue }); + idle_register.add(func, new Data{this, autchroma, autred, autblue}, true); } void DirPyrDenoise::noiseTilePrev (int tileX, int tileY, int prevX, int prevY, int sizeT, int sizeP) { if (!batchMode) { struct Data { - DirPyrDenoise *me; + DirPyrDenoise* self; int tileX; int tileY; int prevX; @@ -318,26 +318,26 @@ void DirPyrDenoise::noiseTilePrev (int tileX, int tileY, int prevX, int prevY, i int sizeP; }; - const auto func = [](gpointer data) -> gboolean { - Data *d = static_cast(data); - DirPyrDenoise *me = d->me; - me->TileLabels->set_text( - Glib::ustring::compose(M("TP_DIRPYRDENOISE_CHROMINANCE_PREVIEW_TILEINFO"), - Glib::ustring::format(std::fixed, std::setprecision(0), d->sizeT), - Glib::ustring::format(std::fixed, std::setprecision(0), d->tileX), - Glib::ustring::format(std::fixed, std::setprecision(0), d->tileY)) - ); - me->PrevLabels->set_text( - Glib::ustring::compose(M("TP_DIRPYRDENOISE_CHROMINANCE_PREVIEW_INFO"), - Glib::ustring::format(std::fixed, std::setprecision(0), d->sizeP), - Glib::ustring::format(std::fixed, std::setprecision(0), d->prevX), - Glib::ustring::format(std::fixed, std::setprecision(0), d->prevY)) - ); - delete d; - return FALSE; - }; + const auto func = + [](Data* data) -> bool + { + DirPyrDenoise* self = data->self; + self->TileLabels->set_text( + Glib::ustring::compose(M("TP_DIRPYRDENOISE_CHROMINANCE_PREVIEW_TILEINFO"), + Glib::ustring::format(std::fixed, std::setprecision(0), data->sizeT), + Glib::ustring::format(std::fixed, std::setprecision(0), data->tileX), + Glib::ustring::format(std::fixed, std::setprecision(0), data->tileY)) + ); + self->PrevLabels->set_text( + Glib::ustring::compose(M("TP_DIRPYRDENOISE_CHROMINANCE_PREVIEW_INFO"), + Glib::ustring::format(std::fixed, std::setprecision(0), data->sizeP), + Glib::ustring::format(std::fixed, std::setprecision(0), data->prevX), + Glib::ustring::format(std::fixed, std::setprecision(0), data->prevY)) + ); + return false; + }; - idle_register.add(func, new Data { this, tileX, tileY, prevX, prevY, sizeT, sizeP }); + idle_register.add(func, new Data{this, tileX, tileY, prevX, prevY, sizeT, sizeP}, true); } } @@ -345,20 +345,20 @@ void DirPyrDenoise::noiseChanged (double nresid, double highresid) { if (!batchMode) { struct Data { - DirPyrDenoise *me; + DirPyrDenoise* self; double nresid; double highresid; }; - const auto func = [](gpointer data) -> gboolean { - Data *d = static_cast(data); - DirPyrDenoise *me = d->me; - me->updateNoiseLabel(d->nresid, d->highresid); - delete d; - return FALSE; - }; + const auto func = + [](Data* data) -> bool + { + DirPyrDenoise* const self = data->self; + self->updateNoiseLabel(data->nresid, data->highresid); + return false; + }; - idle_register.add(func, new Data { this, nresid, highresid }); + idle_register.add(func, new Data{this, nresid, highresid}, true); } } diff --git a/rtgui/editorpanel.cc b/rtgui/editorpanel.cc index 1f46d60e7..d86612c9f 100644 --- a/rtgui/editorpanel.cc +++ b/rtgui/editorpanel.cc @@ -45,10 +45,8 @@ struct spparams { Glib::RefPtr cssProvider; }; -int setprogressStrUI ( void *p ) +bool setprogressStrUI(spparams* s) { - spparams *s = static_cast (p); - if ( ! s->str.empty() ) { s->pProgress->set_text ( M (s->str) ); } @@ -67,8 +65,7 @@ int setprogressStrUI ( void *p ) } } - delete s; - return FALSE; + return false; } @@ -498,7 +495,7 @@ EditorPanel::EditorPanel (FilePanel* filePanel) // build left side panel leftbox = new Gtk::Paned (Gtk::ORIENTATION_VERTICAL); - + // make a subbox to allow resizing of the histogram (if it's on the left) leftsubbox = new Gtk::Box (Gtk::ORIENTATION_VERTICAL); leftsubbox->set_size_request (230, 250); @@ -520,7 +517,7 @@ EditorPanel::EditorPanel (FilePanel* filePanel) leftsubbox->pack_start (*history); leftsubbox->show_all (); - + leftbox->pack2 (*leftsubbox, true, true); leftbox->show_all (); @@ -638,14 +635,14 @@ EditorPanel::EditorPanel (FilePanel* filePanel) // build right side panel vboxright = new Gtk::Paned (Gtk::ORIENTATION_VERTICAL); - + vsubboxright = new Gtk::Box (Gtk::ORIENTATION_VERTICAL, 0); vsubboxright->set_size_request (300, 250); vsubboxright->pack_start (*ppframe, Gtk::PACK_SHRINK, 2); // main notebook vsubboxright->pack_start (*tpc->toolPanelNotebook); - + vboxright->pack2 (*vsubboxright, true, true); // Save buttons @@ -862,7 +859,7 @@ EditorPanel::EditorPanel (FilePanel* filePanel) if (tbTopPanel_1) { tbTopPanel_1->signal_toggled().connect ( sigc::mem_fun (*this, &EditorPanel::tbTopPanel_1_toggled) ); } - + } EditorPanel::~EditorPanel () @@ -1192,7 +1189,7 @@ void EditorPanel::setProgress(double p) spparams *s = new spparams; s->val = p; s->pProgress = progressLabel; - idle_register.add(setprogressStrUI, s); + idle_register.add(setprogressStrUI, s, true); } void EditorPanel::setProgressStr(const Glib::ustring& str) @@ -1201,7 +1198,7 @@ void EditorPanel::setProgressStr(const Glib::ustring& str) s->str = str; s->val = -1; s->pProgress = progressLabel; - idle_register.add(setprogressStrUI, s); + idle_register.add(setprogressStrUI, s, true); } void EditorPanel::setProgressState(bool inProcessing) @@ -1217,30 +1214,27 @@ void EditorPanel::setProgressState(bool inProcessing) p->inProcessing = inProcessing; p->epih = epih; - const auto func = [] (gpointer data) -> gboolean { - spsparams* const p = static_cast (data); - - if (p->epih->destroyed) + const auto func = + [](spsparams* p) -> bool { - if (p->epih->pending == 1) { - delete p->epih; - } else { - p->epih->pending--; + if (p->epih->destroyed) + { + if (p->epih->pending == 1) { + delete p->epih; + } else { + p->epih->pending--; + } + + return false; } - delete p; + p->epih->epanel->refreshProcessingState (p->inProcessing); + p->epih->pending--; - return 0; - } + return false; + }; - p->epih->epanel->refreshProcessingState (p->inProcessing); - p->epih->pending--; - delete p; - - return FALSE; - }; - - idle_register.add (func, p); + idle_register.add(func, p, true); } void EditorPanel::error(const Glib::ustring& descr) @@ -1261,30 +1255,27 @@ void EditorPanel::error(const Glib::ustring& title, const Glib::ustring& descr) p->title = title; p->epih = epih; - const auto func = [] (gpointer data) -> gboolean { - errparams* const p = static_cast (data); - - if (p->epih->destroyed) + const auto func = + [](errparams* p) -> bool { - if (p->epih->pending == 1) { - delete p->epih; - } else { - p->epih->pending--; + if (p->epih->destroyed) + { + if (p->epih->pending == 1) { + delete p->epih; + } else { + p->epih->pending--; + } + + return false; } - delete p; + p->epih->epanel->displayError (p->title, p->descr); + p->epih->pending--; - return 0; - } + return false; + }; - p->epih->epanel->displayError (p->title, p->descr); - p->epih->pending--; - delete p; - - return FALSE; - }; - - idle_register.add (func, p); + idle_register.add(func, p, true); } void EditorPanel::displayError(const Glib::ustring& title, const Glib::ustring& descr) @@ -2376,7 +2367,7 @@ void EditorPanel::updateHistogramPosition (int oldPosition, int newPosition) leftbox->pack1(*histogramPanel, false, false); histogramPanel->unreference(); } - + leftbox->set_position(options.histogramHeight); histogramPanel->reorder (Gtk::POS_LEFT); break; @@ -2396,14 +2387,14 @@ void EditorPanel::updateHistogramPosition (int oldPosition, int newPosition) vboxright->pack1 (*histogramPanel, false, false); histogramPanel->unreference(); } - - vboxright->set_position(options.histogramHeight); + + vboxright->set_position(options.histogramHeight); histogramPanel->reorder (Gtk::POS_RIGHT); break; } iareapanel->imageArea->setPointerMotionHListener (histogramPanel); - + } diff --git a/rtgui/filebrowser.cc b/rtgui/filebrowser.cc index f83e39146..f2ce2cb79 100644 --- a/rtgui/filebrowser.cc +++ b/rtgui/filebrowser.cc @@ -568,31 +568,30 @@ void FileBrowser::doubleClicked (ThumbBrowserEntryBase* entry) void FileBrowser::addEntry (FileBrowserEntry* entry) { struct addparams { - FileBrowser *browser; - FileBrowserEntry *entry; + FileBrowser* self; + FileBrowserEntry* entry; unsigned int session_id; }; addparams* const ap = new addparams; entry->setParent (this); - ap->browser = this; + ap->self = this; ap->entry = entry; ap->session_id = session_id(); - const auto func = [](gpointer data) -> gboolean { - addparams* const ap = static_cast(data); - if (ap->session_id != ap->browser->session_id()) { - delete ap->entry; - delete ap; - } else { - ap->browser->addEntry_(ap->entry); - delete ap; - } + const auto func = + [](addparams* ap) -> bool + { + if (ap->session_id != ap->self->session_id()) { + delete ap->entry; + } else { + ap->self->addEntry_(ap->entry); + } - return FALSE; - }; + return false; + }; - idle_register.add(func, ap); + idle_register.add(func, ap, true); } void FileBrowser::addEntry_ (FileBrowserEntry* entry) @@ -1935,13 +1934,14 @@ void FileBrowser::_thumbRearrangementNeeded () void FileBrowser::thumbRearrangementNeeded () { - const auto func = [](gpointer data) -> gboolean { - static_cast(data)->_thumbRearrangementNeeded(); + const auto func = + [](FileBrowser* self) -> bool + { + self->_thumbRearrangementNeeded(); + return false; + }; - return FALSE; - }; - - idle_register.add(func, this); + idle_register.add(func, this, false); } void FileBrowser::selectionChanged () diff --git a/rtgui/filebrowserentry.cc b/rtgui/filebrowserentry.cc index c91f95912..5d47a54ea 100644 --- a/rtgui/filebrowserentry.cc +++ b/rtgui/filebrowserentry.cc @@ -233,31 +233,29 @@ void FileBrowserEntry::updateImage(rtengine::IImage8* img, double scale, const r const gint priority = G_PRIORITY_LOW; - const auto func = [](gpointer data) -> gboolean { - tiupdate* const params = static_cast(data); - FileBrowserEntryIdleHelper* const feih = params->feih; + const auto func = + [](tiupdate* params) -> bool + { + FileBrowserEntryIdleHelper* const feih = params->feih; - if (feih->destroyed) { - if (feih->pending == 1) { - delete feih; - } else { - feih->pending--; + if (feih->destroyed) { + if (feih->pending == 1) { + delete feih; + } else { + feih->pending--; + } + + params->img->free (); + return false; } - params->img->free (); - delete params; - return 0; - } + feih->fbentry->_updateImage (params->img, params->scale, params->cropParams); + feih->pending--; - feih->fbentry->_updateImage (params->img, params->scale, params->cropParams); - feih->pending--; + return false; + }; - delete params; - - return FALSE; - }; - - idle_register.add(func, param, priority); + idle_register.add(func, param, true, priority); } void FileBrowserEntry::_updateImage(rtengine::IImage8* img, double s, const rtengine::procparams::CropParams& cropParams) diff --git a/rtgui/filecatalog.cc b/rtgui/filecatalog.cc index 55e293718..e9d1720b9 100644 --- a/rtgui/filecatalog.cc +++ b/rtgui/filecatalog.cc @@ -873,13 +873,14 @@ void FileCatalog::previewsFinished (int dir_id) currentEFS = dirEFS; } - const auto func = [](gpointer data) -> gboolean { - static_cast(data)->previewsFinishedUI(); + const auto func = + [](FileCatalog* self) -> bool + { + self->previewsFinishedUI(); + return false; + }; - return FALSE; - }; - - idle_register.add(func, this); + idle_register.add(func, this, false); } void FileCatalog::setEnabled (bool e) @@ -941,24 +942,22 @@ struct FCOIParams { std::vector tmb; }; -int openRequestedUI (void* p) +bool openRequestedUI(FCOIParams* params) { - FCOIParams* params = static_cast(p); params->catalog->_openImage (params->tmb); - delete params; - - return 0; + return false; } void FileCatalog::filterApplied() { - const auto func = [](gpointer data) -> gboolean { - static_cast(data)->_refreshProgressBar(); + const auto func = + [](FileCatalog* self) -> bool + { + self->_refreshProgressBar(); + return false; + }; - return FALSE; - }; - - idle_register.add(func, this); + idle_register.add(func, this, false); } void FileCatalog::openRequested(const std::vector& tmb) @@ -971,7 +970,7 @@ void FileCatalog::openRequested(const std::vector& tmb) tmb[i]->increaseRef (); } - idle_register.add(openRequestedUI, params); + idle_register.add(openRequestedUI, params, true); } void FileCatalog::deleteRequested(const std::vector& tbe, bool inclBatchProcessed) @@ -1229,7 +1228,7 @@ void FileCatalog::developRequested(const std::vector& tbe, bo params.resize.width = options.fastexport_resize_width; params.resize.height = options.fastexport_resize_height; } - + params.resize.enabled = options.fastexport_resize_enabled; params.resize.scale = options.fastexport_resize_scale; params.resize.appliesTo = options.fastexport_resize_appliesTo; @@ -1903,7 +1902,7 @@ void FileCatalog::addAndOpenFile (const Glib::ustring& fname) params->catalog = this; params->tmb.push_back (tmb); tmb->increaseRef (); - idle_register.add(openRequestedUI, params); + idle_register.add(openRequestedUI, params, true); } catch(Gio::Error&) {} } diff --git a/rtgui/filepanel.cc b/rtgui/filepanel.cc index f75983ac0..c842dad66 100644 --- a/rtgui/filepanel.cc +++ b/rtgui/filepanel.cc @@ -139,12 +139,14 @@ FilePanel::FilePanel () : parent(nullptr), error(0) fileCatalog->setFileSelectionListener (this); - const auto func = [](gpointer data) -> gboolean { - static_cast(data)->init(); - return FALSE; - }; + const auto func = + [](FilePanel* self) -> bool + { + self->init(); + return false; + }; - idle_register.add(func, this); + idle_register.add(func, this, false); show_all (); } diff --git a/rtgui/flatfield.cc b/rtgui/flatfield.cc index 057ce731c..ae94255a7 100644 --- a/rtgui/flatfield.cc +++ b/rtgui/flatfield.cc @@ -412,18 +412,19 @@ void FlatField::setShortcutPath(const Glib::ustring& path) void FlatField::flatFieldAutoClipValueChanged(int n) { struct Data { - FlatField *me; + FlatField* self; int n; }; - const auto func = [](gpointer data) -> gboolean { - Data *d = static_cast(data); - FlatField *me = d->me; - me->disableListener(); - me->flatFieldClipControl->setValue (d->n); - me->enableListener(); - delete d; - return FALSE; - }; - idle_register.add(func, new Data { this, n }); -} \ No newline at end of file + const auto func = + [](Data* data) -> bool + { + FlatField* const self = data->self; + self->disableListener(); + self->flatFieldClipControl->setValue (data->n); + self->enableListener(); + return false; + }; + + idle_register.add(func, new Data{this, n}, true); +} diff --git a/rtgui/guiutils.cc b/rtgui/guiutils.cc index f8129b0fb..257927b0c 100644 --- a/rtgui/guiutils.cc +++ b/rtgui/guiutils.cc @@ -43,39 +43,14 @@ IdleRegister::~IdleRegister() destroy(); } -void IdleRegister::add(GSourceFunc function, gpointer data, gint priority) -{ - const auto dispatch = [](gpointer data) -> gboolean { - DataWrapper* const data_wrapper = static_cast(data); - - if (!data_wrapper->function(data_wrapper->data)) { - data_wrapper->self->mutex.lock(); - data_wrapper->self->ids.erase(data_wrapper); - data_wrapper->self->mutex.unlock(); - - delete data_wrapper; - return FALSE; - } - - return TRUE; - }; - - DataWrapper* const data_wrapper = new DataWrapper{ - this, - function, - data - }; - - mutex.lock(); - ids[data_wrapper] = gdk_threads_add_idle_full(priority, dispatch, data_wrapper, nullptr); - mutex.unlock(); -} - void IdleRegister::destroy() { mutex.lock(); for (const auto& id : ids) { g_source_remove(id.second); + if (id.first->deleter) { + id.first->deleter(id.first->data); + } delete id.first; } ids.clear(); @@ -1278,7 +1253,7 @@ MyFileChooserButton::MyFileChooserButton(const Glib::ustring &title, Gtk::FileCh if (GTK_MINOR_VERSION < 20) { set_border_width(2); // margin doesn't work on GTK < 3.20 } - + set_name("MyFileChooserButton"); } @@ -1368,7 +1343,7 @@ std::vector> MyFileChooserButton::list_filters() return file_filters_; } - + bool MyFileChooserButton::set_current_folder(const std::string &filename) { current_folder_ = filename; diff --git a/rtgui/guiutils.h b/rtgui/guiutils.h index 8816eca4f..2cb7ca77e 100644 --- a/rtgui/guiutils.h +++ b/rtgui/guiutils.h @@ -50,7 +50,54 @@ class IdleRegister final : public: ~IdleRegister(); - void add(GSourceFunc function, gpointer data, gint priority = G_PRIORITY_DEFAULT_IDLE); + template + void add(bool (*function)(DATA*), DATA* data, bool delete_data, gint priority = G_PRIORITY_DEFAULT_IDLE) + { + const auto dispatch = + [](gpointer data) -> gboolean + { + DataWrapper* const data_wrapper = static_cast(data); + + // This is safe as per https://en.cppreference.com/w/cpp/language/reinterpret_cast item 7) + if (!reinterpret_cast(data_wrapper->function)(static_cast(data_wrapper->data))) { + data_wrapper->self->mutex.lock(); + data_wrapper->self->ids.erase(data_wrapper); + data_wrapper->self->mutex.unlock(); + + if (data_wrapper->deleter) { + data_wrapper->deleter(data_wrapper->data); + } + + delete data_wrapper; + return FALSE; + } + + return TRUE; + }; + + DataWrapper* const data_wrapper = new DataWrapper{ + this, + reinterpret_cast(function), + data, + [delete_data]() -> GSourceFunc + { + if (delete_data) { + return + [](gpointer data) -> gboolean + { + delete static_cast(data); + return TRUE; + }; + } + return nullptr; + }() + }; + + mutex.lock(); + ids[data_wrapper] = gdk_threads_add_idle_full(priority, dispatch, data_wrapper, nullptr); + mutex.unlock(); + } + void destroy(); private: @@ -58,6 +105,7 @@ private: IdleRegister* const self; GSourceFunc function; gpointer data; + GSourceFunc deleter; }; std::map ids; @@ -399,7 +447,7 @@ public: sigc::signal &signal_selection_changed(); sigc::signal &signal_file_set(); - + std::string get_filename() const; bool set_filename(const std::string &filename); @@ -407,7 +455,7 @@ public: void remove_filter(const Glib::RefPtr &filter); void set_filter(const Glib::RefPtr &filter); std::vector> list_filters(); - + bool set_current_folder(const std::string &filename); std::string get_current_folder() const; diff --git a/rtgui/histogrampanel.cc b/rtgui/histogrampanel.cc index 7c136cbfe..007e1187d 100644 --- a/rtgui/histogrampanel.cc +++ b/rtgui/histogrampanel.cc @@ -44,11 +44,11 @@ HistogramPanel::HistogramPanel () histogramArea = Gtk::manage (new HistogramArea (this)); setExpandAlignProperties(histogramArea, true, true, Gtk::ALIGN_FILL, Gtk::ALIGN_FILL); - + histogramRGBArea = Gtk::manage (new HistogramRGBArea ()); setExpandAlignProperties(histogramRGBArea, true, false, Gtk::ALIGN_FILL, Gtk::ALIGN_END); histogramRGBArea->show(); - + // connecting the two childs histogramArea->signal_factor_changed().connect( sigc::mem_fun(*histogramRGBArea, &HistogramRGBArea::factorChanged) ); @@ -78,7 +78,7 @@ HistogramPanel::HistogramPanel () chroImage_g = new RTImage ("histogram-gold-off-small.png"); rawImage_g = new RTImage ("histogram-bayer-off-small.png"); barImage_g = new RTImage ("histogram-bar-off-small.png"); - + mode0Image = new RTImage ("histogram-mode-linear-small.png"); mode1Image = new RTImage ("histogram-mode-logx-small.png"); mode2Image = new RTImage ("histogram-mode-logxy-small.png"); @@ -226,9 +226,9 @@ void HistogramPanel::resized (Gtk::Allocation& req) histogramRGBArea->updateBackBuffer(-1, -1, -1); histogramRGBArea->queue_draw (); - // Store current height of the histogram + // Store current height of the histogram options.histogramHeight = get_height(); - + } void HistogramPanel::red_toggled () @@ -346,7 +346,7 @@ void HistogramPanel::reorder (Gtk::PositionType align) // DrawModeListener interface: void HistogramPanel::toggleButtonMode () -{ +{ if (options.histogramDrawMode == 0) showMode->set_image(*mode0Image); else if (options.histogramDrawMode == 1) @@ -562,28 +562,28 @@ void HistogramRGBArea::update (int valh, int rh, int gh, int bh) harih->pending++; - const auto func = [](gpointer data) -> gboolean { - HistogramRGBAreaIdleHelper* const harih = static_cast(data); + const auto func = + [](HistogramRGBAreaIdleHelper* harih) -> bool + { + if (harih->destroyed) { + if (harih->pending == 1) { + delete harih; + } else { + harih->pending--; + } - if (harih->destroyed) { - if (harih->pending == 1) { - delete harih; - } else { - harih->pending--; + return false; } - return 0; - } + harih->harea->updateBackBuffer(-1, -1, -1); + harih->harea->queue_draw (); - harih->harea->updateBackBuffer(-1, -1, -1); - harih->harea->queue_draw (); + harih->pending--; - harih->pending--; + return false; + }; - return FALSE; - }; - - idle_register.add(func, harih); + idle_register.add(func, harih, false); } void HistogramRGBArea::updateOptions (bool r, bool g, bool b, bool l, bool c, bool raw, bool bar) @@ -655,7 +655,7 @@ void HistogramRGBArea::factorChanged (double newFactor) // // // HistogramArea -HistogramArea::HistogramArea (DrawModeListener *fml) : +HistogramArea::HistogramArea (DrawModeListener *fml) : valid(false), drawMode(options.histogramDrawMode), myDrawModeListener(fml), oldwidth(-1), oldheight(-1), needRed(options.histogramRed), needGreen(options.histogramGreen), needBlue(options.histogramBlue), @@ -703,14 +703,14 @@ void HistogramArea::get_preferred_height_vfunc (int &minimum_height, int &natura void HistogramArea::get_preferred_width_vfunc (int &minimum_width, int &natural_width) const { - + minimum_width = 200; natural_width = 400; } void HistogramArea::get_preferred_height_for_width_vfunc (int width, int &minimum_height, int &natural_height) const { - + minimum_height = 0; natural_height = 0; } @@ -722,7 +722,7 @@ void HistogramArea::get_preferred_width_for_height_vfunc (int height, int &minim void HistogramArea::updateOptions (bool r, bool g, bool b, bool l, bool c, bool raw, int mode) { - + options.histogramRed = needRed = r; options.histogramGreen = needGreen = g; options.histogramBlue = needBlue = b; @@ -761,29 +761,29 @@ void HistogramArea::update( haih->pending++; // Can be done outside of the GUI thread - const auto func = [](gpointer data) -> gboolean { - HistogramAreaIdleHelper* const haih = static_cast(data); + const auto func = + [](HistogramAreaIdleHelper* haih) -> bool + { + if (haih->destroyed) { + if (haih->pending == 1) { + delete haih; + } else { + haih->pending--; + } - if (haih->destroyed) { - if (haih->pending == 1) { - delete haih; - } else { - haih->pending--; + return false; } - return 0; - } + 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; + }; - return FALSE; - }; - - idle_register.add(func, haih); + idle_register.add(func, haih, false); } void HistogramArea::updateBackBuffer () @@ -889,7 +889,7 @@ void HistogramArea::updateBackBuffer () // Compute the highest point of the histogram for scaling // Values at far left and right end (0 and 255) are handled differently - + unsigned int histheight = 0; for (int i = 1; i < 255; i++) { @@ -915,7 +915,7 @@ void HistogramArea::updateBackBuffer () } int realhistheight = histheight; - + if (realhistheight < winh - 2) { realhistheight = winh - 2; } @@ -960,7 +960,7 @@ void HistogramArea::updateBackBuffer () cr->stroke (); drawMarks(cr, bhchanged, realhistheight, w, ui, oi); } - + } // Draw the frame's border @@ -1044,16 +1044,16 @@ bool HistogramArea::on_button_press_event (GdkEventButton* event) { isPressed = true; movingPosition = event->x; - + if (event->type == GDK_2BUTTON_PRESS && event->button == 1) { - + drawMode = (drawMode + 1) % 3; options.histogramDrawMode = (options.histogramDrawMode + 1) % 3; - + if (myDrawModeListener) { myDrawModeListener->toggleButtonMode (); } - + updateBackBuffer (); queue_draw (); } @@ -1072,19 +1072,19 @@ bool HistogramArea::on_motion_notify_event (GdkEventMotion* event) if (isPressed) { double mod = 1 + (event->x - movingPosition) / get_width(); - + factor /= mod; if (factor < 1.0) factor = 1.0; if (factor > 100.0) factor = 100.0; - + sigFactorChanged.emit(factor); - + setDirty(true); queue_draw (); } - + return true; } diff --git a/rtgui/mydiagonalcurve.cc b/rtgui/mydiagonalcurve.cc index 0bc58f28e..d07ce5943 100644 --- a/rtgui/mydiagonalcurve.cc +++ b/rtgui/mydiagonalcurve.cc @@ -1516,28 +1516,28 @@ void MyDiagonalCurve::updateBackgroundHistogram (LUTu & hist) mcih->pending++; - const auto func = [](gpointer data) -> gboolean { - MyCurveIdleHelper* const mcih = static_cast(data); + const auto func = + [](MyCurveIdleHelper* mcih) -> bool + { + if (mcih->destroyed) { + if (mcih->pending == 1) { + delete mcih; + } else { + mcih->pending--; + } - if (mcih->destroyed) { - if (mcih->pending == 1) { - delete mcih; - } else { - mcih->pending--; + return false; } - return 0; - } + mcih->clearPixmap (); + mcih->myCurve->queue_draw (); - mcih->clearPixmap (); - mcih->myCurve->queue_draw (); + mcih->pending--; - mcih->pending--; + return false; + }; - return FALSE; - }; - - idle_register.add(func, mcih); + 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 a251986bf..5029397a0 100644 --- a/rtgui/previewhandler.cc +++ b/rtgui/previewhandler.cc @@ -67,40 +67,38 @@ void PreviewHandler::setImage(rtengine::IImage8* i, double scale, const rtengine iap->scale = scale; iap->cp = cp; - const auto func = [](gpointer data) -> gboolean { - iaimgpar* const iap = static_cast(data); - PreviewHandlerIdleHelper* const pih = iap->pih; + const auto func = + [](iaimgpar* iap) -> bool + { + PreviewHandlerIdleHelper* const pih = iap->pih; - if (pih->destroyed) { - if (pih->pending == 1) { - delete pih; - } else { - pih->pending--; + if (pih->destroyed) { + if (pih->pending == 1) { + delete pih; + } else { + pih->pending--; + } + + return false; } - delete iap; + if (pih->phandler->image) { + IImage8* const oldImg = pih->phandler->image; + oldImg->getMutex().lock (); + pih->phandler->image = iap->image; + oldImg->getMutex().unlock (); + } else { + pih->phandler->image = iap->image; + } - return FALSE; - } + pih->phandler->cropParams = iap->cp; + pih->phandler->previewScale = iap->scale; + pih->pending--; - if (pih->phandler->image) { - IImage8* const oldImg = pih->phandler->image; - oldImg->getMutex().lock (); - pih->phandler->image = iap->image; - oldImg->getMutex().unlock (); - } else { - pih->phandler->image = iap->image; - } + return false; + }; - pih->phandler->cropParams = iap->cp; - pih->phandler->previewScale = iap->scale; - pih->pending--; - delete iap; - - return FALSE; - }; - - idle_register.add(func, iap); + idle_register.add(func, iap, true); } @@ -112,41 +110,39 @@ void PreviewHandler::delImage(IImage8* i) iap->image = i; iap->pih = pih; - const auto func = [](gpointer data) -> gboolean { - iaimgpar* iap = static_cast(data); - PreviewHandlerIdleHelper* pih = iap->pih; + const auto func = + [](iaimgpar* iap) -> bool + { + PreviewHandlerIdleHelper* const pih = iap->pih; - if (pih->destroyed) { - if (pih->pending == 1) { - delete pih; - } else { - pih->pending--; + if (pih->destroyed) { + if (pih->pending == 1) { + delete pih; + } else { + pih->pending--; + } + + return false; } - delete iap; + if (pih->phandler->image) { + IImage8* oldImg = pih->phandler->image; + oldImg->getMutex().lock (); + pih->phandler->image = nullptr; + oldImg->getMutex().unlock (); + } - return FALSE; - } + iap->image->free (); + pih->phandler->previewImgMutex.lock (); + pih->phandler->previewImg.clear (); + pih->phandler->previewImgMutex.unlock (); - if (pih->phandler->image) { - IImage8* oldImg = pih->phandler->image; - oldImg->getMutex().lock (); - pih->phandler->image = nullptr; - oldImg->getMutex().unlock (); - } + pih->pending--; - iap->image->free (); - pih->phandler->previewImgMutex.lock (); - pih->phandler->previewImg.clear (); - pih->phandler->previewImgMutex.unlock (); + return false; + }; - pih->pending--; - delete iap; - - return FALSE; - }; - - idle_register.add(func, iap); + idle_register.add(func, iap, true); } void PreviewHandler::imageReady(const rtengine::procparams::CropParams& cp) @@ -156,34 +152,32 @@ void PreviewHandler::imageReady(const rtengine::procparams::CropParams& cp) iap->pih = pih; iap->cp = cp; - const auto func = [](gpointer data) -> gboolean { - iaimgpar* const iap = static_cast(data); - PreviewHandlerIdleHelper* pih = iap->pih; + const auto func = + [](iaimgpar* iap) -> bool + { + PreviewHandlerIdleHelper* const pih = iap->pih; - if (pih->destroyed) { - if (pih->pending == 1) { - delete pih; - } else { - pih->pending--; + if (pih->destroyed) { + if (pih->pending == 1) { + delete pih; + } else { + pih->pending--; + } + + return false; } - delete iap; + 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->previewImageChanged (); + pih->pending--; - return FALSE; - } + 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.unlock (); - pih->phandler->cropParams = iap->cp; - pih->phandler->previewImageChanged (); - pih->pending--; - delete iap; - - return FALSE; - }; - - idle_register.add(func, iap); + 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 0de1f7db0..c57ff236a 100644 --- a/rtgui/resize.cc +++ b/rtgui/resize.cc @@ -95,7 +95,7 @@ Resize::Resize () : FoldableToolPanel(this, "resize", M("TP_RESIZE_LABEL"), fals allowUpscaling = Gtk::manage(new Gtk::CheckButton(M("TP_RESIZE_ALLOW_UPSCALING"))); sizeBox->pack_start(*allowUpscaling); allowUpscaling->signal_toggled().connect(sigc::mem_fun(*this, &Resize::allowUpscalingChanged)); - + sizeBox->show_all (); sizeBox->reference (); @@ -366,76 +366,76 @@ void Resize::sizeChanged(int mw, int mh, int ow, int oh) void Resize::setDimensions () { - const auto func = [](gpointer data) -> gboolean { - Resize* const self = static_cast(data); + const auto func = + [](Resize* self) -> bool + { + self->wconn.block(true); + self->hconn.block(true); + self->scale->block(true); - self->wconn.block(true); - self->hconn.block(true); - self->scale->block(true); + int refw, refh; - int refw, refh; - - if (self->appliesTo->get_active_row_number() == 0 && self->cropw) { - // Applies to Cropped area - refw = self->cropw; - refh = self->croph; - } else { - // Applies to Full image or crop is disabled - refw = self->maxw; - refh = self->maxh; - } - - self->w->set_range(32, MAX_SCALE * refw); - self->h->set_range(32, MAX_SCALE * refh); - - switch (self->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))); - break; + if (self->appliesTo->get_active_row_number() == 0 && self->cropw) { + // Applies to Cropped area + refw = self->cropw; + refh = self->croph; + } else { + // Applies to Full image or crop is disabled + refw = self->maxw; + refh = self->maxh; } - 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))); - break; + self->w->set_range(32, MAX_SCALE * refw); + self->h->set_range(32, MAX_SCALE * refh); + + switch (self->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))); + 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))); + 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))); + 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); + + self->scale->setValue(tmp_scale); + break; + } + + default: { + 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))); - break; - } + self->scale->block(false); + self->wconn.block(false); + self->hconn.block(false); - 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); + return false; + }; - self->scale->setValue(tmp_scale); - break; - } - - default: { - break; - } - } - - self->scale->block(false); - self->wconn.block(false); - self->hconn.block(false); - - return FALSE; - }; - - idle_register.add(func, this); + idle_register.add(func, this, false); } void Resize::fitBoxScale() diff --git a/rtgui/retinex.cc b/rtgui/retinex.cc index 08883708e..0e2bddbda 100644 --- a/rtgui/retinex.cc +++ b/rtgui/retinex.cc @@ -673,14 +673,16 @@ void Retinex::minmaxChanged (double cdma, double cdmin, double mini, double maxi nextminT = Tmin; nextmaxT = Tmax; - const auto func = [] (gpointer data) -> gboolean { - GThreadLock lock; // All GUI access from idle_add callbacks or separate thread HAVE to be protected - static_cast (data)->minmaxComputed_(); + const auto func = + [](Retinex* self) -> 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_(); + return false; + }; - return FALSE; - }; - - idle_register.add (func, this); + idle_register.add(func, this, false); } bool Retinex::minmaxComputed_ () diff --git a/rtgui/tonecurve.cc b/rtgui/tonecurve.cc index 06abe1fd2..d4c9e8ab6 100644 --- a/rtgui/tonecurve.cc +++ b/rtgui/tonecurve.cc @@ -45,7 +45,7 @@ ToneCurve::ToneCurve () : FoldableToolPanel(this, "tonecurve", M("TP_EXPOSURE_LA pack_start(*clampOOG); pack_start (*Gtk::manage (new Gtk::HSeparator())); clampOOG->signal_toggled().connect(sigc::mem_fun(*this, &ToneCurve::clampOOGChanged)); - + //----------- Auto Levels ---------------------------------- abox = Gtk::manage (new Gtk::HBox ()); abox->set_spacing (10); @@ -238,7 +238,7 @@ void ToneCurve::read (const ProcParams* pp, const ParamsEdited* pedited) 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 } @@ -604,7 +604,7 @@ void ToneCurve::adjusterChanged(Adjuster* a, double newval) if (a != expcomp && a != hlcompr && a != hlcomprthresh) { setHistmatching(false); } - + Glib::ustring costr; if (a == expcomp) { @@ -629,7 +629,7 @@ void ToneCurve::adjusterChanged(Adjuster* a, double newval) listener->panelChanged (EvSaturation, costr); } else if (a == hlcompr) { listener->panelChanged (EvHLCompr, costr); - + if (!hlcompr->getAddMode() && !batchMode) { hlcomprthresh->set_sensitive(!((int)hlcompr->getValue () == 0)); //at hlcompr=0 hlcomprthresh value has no effect } @@ -650,7 +650,7 @@ void ToneCurve::neutral_pressed () // and sets neutral values to params in exposure panel setHistmatching(false); - + if (batchMode) { autolevels->set_inconsistent (false); autoconn.block (true); @@ -680,7 +680,7 @@ void ToneCurve::neutral_pressed () 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 } @@ -754,7 +754,7 @@ void ToneCurve::autolevels_toggled () if (!black->getAddMode()) { 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 } @@ -857,7 +857,7 @@ bool ToneCurve::autoExpComputed_ () 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 } @@ -979,7 +979,7 @@ bool ToneCurve::histmatchingComputed() 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 } @@ -1013,13 +1013,14 @@ void ToneCurve::autoExpChanged(double expcomp, int bright, int contr, int black, nextHlcomprthresh = hlcomprthresh; nextHLRecons = hlrecons; - const auto func = [](gpointer data) -> gboolean { - static_cast(data)->autoExpComputed_(); + const auto func = + [](ToneCurve* self) -> bool + { + self->autoExpComputed_(); + return false; + }; - return FALSE; - }; - - idle_register.add(func, this); + idle_register.add(func, this, false); } void ToneCurve::autoMatchedToneCurveChanged(rtengine::procparams::ToneCurveParams::TcMode curveMode, const std::vector& curve) @@ -1027,11 +1028,12 @@ void ToneCurve::autoMatchedToneCurveChanged(rtengine::procparams::ToneCurveParam nextToneCurveMode = curveMode; nextToneCurve = curve; - const auto func = [](gpointer data) -> gboolean { - static_cast(data)->histmatchingComputed(); + const auto func = + [](ToneCurve* self) -> bool + { + self->histmatchingComputed(); + return false; + }; - return FALSE; - }; - - idle_register.add(func, this); + idle_register.add(func, this, false); } diff --git a/rtgui/toolpanelcoord.cc b/rtgui/toolpanelcoord.cc index 43aaeecd2..1c9b17a5a 100644 --- a/rtgui/toolpanelcoord.cc +++ b/rtgui/toolpanelcoord.cc @@ -263,74 +263,74 @@ void ToolPanelCoordinator::imageTypeChanged (bool isRaw, bool isBayer, bool isXt { if (isRaw) { if (isBayer) { - const auto func = [](gpointer data) -> gboolean { - ToolPanelCoordinator* const self = static_cast(data); + const auto func = + [](ToolPanelCoordinator* self) -> 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); - 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); - - return FALSE; - }; - idle_register.add(func, this); + return false; + }; + idle_register.add(func, this, false); } else if (isXtrans) { - const auto func = [](gpointer data) -> gboolean { - ToolPanelCoordinator* const self = static_cast(data); + const auto func = + [](ToolPanelCoordinator* self) -> 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); - 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); - - return FALSE; - }; - idle_register.add(func, this); + return false; + }; + idle_register.add(func, this, false); } else if (isMono) { - const auto func = [](gpointer data) -> gboolean { - ToolPanelCoordinator* const self = static_cast(data); + const auto func = + [](ToolPanelCoordinator* self) -> 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); - 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); - - return FALSE; - }; - idle_register.add(func, this); + return false; + }; + idle_register.add(func, this, false); } else { - const auto func = [](gpointer data) -> gboolean { - ToolPanelCoordinator* const self = static_cast(data); + const auto func = + [](ToolPanelCoordinator* self) -> 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); - 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); - - return FALSE; - }; - idle_register.add(func, this); + return false; + }; + idle_register.add(func, this, false); } } else { - const auto func = [](gpointer data) -> gboolean { - ToolPanelCoordinator* const self = static_cast(data); + const auto func = + [](ToolPanelCoordinator* self) -> bool + { + self->rawPanelSW->set_sensitive (false); + self->retinex->FoldableToolPanel::setGrayedOut(true); - self->rawPanelSW->set_sensitive (false); - self->retinex->FoldableToolPanel::setGrayedOut(true); - - return FALSE; - }; - idle_register.add(func, this); + return false; + }; + idle_register.add(func, this, false); } } diff --git a/rtgui/wavelet.cc b/rtgui/wavelet.cc index 7aa03050a..5b395fc91 100644 --- a/rtgui/wavelet.cc +++ b/rtgui/wavelet.cc @@ -888,22 +888,22 @@ void Wavelet::wavChanged (double nlevel) { if (!batchMode) { struct Data { - Wavelet *me; + Wavelet *self; double nlevel; }; - const auto func = [](gpointer data) -> gboolean { - Data *d = static_cast(data); - Wavelet *me = d->me; - me->wavLabels->set_text( - Glib::ustring::compose(M("TP_WAVELET_LEVLABEL"), - Glib::ustring::format(std::fixed, std::setprecision(0), d->nlevel)) - ); - delete d; - return FALSE; - }; + const auto func = + [](Data* data) -> bool + { + Wavelet* self = data->self; + self->wavLabels->set_text( + Glib::ustring::compose(M("TP_WAVELET_LEVLABEL"), + Glib::ustring::format(std::fixed, std::setprecision(0), data->nlevel)) + ); + return false; + }; - idle_register.add(func, new Data { this, nlevel }); + idle_register.add(func, new Data{this, nlevel}, true); } } diff --git a/rtgui/whitebalance.cc b/rtgui/whitebalance.cc index 1257a9c58..fcd983618 100644 --- a/rtgui/whitebalance.cc +++ b/rtgui/whitebalance.cc @@ -695,7 +695,7 @@ void WhiteBalance::read (const ProcParams* pp, const ParamsEdited* pedited) } green->setLogScale(10, green->getValue(), true); - + methconn.block (false); enableListener (); } @@ -915,22 +915,23 @@ void WhiteBalance::WBChanged(double temperature, double greenVal) double green_val; }; - const auto func = [](gpointer data) -> gboolean { - WhiteBalance* const self = static_cast(static_cast(data)->self); - const double temperature = static_cast(data)->temperature; - const double green_val = static_cast(data)->green_val; - delete static_cast(data); + const auto func = + [](Data* data) -> bool + { + WhiteBalance* const self = static_cast(data->self); + const double temperature = data->temperature; + const double green_val = data->green_val; - self->disableListener(); - self->setEnabled(true); - self->temp->setValue(temperature); - self->green->setValue(green_val); - self->temp->setDefault(temperature); - self->green->setDefault(green_val); - self->enableListener(); + self->disableListener(); + self->setEnabled(true); + self->temp->setValue(temperature); + self->green->setValue(green_val); + self->temp->setDefault(temperature); + self->green->setDefault(green_val); + self->enableListener(); - return FALSE; - }; + return false; + }; - idle_register.add(func, new Data{this, temperature, greenVal}); + idle_register.add(func, new Data{this, temperature, greenVal}, true); } diff --git a/rtgui/xtransprocess.cc b/rtgui/xtransprocess.cc index 47556e54f..72a2db2b0 100644 --- a/rtgui/xtransprocess.cc +++ b/rtgui/xtransprocess.cc @@ -255,18 +255,19 @@ void XTransProcess::checkBoxToggled (CheckBox* c, CheckValue newval) void XTransProcess::autoContrastChanged (double autoContrast) { struct Data { - XTransProcess *me; + XTransProcess* self; double autoContrast; }; - const auto func = [](gpointer data) -> gboolean { - Data *d = static_cast(data); - XTransProcess *me = d->me; - me->disableListener(); - me->dualDemosaicContrast->setValue(d->autoContrast); - me->enableListener(); - delete d; - return FALSE; - }; - idle_register.add(func, new Data { this, autoContrast }); + const auto func = + [](Data* data) -> bool + { + XTransProcess* self = data->self; + self->disableListener(); + self->dualDemosaicContrast->setValue(data->autoContrast); + self->enableListener(); + return false; + }; + + idle_register.add(func, new Data{this, autoContrast}, true); } From 1d0c128209650dfe56ae989206f8b22cd70ed328 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fl=C3=B6ssie?= Date: Sun, 28 Oct 2018 19:35:31 +0100 Subject: [PATCH 04/17] Fix Windows build (#4892) --- rtgui/batchqueue.cc | 10 ++++++---- rtgui/dirbrowser.cc | 13 +++++++------ rtgui/filecatalog.cc | 13 +++++++------ 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/rtgui/batchqueue.cc b/rtgui/batchqueue.cc index de9864226..bd7c4b015 100644 --- a/rtgui/batchqueue.cc +++ b/rtgui/batchqueue.cc @@ -436,10 +436,12 @@ void BatchQueue::cancelItems (const std::vector& items) if (entry->thumbnail) entry->thumbnail->imageRemovedFromQueue (); - const auto func = [](BatchQueueEntry* bqe) -> bool { - ::g_remove(bqe->savedParamsFile.c_str()); - return false; - }; + const auto func = + [](BatchQueueEntry* bqe) -> bool + { + ::g_remove(bqe->savedParamsFile.c_str()); + return false; + }; idle_register.add(func, entry, true); } diff --git a/rtgui/dirbrowser.cc b/rtgui/dirbrowser.cc index 501296860..47a8eb71a 100644 --- a/rtgui/dirbrowser.cc +++ b/rtgui/dirbrowser.cc @@ -248,13 +248,14 @@ int updateVolumesUI (void* br) void DirBrowser::winDirChanged () { - const auto func = [](gpointer data) -> gboolean { - static_cast(data)->updateDirTreeRoot(); + const auto func = + [](DirBrowser* self) -> bool + { + self->updateDirTreeRoot(); + return false; + }; - return FALSE; - }; - - idle_register.add(func, this); + idle_register.add(func, this, false); } #endif diff --git a/rtgui/filecatalog.cc b/rtgui/filecatalog.cc index e9d1720b9..799e68350 100644 --- a/rtgui/filecatalog.cc +++ b/rtgui/filecatalog.cc @@ -1793,13 +1793,14 @@ void FileCatalog::reparseDirectory () void FileCatalog::winDirChanged () { - const auto func = [](gpointer data) -> gboolean { - static_cast(data)->reparseDirectory(); + const auto func = + [](FileCatalog* self) -> bool + { + self->reparseDirectory(); + return false; + }; - return FALSE; - }; - - idle_register.add(func, this); + idle_register.add(func, this, false); } #else From 00b62d2b652a2c6ef389a0c0243a41ad9ad8ba2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fl=C3=B6ssie?= Date: Sun, 11 Nov 2018 20:32:01 +0100 Subject: [PATCH 05/17] Add @thirtythreeforty's `std::function<>` variant (#4892) Also convert `batchqueue.cc` where applicable. --- rtgui/batchqueue.cc | 69 +++++++++++++++++++-------------------------- rtgui/guiutils.cc | 13 +++++++++ rtgui/guiutils.h | 2 ++ 3 files changed, 44 insertions(+), 40 deletions(-) diff --git a/rtgui/batchqueue.cc b/rtgui/batchqueue.cc index bd7c4b015..2841c6811 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 queueEmptied; - bool queueError; - Glib::ustring queueErrorMessage; -}; - -bool bqnotifylistenerUI(NLParams* params) -{ - params->listener->queueSizeChanged (params->qsize, params->queueEmptied, params->queueError, params->queueErrorMessage); - return false; -} - -} - BatchQueue::BatchQueue (FileCatalog* aFileCatalog) : processing(nullptr), fileCatalog(aFileCatalog), sequence(0), listener(nullptr) { @@ -604,14 +585,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) @@ -636,12 +616,15 @@ void BatchQueue::error(const Glib::ustring& descr) } if (listener) { - NLParams* params = new NLParams; - params->listener = listener; - params->queueEmptied = false; - params->queueError = true; - params->queueErrorMessage = descr; - idle_register.add(bqnotifylistenerUI, params, true); + BatchQueueListener* const listener_copy = listener; + + idle_register.add( + [listener_copy, descr]() -> bool + { + listener_copy->queueSizeChanged(0, false, true, descr); + return false; + } + ); } } @@ -975,15 +958,21 @@ void BatchQueue::notifyListener (bool queueEmptied) { if (listener) { - NLParams* params = new NLParams; - params->listener = listener; - { - MYREADERLOCK(l, entryRW); - params->qsize = fd.size(); - } - params->queueEmptied = queueEmptied; - params->queueError = false; - idle_register.add(bqnotifylistenerUI, params, true); + BatchQueueListener* const listener_copy = listener; + const std::size_t queue_size = + [](MyRWMutex& mutex, const std::vector& fd) -> std::size_t + { + MYREADERLOCK(l, mutex); + return fd.size(); + }(entryRW, fd); + + idle_register.add( + [listener_copy, queue_size, queueEmptied]() -> bool + { + listener_copy->queueSizeChanged(queue_size, queueEmptied, false, {}); + return false; + } + ); } } diff --git a/rtgui/guiutils.cc b/rtgui/guiutils.cc index 257927b0c..bd9828933 100644 --- a/rtgui/guiutils.cc +++ b/rtgui/guiutils.cc @@ -43,6 +43,19 @@ IdleRegister::~IdleRegister() destroy(); } +void IdleRegister::add(std::function function, gint priority) +{ + using Function = std::function; + + const auto func = + [](Function* function) + { + return (*function)(); + }; + + add(func, new Function(std::move(function)), true, priority); +} + void IdleRegister::destroy() { mutex.lock(); diff --git a/rtgui/guiutils.h b/rtgui/guiutils.h index 2cb7ca77e..43f94e4db 100644 --- a/rtgui/guiutils.h +++ b/rtgui/guiutils.h @@ -19,6 +19,7 @@ #ifndef __GUI_UTILS_ #define __GUI_UTILS_ +#include #include #include @@ -98,6 +99,7 @@ public: mutex.unlock(); } + void add(std::function function, gint priority = G_PRIORITY_DEFAULT_IDLE); void destroy(); private: 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 06/17] 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); + } + ); } } From b9942422e76b98a73269bc2455ccfffd870dc792 Mon Sep 17 00:00:00 2001 From: heckflosse Date: Tue, 1 Jan 2019 17:36:17 +0100 Subject: [PATCH 07/17] Change microcontrast uniformity adjuster range, fixes #5129 --- rtdata/profiles/Pixel Shift/PS ISO Low.pp3 | 2 +- rtdata/profiles/Pixel Shift/PS No Motion.pp3 | 2 +- rtengine/ipsharpen.cc | 2 +- rtengine/procparams.cc | 10 ++++++++-- rtengine/procparams.h | 2 +- rtgui/ppversion.h | 4 +++- rtgui/sharpenmicro.cc | 2 +- 7 files changed, 16 insertions(+), 8 deletions(-) diff --git a/rtdata/profiles/Pixel Shift/PS ISO Low.pp3 b/rtdata/profiles/Pixel Shift/PS ISO Low.pp3 index afd3b762c..5587b19e0 100644 --- a/rtdata/profiles/Pixel Shift/PS ISO Low.pp3 +++ b/rtdata/profiles/Pixel Shift/PS ISO Low.pp3 @@ -12,7 +12,7 @@ Enabled=true Contrast=15 Matrix=false Strength=20 -Uniformity=50 +Uniformity=5 [RAW] CA=true diff --git a/rtdata/profiles/Pixel Shift/PS No Motion.pp3 b/rtdata/profiles/Pixel Shift/PS No Motion.pp3 index af624912e..f1d889f97 100644 --- a/rtdata/profiles/Pixel Shift/PS No Motion.pp3 +++ b/rtdata/profiles/Pixel Shift/PS No Motion.pp3 @@ -12,7 +12,7 @@ Enabled=true Contrast=15 Matrix=false Strength=20 -Uniformity=50 +Uniformity=5 [RAW] CA=true diff --git a/rtengine/ipsharpen.cc b/rtengine/ipsharpen.cc index 8437fae47..84068ced9 100644 --- a/rtengine/ipsharpen.cc +++ b/rtengine/ipsharpen.cc @@ -643,7 +643,7 @@ BENCHFUN const int k = params->sharpenMicro.matrix ? 1 : 2; // k=2 matrix 5x5 k=1 matrix 3x3 const int width = W, height = H; - const int unif = params->sharpenMicro.uniformity / 10.0f; //put unif between 0 to 10 + const int unif = params->sharpenMicro.uniformity; const float amount = (k == 1 ? 2.7f : 1.f) * params->sharpenMicro.amount / 1500.0f; //amount 2000.0 quasi no artifacts ==> 1500 = maximum, after artifacts, 25/9 if 3x3 if (settings->verbose) { diff --git a/rtengine/procparams.cc b/rtengine/procparams.cc index 5c4596745..fe4512691 100644 --- a/rtengine/procparams.cc +++ b/rtengine/procparams.cc @@ -1149,7 +1149,7 @@ SharpenMicroParams::SharpenMicroParams() : matrix(false), amount(20.0), contrast(20.0), - uniformity(50.0) + uniformity(5) { } @@ -3962,7 +3962,13 @@ int ProcParams::load(const Glib::ustring& fname, ParamsEdited* pedited) pedited->sharpenMicro.contrast = true; } } - assignFromKeyfile(keyFile, "SharpenMicro", "Uniformity", pedited, sharpenMicro.uniformity, pedited->sharpenMicro.uniformity); + if (ppVersion >= 346) { + assignFromKeyfile(keyFile, "SharpenMicro", "Uniformity", pedited, sharpenMicro.uniformity, pedited->sharpenMicro.uniformity); + } else { + double temp; + assignFromKeyfile(keyFile, "SharpenMicro", "Uniformity", pedited, temp, pedited->sharpenMicro.uniformity); + sharpenMicro.uniformity = temp / 10; + } } if (keyFile.has_group("Vibrance")) { diff --git a/rtengine/procparams.h b/rtengine/procparams.h index d1b70b9c2..50e77d32e 100644 --- a/rtengine/procparams.h +++ b/rtengine/procparams.h @@ -531,7 +531,7 @@ struct SharpenMicroParams { bool matrix; double amount; double contrast; - double uniformity; + int uniformity; SharpenMicroParams(); diff --git a/rtgui/ppversion.h b/rtgui/ppversion.h index 91a9633c0..89f93ed44 100644 --- a/rtgui/ppversion.h +++ b/rtgui/ppversion.h @@ -1,11 +1,13 @@ #pragma once // This number has to be incremented whenever the PP3 file format is modified or the behaviour of a tool changes -#define PPVERSION 345 +#define PPVERSION 346 #define PPVERSION_AEXP 301 //value of PPVERSION when auto exposure algorithm was modified /* Log of version changes + 346 2019-01-01 + changed microcontrast uniformity 345 2018-10-21 dual demosaic auto contrast threshold 344 2018-10-04 diff --git a/rtgui/sharpenmicro.cc b/rtgui/sharpenmicro.cc index 7e981db96..8686b747b 100644 --- a/rtgui/sharpenmicro.cc +++ b/rtgui/sharpenmicro.cc @@ -40,7 +40,7 @@ SharpenMicro::SharpenMicro () : FoldableToolPanel(this, "sharpenmicro", M("TP_SH amount->setAdjusterListener (this); amount->show(); - uniformity = Gtk::manage(new Adjuster (M("TP_SHARPENMICRO_UNIFORMITY"), 0, 100, 10, 50)); + uniformity = Gtk::manage(new Adjuster (M("TP_SHARPENMICRO_UNIFORMITY"), 0, 10, 1, 5)); uniformity->setAdjusterListener (this); uniformity->show(); From 732bbf1a554dd2e218b8947f70d9abf083cb0c16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fl=C3=B6ssie?= Date: Tue, 1 Jan 2019 17:55:36 +0100 Subject: [PATCH 08/17] Convert `BatchQueue::cancelItems()` to functional `IdleRegister::add()` --- rtgui/batchqueue.cc | 50 ++++++++++++++++++++++++++++++++++---------- rtgui/batchqueue.h | 15 +++++++++---- rtgui/filecatalog.cc | 2 +- 3 files changed, 51 insertions(+), 16 deletions(-) diff --git a/rtgui/batchqueue.cc b/rtgui/batchqueue.cc index a995797f3..f6c598df7 100644 --- a/rtgui/batchqueue.cc +++ b/rtgui/batchqueue.cc @@ -86,6 +86,17 @@ BatchQueue::BatchQueue (FileCatalog* aFileCatalog) : processing(nullptr), fileCa BatchQueue::~BatchQueue () { + std::set removable_bqes; + + mutex_removable_batch_queue_entries.lock(); + removable_batch_queue_entries.swap(removable_bqes); + mutex_removable_batch_queue_entries.unlock(); + + for (const auto entry : removable_bqes) { + ::g_remove(entry->savedParamsFile.c_str()); + delete entry; + } + idle_register.destroy(); MYWRITERLOCK(l, entryRW); @@ -395,6 +406,8 @@ Glib::ustring BatchQueue::getTempFilenameForParams( const Glib::ustring &filenam void BatchQueue::cancelItems (const std::vector& items) { + std::set removable_bqes; + { MYWRITERLOCK(l, entryRW); @@ -417,14 +430,7 @@ void BatchQueue::cancelItems (const std::vector& items) if (entry->thumbnail) entry->thumbnail->imageRemovedFromQueue (); - const auto func = - [](BatchQueueEntry* bqe) -> bool - { - ::g_remove(bqe->savedParamsFile.c_str()); - return false; - }; - - idle_register.add(func, entry, true); + removable_bqes.insert(entry); } for (const auto entry : fd) @@ -434,6 +440,30 @@ void BatchQueue::cancelItems (const std::vector& items) selected.clear (); } + if (!removable_bqes.empty()) { + mutex_removable_batch_queue_entries.lock(); + removable_batch_queue_entries.insert(removable_bqes.begin(), removable_bqes.end()); + mutex_removable_batch_queue_entries.unlock(); + + idle_register.add( + [this]() -> bool + { + std::set removable_bqes; + + mutex_removable_batch_queue_entries.lock(); + removable_batch_queue_entries.swap(removable_bqes); + mutex_removable_batch_queue_entries.unlock(); + + for (const auto entry : removable_bqes) { + ::g_remove(entry->savedParamsFile.c_str()); + delete entry; + } + + return false; + } + ); + } + saveBatchQueue (); redraw (); @@ -940,9 +970,7 @@ Glib::ustring BatchQueue::autoCompleteFileName (const Glib::ustring& fileName, c void BatchQueue::buttonPressed (LWButton* button, int actionCode, void* actionData) { - - std::vector bqe; - bqe.push_back (static_cast(actionData)); + const std::vector bqe = {static_cast(actionData)}; if (actionCode == 10) { // cancel cancelItems (bqe); diff --git a/rtgui/batchqueue.h b/rtgui/batchqueue.h index c05ca54fe..7751ec176 100644 --- a/rtgui/batchqueue.h +++ b/rtgui/batchqueue.h @@ -18,12 +18,16 @@ #ifndef _BATCHQUEUE_ #define _BATCHQUEUE_ +#include + #include -#include "threadutils.h" -#include "batchqueueentry.h" + #include "../rtengine/rtengine.h" -#include "options.h" + +#include "batchqueueentry.h" #include "lwbuttonset.h" +#include "options.h" +#include "threadutils.h" #include "thumbbrowserbase.h" class BatchQueueListener @@ -85,7 +89,7 @@ public: static Glib::ustring calcAutoFileNameBase (const Glib::ustring& origFileName, int sequence = 0); static int calcMaxThumbnailHeight(); -protected: +private: int getMaxThumbnailHeight() const override; void saveThumbnailHeight (int height) override; int getThumbnailHeight () override; @@ -111,6 +115,9 @@ protected: BatchQueueListener* listener; + std::set removable_batch_queue_entries; + MyMutex mutex_removable_batch_queue_entries; + IdleRegister idle_register; }; diff --git a/rtgui/filecatalog.cc b/rtgui/filecatalog.cc index aebd0f990..5ebac5e12 100644 --- a/rtgui/filecatalog.cc +++ b/rtgui/filecatalog.cc @@ -930,7 +930,7 @@ void FileCatalog::filterApplied() void FileCatalog::openRequested(const std::vector& tmb) { - for (auto thumb : tmb) { + for (const auto thumb : tmb) { thumb->increaseRef(); } From b21d910573e951ad51b4058bb5ecedc63c8bde57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fl=C3=B6ssie?= Date: Tue, 1 Jan 2019 20:58:26 +0100 Subject: [PATCH 09/17] Remove legacy `IdleRegister::add<>()` --- rtgui/bayerprocess.cc | 59 +++++++++++++--------------------- rtgui/colorappearance.cc | 66 +++++++++++++-------------------------- rtgui/editorpanel.cc | 30 ++++++------------ rtgui/filebrowser.cc | 27 ++++++---------- rtgui/filebrowserentry.cc | 36 ++++++--------------- rtgui/flatfield.cc | 21 +++++-------- rtgui/guiutils.cc | 31 ++++++++++++------ rtgui/guiutils.h | 52 +----------------------------- rtgui/wavelet.cc | 23 ++++++-------- rtgui/whitebalance.cc | 29 +++++++---------- rtgui/xtransprocess.cc | 21 +++++-------- 11 files changed, 128 insertions(+), 267 deletions(-) diff --git a/rtgui/bayerprocess.cc b/rtgui/bayerprocess.cc index ad9db9c2c..74cf27dde 100644 --- a/rtgui/bayerprocess.cc +++ b/rtgui/bayerprocess.cc @@ -718,56 +718,39 @@ void BayerProcess::pixelShiftMotionMethodChanged () void BayerProcess::FrameCountChanged(int n, int frameNum) { - struct Data { - BayerProcess *me; - int n; - int frameNum; - }; - - const auto func = - [](Data* d) -> bool + idle_register.add( + [this, n, frameNum]() -> bool { - BayerProcess *me = d->me; - me->imageNumber->block (true); - int n = d->n; - int frameNum = d->frameNum; + imageNumber->block(true); - me->imageNumber->remove_all(); - me->imageNumber->append("1"); - for(int i = 2; i <= std::min(n, 4); ++i) { + imageNumber->remove_all(); + imageNumber->append("1"); + for (int i = 2; i <= std::min(n, 4); ++i) { std::ostringstream entry; entry << i; - me->imageNumber->append(entry.str()); + imageNumber->append(entry.str()); } - me->imageNumber->set_active(std::min(frameNum, n - 1)); - if(n == 1) { - me->imageNumberBox->hide(); + imageNumber->set_active(std::min(frameNum, n - 1)); + if (n == 1) { + imageNumberBox->hide(); } else { - me->imageNumberBox->show(); + imageNumberBox->show(); } - me->imageNumber->block (false); + imageNumber->block (false); return false; - }; - - idle_register.add(func, new Data{this, n, frameNum}, true); + } + ); } void BayerProcess::autoContrastChanged (double autoContrast) { - struct Data { - BayerProcess* self; - double autoContrast; - }; - - const auto func = - [](Data* data) -> bool + idle_register.add( + [this, autoContrast]() -> bool { - BayerProcess* const self = data->self; - self->disableListener(); - self->dualDemosaicContrast->setValue(data->autoContrast); - self->enableListener(); + disableListener(); + dualDemosaicContrast->setValue(autoContrast); + enableListener(); return false; - }; - - idle_register.add(func, new Data{this, autoContrast}, true); + } + ); } diff --git a/rtgui/colorappearance.cc b/rtgui/colorappearance.cc index bbf5ed5d7..dea55ced4 100644 --- a/rtgui/colorappearance.cc +++ b/rtgui/colorappearance.cc @@ -1447,64 +1447,42 @@ void ColorAppearance::setDefaults (const ProcParams* defParams, const ParamsEdit void ColorAppearance::autoCamChanged (double ccam, double ccamout) { - struct Data { - ColorAppearance* me; - double ccam; - double ccamout; - }; - - const auto func = - [](Data* data) -> bool + idle_register.add( + [this, ccam, ccamout]() -> bool { - ColorAppearance* const self = data->me; - self->disableListener(); - self->degree->setValue(data->ccam); - self->degreeout->setValue(data->ccamout); - self->enableListener(); + disableListener(); + degree->setValue(ccam); + degreeout->setValue(ccamout); + enableListener(); return false; - }; - - idle_register.add(func, new Data{this, ccam, ccamout}, true); + } + ); } void ColorAppearance::adapCamChanged (double cadap) { - struct Data { - ColorAppearance* self; - double cadap; - }; - - const auto func = - [](Data* data) -> bool + idle_register.add( + [this, cadap]() -> bool { - ColorAppearance* const self = data->self; - self->disableListener(); - self->adapscen->setValue(data->cadap); - self->enableListener(); + disableListener(); + adapscen->setValue(cadap); + enableListener(); return false; - }; - - idle_register.add(func, new Data{this, cadap}, true); + } + ); } void ColorAppearance::ybCamChanged (int ybsc) { - struct Data { - ColorAppearance* self; - int ybsc; - }; - - const auto func = - [](Data* data) -> bool + idle_register.add( + [this, ybsc]() -> bool { - ColorAppearance* self = data->self; - self->disableListener(); - self->ybscen->setValue(data->ybsc); - self->enableListener(); + disableListener(); + ybscen->setValue(ybsc); + enableListener(); return false; - }; - - idle_register.add(func, new Data{this, ybsc}, true); + } + ); } void ColorAppearance::colorForValue (double valX, double valY, enum ColorCaller::ElemType elemType, int callerId, ColorCaller *caller) diff --git a/rtgui/editorpanel.cc b/rtgui/editorpanel.cc index b0e945ce1..cfd2d0486 100644 --- a/rtgui/editorpanel.cc +++ b/rtgui/editorpanel.cc @@ -1193,38 +1193,28 @@ void EditorPanel::setProgressStr(const Glib::ustring& str) void EditorPanel::setProgressState(bool inProcessing) { - struct spsparams { - bool inProcessing; - EditorPanelIdleHelper* epih; - }; - epih->pending++; - spsparams* p = new spsparams; - p->inProcessing = inProcessing; - p->epih = epih; - - const auto func = - [](spsparams* p) -> bool + idle_register.add( + [this, inProcessing]() -> bool { - if (p->epih->destroyed) + if (epih->destroyed) { - if (p->epih->pending == 1) { - delete p->epih; + if (epih->pending == 1) { + delete epih; } else { - p->epih->pending--; + --epih->pending; } return false; } - p->epih->epanel->refreshProcessingState (p->inProcessing); - p->epih->pending--; + epih->epanel->refreshProcessingState(inProcessing); + --epih->pending; return false; - }; - - idle_register.add(func, p, true); + } + ); } void EditorPanel::error(const Glib::ustring& descr) diff --git a/rtgui/filebrowser.cc b/rtgui/filebrowser.cc index 20cb3350f..d489bb1d3 100644 --- a/rtgui/filebrowser.cc +++ b/rtgui/filebrowser.cc @@ -565,31 +565,22 @@ void FileBrowser::doubleClicked (ThumbBrowserEntryBase* entry) void FileBrowser::addEntry (FileBrowserEntry* entry) { - struct addparams { - FileBrowser* self; - FileBrowserEntry* entry; - unsigned int session_id; - }; + entry->setParent(this); - addparams* const ap = new addparams; - entry->setParent (this); - ap->self = this; - ap->entry = entry; - ap->session_id = session_id(); + const unsigned int sid = session_id(); - const auto func = - [](addparams* ap) -> bool + idle_register.add( + [this, entry, sid]() -> bool { - if (ap->session_id != ap->self->session_id()) { - delete ap->entry; + if (sid != session_id()) { + delete entry; } else { - ap->self->addEntry_(ap->entry); + addEntry_(entry); } return false; - }; - - idle_register.add(func, ap, true); + } + ); } void FileBrowser::addEntry_ (FileBrowserEntry* entry) diff --git a/rtgui/filebrowserentry.cc b/rtgui/filebrowserentry.cc index 5d47a54ea..70d2fc128 100644 --- a/rtgui/filebrowserentry.cc +++ b/rtgui/filebrowserentry.cc @@ -217,45 +217,27 @@ void FileBrowserEntry::updateImage(rtengine::IImage8* img, double scale, const r redrawRequests++; feih->pending++; - struct tiupdate { - FileBrowserEntryIdleHelper* feih; - rtengine::IImage8* img; - double scale; - rtengine::procparams::CropParams cropParams; - }; - - tiupdate* param = new tiupdate{ - feih, - img, - scale, - cropParams - }; - - const gint priority = G_PRIORITY_LOW; - - const auto func = - [](tiupdate* params) -> bool + idle_register.add( + [this, img, scale, cropParams]() -> bool { - FileBrowserEntryIdleHelper* const feih = params->feih; - if (feih->destroyed) { if (feih->pending == 1) { delete feih; } else { - feih->pending--; + --feih->pending; } - params->img->free (); + img->free(); return false; } - feih->fbentry->_updateImage (params->img, params->scale, params->cropParams); - feih->pending--; + feih->fbentry->_updateImage(img, scale, cropParams); + --feih->pending; return false; - }; - - idle_register.add(func, param, true, priority); + }, + G_PRIORITY_LOW + ); } void FileBrowserEntry::_updateImage(rtengine::IImage8* img, double s, const rtengine::procparams::CropParams& cropParams) diff --git a/rtgui/flatfield.cc b/rtgui/flatfield.cc index ae94255a7..86d27aacf 100644 --- a/rtgui/flatfield.cc +++ b/rtgui/flatfield.cc @@ -411,20 +411,13 @@ void FlatField::setShortcutPath(const Glib::ustring& path) void FlatField::flatFieldAutoClipValueChanged(int n) { - struct Data { - FlatField* self; - int n; - }; - - const auto func = - [](Data* data) -> bool + idle_register.add( + [this, n]() -> bool { - FlatField* const self = data->self; - self->disableListener(); - self->flatFieldClipControl->setValue (data->n); - self->enableListener(); + disableListener(); + flatFieldClipControl->setValue(n); + enableListener(); return false; - }; - - idle_register.add(func, new Data{this, n}, true); + } + ); } diff --git a/rtgui/guiutils.cc b/rtgui/guiutils.cc index bd9828933..a645846d1 100644 --- a/rtgui/guiutils.cc +++ b/rtgui/guiutils.cc @@ -45,15 +45,31 @@ IdleRegister::~IdleRegister() void IdleRegister::add(std::function function, gint priority) { - using Function = std::function; - - const auto func = - [](Function* function) + const auto dispatch = + [](gpointer data) -> gboolean { - return (*function)(); + DataWrapper* const data_wrapper = static_cast(data); + + if (!data_wrapper->function()) { + data_wrapper->self->mutex.lock(); + data_wrapper->self->ids.erase(data_wrapper); + data_wrapper->self->mutex.unlock(); + + delete data_wrapper; + return FALSE; + } + + return TRUE; }; - add(func, new Function(std::move(function)), true, priority); + DataWrapper* const data_wrapper = new DataWrapper{ + this, + std::move(function) + }; + + mutex.lock(); + ids[data_wrapper] = gdk_threads_add_idle_full(priority, dispatch, data_wrapper, nullptr); + mutex.unlock(); } void IdleRegister::destroy() @@ -61,9 +77,6 @@ void IdleRegister::destroy() mutex.lock(); for (const auto& id : ids) { g_source_remove(id.second); - if (id.first->deleter) { - id.first->deleter(id.first->data); - } delete id.first; } ids.clear(); diff --git a/rtgui/guiutils.h b/rtgui/guiutils.h index 309965520..a5705630f 100644 --- a/rtgui/guiutils.h +++ b/rtgui/guiutils.h @@ -51,63 +51,13 @@ class IdleRegister final : public: ~IdleRegister(); - template - void add(bool (*function)(DATA*), DATA* data, bool delete_data, gint priority = G_PRIORITY_DEFAULT_IDLE) - { - const auto dispatch = - [](gpointer data) -> gboolean - { - DataWrapper* const data_wrapper = static_cast(data); - - // This is safe as per https://en.cppreference.com/w/cpp/language/reinterpret_cast item 7) - if (!reinterpret_cast(data_wrapper->function)(static_cast(data_wrapper->data))) { - data_wrapper->self->mutex.lock(); - data_wrapper->self->ids.erase(data_wrapper); - data_wrapper->self->mutex.unlock(); - - if (data_wrapper->deleter) { - data_wrapper->deleter(data_wrapper->data); - } - - delete data_wrapper; - return FALSE; - } - - return TRUE; - }; - - DataWrapper* const data_wrapper = new DataWrapper{ - this, - reinterpret_cast(function), - data, - [delete_data]() -> GSourceFunc - { - if (delete_data) { - return - [](gpointer data) -> gboolean - { - delete static_cast(data); - return TRUE; - }; - } - return nullptr; - }() - }; - - mutex.lock(); - ids[data_wrapper] = gdk_threads_add_idle_full(priority, dispatch, data_wrapper, nullptr); - mutex.unlock(); - } - void add(std::function function, gint priority = G_PRIORITY_DEFAULT_IDLE); void destroy(); private: struct DataWrapper { IdleRegister* const self; - GSourceFunc function; - gpointer data; - GSourceFunc deleter; + std::function function; }; std::map ids; diff --git a/rtgui/wavelet.cc b/rtgui/wavelet.cc index 5b395fc91..60915fa02 100644 --- a/rtgui/wavelet.cc +++ b/rtgui/wavelet.cc @@ -887,23 +887,18 @@ Wavelet::~Wavelet () void Wavelet::wavChanged (double nlevel) { if (!batchMode) { - struct Data { - Wavelet *self; - double nlevel; - }; - - const auto func = - [](Data* data) -> bool + idle_register.add( + [this, nlevel]() -> bool { - Wavelet* self = data->self; - self->wavLabels->set_text( - Glib::ustring::compose(M("TP_WAVELET_LEVLABEL"), - Glib::ustring::format(std::fixed, std::setprecision(0), data->nlevel)) + wavLabels->set_text( + Glib::ustring::compose( + M("TP_WAVELET_LEVLABEL"), + Glib::ustring::format(std::fixed, std::setprecision(0), nlevel) + ) ); return false; - }; - - idle_register.add(func, new Data{this, nlevel}, true); + } + ); } } diff --git a/rtgui/whitebalance.cc b/rtgui/whitebalance.cc index dbb65867f..02fb8d793 100644 --- a/rtgui/whitebalance.cc +++ b/rtgui/whitebalance.cc @@ -913,25 +913,18 @@ inline Gtk::TreeRow WhiteBalance::getActiveMethod () void WhiteBalance::WBChanged(double temperature, double greenVal) { - struct Data { - WhiteBalance* self; - double temperature; - double green_val; - }; - - const auto func = - [](Data* data) -> bool + idle_register.add( + [this, temperature, greenVal]() -> bool { - data->self->disableListener(); - data->self->setEnabled(true); - data->self->temp->setValue(data->temperature); - data->self->green->setValue(data->green_val); - data->self->temp->setDefault(data->temperature); - data->self->green->setDefault(data->green_val); - data->self->enableListener(); + disableListener(); + setEnabled(true); + temp->setValue(temperature); + green->setValue(greenVal); + temp->setDefault(temperature); + green->setDefault(greenVal); + enableListener(); return false; - }; - - idle_register.add(func, new Data{this, temperature, greenVal}, true); + } + ); } diff --git a/rtgui/xtransprocess.cc b/rtgui/xtransprocess.cc index 72a2db2b0..9639ce29d 100644 --- a/rtgui/xtransprocess.cc +++ b/rtgui/xtransprocess.cc @@ -254,20 +254,13 @@ void XTransProcess::checkBoxToggled (CheckBox* c, CheckValue newval) void XTransProcess::autoContrastChanged (double autoContrast) { - struct Data { - XTransProcess* self; - double autoContrast; - }; - - const auto func = - [](Data* data) -> bool + idle_register.add( + [this, autoContrast]() -> bool { - XTransProcess* self = data->self; - self->disableListener(); - self->dualDemosaicContrast->setValue(data->autoContrast); - self->enableListener(); + disableListener(); + dualDemosaicContrast->setValue(autoContrast); + enableListener(); return false; - }; - - idle_register.add(func, new Data{this, autoContrast}, true); + } + ); } From 2369440390de378e3d310b7f4cdf8eac31a24faa Mon Sep 17 00:00:00 2001 From: heckflosse Date: Wed, 16 Jan 2019 14:24:19 +0100 Subject: [PATCH 10/17] Fix standard tonecurve for non sse builds, also inluced speedup for sse builds --- rtengine/curves.h | 48 +++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/rtengine/curves.h b/rtengine/curves.h index fe93bcde5..95274954c 100644 --- a/rtengine/curves.h +++ b/rtengine/curves.h @@ -49,8 +49,7 @@ namespace rtengine class ToneCurve; class ColorAppearance; -template -void setUnlessOOG(T &r, T &g, T &b, const T &rr, const T &gg, const T &bb) +inline void setUnlessOOG(float &r, float &g, float &b, const float &rr, const float &gg, const float &bb) { if (!OOG(r) || !OOG(g) || !OOG(b)) { r = rr; @@ -59,6 +58,24 @@ void setUnlessOOG(T &r, T &g, T &b, const T &rr, const T &gg, const T &bb) } } +#ifdef __SSE2__ +inline vmask OOG(const vfloat val) +{ + return vorm(vmaskf_lt(val, ZEROV), vmaskf_gt(val, F2V(65535.f))); +} + + +inline void setUnlessOOG(vfloat &r, vfloat &g, vfloat &b, const vfloat rr, const vfloat gg, const vfloat bb) +{ + vmask cond = vandm(vandm(OOG(r), OOG(g)), OOG(b)); + if (!_mm_movemask_ps((vfloat)cond)) { + r = rr; + g = gg; + b = bb; + } +} +#endif + bool sanitizeCurve(std::vector& curve); namespace curves { @@ -967,33 +984,24 @@ inline void StandardToneCurve::BatchApply( break; #endif } - curves::setLutVal(lutToneCurve, r[i], g[i], b[i]); + setUnlessOOG(r[i], g[i], b[i], lutToneCurve[r[i]], lutToneCurve[g[i]], lutToneCurve[b[i]]); i++; } #ifdef __SSE2__ - float tmpr[4] ALIGNED16; - float tmpg[4] ALIGNED16; - float tmpb[4] ALIGNED16; - // float mv = lutToneCurve[MAXVALF]; for (; i + 3 < end; i += 4) { - __m128 r_val = LVF(r[i]); - __m128 g_val = LVF(g[i]); - __m128 b_val = LVF(b[i]); - STVF(tmpr[0], lutToneCurve[r_val]); - STVF(tmpg[0], lutToneCurve[g_val]); - STVF(tmpb[0], lutToneCurve[b_val]); - for (int j = 0; j < 4; ++j) { - setUnlessOOG(r[i+j], g[i+j], b[i+j], tmpr[j], tmpg[j], tmpb[j]); - // curves::setLutVal(r[i+j], tmpr[j], mv); - // curves::setLutVal(g[i+j], tmpg[j], mv); - // curves::setLutVal(b[i+j], tmpb[j], mv); - } + vfloat r_val = LVF(r[i]); + vfloat g_val = LVF(g[i]); + vfloat b_val = LVF(b[i]); + setUnlessOOG(r_val, g_val, b_val, lutToneCurve[r_val], lutToneCurve[g_val], lutToneCurve[b_val]); + STVF(r[i], r_val); + STVF(g[i], g_val); + STVF(b[i], b_val); } // Remainder in non-SSE. for (; i < end; ++i) { - curves::setLutVal(lutToneCurve, r[i], g[i], b[i]); + setUnlessOOG(r[i], g[i], b[i], lutToneCurve[r[i]], lutToneCurve[g[i]], lutToneCurve[b[i]]); } #endif } From 23202d1f10698ffdf0dcd53d9c49e8c790ea2449 Mon Sep 17 00:00:00 2001 From: heckflosse Date: Wed, 16 Jan 2019 14:44:08 +0100 Subject: [PATCH 11/17] Fix wrong sse version of setUnlessOOG() --- rtengine/curves.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/rtengine/curves.h b/rtengine/curves.h index 95274954c..ddbc61a58 100644 --- a/rtengine/curves.h +++ b/rtengine/curves.h @@ -68,11 +68,9 @@ inline vmask OOG(const vfloat val) inline void setUnlessOOG(vfloat &r, vfloat &g, vfloat &b, const vfloat rr, const vfloat gg, const vfloat bb) { vmask cond = vandm(vandm(OOG(r), OOG(g)), OOG(b)); - if (!_mm_movemask_ps((vfloat)cond)) { - r = rr; - g = gg; - b = bb; - } + r = vself(cond, r, rr); + g = vself(cond, g, gg); + b = vself(cond, b, bb); } #endif From b3972dee37640ad0ba6623111283f9b523447fa1 Mon Sep 17 00:00:00 2001 From: heckflosse Date: Wed, 16 Jan 2019 15:16:16 +0100 Subject: [PATCH 12/17] Small speedup for sse version of WeightedStdToneCurve::BatchApply() --- rtengine/curves.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/rtengine/curves.h b/rtengine/curves.h index ddbc61a58..b88a3bdc4 100644 --- a/rtengine/curves.h +++ b/rtengine/curves.h @@ -1159,10 +1159,6 @@ inline void WeightedStdToneCurve::BatchApply(const size_t start, const size_t en const vfloat zd5v = F2V(0.5f); const vfloat zd25v = F2V(0.25f); - float tmpr[4] ALIGNED16; - float tmpg[4] ALIGNED16; - float tmpb[4] ALIGNED16; - for (; i + 3 < end; i += 4) { vfloat r_val = vclampf(LVF(r[i]), ZEROV, c65535v); vfloat g_val = vclampf(LVF(g[i]), ZEROV, c65535v); @@ -1179,12 +1175,16 @@ inline void WeightedStdToneCurve::BatchApply(const size_t start, const size_t en vfloat r3 = Triangle(b_val, b3, r_val); vfloat g3 = Triangle(b_val, b3, g_val); - STVF(tmpr[0], vclampf(r1 * zd5v + r2 * zd25v + r3 * zd25v, ZEROV, c65535v)); - STVF(tmpg[0], vclampf(g1 * zd25v + g2 * zd5v + g3 * zd25v, ZEROV, c65535v)); - STVF(tmpb[0], vclampf(b1 * zd25v + b2 * zd25v + b3 * zd5v, ZEROV, c65535v)); - for (int j = 0; j < 4; ++j) { - setUnlessOOG(r[i+j], g[i+j], b[i+j], tmpr[j], tmpg[j], tmpb[j]); - } + vfloat r_old = LVF(r[i]); + vfloat g_old = LVF(g[i]); + vfloat b_old = LVF(b[i]); + vfloat r_new = vclampf(r1 * zd5v + r2 * zd25v + r3 * zd25v, ZEROV, c65535v); + vfloat g_new = vclampf(g1 * zd25v + g2 * zd5v + g3 * zd25v, ZEROV, c65535v); + vfloat b_new = vclampf(b1 * zd25v + b2 * zd25v + b3 * zd5v, ZEROV, c65535v); + setUnlessOOG(r_old, g_old, b_old, r_new, g_new, b_new); + STVF(r[i], r_old); + STVF(g[i], g_old); + STVF(b[i], b_old); } // Remainder in non-SSE. From 02f8e918972060a372571ad23d1d5fccd26f2524 Mon Sep 17 00:00:00 2001 From: TooWaBoo Date: Sat, 19 Jan 2019 10:52:07 +0100 Subject: [PATCH 13/17] Update Deutsch locale --- rtdata/languages/Deutsch | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/rtdata/languages/Deutsch b/rtdata/languages/Deutsch index 5ec13a759..5f232a286 100644 --- a/rtdata/languages/Deutsch +++ b/rtdata/languages/Deutsch @@ -76,6 +76,7 @@ #75 02.12.2018 Erweiterung (TooWaBoo) RT 5.5 #76 11.12.2018 Erweiterung (TooWaBoo) RT 5.5 #77 16.12.2018 Korrektur Farbwähler-Tooltip (TooWaBoo) RT 5.5 +#78 19.01.2019 Erweiterung (TooWaBoo) RT 5.5 ABOUT_TAB_BUILD;Version ABOUT_TAB_CREDITS;Danksagungen @@ -2412,7 +2413,7 @@ ZOOMPANEL_ZOOMOUT;Herauszoomen\nTaste: - ! Untranslated keys follow; remove the ! prefix after an entry is translated. !!!!!!!!!!!!!!!!!!!!!!!!! -!HISTORY_MSG_SHARPENING_BLUR;Sharpening - Blur radius -!MAIN_TAB_FAVORITES;Favorites -!MAIN_TAB_FAVORITES_TOOLTIP;Shortcut: Alt-u -!TP_SHARPENING_BLUR;Blur radius +HISTORY_MSG_SHARPENING_BLUR;(Schärfung)\nWeichzeichnerradius +MAIN_TAB_FAVORITES;Favoriten +MAIN_TAB_FAVORITES_TOOLTIP;Taste: Alt + u +TP_SHARPENING_BLUR;Weichzeichnerradius From 52aabfc93a4c472cc49b9ff5d366d466fb390877 Mon Sep 17 00:00:00 2001 From: heckflosse Date: Sat, 19 Jan 2019 13:14:29 +0100 Subject: [PATCH 14/17] don't force b&w when ciecam02 and b&w are enabled --- rtengine/simpleprocess.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rtengine/simpleprocess.cc b/rtengine/simpleprocess.cc index 87c33e8f8..dd844ad5c 100644 --- a/rtengine/simpleprocess.cc +++ b/rtengine/simpleprocess.cc @@ -1236,7 +1236,7 @@ private: cmsHPROFILE jprof = nullptr; constexpr bool customGamma = false; constexpr bool useLCMS = false; - bool bwonly = params.blackwhite.enabled && !params.colorToning.enabled && !autili && !butili ; + bool bwonly = params.blackwhite.enabled && !params.colorToning.enabled && !autili && !butili && !params.colorappearance.enabled; ///////////// Custom output gamma has been removed, the user now has to create ///////////// a new output profile with the ICCProfileCreator From 4d241d7e1048e4550074af97d9aea9703b2e6c0b Mon Sep 17 00:00:00 2001 From: heckflosse Date: Sat, 19 Jan 2019 19:10:46 +0100 Subject: [PATCH 15/17] Wrong clipping when using the new v2 and v4 profiles, fixes #5142 --- rtengine/imagefloat.cc | 3 --- rtengine/iplab2rgb.cc | 7 ------- 2 files changed, 10 deletions(-) diff --git a/rtengine/imagefloat.cc b/rtengine/imagefloat.cc index 940806419..0d978aa5b 100644 --- a/rtengine/imagefloat.cc +++ b/rtengine/imagefloat.cc @@ -143,9 +143,6 @@ void Imagefloat::getScanline (int row, unsigned char* buffer, int bps, bool isFl float ri = r(row, i); float gi = g(row, i); float bi = b(row, i); - if (ri > 65535.f || gi > 65535.f || bi > 65535.f) { - filmlike_clip(&ri, &gi, &bi); - } if (bps == 16) { sbuffer[ix++] = CLIP(ri); sbuffer[ix++] = CLIP(gi); diff --git a/rtengine/iplab2rgb.cc b/rtengine/iplab2rgb.cc index 9ab8e1d01..04358f6af 100644 --- a/rtengine/iplab2rgb.cc +++ b/rtengine/iplab2rgb.cc @@ -41,9 +41,6 @@ inline void copyAndClampLine(const float *src, unsigned char *dst, const int W) float r = src[iy] * MAXVALF; float g = src[iy+1] * MAXVALF; float b = src[iy+2] * MAXVALF; - if (r > MAXVALF || g > MAXVALF || b > MAXVALF) { - filmlike_clip(&r, &g, &b); - } dst[iy] = uint16ToUint8Rounded(CLIP(r)); dst[iy+1] = uint16ToUint8Rounded(CLIP(g)); dst[iy+2] = uint16ToUint8Rounded(CLIP(b)); @@ -73,10 +70,6 @@ inline void copyAndClamp(const LabImage *src, unsigned char *dst, const double r Color::Lab2XYZ(rL[j], ra[j], rb[j], x_, y_, z_ ); Color::xyz2rgb(x_, y_, z_, R, G, B, rgb_xyz); - if (R > MAXVALF || G > MAXVALF || B > MAXVALF) { - filmlike_clip(&R, &G, &B); - } - dst[ix++] = uint16ToUint8Rounded(Color::gamma2curve[R]); dst[ix++] = uint16ToUint8Rounded(Color::gamma2curve[G]); dst[ix++] = uint16ToUint8Rounded(Color::gamma2curve[B]); From 36ca01616b0c30f499862428ddd152f6d813100f Mon Sep 17 00:00:00 2001 From: heckflosse Date: Sat, 19 Jan 2019 19:15:32 +0100 Subject: [PATCH 16/17] Segfault when v2 ICC profiles do not contain parsable 'gamma/slope' info, fixes #5144 --- rtengine/iccstore.cc | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/rtengine/iccstore.cc b/rtengine/iccstore.cc index 33972075c..b0248456a 100644 --- a/rtengine/iccstore.cc +++ b/rtengine/iccstore.cc @@ -255,14 +255,21 @@ bool get_RT_gamma_slope(cmsHPROFILE profile, double &gammatag, double &slopetag) modelDesc = utf32_to_utf8(buffer, count); #endif if (!modelDesc.empty()) { - std::size_t pos = modelDesc.find("g"); - std::size_t posmid = modelDesc.find("s"); - std::size_t posend = modelDesc.find("!"); - std::string strgamma = modelDesc.substr(pos + 1, (posmid - pos)); - gammatag = std::stod(strgamma.c_str()); - std::string strslope = modelDesc.substr(posmid + 1, (posend - posmid)); - slopetag = std::stod(strslope.c_str()); - return true; + try { + std::size_t pos = modelDesc.find("g"); + std::size_t posmid = modelDesc.find("s"); + std::size_t posend = modelDesc.find("!"); + if (pos == std::string::npos || posmid == std::string::npos || posend == std::string::npos) { + return false; + } + std::string strgamma = modelDesc.substr(pos + 1, (posmid - pos)); + gammatag = std::stod(strgamma.c_str()); + std::string strslope = modelDesc.substr(posmid + 1, (posend - posmid)); + slopetag = std::stod(strslope.c_str()); + return true; + } catch (std::invalid_argument &) { + return false; + } } } } From 3fc7c2596521a3dc40b3c951200dcb9520681cbc Mon Sep 17 00:00:00 2001 From: heckflosse Date: Sat, 19 Jan 2019 19:22:45 +0100 Subject: [PATCH 17/17] softproof not working when no printer profile is set (no sRGB preview on wide gamut screens), fixes #5143 --- rtengine/improcfun.cc | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/rtengine/improcfun.cc b/rtengine/improcfun.cc index bf35bee70..404229d10 100644 --- a/rtengine/improcfun.cc +++ b/rtengine/improcfun.cc @@ -338,14 +338,39 @@ void ImProcFunctions::updateColorProfiles (const Glib::ustring& monitorProfile, // flags |= cmsFLAGS_GAMUTCHECK; // } + const auto make_gamma_table = + [](cmsHPROFILE prof, cmsTagSignature tag) -> void + { + cmsToneCurve *tc = static_cast(cmsReadTag(prof, tag)); + if (tc) { + const cmsUInt16Number *table = cmsGetToneCurveEstimatedTable(tc); + cmsToneCurve *tc16 = cmsBuildTabulatedToneCurve16(nullptr, cmsGetToneCurveEstimatedTableEntries(tc), table); + if (tc16) { + cmsWriteTag(prof, tag, tc16); + cmsFreeToneCurve(tc16); + } + } + }; + + cmsHPROFILE softproof = ProfileContent(oprof).toProfile(); + if (softproof) { + make_gamma_table(softproof, cmsSigRedTRCTag); + make_gamma_table(softproof, cmsSigGreenTRCTag); + make_gamma_table(softproof, cmsSigBlueTRCTag); + } + monitorTransform = cmsCreateProofingTransform ( iprof, TYPE_Lab_FLT, monitor, TYPE_RGB_FLT, - oprof, + softproof, //oprof, monitorIntent, outIntent, flags ); + if (softproof) { + cmsCloseProfile(softproof); + } + if (monitorTransform) { softProofCreated = true; }