From 0bca993c738139a72397c357934e8f675ea0cd88 Mon Sep 17 00:00:00 2001 From: Desmis Date: Mon, 26 Oct 2020 08:55:25 +0100 Subject: [PATCH] Fixed crash in Log encoding when WhiteEv is near zero --- rtengine/improcfun.h | 2 +- rtengine/iplocallab.cc | 12 +++++++++--- rtgui/locallabtools2.cc | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/rtengine/improcfun.h b/rtengine/improcfun.h index e44780a13..a237e7c82 100644 --- a/rtengine/improcfun.h +++ b/rtengine/improcfun.h @@ -263,7 +263,7 @@ public: //3 functions from Alberto Griggio, adapted J.Desmis 2019 void filmGrain(Imagefloat *rgb, int isogr, int strengr, int scalegr, int bfw, int bfh); - void log_encode(Imagefloat *rgb, const struct local_params & lp, bool multiThread, int bfw, int bfh); + 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, int fw, int fh, float xsta, float xend, float ysta, float yend, int SCALE); void MSRLocal(int call, int sp, bool fftw, int lum, float** reducDE, LabImage * bufreti, LabImage * bufmask, LabImage * buforig, LabImage * buforigmas, float** luminance, const float* const *originalLuminance, diff --git a/rtengine/iplocallab.cc b/rtengine/iplocallab.cc index dfba8a4c2..08c9e4d68 100644 --- a/rtengine/iplocallab.cc +++ b/rtengine/iplocallab.cc @@ -1561,7 +1561,7 @@ float find_gray(float source_gray, float target_gray) // basic log encoding taken from ACESutil.Lin_to_Log2, from // https://github.com/ampas/aces-dev // (as seen on pixls.us) -void ImProcFunctions::log_encode(Imagefloat *rgb, const struct local_params & lp, bool multiThread, int bfw, int bfh) +void ImProcFunctions::log_encode(Imagefloat *rgb, struct local_params & lp, bool multiThread, int bfw, int bfh) { /* J.Desmis 12 2019 small adaptations to local adjustments @@ -1570,7 +1570,13 @@ void ImProcFunctions::log_encode(Imagefloat *rgb, const struct local_params & lp // BENCHFUN const float gray = lp.sourcegray / 100.f; const float shadows_range = lp.blackev; - const float dynamic_range = lp.whiteev - lp.blackev; + if(lp.whiteev < 0.5f) { + lp.whiteev = 0.5f; + } + float dynamic_range = lp.whiteev - lp.blackev; + if (dynamic_range < 0.5f) { + dynamic_range = 0.5f; + } const float noise = pow_F(2.f, -16.f); const float log2 = xlogf(lp.baselog); const float base = lp.targetgray > 1 && lp.targetgray < 100 && dynamic_range > 0 ? find_gray(std::abs(lp.blackev) / dynamic_range, lp.targetgray / 100.f) : 0.f; @@ -1830,7 +1836,7 @@ void ImProcFunctions::getAutoLogloc(int sp, ImageSource *imgsrc, float *sourceg, } } -void tone_eq(array2D &R, array2D &G, array2D &B, const struct local_params & lp, const Glib::ustring &workingProfile, double scale, bool multithread) +void tone_eq(array2D &R, array2D &G, array2D &B, const struct local_params & lp, const Glib::ustring &workingProfile, double scale, bool multithread) // adapted from the tone equalizer of darktable /* Copyright 2019 Alberto Griggio diff --git a/rtgui/locallabtools2.cc b/rtgui/locallabtools2.cc index 38f5a756d..bc07769da 100644 --- a/rtgui/locallabtools2.cc +++ b/rtgui/locallabtools2.cc @@ -4655,7 +4655,7 @@ LocallabLog::LocallabLog(): autocompute(Gtk::manage(new Gtk::ToggleButton(M("TP_LOCALLAB_LOGAUTO")))), logPFrame(Gtk::manage(new Gtk::Frame(M("TP_LOCALLAB_LOGPFRA")))), blackEv(Gtk::manage(new Adjuster(M("TP_LOCALLAB_BLACK_EV"), -16.0, 0.0, 0.1, -5.0))), - whiteEv(Gtk::manage(new Adjuster(M("TP_LOCALLAB_WHITE_EV"), 0.0, 32.0, 0.1, 10.0))), + whiteEv(Gtk::manage(new Adjuster(M("TP_LOCALLAB_WHITE_EV"), 0.5, 32.0, 0.1, 10.0))), fullimage(Gtk::manage(new Gtk::CheckButton(M("TP_LOCALLAB_FULLIMAGE")))), Autogray(Gtk::manage(new Gtk::CheckButton(M("TP_LOCALLAB_AUTOGRAY")))), sourceGray(Gtk::manage(new Adjuster(M("TP_LOCALLAB_SOURCE_GRAY"), 1.0, 100.0, 0.1, 10.0))),