From eeebe587ba4a899a10972c23a8e630ffa012e5d7 Mon Sep 17 00:00:00 2001 From: heckflosse Date: Sun, 8 Jul 2018 20:24:17 +0200 Subject: [PATCH] Call Histogram matching only if necessary, #4674 --- rtengine/histmatching.cc | 1 + rtengine/improccoordinator.cc | 5 ++++- rtengine/procparams.cc | 17 ++++++++++++++++- rtengine/procparams.h | 3 ++- rtengine/simpleprocess.cc | 5 +++-- rtgui/icmpanel.cc | 1 + rtgui/paramsedited.cc | 6 ++++++ rtgui/paramsedited.h | 1 + rtgui/ppversion.h | 4 +++- rtgui/profilechangelistener.h | 2 +- rtgui/profilepanel.cc | 2 +- rtgui/tonecurve.cc | 6 ++++++ rtgui/tonecurve.h | 1 + rtgui/toolpanelcoord.cc | 4 ++-- rtgui/toolpanelcoord.h | 2 +- 15 files changed, 49 insertions(+), 11 deletions(-) diff --git a/rtengine/histmatching.cc b/rtengine/histmatching.cc index 0faa8c357..076a77f64 100644 --- a/rtengine/histmatching.cc +++ b/rtengine/histmatching.cc @@ -26,6 +26,7 @@ #include "iccstore.h" #include "../rtgui/mydiagonalcurve.h" #include "improcfun.h" +#define BENCHMARK #include "StopWatch.h" #include diff --git a/rtengine/improccoordinator.cc b/rtengine/improccoordinator.cc index 29eeb07e8..2ec2df5fc 100644 --- a/rtengine/improccoordinator.cc +++ b/rtengine/improccoordinator.cc @@ -439,7 +439,9 @@ void ImProcCoordinator::updatePreviewImage (int todo, Crop* cropCall) params.toneCurve.black, params.toneCurve.hlcompr, params.toneCurve.hlcomprthresh, params.toneCurve.hrenabled); } if (params.toneCurve.histmatching) { - imgsrc->getAutoMatchedToneCurve(params.icm, params.toneCurve.curve); + if (!params.toneCurve.fromHistMatching) { + imgsrc->getAutoMatchedToneCurve(params.icm, params.toneCurve.curve); + } if (params.toneCurve.autoexp) { params.toneCurve.expcomp = 0.0; @@ -451,6 +453,7 @@ void ImProcCoordinator::updatePreviewImage (int todo, Crop* cropCall) params.toneCurve.brightness = 0; params.toneCurve.contrast = 0; params.toneCurve.black = 0; + params.toneCurve.fromHistMatching = true; if (aeListener) { aeListener->autoMatchedToneCurveChanged(params.toneCurve.curveMode, params.toneCurve.curve); diff --git a/rtengine/procparams.cc b/rtengine/procparams.cc index 4218c88ac..4c3e47701 100644 --- a/rtengine/procparams.cc +++ b/rtengine/procparams.cc @@ -328,6 +328,7 @@ ToneCurveParams::ToneCurveParams() : hlcompr(0), hlcomprthresh(33), histmatching(false), + fromHistMatching(false), clampOOG(true) { } @@ -352,6 +353,7 @@ bool ToneCurveParams::operator ==(const ToneCurveParams& other) const && hlcompr == other.hlcompr && hlcomprthresh == other.hlcomprthresh && histmatching == other.histmatching + && fromHistMatching == other.fromHistMatching && clampOOG == other.clampOOG; } @@ -2758,6 +2760,7 @@ int ProcParams::save(const Glib::ustring& fname, const Glib::ustring& fname2, bo saveToKeyfile(!pedited || pedited->toneCurve.hlcomprthresh, "Exposure", "HighlightComprThreshold", toneCurve.hlcomprthresh, keyFile); saveToKeyfile(!pedited || pedited->toneCurve.shcompr, "Exposure", "ShadowCompr", toneCurve.shcompr, keyFile); saveToKeyfile(!pedited || pedited->toneCurve.histmatching, "Exposure", "HistogramMatching", toneCurve.histmatching, keyFile); + saveToKeyfile(!pedited || pedited->toneCurve.fromHistMatching, "Exposure", "FromHistogramMatching", toneCurve.fromHistMatching, keyFile); saveToKeyfile(!pedited || pedited->toneCurve.clampOOG, "Exposure", "ClampOOG", toneCurve.clampOOG, keyFile); // Highlight recovery @@ -3530,6 +3533,14 @@ int ProcParams::load(const Glib::ustring& fname, ParamsEdited* pedited) assignFromKeyfile(keyFile, "Exposure", "Curve2", pedited, toneCurve.curve2, pedited->toneCurve.curve2); } assignFromKeyfile(keyFile, "Exposure", "HistogramMatching", pedited, toneCurve.histmatching, pedited->toneCurve.histmatching); + if (ppVersion < 340) { + toneCurve.fromHistMatching = false; + if (pedited) { + pedited->toneCurve.fromHistMatching = true; + } + } else { + assignFromKeyfile(keyFile, "Exposure", "FromHistogramMatching", pedited, toneCurve.fromHistMatching, pedited->toneCurve.fromHistMatching); + } assignFromKeyfile(keyFile, "Exposure", "ClampOOG", pedited, toneCurve.clampOOG, pedited->toneCurve.clampOOG); } @@ -5048,10 +5059,14 @@ void PartialProfile::set(bool v) } } -void PartialProfile::applyTo(ProcParams* destParams) const +void PartialProfile::applyTo(ProcParams* destParams, bool fromLastSave) const { if (destParams && pparams && pedited) { + bool fromHistMatching = fromLastSave && destParams->toneCurve.histmatching && pparams->toneCurve.histmatching; pedited->combine (*destParams, *pparams, true); + if (!fromLastSave) { + destParams->toneCurve.fromHistMatching = fromHistMatching; + } } } diff --git a/rtengine/procparams.h b/rtengine/procparams.h index b6fd1befd..a3471fc65 100644 --- a/rtengine/procparams.h +++ b/rtengine/procparams.h @@ -281,6 +281,7 @@ struct ToneCurveParams { int hlcompr; // Highlight Recovery's compression int hlcomprthresh; // Highlight Recovery's threshold bool histmatching; // histogram matching + bool fromHistMatching; bool clampOOG; // clamp out of gamut colours ToneCurveParams(); @@ -1516,7 +1517,7 @@ public: void clearGeneral(); int load(const Glib::ustring& fName); void set(bool v); - void applyTo(ProcParams* destParams) const ; + void applyTo(ProcParams* destParams, bool fromLastSaved = false) const ; rtengine::procparams::ProcParams* pparams; ParamsEdited* pedited; diff --git a/rtengine/simpleprocess.cc b/rtengine/simpleprocess.cc index f825e34a9..d57264406 100644 --- a/rtengine/simpleprocess.cc +++ b/rtengine/simpleprocess.cc @@ -749,7 +749,9 @@ private: ipf.getAutoExp (aehist, aehistcompr, params.toneCurve.clip, expcomp, bright, contr, black, hlcompr, hlcomprthresh); } if (params.toneCurve.histmatching) { - imgsrc->getAutoMatchedToneCurve(params.icm, params.toneCurve.curve); + if (!params.toneCurve.fromHistMatching) { + imgsrc->getAutoMatchedToneCurve(params.icm, params.toneCurve.curve); + } if (params.toneCurve.autoexp) { params.toneCurve.expcomp = 0.0; @@ -761,7 +763,6 @@ private: params.toneCurve.brightness = 0; params.toneCurve.contrast = 0; params.toneCurve.black = 0; - } // at this stage, we can flush the raw data to free up quite an important amount of memory diff --git a/rtgui/icmpanel.cc b/rtgui/icmpanel.cc index f71ff354b..e2664376b 100644 --- a/rtgui/icmpanel.cc +++ b/rtgui/icmpanel.cc @@ -651,6 +651,7 @@ void ICMPanel::write (ProcParams* pp, ParamsEdited* pedited) pp->icm.gampos = (double) gampos->getValue(); pp->icm.slpos = (double) slpos->getValue(); pp->icm.outputBPC = obpc->get_active (); + pp->toneCurve.fromHistMatching = false; if (pedited) { pedited->icm.input = !iunchanged->get_active (); diff --git a/rtgui/paramsedited.cc b/rtgui/paramsedited.cc index ad9df6896..5ff8d1c54 100644 --- a/rtgui/paramsedited.cc +++ b/rtgui/paramsedited.cc @@ -50,6 +50,7 @@ void ParamsEdited::set (bool v) toneCurve.hrenabled = v; toneCurve.method = v; toneCurve.histmatching = v; + toneCurve.fromHistMatching = v; toneCurve.clampOOG = v; retinex.cdcurve = v; retinex.mapcurve = v; @@ -602,6 +603,7 @@ void ParamsEdited::initFrom (const std::vector toneCurve.hrenabled = toneCurve.hrenabled && p.toneCurve.hrenabled == other.toneCurve.hrenabled; toneCurve.method = toneCurve.method && p.toneCurve.method == other.toneCurve.method; toneCurve.histmatching = toneCurve.histmatching && p.toneCurve.histmatching == other.toneCurve.histmatching; + toneCurve.fromHistMatching = toneCurve.fromHistMatching && p.toneCurve.fromHistMatching == other.toneCurve.fromHistMatching; toneCurve.clampOOG = toneCurve.clampOOG && p.toneCurve.clampOOG == other.toneCurve.clampOOG; retinex.cdcurve = retinex.cdcurve && p.retinex.cdcurve == other.retinex.cdcurve; retinex.mapcurve = retinex.mapcurve && p.retinex.mapcurve == other.retinex.mapcurve; @@ -1194,6 +1196,10 @@ void ParamsEdited::combine (rtengine::procparams::ProcParams& toEdit, const rten toEdit.toneCurve.histmatching = mods.toneCurve.histmatching; } + if (toneCurve.fromHistMatching) { + toEdit.toneCurve.fromHistMatching = mods.toneCurve.fromHistMatching; + } + if (toneCurve.clampOOG) { toEdit.toneCurve.clampOOG = mods.toneCurve.clampOOG; } diff --git a/rtgui/paramsedited.h b/rtgui/paramsedited.h index 959a1ff39..974a1a31f 100644 --- a/rtgui/paramsedited.h +++ b/rtgui/paramsedited.h @@ -54,6 +54,7 @@ public: bool hrenabled; bool method; bool histmatching; + bool fromHistMatching; bool clampOOG; }; diff --git a/rtgui/ppversion.h b/rtgui/ppversion.h index 7c6a291c0..a09f59d7a 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 339 +#define PPVERSION 340 #define PPVERSION_AEXP 301 //value of PPVERSION when auto exposure algorithm was modified /* Log of version changes + 340 2018-07-08 + store whether curve is from histogram matching 339 2018-07-04 added allowUpscaling to ResizeParams 338 2018-06-15 diff --git a/rtgui/profilechangelistener.h b/rtgui/profilechangelistener.h index b3baa62d7..79705b114 100644 --- a/rtgui/profilechangelistener.h +++ b/rtgui/profilechangelistener.h @@ -27,7 +27,7 @@ class ProfileChangeListener public: virtual ~ProfileChangeListener() {} - virtual void profileChange (const rtengine::procparams::PartialProfile* nparams, rtengine::ProcEvent event, const Glib::ustring& descr, const ParamsEdited* paramsEdited = nullptr) {} + virtual void profileChange (const rtengine::procparams::PartialProfile* nparams, rtengine::ProcEvent event, const Glib::ustring& descr, const ParamsEdited* paramsEdited = nullptr, bool fromLastSaved = false) {} virtual void setDefaults (rtengine::procparams::ProcParams* defparams) {} }; diff --git a/rtgui/profilepanel.cc b/rtgui/profilepanel.cc index 98210860f..d6259884f 100644 --- a/rtgui/profilepanel.cc +++ b/rtgui/profilepanel.cc @@ -797,7 +797,7 @@ void ProfilePanel::initProfile (const Glib::ustring& profileFullPath, ProcParams if (tpc) { tpc->setDefaults (lastsaved->pparams); - tpc->profileChange (lastsaved, EvPhotoLoaded, profiles->getSelectedEntry()->label); + tpc->profileChange (lastsaved, EvPhotoLoaded, profiles->getSelectedEntry()->label, nullptr, true); } } else { if (pse) { diff --git a/rtgui/tonecurve.cc b/rtgui/tonecurve.cc index be683c3ee..30c9dadee 100644 --- a/rtgui/tonecurve.cc +++ b/rtgui/tonecurve.cc @@ -243,6 +243,7 @@ void ToneCurve::read (const ProcParams* pp, const ParamsEdited* pedited) toneCurveMode2->set_active(rtengine::toUnderlying(pp->toneCurve.curveMode2)); histmatching->set_active(pp->toneCurve.histmatching); + fromHistMatching = pp->toneCurve.fromHistMatching; clampOOG->set_active(pp->toneCurve.clampOOG); if (pedited) { @@ -366,6 +367,7 @@ void ToneCurve::write (ProcParams* pp, ParamsEdited* pedited) } pp->toneCurve.histmatching = histmatching->get_active(); + pp->toneCurve.fromHistMatching = fromHistMatching; pp->toneCurve.clampOOG = clampOOG->get_active(); if (pedited) { @@ -386,6 +388,7 @@ void ToneCurve::write (ProcParams* pp, ParamsEdited* pedited) pedited->toneCurve.method = method->get_active_row_number() != 4; pedited->toneCurve.hrenabled = !hrenabled->get_inconsistent(); pedited->toneCurve.histmatching = !histmatching->get_inconsistent(); + pedited->toneCurve.fromHistMatching = true; pedited->toneCurve.clampOOG = !clampOOG->get_inconsistent(); } @@ -916,6 +919,7 @@ void ToneCurve::updateCurveBackgroundHistogram (LUTu & histToneCurve, LUTu & his void ToneCurve::setHistmatching(bool enabled) { + fromHistMatching = enabled; if (histmatching->get_active()) { histmatchconn.block(true); histmatching->set_active(enabled); @@ -930,6 +934,7 @@ void ToneCurve::histmatchingToggled() if (listener) { if (!batchMode) { if (histmatching->get_active()) { + fromHistMatching = false; listener->panelChanged(EvHistMatching, M("GENERAL_ENABLED")); waitForAutoExp(); } else { @@ -984,6 +989,7 @@ bool ToneCurve::histmatchingComputed() shape->openIfNonlinear(); enableListener(); + fromHistMatching = true; return false; } diff --git a/rtgui/tonecurve.h b/rtgui/tonecurve.h index 7d4440e2c..ce431986a 100644 --- a/rtgui/tonecurve.h +++ b/rtgui/tonecurve.h @@ -58,6 +58,7 @@ protected: MyComboBoxText* toneCurveMode; MyComboBoxText* toneCurveMode2; Gtk::ToggleButton *histmatching; + bool fromHistMatching; Gtk::CheckButton *clampOOG; bool clipDirty, lastAuto; diff --git a/rtgui/toolpanelcoord.cc b/rtgui/toolpanelcoord.cc index d0107c46c..0b4e86a26 100644 --- a/rtgui/toolpanelcoord.cc +++ b/rtgui/toolpanelcoord.cc @@ -403,7 +403,7 @@ void ToolPanelCoordinator::panelChanged (rtengine::ProcEvent event, const Glib:: } } -void ToolPanelCoordinator::profileChange (const PartialProfile *nparams, rtengine::ProcEvent event, const Glib::ustring& descr, const ParamsEdited* paramsEdited) +void ToolPanelCoordinator::profileChange (const PartialProfile *nparams, rtengine::ProcEvent event, const Glib::ustring& descr, const ParamsEdited* paramsEdited, bool fromLastSave) { int fw, fh, tr; @@ -425,7 +425,7 @@ void ToolPanelCoordinator::profileChange (const PartialProfile *nparams, rtengi } // And apply the partial profile nparams to mergedParams - nparams->applyTo (mergedParams); + nparams->applyTo (mergedParams, fromLastSave); // Derive the effective changes, if it's a profile change, to prevent slow RAW rerendering if not necessary bool filterRawRefresh = false; diff --git a/rtgui/toolpanelcoord.h b/rtgui/toolpanelcoord.h index 5360914c3..3b70b392d 100644 --- a/rtgui/toolpanelcoord.h +++ b/rtgui/toolpanelcoord.h @@ -222,7 +222,7 @@ public: void imageTypeChanged (bool isRaw, bool isBayer, bool isXtrans, bool isMono = false); // profilechangelistener interface - void profileChange (const rtengine::procparams::PartialProfile* nparams, rtengine::ProcEvent event, const Glib::ustring& descr, const ParamsEdited* paramsEdited = nullptr); + void profileChange (const rtengine::procparams::PartialProfile* nparams, rtengine::ProcEvent event, const Glib::ustring& descr, const ParamsEdited* paramsEdited = nullptr, bool fromLastSave = false); void setDefaults (rtengine::procparams::ProcParams* defparams); // DirSelectionListener interface