From 4397842fea382e02a75b0fd9c92ef9a7e11ba4b1 Mon Sep 17 00:00:00 2001 From: Desmis Date: Sat, 9 Mar 2019 12:53:25 +0100 Subject: [PATCH] Improvmant to Exposure - Shadows Highlights --- rtengine/color.cc | 19 +++++++++++++++++++ rtengine/color.h | 10 +++++++--- rtengine/curves.cc | 16 +++++++--------- rtengine/iplocallab.cc | 11 ++++------- rtengine/procparams.cc | 4 ++-- rtgui/locallab.cc | 4 ++-- 6 files changed, 41 insertions(+), 23 deletions(-) diff --git a/rtengine/color.cc b/rtengine/color.cc index b0122c2f0..a0e7b06d8 100644 --- a/rtengine/color.cc +++ b/rtengine/color.cc @@ -44,6 +44,8 @@ LUTf Color::igammatab_srgb1; LUTf Color::gammatab_srgb; LUTf Color::gammatab_srgb1; LUTf Color::gammatab_srgb327; +LUTf Color::gammatab_bt709; +LUTf Color::igammatab_bt709; LUTf Color::denoiseGammaTab; LUTf Color::denoiseIGammaTab; @@ -129,8 +131,10 @@ void Color::init() gammatabThumb(maxindex, 0); igammatab_srgb(maxindex, 0); + igammatab_bt709(maxindex, 0); igammatab_srgb1(maxindex, 0); gammatab_srgb(maxindex, 0); + gammatab_bt709(maxindex, 0); gammatab_srgb1(maxindex, 0); gammatab_srgb327(32768, 0); @@ -295,6 +299,21 @@ void Color::init() break; } +#ifdef _OPENMP + #pragma omp section +#endif + + for (int i = 0; i < maxindex; i++) { + gammatab_bt709[i] = 65535.0 * gamma709(i / 65535.0); + } + +#ifdef _OPENMP + #pragma omp section +#endif + + for (int i = 0; i < maxindex; i++) { + igammatab_bt709[i] = 65535.0 * igamma709(i / 65535.0); + } #ifdef _OPENMP #pragma omp section #endif diff --git a/rtengine/color.h b/rtengine/color.h index 9931e434d..2487b3a5b 100644 --- a/rtengine/color.h +++ b/rtengine/color.h @@ -164,11 +164,13 @@ public: static LUTf gammatab_srgb; static LUTf gammatab_srgb327; static LUTf gammatab_srgb1; + static LUTf gammatab_bt709; static LUTf denoiseGammaTab; static LUTf denoiseIGammaTab; static LUTf igammatab_24_17; + static LUTf igammatab_bt709; static LUTf gammatab_24_17a; static LUTf gammatab_13_2; static LUTf igammatab_13_2; @@ -1159,23 +1161,25 @@ public: } - /* + /** * @brief Get the gamma value for Gamma=2.2 Slope=4.5 * @param x red, green or blue channel's value [0 ; 1] * @return the gamma modified's value [0 ; 1] * + **/ static inline double gamma709 (double x) { return x <= 0.0176 ? x*4.5 : 1.0954*exp(log(x)/2.2)-0.0954; } - + /** * @brief Get the inverse gamma value for Gamma=2.2 Slope=4.5 * @param x red, green or blue channel's value [0 ; 1] * @return the inverse gamma modified's value [0 ; 1] * + **/ static inline double igamma709 (double x) { return x <= 0.0795 ? x/4.5 : exp(log((x+0.0954)/1.0954)*2.2); } - */ + diff --git a/rtengine/curves.cc b/rtengine/curves.cc index 74441ade1..e64a3275d 100644 --- a/rtengine/curves.cc +++ b/rtengine/curves.cc @@ -1059,13 +1059,11 @@ void CurveFactory::complexCurvelocal(double ecomp, double black, double hlcompr, int skip) { - // the curve shapes are defined in sRGB gamma, but the output curves will operate on linear floating point data, - // hence we do both forward and inverse gamma conversions here. - const float gamma_ = Color::sRGBGammaCurve; - const float start = expf(gamma_ * logf(-0.055f / ((1.0f / gamma_ - 1.0f) * 1.055f))); - const float slope = 1.055f * powf(start, 1.0f / gamma_ - 1.f) - 0.055f / start; - const float mul = 1.055f; - const float add = 0.055f; + const float gamma_ = 2.22; //BT 709 + const float start = expf(gamma_ * logf(-0.0954f / ((1.0f / gamma_ - 1.0f) * 1.0954f))); + const float slope = 1.0954f * powf(start, 1.0f / gamma_ - 1.f) - 0.0954f / start; + const float mul = 1.0954f; + const float add = 0.0954f; float maxran = 65536.f; //65536 // ecomp /= 100.; @@ -1255,7 +1253,7 @@ void CurveFactory::complexCurvelocal(double ecomp, double black, double hlcompr, shCurve[0] = CLIPD(val2) / val; // gamma correction - val = Color::gammatab_srgb[0] / maxran; + val = Color::gammatab_bt709[0] / maxran; // store result in a temporary array dcurve[0] = CLIPD(val); @@ -1266,7 +1264,7 @@ void CurveFactory::complexCurvelocal(double ecomp, double black, double hlcompr, shCurve[i] = val2 / val; // gamma correction - val = Color::gammatab_srgb[i] / maxran; + val = Color::gammatab_bt709[i] / maxran; // store result in a temporary array dcurve[i] = val; } diff --git a/rtengine/iplocallab.cc b/rtengine/iplocallab.cc index e1ee99e71..1865146aa 100644 --- a/rtengine/iplocallab.cc +++ b/rtengine/iplocallab.cc @@ -3495,15 +3495,13 @@ void ImProcFunctions::transit_shapedetect(int senstype, LabImage * bufexporig, L float factorx = localFactor; float diflc = 0.f; float newhr = 0.f; - - if (senstype == 4 || senstype == 6 || senstype == 2 || senstype == 3 || senstype == 8 || senstype == 9) {//all except color and light (TODO) and exposure + if (senstype == 4 || senstype == 6 || senstype == 2 || senstype == 3 || senstype == 8) {//all except color and light (TODO) and exposure float lightc = bufexporig->L[loy - begy][lox - begx]; - float fli = ((100.f + realstrdE) / 100.f); float diflc = lightc * fli - original->L[y][x]; diflc *= factorx; transformed->L[y][x] = CLIP(original->L[y][x] + diflc); - } else if (senstype == 1 || senstype == 0) { + } else if (senstype == 1 || senstype == 0 || senstype == 9) { transformed->L[y][x] = CLIP(original->L[y][x] + 328.f * factorx * realstrdE); diflc = 328.f * factorx * realstrdE; } @@ -3592,12 +3590,12 @@ void ImProcFunctions::transit_shapedetect(int senstype, LabImage * bufexporig, L float diflc = 0.f; float newhr = 0.f; - if (senstype == 4 || senstype == 6 || senstype == 2 || senstype == 3 || senstype == 8 || senstype == 9) {//retinex & cbdl + if (senstype == 4 || senstype == 6 || senstype == 2 || senstype == 3 || senstype == 8 ) {//retinex & cbdl float lightc = bufexporig->L[loy - begy][lox - begx]; float fli = ((100.f + realstrdE) / 100.f); float diflc = lightc * fli - original->L[y][x]; transformed->L[y][x] = CLIP(original->L[y][x] + diflc); - } else if (senstype == 1 || senstype == 0) { + } else if (senstype == 1 || senstype == 0 || senstype == 9) { transformed->L[y][x] = CLIP(original->L[y][x] + 328.f * realstrdE);//kch fach diflc = 328.f * realstrdE; } @@ -7565,7 +7563,6 @@ void ImProcFunctions::Lab_Local(int call, int sp, float** shbuffer, LabImage * o } } -//to do Modulate bufexporig and bufexptemp with blend L, H, C and masks float chprosl = 1.f; diff --git a/rtengine/procparams.cc b/rtengine/procparams.cc index 9f8779d33..71a971adb 100644 --- a/rtengine/procparams.cc +++ b/rtengine/procparams.cc @@ -2387,8 +2387,8 @@ LocallabParams::LocallabSpot::LocallabSpot() : // Exposure expexpose(false), expcomp(0.0), - hlcompr(60), - hlcomprthresh(33), + hlcompr(0), + hlcomprthresh(0), black(0), shcompr(50), expchroma(30), diff --git a/rtgui/locallab.cc b/rtgui/locallab.cc index bbc61719e..1ae92c0c2 100644 --- a/rtgui/locallab.cc +++ b/rtgui/locallab.cc @@ -86,8 +86,8 @@ Locallab::Locallab(): radmaskcol(Gtk::manage(new Adjuster(M("TP_LOCALLAB_RADMASKCOL"), 0.0, 100.0, 0.1, 10.))), // Exposure expcomp(Gtk::manage(new Adjuster(M("TP_EXPOSURE_EXPCOMP"), -2.0, 4.0, 0.05, 0.0))), - hlcompr(Gtk::manage(new Adjuster(M("TP_EXPOSURE_COMPRHIGHLIGHTS"), 0, 500, 1, 60))), - hlcomprthresh(Gtk::manage(new Adjuster(M("TP_EXPOSURE_COMPRHIGHLIGHTSTHRESHOLD"), 0, 100, 1, 33))), + hlcompr(Gtk::manage(new Adjuster(M("TP_EXPOSURE_COMPRHIGHLIGHTS"), 0, 500, 1, 0))), + hlcomprthresh(Gtk::manage(new Adjuster(M("TP_EXPOSURE_COMPRHIGHLIGHTSTHRESHOLD"), 0, 100, 1, 0))), black(Gtk::manage(new Adjuster(M("TP_EXPOSURE_BLACKLEVEL"), -16384, 32768, 50, 0))), shcompr(Gtk::manage(new Adjuster(M("TP_EXPOSURE_COMPRSHADOWS"), 0, 100, 1, 50))), expchroma(Gtk::manage(new Adjuster(M("TP_LOCALLAB_EXPCHROMA"), -50, 100, 1, 30))),