From 14f3dfc128b10366ff7c54d8adddd1707c0e2940 Mon Sep 17 00:00:00 2001 From: Desmis Date: Sun, 3 Mar 2019 12:08:00 +0100 Subject: [PATCH] Improve mask exposure with guidefilter --- rtdata/languages/default | 1 + rtengine/iplocallab.cc | 31 ++++++++++++++++++++++++++++--- rtengine/procevents.h | 1 + rtengine/procparams.cc | 4 ++++ rtengine/procparams.h | 1 + rtengine/refreshmap.cc | 3 ++- rtgui/locallab.cc | 18 ++++++++++++++++++ rtgui/locallab.h | 1 + rtgui/paramsedited.cc | 7 +++++++ rtgui/paramsedited.h | 1 + 10 files changed, 64 insertions(+), 4 deletions(-) diff --git a/rtdata/languages/default b/rtdata/languages/default index 9e96f7ef6..2ff997c63 100644 --- a/rtdata/languages/default +++ b/rtdata/languages/default @@ -886,6 +886,7 @@ HISTORY_MSG_631;Local - SH S tonalwidth HISTORY_MSG_632;Local - SH radius HISTORY_MSG_633;Local - SH Scope HISTORY_MSG_634;Local - radius color +HISTORY_MSG_635;Local - radius Exp HISTORY_MSG_CLAMPOOG;Clip out-of-gamut colors HISTORY_MSG_COLORTONING_LABGRID_VALUE;CT - Color correction HISTORY_MSG_COLORTONING_LABREGION_AB;CT - Color correction diff --git a/rtengine/iplocallab.cc b/rtengine/iplocallab.cc index c3f0c8543..648014981 100644 --- a/rtengine/iplocallab.cc +++ b/rtengine/iplocallab.cc @@ -145,6 +145,7 @@ struct local_params { float struexc; float blendmacol; float radmacol; + float radmaexp; float blendmaexp; float struexp; float blurexp; @@ -467,6 +468,7 @@ static void calcLocalParams(int sp, int oW, int oH, const LocallabParams& locall float blendmaskcolor = ((float) locallab.spots.at(sp).blendmaskcol) / 100.f ; float radmaskcolor = ((float) locallab.spots.at(sp).radmaskcol); float blendmaskexpo = ((float) locallab.spots.at(sp).blendmaskexp) / 100.f ; + float radmaskexpo = ((float) locallab.spots.at(sp).radmaskexp); float structexpo = (float) locallab.spots.at(sp).structexp; float blurexpo = (float) locallab.spots.at(sp).blurexpde; float blurcolor = (float) locallab.spots.at(sp).blurcolde; @@ -515,6 +517,7 @@ static void calcLocalParams(int sp, int oW, int oH, const LocallabParams& locall lp.strengrid = strengthgrid; lp.blendmacol = blendmaskcolor; lp.radmacol = radmaskcolor; + lp.radmaexp = radmaskexpo; lp.struexc = structexclude; lp.blendmaexp = blendmaskexpo; lp.struexp = structexpo; @@ -7277,6 +7280,8 @@ void ImProcFunctions::Lab_Local(int call, int sp, float** shbuffer, LabImage * o } + array2D ble(bfw, bfh); + array2D guid(bfw, bfh); #ifdef _OPENMP #pragma omp parallel for schedule(dynamic,16) @@ -7351,14 +7356,34 @@ void ImProcFunctions::Lab_Local(int call, int sp, float** shbuffer, LabImage * o bufmaskblurexp->L[loy - begy][lox - begx] = CLIPLOC(kmaskLexp + kmaskHL); bufmaskblurexp->a[loy - begy][lox - begx] = CLIPC(kmaskCa + kmaskHa); bufmaskblurexp->b[loy - begy][lox - begx] = CLIPC(kmaskCb + kmaskHb); + ble[loy - begy][lox - begx] = bufmaskblurexp->L[loy - begy][lox - begx] / 32768.f; + guid[loy - begy][lox - begx] = bufexporig->L[loy - begy][lox - begx] / 32768.f; } } } + if ((lp.showmaskexpmet == 2 || lp.enaExpMask || lp.showmaskexpmet == 3) && lp.radmaexp > 0.f) { - float radiusb = 3.f / sk; + guidedFilter(guid, ble, ble, lp.radmaexp * 10.f / sk, 0.075, multiThread, 4); + +#ifdef _OPENMP + #pragma omp parallel for schedule(dynamic,16) +#endif + + for (int y = 0; y < transformed->H ; y++) //{ + for (int x = 0; x < transformed->W; x++) { + int lox = cx + x; + int loy = cy + y; + + if (lox >= begx && lox < xEn && loy >= begy && loy < yEn) { + bufmaskblurexp->L[loy - begy][lox - begx] = ble[loy - begy][lox - begx] * 32768.f; + } + } + } + + float radiusb = 1.f / sk; if (lp.showmaskexpmet == 2 || lp.enaExpMask || lp.showmaskexpmet == 3) { @@ -7367,8 +7392,8 @@ void ImProcFunctions::Lab_Local(int call, int sp, float** shbuffer, LabImage * o #endif { gaussianBlur(bufmaskblurexp->L, bufmaskorigexp->L, bfw, bfh, radiusb); - gaussianBlur(bufmaskblurexp->a, bufmaskorigexp->a, bfw, bfh, radiusb); - gaussianBlur(bufmaskblurexp->b, bufmaskorigexp->b, bfw, bfh, radiusb); + gaussianBlur(bufmaskblurexp->a, bufmaskorigexp->a, bfw, bfh, 1.f + (0.2f * lp.radmaexp) / sk); + gaussianBlur(bufmaskblurexp->b, bufmaskorigexp->b, bfw, bfh, 1.f + (0.2f * lp.radmaexp) / sk); } delete bufmaskblurexp; diff --git a/rtengine/procevents.h b/rtengine/procevents.h index 0b92f4748..abe87e704 100644 --- a/rtengine/procevents.h +++ b/rtengine/procevents.h @@ -661,6 +661,7 @@ enum ProcEventCode { Evlocallabsh_radius = 631, Evlocallabsensihs = 632, Evlocallabradmaskcol = 633, + Evlocallabradmaskexp = 634, NUMOFEVENTS }; diff --git a/rtengine/procparams.cc b/rtengine/procparams.cc index b8670c4f5..afee412a2 100644 --- a/rtengine/procparams.cc +++ b/rtengine/procparams.cc @@ -2403,6 +2403,7 @@ LocallabParams::LocallabSpot::LocallabSpot() : LLmaskexpcurve{(double)FCT_MinMaxCPoints, 0.0, 1.0, 0.35, 0.35, 0.50, 1.0, 0.35, 0.35, 1.0, 1.0, 0.35, 0.35}, HHmaskexpcurve{(double)FCT_MinMaxCPoints, 0.0, 1.0, 0.35, 0.35, 0.50, 1.0, 0.35, 0.35, 1.0, 1.0, 0.35, 0.35}, blendmaskexp(0), + radmaskexp(10.0), // Shadow highlight expshadhigh(false), highlights(0), @@ -2561,6 +2562,7 @@ bool LocallabParams::LocallabSpot::operator ==(const LocallabSpot& other) const && LLmaskexpcurve == other.LLmaskexpcurve && HHmaskexpcurve == other.HHmaskexpcurve && blendmaskexp == other.blendmaskexp + && radmaskexp == other.radmaskexp // Shadow highlight && expshadhigh == other.expshadhigh && highlights == other.highlights @@ -3674,6 +3676,7 @@ int ProcParams::save(const Glib::ustring& fname, const Glib::ustring& fname2, bo saveToKeyfile(!pedited || pedited->locallab.spots.at(i).LLmaskexpcurve, "Locallab", "LLmaskexpCurve_" + std::to_string(i), spot.LLmaskexpcurve, keyFile); saveToKeyfile(!pedited || pedited->locallab.spots.at(i).HHmaskexpcurve, "Locallab", "HHmaskexpCurve_" + std::to_string(i), spot.HHmaskexpcurve, keyFile); saveToKeyfile(!pedited || pedited->locallab.spots.at(i).blendmaskexp, "Locallab", "Blendmaskexp_" + std::to_string(i), spot.blendmaskexp, keyFile); + saveToKeyfile(!pedited || pedited->locallab.spots.at(i).radmaskexp, "Locallab", "Radmaskexp_" + std::to_string(i), spot.radmaskexp, keyFile); // Shadow highlight saveToKeyfile(!pedited || pedited->locallab.spots.at(i).expshadhigh, "Locallab", "Expshadhigh_" + std::to_string(i), spot.expshadhigh, keyFile); saveToKeyfile(!pedited || pedited->locallab.spots.at(i).highlights, "Locallab", "highlights_" + std::to_string(i), spot.highlights, keyFile); @@ -4916,6 +4919,7 @@ int ProcParams::load(const Glib::ustring& fname, ParamsEdited* pedited) assignFromKeyfile(keyFile, "Locallab", "LLmaskexpCurve_" + std::to_string(i), pedited, spot.LLmaskexpcurve, spotEdited.LLmaskexpcurve); assignFromKeyfile(keyFile, "Locallab", "HHmaskexpCurve_" + std::to_string(i), pedited, spot.HHmaskexpcurve, spotEdited.HHmaskexpcurve); assignFromKeyfile(keyFile, "Locallab", "Blendmaskexp_" + std::to_string(i), pedited, spot.blendmaskexp, spotEdited.blendmaskexp); + assignFromKeyfile(keyFile, "Locallab", "Radmaskexp_" + std::to_string(i), pedited, spot.radmaskexp, spotEdited.radmaskexp); // Shadow highlight assignFromKeyfile(keyFile, "Locallab", "Expshadhigh_" + std::to_string(i), pedited, spot.expshadhigh, spotEdited.expshadhigh); assignFromKeyfile(keyFile, "Locallab", "highlights_" + std::to_string(i), pedited, spot.highlights, spotEdited.highlights); diff --git a/rtengine/procparams.h b/rtengine/procparams.h index c3bd2bf96..fb7192e4c 100644 --- a/rtengine/procparams.h +++ b/rtengine/procparams.h @@ -1004,6 +1004,7 @@ struct LocallabParams { std::vector LLmaskexpcurve; std::vector HHmaskexpcurve; int blendmaskexp; + double radmaskexp; // Shadow highlight bool expshadhigh; int highlights; diff --git a/rtengine/refreshmap.cc b/rtengine/refreshmap.cc index c30159f17..b2db8accb 100644 --- a/rtengine/refreshmap.cc +++ b/rtengine/refreshmap.cc @@ -660,7 +660,8 @@ int refreshmap[rtengine::NUMOFEVENTS] = { LUMINANCECURVE, //EvLocallabs_tonalwidth LUMINANCECURVE, //EvLocallabsh_radius LUMINANCECURVE, //EvLocallabsensihs - LUMINANCECURVE //Evlocallabradmaskcol + LUMINANCECURVE, //Evlocallabradmaskcol + LUMINANCECURVE //Evlocallabradmaskexp }; diff --git a/rtgui/locallab.cc b/rtgui/locallab.cc index e8a035ede..5d4116683 100644 --- a/rtgui/locallab.cc +++ b/rtgui/locallab.cc @@ -96,6 +96,7 @@ Locallab::Locallab(): structexp(Gtk::manage(new Adjuster(M("TP_LOCALLAB_STRUCCOL"), 0, 100, 1, 0))), blurexpde(Gtk::manage(new Adjuster(M("TP_LOCALLAB_BLURDE"), 2, 100, 1, 5))), blendmaskexp(Gtk::manage(new Adjuster(M("TP_LOCALLAB_BLENDMASKCOL"), -100, 100, 1, 0))), + radmaskexp(Gtk::manage(new Adjuster(M("TP_LOCALLAB_RADMASKCOL"), 0.0, 100.0, 0.1, 10.))), //Shadow hightlights highlights(Gtk::manage(new Adjuster(M("TP_SHADOWSHLIGHTS_HIGHLIGHTS"), 0, 100, 1, 0))), h_tonalwidth(Gtk::manage(new Adjuster(M("TP_SHADOWSHLIGHTS_HLTONALW"), 10, 100, 1, 70))), @@ -429,6 +430,7 @@ Locallab::Locallab(): blurexpde->setAdjusterListener(this); blendmaskexp->setAdjusterListener(this); + radmaskexp->setAdjusterListener(this); curveEditorG->setCurveListener(this); @@ -498,6 +500,7 @@ Locallab::Locallab(): maskexpBox->pack_start(*enaExpMask, Gtk::PACK_SHRINK, 0); maskexpBox->pack_start(*maskexpCurveEditorG, Gtk::PACK_SHRINK, 4); // Padding is mandatory to correct behavior of curve editor maskexpBox->pack_start(*blendmaskexp, Gtk::PACK_SHRINK, 0); + maskexpBox->pack_start(*radmaskexp, Gtk::PACK_SHRINK, 0); maskexpFrame->add(*maskexpBox); exposeBox->pack_start(*maskexpFrame); @@ -1608,6 +1611,7 @@ void Locallab::write(ProcParams* pp, ParamsEdited* pedited) pp->locallab.spots.at(pp->locallab.selspot).CCmaskexpcurve = CCmaskexpshape->getCurve(); pp->locallab.spots.at(pp->locallab.selspot).HHmaskexpcurve = HHmaskexpshape->getCurve(); pp->locallab.spots.at(pp->locallab.selspot).blendmaskexp = blendmaskexp->getIntValue(); + pp->locallab.spots.at(pp->locallab.selspot).radmaskexp = radmaskexp->getValue(); // Shadow highlight pp->locallab.spots.at(pp->locallab.selspot).expshadhigh = expshadhigh->getEnabled(); pp->locallab.spots.at(pp->locallab.selspot).highlights = highlights->getIntValue(); @@ -1782,6 +1786,7 @@ void Locallab::write(ProcParams* pp, ParamsEdited* pedited) pe->locallab.spots.at(pp->locallab.selspot).LLmaskexpcurve = pe->locallab.spots.at(pp->locallab.selspot).LLmaskexpcurve || !LLmaskexpshape->isUnChanged(); pe->locallab.spots.at(pp->locallab.selspot).HHmaskexpcurve = pe->locallab.spots.at(pp->locallab.selspot).HHmaskexpcurve || !HHmaskexpshape->isUnChanged(); pe->locallab.spots.at(pp->locallab.selspot).blendmaskexp = pe->locallab.spots.at(pp->locallab.selspot).blendmaskexp || blendmaskexp->getEditedState(); + pe->locallab.spots.at(pp->locallab.selspot).radmaskexp = pe->locallab.spots.at(pp->locallab.selspot).radmaskexp || radmaskexp->getEditedState(); // Shadow highlight pe->locallab.spots.at(pp->locallab.selspot).expshadhigh = pe->locallab.spots.at(pp->locallab.selspot).expshadhigh || !expshadhigh->get_inconsistent(); pe->locallab.spots.at(pp->locallab.selspot).highlights = pe->locallab.spots.at(pp->locallab.selspot).highlights || highlights->getEditedState(); @@ -1941,6 +1946,7 @@ void Locallab::write(ProcParams* pp, ParamsEdited* pedited) pedited->locallab.spots.at(pp->locallab.selspot).LLmaskexpcurve = pedited->locallab.spots.at(pp->locallab.selspot).LLmaskexpcurve || !LLmaskexpshape->isUnChanged(); pedited->locallab.spots.at(pp->locallab.selspot).HHmaskexpcurve = pedited->locallab.spots.at(pp->locallab.selspot).HHmaskexpcurve || !HHmaskexpshape->isUnChanged(); pedited->locallab.spots.at(pp->locallab.selspot).blendmaskexp = pedited->locallab.spots.at(pp->locallab.selspot).blendmaskexp || blendmaskexp->getEditedState(); + pedited->locallab.spots.at(pp->locallab.selspot).radmaskexp = pedited->locallab.spots.at(pp->locallab.selspot).radmaskexp || radmaskexp->getEditedState(); // Shadow highlight pedited->locallab.spots.at(pp->locallab.selspot).expshadhigh = pedited->locallab.spots.at(pp->locallab.selspot).expshadhigh || !expshadhigh->get_inconsistent(); pedited->locallab.spots.at(pp->locallab.selspot).highlights = pedited->locallab.spots.at(pp->locallab.selspot).highlights || highlights->getEditedState(); @@ -2708,6 +2714,7 @@ void Locallab::setDefaults(const ProcParams * defParams, const ParamsEdited * pe structexp->setDefault((double)defSpot->structexp); blurexpde->setDefault((double)defSpot->blurexpde); blendmaskexp->setDefault((double)defSpot->blendmaskexp); + radmaskexp->setDefault(defSpot->radmaskexp); //Shadow highlight highlights->setDefault((double)defSpot->highlights); h_tonalwidth->setDefault((double)defSpot->h_tonalwidth); @@ -2801,6 +2808,7 @@ void Locallab::setDefaults(const ProcParams * defParams, const ParamsEdited * pe structexp->setDefaultEditedState(Irrelevant); blurexpde->setDefaultEditedState(Irrelevant); blendmaskexp->setDefaultEditedState(Irrelevant); + radmaskexp->setDefaultEditedState(Irrelevant); //Shadow highlight highlights->setDefaultEditedState(Irrelevant); h_tonalwidth->setDefaultEditedState(Irrelevant); @@ -2898,6 +2906,7 @@ void Locallab::setDefaults(const ProcParams * defParams, const ParamsEdited * pe structexp->setDefaultEditedState(defSpotState->structexp ? Edited : UnEdited); blurexpde->setDefaultEditedState(defSpotState->blurexpde ? Edited : UnEdited); blendmaskexp->setDefaultEditedState(defSpotState->blendmaskexp ? Edited : UnEdited); + radmaskexp->setDefaultEditedState(defSpotState->radmaskexp ? Edited : UnEdited); //Shadow highlight highlights->setDefaultEditedState(defSpotState->highlights ? Edited : UnEdited); h_tonalwidth->setDefaultEditedState(defSpotState->h_tonalwidth ? Edited : UnEdited); @@ -3142,6 +3151,12 @@ void Locallab::adjusterChanged(Adjuster * a, double newval) } } + if (a == radmaskexp) { + if (listener) { + listener->panelChanged(Evlocallabradmaskexp, radmaskexp->getTextValue()); + } + } + } if (getEnabled() && expshadhigh->getEnabled()) { @@ -3572,6 +3587,7 @@ void Locallab::setBatchMode(bool batchMode) structexp->showEditedCB(); blurexpde->showEditedCB(); blendmaskexp->showEditedCB(); + radmaskexp->showEditedCB(); //Shadow Highlight highlights->showEditedCB(); h_tonalwidth->showEditedCB(); @@ -3938,6 +3954,7 @@ void Locallab::updateLocallabGUI(const rtengine::procparams::ProcParams* pp, con LLmaskexpshape->setCurve(pp->locallab.spots.at(index).LLmaskexpcurve); HHmaskexpshape->setCurve(pp->locallab.spots.at(index).HHmaskexpcurve); blendmaskexp->setValue(pp->locallab.spots.at(index).blendmaskexp); + radmaskexp->setValue(pp->locallab.spots.at(index).radmaskexp); // Shadow highlight expshadhigh->setEnabled(pp->locallab.spots.at(index).expshadhigh); highlights->setValue(pp->locallab.spots.at(index).highlights); @@ -4140,6 +4157,7 @@ void Locallab::updateLocallabGUI(const rtengine::procparams::ProcParams* pp, con LLmaskexpshape->setUnChanged(!spotState->LLmaskexpcurve); HHmaskexpshape->setUnChanged(!spotState->HHmaskexpcurve); blendmaskexp->setEditedState(spotState->blendmaskexp ? Edited : UnEdited); + radmaskexp->setEditedState(spotState->radmaskexp ? Edited : UnEdited); // Shadow highlight expshadhigh->set_inconsistent(!spotState->expshadhigh); diff --git a/rtgui/locallab.h b/rtgui/locallab.h index 415fa5459..1b3e32bbe 100644 --- a/rtgui/locallab.h +++ b/rtgui/locallab.h @@ -111,6 +111,7 @@ private: Adjuster* const structexp; Adjuster* const blurexpde; Adjuster* const blendmaskexp; + Adjuster* const radmaskexp; //Shadow highlight Adjuster* const highlights; Adjuster* const h_tonalwidth; diff --git a/rtgui/paramsedited.cc b/rtgui/paramsedited.cc index 146503ac1..fdf4bbc32 100644 --- a/rtgui/paramsedited.cc +++ b/rtgui/paramsedited.cc @@ -987,6 +987,7 @@ void ParamsEdited::initFrom(const std::vector& locallab.spots.at(j).LLmaskexpcurve = locallab.spots.at(j).LLmaskexpcurve && pSpot.LLmaskexpcurve == otherSpot.LLmaskexpcurve; locallab.spots.at(j).HHmaskexpcurve = locallab.spots.at(j).HHmaskexpcurve && pSpot.HHmaskexpcurve == otherSpot.HHmaskexpcurve; locallab.spots.at(j).blendmaskexp = locallab.spots.at(j).blendmaskexp && pSpot.blendmaskexp == otherSpot.blendmaskexp; + locallab.spots.at(j).radmaskexp = locallab.spots.at(j).radmaskexp && pSpot.radmaskexp == otherSpot.radmaskexp; // Shadow highlight locallab.spots.at(j).expshadhigh = locallab.spots.at(j).expshadhigh && pSpot.expshadhigh == otherSpot.expshadhigh; locallab.spots.at(j).highlights = locallab.spots.at(j).highlights && pSpot.highlights == otherSpot.highlights; @@ -2746,6 +2747,10 @@ void ParamsEdited::combine(rtengine::procparams::ProcParams& toEdit, const rteng toEdit.locallab.spots.at(i).blendmaskexp = mods.locallab.spots.at(i).blendmaskexp; } + if (locallab.spots.at(i).radmaskexp) { + toEdit.locallab.spots.at(i).radmaskexp = mods.locallab.spots.at(i).radmaskexp; + } + // Shadow highlight if (locallab.spots.at(i).expshadhigh) { @@ -4058,6 +4063,7 @@ LocallabParamsEdited::LocallabSpotEdited::LocallabSpotEdited(bool v) : LLmaskexpcurve(v), HHmaskexpcurve(v), blendmaskexp(v), + radmaskexp(v), // Shadow highlight expshadhigh(v), highlights(v), @@ -4213,6 +4219,7 @@ void LocallabParamsEdited::LocallabSpotEdited::set(bool v) LLmaskexpcurve = v; HHmaskexpcurve = v; blendmaskexp = v; + radmaskexp = v; // Shadow highlight expshadhigh = v; highlights = v; diff --git a/rtgui/paramsedited.h b/rtgui/paramsedited.h index 1f3ea1252..ac0d8906a 100644 --- a/rtgui/paramsedited.h +++ b/rtgui/paramsedited.h @@ -527,6 +527,7 @@ public: bool LLmaskexpcurve; bool HHmaskexpcurve; bool blendmaskexp; + bool radmaskexp; // Shadow highlight bool expshadhigh; bool highlights;