diff --git a/rtengine/dcrop.cc b/rtengine/dcrop.cc index 09e420c8e..1e67c4f11 100644 --- a/rtengine/dcrop.cc +++ b/rtengine/dcrop.cc @@ -1039,8 +1039,12 @@ void Crop::update(int todo) hltonecurveloc2, shtonecurveloc2, tonecurveloc2, lightCurveloc2, avge, skip); // Locallab mask are only shown for selected spot + int fh = parent->fh; + int fw = parent->fw; + if (sp == params.locallab.selspot) { - parent->ipf.Lab_Local(1, sp, (float**)shbuffer, labnCrop, labnCrop, reservCrop.get(), savenormtmCrop.get(), savenormretiCrop.get(), lastorigCrop.get(), cropx / skip, cropy / skip, skips(parent->fw, skip), skips(parent->fh, skip), skip, locRETgainCurve, locRETtransCurve, + + parent->ipf.Lab_Local(1, sp, (float**)shbuffer, labnCrop, labnCrop, reservCrop.get(), savenormtmCrop.get(), savenormretiCrop.get(), lastorigCrop.get(), fw, fh, cropx / skip, cropy / skip, skips(parent->fw, skip), skips(parent->fh, skip), skip, locRETgainCurve, locRETtransCurve, lllocalcurve2,locallutili, cllocalcurve2, localclutili, lclocalcurve2, locallcutili, @@ -1109,7 +1113,7 @@ void Crop::update(int todo) params.softlight.enabled = false; } } else { - parent->ipf.Lab_Local(1, sp, (float**)shbuffer, labnCrop, labnCrop, reservCrop.get(), savenormtmCrop.get(), savenormretiCrop.get(), lastorigCrop.get(), cropx / skip, cropy / skip, skips(parent->fw, skip), skips(parent->fh, skip), skip, locRETgainCurve, locRETtransCurve, + parent->ipf.Lab_Local(1, sp, (float**)shbuffer, labnCrop, labnCrop, reservCrop.get(), savenormtmCrop.get(), savenormretiCrop.get(), lastorigCrop.get(), fw, fh, cropx / skip, cropy / skip, skips(parent->fw, skip), skips(parent->fh, skip), skip, locRETgainCurve, locRETtransCurve, lllocalcurve2,locallutili, cllocalcurve2, localclutili, lclocalcurve2, locallcutili, diff --git a/rtengine/improccoordinator.cc b/rtengine/improccoordinator.cc index 938048169..ed6723e57 100644 --- a/rtengine/improccoordinator.cc +++ b/rtengine/improccoordinator.cc @@ -1035,7 +1035,7 @@ void ImProcCoordinator::updatePreviewImage(int todo, bool panningRelatedChange) } else { ipf.calc_ref(sp, nprevl, nprevl, 0, 0, pW, pH, scale, huerefblu, chromarefblu, lumarefblu, huere, chromare, lumare, sobelre, avge, locwavCurveden, locwavdenutili); } - // + meantme = 0.f; stdtme = 0.f; meanretie = 0.f; @@ -1119,7 +1119,8 @@ void ImProcCoordinator::updatePreviewImage(int todo, bool panningRelatedChange) float Tmin; float Tmax; int lastsav; - ipf.Lab_Local(3, sp, (float**)shbuffer, nprevl, nprevl, reserv.get(), savenormtm.get(), savenormreti.get(), lastorigimp.get(), 0, 0, pW, pH, scale, locRETgainCurve, locRETtransCurve, + + ipf.Lab_Local(3, sp, (float**)shbuffer, nprevl, nprevl, reserv.get(), savenormtm.get(), savenormreti.get(), lastorigimp.get(), fw, fh, 0, 0, pW, pH, scale, locRETgainCurve, locRETtransCurve, lllocalcurve, locallutili, cllocalcurve, localclutili, lclocalcurve, locallcutili, @@ -1209,7 +1210,6 @@ void ImProcCoordinator::updatePreviewImage(int todo, bool panningRelatedChange) } else { ipf.calc_ref(sp, nprevl, nprevl, 0, 0, pW, pH, scale, huerefblu, chromarefblu, lumarefblu, huer, chromar, lumar, sobeler, avg, locwavCurveden, locwavdenutili); } - // Update Locallab reference values according to recurs parameter if (params->locallab.spots.at(sp).recurs) { locallref.at(sp).chromar = chromar; diff --git a/rtengine/improcfun.h b/rtengine/improcfun.h index ae914fcda..2fec871da 100644 --- a/rtengine/improcfun.h +++ b/rtengine/improcfun.h @@ -284,7 +284,7 @@ enum class BlurType { float maxdE, float mindE, float maxdElim, float mindElim, float iterat, float limscope, int scope, float balance, float balanceh, float lumask); //3 functions from Alberto Griggio, adapted J.Desmis 2019 - void filmGrain(Imagefloat *rgb, int isogr, int strengr, int scalegr,float divgr, int bfw, int bfh); + void filmGrain(Imagefloat *rgb, int isogr, int strengr, int scalegr,float divgr, int bfw, int bfh, int call, int fw, int fh); void log_encode(Imagefloat *rgb, struct local_params & lp, bool multiThread, int bfw, int bfh); void getAutoLogloc(int sp, ImageSource *imgsrc, float *sourceg, float *blackev, float *whiteev, bool *Autogr, float *sourceab, int fw, int fh, float xsta, float xend, float ysta, float yend, int SCALE); @@ -302,7 +302,7 @@ enum class BlurType { void calc_ref(int sp, LabImage* original, LabImage* transformed, int cx, int cy, int oW, int oH, int sk, double &huerefblur, double &chromarefblur, double &lumarefblur, double &hueref, double &chromaref, double &lumaref, double &sobelref, float &avg, const LocwavCurve & locwavCurveden, bool locwavdenutili); void copy_ref(LabImage* spotbuffer, LabImage* original, LabImage* transformed, int cx, int cy, int sk, const struct local_params & lp, double &huerefspot, double &chromarefspot, double &lumarefspot); void paste_ref(LabImage* spotbuffer, LabImage* transformed, int cx, int cy, int sk, const struct local_params & lp); - void Lab_Local(int call, int sp, float** shbuffer, LabImage* original, LabImage* transformed, LabImage* reserved, LabImage * savenormtm, LabImage * savenormreti, LabImage* lastorig, int cx, int cy, int oW, int oH, int sk, const LocretigainCurve& locRETgainCcurve, const LocretitransCurve &locRETtransCcurve, + void Lab_Local(int call, int sp, float** shbuffer, LabImage* original, LabImage* transformed, LabImage* reserved, LabImage * savenormtm, LabImage * savenormreti, LabImage* lastorig, int fw, int fh, int cx, int cy, int oW, int oH, int sk, const LocretigainCurve& locRETgainCcurve, const LocretitransCurve &locRETtransCcurve, const LUTf& lllocalcurve, bool locallutili, const LUTf& cllocalcurve, bool localclutili, const LUTf& lclocalcurve, bool locallcutili, diff --git a/rtengine/ipgrain.cc b/rtengine/ipgrain.cc index d03a3ba33..6d2c116cd 100644 --- a/rtengine/ipgrain.cc +++ b/rtengine/ipgrain.cc @@ -89,7 +89,7 @@ const int permutation[] class GrainEvaluator { public: - GrainEvaluator(int offset_x, int offset_y, int full_width, int full_height, double scale, float divgr): + GrainEvaluator(int offset_x, int offset_y, int full_width, int full_height, double scale, float divgr, int call, int fww, int fhh): ox(offset_x), oy(offset_y), fw(full_width), @@ -101,27 +101,33 @@ public: evaluate_grain_lut(mb, divgr); } - void operator()(int isogr, int strengr, int scalegr, float divgr, Imagefloat *lab, bool multithread) + void operator()(int isogr, int strengr, int scalegr, float divgr, Imagefloat *lab, bool multithread, int call, int fww, int fhh) { const double strength = (strengr / 100.0); const double octaves = 3.; const double wd = std::min(fw, fh); + const double wdf = std::min(fww, fhh); + const double zoom = (1.0 + 8 * (double(isogr) / GRAIN_SCALE_FACTOR) / 100.0) / 800.0; const double s = std::max(scale / 3.0, 1.0) / (double(std::max(scalegr, 1)) / 100.0); - // printf("s=%f \n", s); const int W = lab->getWidth(); const int H = lab->getHeight(); float **lab_L = lab->g.ptrs; + double wddf = wd; + if (call == 1 || call == 3) { + wddf = wdf; + } + #ifdef _OPENMP # pragma omp parallel for if (multithread) #endif for (int j = 0; j < H; ++j) { double wy = oy + j; - double y = wy / wd; + double y = wy / wddf; for (int i = 0; i < W; ++i) { double wx = ox + i; - double x = wx / wd; + double x = wx / wddf; double noise = simplex_2d_noise(x, y, octaves, 1.0, zoom) / s; lab_L[j][i] += lut_lookup(noise * strength * GRAIN_LIGHTNESS_STRENGTH_SCALE, lab_L[j][i] / 32768.f); } @@ -371,14 +377,14 @@ private: } // namespace -void ImProcFunctions::filmGrain(Imagefloat *rgb, int isogr, int strengr, int scalegr, float divgr, int bfw, int bfh) +void ImProcFunctions::filmGrain(Imagefloat *rgb, int isogr, int strengr, int scalegr, float divgr, int bfw, int bfh, int call, int fw, int fh) { if (settings->verbose) { printf("iso=%i strength=%i scale=%i gamma=%f\n", isogr, strengr, scalegr, divgr); } - GrainEvaluator ge(0, 0, bfw, bfh, scale, divgr); - ge(isogr, strengr, scalegr, divgr, rgb, multiThread); + GrainEvaluator ge(0, 0, bfw, bfh, scale, divgr, call, fw, fh); + ge(isogr, strengr, scalegr, divgr, rgb, multiThread, call, fw, fh); } } // namespace rtengine diff --git a/rtengine/iplocallab.cc b/rtengine/iplocallab.cc index fcc8a9462..da829ec5e 100644 --- a/rtengine/iplocallab.cc +++ b/rtengine/iplocallab.cc @@ -11281,7 +11281,7 @@ void ImProcFunctions::NLMeans(float **img, int strength, int detail_thresh, int } void ImProcFunctions::Lab_Local( - int call, int sp, float** shbuffer, LabImage * original, LabImage * transformed, LabImage * reserved, LabImage * savenormtm, LabImage * savenormreti, LabImage * lastorig, int cx, int cy, int oW, int oH, int sk, + int call, int sp, float** shbuffer, LabImage * original, LabImage * transformed, LabImage * reserved, LabImage * savenormtm, LabImage * savenormreti, LabImage * lastorig, int fw, int fh, int cx, int cy, int oW, int oH, int sk, const LocretigainCurve& locRETgainCcurve, const LocretitransCurve& locRETtransCcurve, const LUTf& lllocalcurve, bool locallutili, const LUTf& cllocalcurve, bool localclutili, @@ -11876,7 +11876,7 @@ void ImProcFunctions::Lab_Local( } - filmGrain(tmpImage, isogr, strengr, scalegr, divgr, wi, he); + filmGrain(tmpImage, isogr, strengr, scalegr, divgr, wi, he, call, fw, fh); for (int y = 0; y < he ; y++) { for (int x = 0; x < wi; x++) { diff --git a/rtengine/simpleprocess.cc b/rtengine/simpleprocess.cc index f59140786..e343e6d52 100644 --- a/rtengine/simpleprocess.cc +++ b/rtengine/simpleprocess.cc @@ -1142,7 +1142,7 @@ private: float Tmax; // No Locallab mask is shown in exported picture - ipf.Lab_Local(2, sp, shbuffer, labView, labView, reservView.get(), savenormtmView.get(), savenormretiView.get(), lastorigView.get(), 0, 0, fw, fh, 1, locRETgainCurve, locRETtransCurve, + ipf.Lab_Local(2, sp, shbuffer, labView, labView, reservView.get(), savenormtmView.get(), savenormretiView.get(), lastorigView.get(), fw, fh, 0, 0, fw, fh, 1, locRETgainCurve, locRETtransCurve, lllocalcurve, locallutili, cllocalcurve, localclutili, lclocalcurve, locallcutili,