From 7ca8de08ab3140e53beb184b3b4937082aef7e50 Mon Sep 17 00:00:00 2001 From: Beep6581 Date: Sat, 17 Oct 2015 14:45:24 +0200 Subject: [PATCH] astyle all modified files in retinex branch --- rtengine/color.cc | 9 +- rtengine/color.h | 10 +- rtengine/curves.cc | 2 + rtengine/helpersse2.h | 30 +-- rtengine/ipretinex.cc | 49 ++-- rtengine/procparams.cc | 14 +- rtengine/rawimagesource.cc | 419 +++++++++++++++++++---------------- rtengine/simpleprocess.cc | 1 + rtgui/batchtoolpanelcoord.cc | 16 +- rtgui/editorpanel.cc | 1 + rtgui/paramsedited.cc | 6 +- rtgui/partialpastedlg.cc | 2 +- rtgui/preferences.cc | 2 +- rtgui/retinex.cc | 27 ++- rtgui/retinex.h | 4 +- 15 files changed, 324 insertions(+), 268 deletions(-) diff --git a/rtengine/color.cc b/rtengine/color.cc index 13bad89db..c0dbab4d3 100644 --- a/rtengine/color.cc +++ b/rtengine/color.cc @@ -209,7 +209,7 @@ void Color::init () for (int i = 0; i < 65536; i++) { gammatab_13_2[i] = (65535.0 * gamma13_2 (i / 65535.0)); } - + for (int i = 0; i < 65536; i++) { igammatab_13_2[i] = (65535.0 * igamma13_2 (i / 65535.0)); } @@ -217,7 +217,7 @@ void Color::init () for (int i = 0; i < 65536; i++) { gammatab_115_2[i] = (65535.0 * gamma115_2 (i / 65535.0)); } - + for (int i = 0; i < 65536; i++) { igammatab_115_2[i] = (65535.0 * igamma115_2 (i / 65535.0)); } @@ -225,14 +225,15 @@ void Color::init () for (int i = 0; i < 65536; i++) { gammatab_145_3[i] = (65535.0 * gamma145_3 (i / 65535.0)); } - + for (int i = 0; i < 65536; i++) { igammatab_145_3[i] = (65535.0 * igamma145_3 (i / 65535.0)); } - + for (int i = 0; i < 65536; i++) { gammatab_26_11[i] = (65535.0 * gamma26_11 (i / 65535.0)); } + //gammatab_145_3 for (int i = 0; i < 65536; i++) { igammatab_26_11[i] = (65535.0 * igamma26_11 (i / 65535.0)); diff --git a/rtengine/color.h b/rtengine/color.h index cc3a1f295..c179946f0 100644 --- a/rtengine/color.h +++ b/rtengine/color.h @@ -956,7 +956,7 @@ public: { return x <= 0.016613 ? x * 2.0 : 1.009968 * exp(log(x) / 1.3) - 0.009968; } - + static inline double igamma13_2 (double x) { return x <= 0.033226 ? x / 2.0 : exp(log((x + 0.009968) / 1.009968) * 1.3); @@ -966,17 +966,17 @@ public: { return x <= 0.001692 ? x * 2.0 : 1.000508 * exp(log(x) / 1.15) - 0.000508; } - + static inline double igamma115_2 (double x) { return x <= 0.003384 ? x / 2.0 : exp(log((x + 0.000508) / 1.000508) * 1.15); } - + static inline double gamma145_3 (double x) { return x <= 0.009115 ? x * 3.0 : 1.012305 * exp(log(x) / 1.45) - 0.012305; } - + static inline double igamma145_3 (double x) { return x <= 0.027345 ? x / 3.0 : exp(log((x + 0.012305) / 1.012305) * 1.45); @@ -992,7 +992,7 @@ public: return (x <= start * slope ? x / slope : exp(log((x + add) / mul) * gamma) ); } - + // gamma function with adjustable parameters //same as above with values calculate with Calcgamma above diff --git a/rtengine/curves.cc b/rtengine/curves.cc index 2d355a071..4ad1d06bd 100644 --- a/rtengine/curves.cc +++ b/rtengine/curves.cc @@ -513,6 +513,7 @@ void CurveFactory::curveDehaContL ( bool & dehacontlutili, const std::vector= 9) || __GNUC__ > 4 - #define LVF(x) _mm_load_ps(&x) - #define LVFU(x) _mm_loadu_ps(&x) - #define STVF(x,y) _mm_store_ps(&x,y) - #define STVFU(x,y) _mm_storeu_ps(&x,y) - #else // there is a bug in gcc 4.7.x when using openmp and aligned memory and -O3 - #define LVF(x) _mm_loadu_ps(&x) - #define LVFU(x) _mm_loadu_ps(&x) - #define STVF(x,y) _mm_storeu_ps(&x,y) - #define STVFU(x,y) _mm_storeu_ps(&x,y) - #endif +#if (__GNUC__ == 4 && __GNUC_MINOR__ >= 9) || __GNUC__ > 4 +#define LVF(x) _mm_load_ps(&x) +#define LVFU(x) _mm_loadu_ps(&x) +#define STVF(x,y) _mm_store_ps(&x,y) +#define STVFU(x,y) _mm_storeu_ps(&x,y) +#else // there is a bug in gcc 4.7.x when using openmp and aligned memory and -O3 +#define LVF(x) _mm_loadu_ps(&x) +#define LVFU(x) _mm_loadu_ps(&x) +#define STVF(x,y) _mm_storeu_ps(&x,y) +#define STVFU(x,y) _mm_storeu_ps(&x,y) +#endif #else - #define LVF(x) _mm_load_ps(&x) - #define LVFU(x) _mm_loadu_ps(&x) - #define STVF(x,y) _mm_store_ps(&x,y) - #define STVFU(x,y) _mm_storeu_ps(&x,y) +#define LVF(x) _mm_load_ps(&x) +#define LVFU(x) _mm_loadu_ps(&x) +#define STVF(x,y) _mm_store_ps(&x,y) +#define STVFU(x,y) _mm_storeu_ps(&x,y) #endif // Load 8 floats from a and combine a[0],a[2],a[4] and a[6] into a vector of 4 floats diff --git a/rtengine/ipretinex.cc b/rtengine/ipretinex.cc index 8a283ac56..54d6888ea 100644 --- a/rtengine/ipretinex.cc +++ b/rtengine/ipretinex.cc @@ -94,7 +94,7 @@ void retinex_scales( float* scales, int nscales, int mode, int s, float high) size_step = (float) log(s - 2.0f) / (float) nscales; for ( int i = 0; i < nscales; ++i ) { - scales[i] = high*s - (float)pow (10.f, (i * size_step) / log (10.f)); + scales[i] = high * s - (float)pow (10.f, (i * size_step) / log (10.f)); } } } @@ -225,12 +225,17 @@ void RawImageSource::MSR(float** luminance, float** originalLuminance, float **e limD *= useHslLin ? 10.f : 1.f; float ilimD = 1.f / limD; int moderetinex = 2; // default to 2 ( deh.retinexMethod == "high" ) - float hig = ((float) deh.highl)/100.f; + float hig = ((float) deh.highl) / 100.f; bool higplus = false ; float elogt; float hl = deh.baselog; - if(hl >= 2.71828f) elogt = 2.71828f + SQR(SQR(hl - 2.71828f)); - else elogt = hl; + + if(hl >= 2.71828f) { + elogt = 2.71828f + SQR(SQR(hl - 2.71828f)); + } else { + elogt = hl; + } + elogt = 2.71828f;//disabled baselog FlatCurve* shcurve = NULL;//curve L=f(H) bool lhutili = false; @@ -243,14 +248,15 @@ void RawImageSource::MSR(float** luminance, float** originalLuminance, float **e delete shcurve; shcurve = NULL; } - } - else { + } else { lhutili = true; } } - if(deh.retinexMethod == "highliplus") higplus = true; + if(deh.retinexMethod == "highliplus") { + higplus = true; + } if (deh.retinexMethod == "uni") { moderetinex = 0; @@ -259,13 +265,15 @@ void RawImageSource::MSR(float** luminance, float** originalLuminance, float **e if (deh.retinexMethod == "low") { moderetinex = 1; } + if (deh.retinexMethod == "highli" || deh.retinexMethod == "highliplus") { moderetinex = 3; } - float aahi = 49.f/99.f;////reduce sensibility 50% + + float aahi = 49.f / 99.f; ////reduce sensibility 50% float bbhi = 1.f - aahi; float high; - high = bbhi + aahi*(float) deh.highl; + high = bbhi + aahi * (float) deh.highl; retinex_scales( RetinexScales, scal, moderetinex, nei, high ); int H_L = height; @@ -331,7 +339,7 @@ void RawImageSource::MSR(float** luminance, float** originalLuminance, float **e } } else { for (; j < W_L - 3; j += 4) { - _mm_storeu_ps(&luminance[i][j], LVFU(luminance[i][j]) + pondv * xlogf(LIMV(LVFU(src[i][j]) / LVFU(out[i][j]), limMinv, limMaxv) )/xlogf(elogtv)); + _mm_storeu_ps(&luminance[i][j], LVFU(luminance[i][j]) + pondv * xlogf(LIMV(LVFU(src[i][j]) / LVFU(out[i][j]), limMinv, limMaxv) ) / xlogf(elogtv)); } } @@ -343,7 +351,7 @@ void RawImageSource::MSR(float** luminance, float** originalLuminance, float **e } } else { for (; j < W_L; j++) { - luminance[i][j] += pond * xlogf(LIM(src[i][j] / out[i][j], ilimD, limD))/log(elogt);// /logt ? + luminance[i][j] += pond * xlogf(LIM(src[i][j] / out[i][j], ilimD, limD)) / log(elogt); // /logt ? } } } @@ -457,7 +465,7 @@ void RawImageSource::MSR(float** luminance, float** originalLuminance, float **e } delta = maxi - mini; - // printf("maxi=%f mini=%f mean=%f std=%f delta=%f maxtr=%f mintr=%f\n", maxi, mini, mean, stddv, delta, maxtr, mintr); + // printf("maxi=%f mini=%f mean=%f std=%f delta=%f maxtr=%f mintr=%f\n", maxi, mini, mean, stddv, delta, maxtr, mintr); if ( !delta ) { delta = 1.0f; @@ -492,19 +500,26 @@ void RawImageSource::MSR(float** luminance, float** originalLuminance, float **e if(cd < cdmin) { cdmin = cd; } + float str = strength; + if(lhutili) { // S=f(H) { float HH = exLuminance[i][j]; float valparam; - if(useHsl || useHslLin) valparam = float((shcurve->getVal(HH) - 0.5f)); - else valparam = float((shcurve->getVal(Color::huelab_to_huehsv2(HH)) - 0.5f)); - str *= (1.f + 2.f*valparam); + + if(useHsl || useHslLin) { + valparam = float((shcurve->getVal(HH) - 0.5f)); + } else { + valparam = float((shcurve->getVal(Color::huelab_to_huehsv2(HH)) - 0.5f)); + } + + str *= (1.f + 2.f * valparam); } } - // if(exLuminance[i][j] > 65535.f*hig && higplus) str *= hig; - luminance[i][j] = clipretinex( cd, 0.f, 32768.f ) * str + (1.f - str) * originalLuminance[i][j]; + // if(exLuminance[i][j] > 65535.f*hig && higplus) str *= hig; + luminance[i][j] = clipretinex( cd, 0.f, 32768.f ) * str + (1.f - str) * originalLuminance[i][j]; } #ifdef _OPENMP diff --git a/rtengine/procparams.cc b/rtengine/procparams.cc index 501d0a030..eaf90d5c2 100644 --- a/rtengine/procparams.cc +++ b/rtengine/procparams.cc @@ -3915,14 +3915,14 @@ int ProcParams::load (Glib::ustring fname, ParamsEdited* pedited) } } -/* if (keyFile.has_key ("Retinex", "grbl")) { - retinex.grbl = keyFile.get_integer ("Retinex", "grbl"); + /* if (keyFile.has_key ("Retinex", "grbl")) { + retinex.grbl = keyFile.get_integer ("Retinex", "grbl"); - if (pedited) { - pedited->retinex.grbl = true; - } - } -*/ + if (pedited) { + pedited->retinex.grbl = true; + } + } + */ if (keyFile.has_key ("Retinex", "CDCurve")) { retinex.cdcurve = keyFile.get_double_list ("Retinex", "CDCurve"); diff --git a/rtengine/rawimagesource.cc b/rtengine/rawimagesource.cc index 0e590ccd1..2c0d8ad2f 100644 --- a/rtengine/rawimagesource.cc +++ b/rtengine/rawimagesource.cc @@ -1855,99 +1855,111 @@ void RawImageSource::retinexPrepareBuffers(ColorManagementParams cmp, RetinexPar conversionBuffer[1] (W - 2 * border, H - 2 * border); conversionBuffer[2] (W - 2 * border, H - 2 * border); conversionBuffer[3] (W - 2 * border, H - 2 * border); - - LUTf *retinexgamtab;//gamma before and after Retinex to restore tones - LUTf lutTonereti; - lutTonereti(65536); - - if(retinexParams.gammaretinex == "low") - retinexgamtab = &(Color::gammatab_115_2); - else if(retinexParams.gammaretinex == "mid") - retinexgamtab = &(Color::gammatab_13_2); - else if(retinexParams.gammaretinex == "hig") - retinexgamtab = &(Color::gammatab_145_3); - else if(retinexParams.gammaretinex == "fre"){ - double g_a0, g_a1, g_a2, g_a3, g_a4, g_a5; - double pwr = 1.0 / retinexParams.gam; - double gamm = retinexParams.gam; - double ts = retinexParams.slope; - double gamm2 = retinexParams.gam; - if(gamm2 < 1.) {pwr = 1./pwr; gamm = 1. / gamm;} - - int mode = 0, imax = 0; - Color::calcGamma(pwr, ts, mode, imax, g_a0, g_a1, g_a2, g_a3, g_a4, g_a5); // call to calcGamma with selected gamma and slope - // printf("g_a0=%f g_a1=%f g_a2=%f g_a3=%f g_a4=%f\n", g_a0,g_a1,g_a2,g_a3,g_a4); - for (int i = 0; i < 65536; i++) { - double val = (i) / 65535.; - double start = g_a3; - double add = g_a4; - double mul = 1. + g_a4; - double x; - if(gamm2 < 1.) {start = g_a2; add = g_a4; - x = Color::igammareti (val, gamm, start, ts, mul , add);} - else - x = Color::gammareti (val, gamm, start, ts, mul , add); - - lutTonereti[i] = CLIP(x * 65535.);// CLIP avoid in some case extra values - } - retinexgamtab = &lutTonereti; + + LUTf *retinexgamtab;//gamma before and after Retinex to restore tones + LUTf lutTonereti; + lutTonereti(65536); + + if(retinexParams.gammaretinex == "low") { + retinexgamtab = &(Color::gammatab_115_2); + } else if(retinexParams.gammaretinex == "mid") { + retinexgamtab = &(Color::gammatab_13_2); + } else if(retinexParams.gammaretinex == "hig") { + retinexgamtab = &(Color::gammatab_145_3); + } else if(retinexParams.gammaretinex == "fre") { + double g_a0, g_a1, g_a2, g_a3, g_a4, g_a5; + double pwr = 1.0 / retinexParams.gam; + double gamm = retinexParams.gam; + double ts = retinexParams.slope; + double gamm2 = retinexParams.gam; + + if(gamm2 < 1.) { + pwr = 1. / pwr; + gamm = 1. / gamm; } -/* -//test with amsterdam.pef and other files -float rr,gg,bb; -rr=red[50][2300]; -gg=green[50][2300]; -bb=blue[50][2300]; -printf("rr=%f gg=%f bb=%f \n",rr,gg,bb); -rr=red[1630][370]; -gg=green[1630][370]; -bb=blue[1630][370]; -printf("rr1=%f gg1=%f bb1=%f \n",rr,gg,bb); -rr=red[380][1630]; -gg=green[380][1630]; -bb=blue[380][1630]; -printf("rr2=%f gg2=%f bb2=%f \n",rr,gg,bb); -*/ -/* -if(retinexParams.highlig < 100 && retinexParams.retinexMethod == "highliplus") {//try to recover magenta...very difficult ! - float hig = ((float)retinexParams.highlig)/100.f; - float higgb = ((float)retinexParams.grbl)/100.f; - -#ifdef _OPENMP - #pragma omp parallel for -#endif - for (int i = border; i < H - border; i++ ) { - for (int j = border; j < W - border; j++ ) { - float R_,G_,B_; - R_=red[i][j]; - G_=green[i][j]; - B_=blue[i][j]; - - //empirical method to find highlight magenta with no conversion RGB and no white balance - //red = master Gr and Bl default higgb=0.5 - // if(R_>65535.f*hig && G_ > 65535.f*higgb && B_ > 65535.f*higgb) conversionBuffer[3][i - border][j - border] = R_; - // else conversionBuffer[3][i - border][j - border] = 0.f; + + int mode = 0, imax = 0; + Color::calcGamma(pwr, ts, mode, imax, g_a0, g_a1, g_a2, g_a3, g_a4, g_a5); // call to calcGamma with selected gamma and slope + + // printf("g_a0=%f g_a1=%f g_a2=%f g_a3=%f g_a4=%f\n", g_a0,g_a1,g_a2,g_a3,g_a4); + for (int i = 0; i < 65536; i++) { + double val = (i) / 65535.; + double start = g_a3; + double add = g_a4; + double mul = 1. + g_a4; + double x; + + if(gamm2 < 1.) { + start = g_a2; + add = g_a4; + x = Color::igammareti (val, gamm, start, ts, mul , add); + } else { + x = Color::gammareti (val, gamm, start, ts, mul , add); } - } -} -*/ -if(retinexParams.gammaretinex != "none" && retinexParams.str != 0) {//gamma + + lutTonereti[i] = CLIP(x * 65535.);// CLIP avoid in some case extra values + } + + retinexgamtab = &lutTonereti; + } + + /* + //test with amsterdam.pef and other files + float rr,gg,bb; + rr=red[50][2300]; + gg=green[50][2300]; + bb=blue[50][2300]; + printf("rr=%f gg=%f bb=%f \n",rr,gg,bb); + rr=red[1630][370]; + gg=green[1630][370]; + bb=blue[1630][370]; + printf("rr1=%f gg1=%f bb1=%f \n",rr,gg,bb); + rr=red[380][1630]; + gg=green[380][1630]; + bb=blue[380][1630]; + printf("rr2=%f gg2=%f bb2=%f \n",rr,gg,bb); + */ + /* + if(retinexParams.highlig < 100 && retinexParams.retinexMethod == "highliplus") {//try to recover magenta...very difficult ! + float hig = ((float)retinexParams.highlig)/100.f; + float higgb = ((float)retinexParams.grbl)/100.f; + + #ifdef _OPENMP + #pragma omp parallel for + #endif + for (int i = border; i < H - border; i++ ) { + for (int j = border; j < W - border; j++ ) { + float R_,G_,B_; + R_=red[i][j]; + G_=green[i][j]; + B_=blue[i][j]; + + //empirical method to find highlight magenta with no conversion RGB and no white balance + //red = master Gr and Bl default higgb=0.5 + // if(R_>65535.f*hig && G_ > 65535.f*higgb && B_ > 65535.f*higgb) conversionBuffer[3][i - border][j - border] = R_; + // else conversionBuffer[3][i - border][j - border] = 0.f; + } + } + } + */ + if(retinexParams.gammaretinex != "none" && retinexParams.str != 0) {//gamma #ifdef _OPENMP #pragma omp parallel for -#endif +#endif + for (int i = border; i < H - border; i++ ) { for (int j = border; j < W - border; j++ ) { - float R_,G_,B_; - R_=red[i][j]; - G_=green[i][j]; - B_=blue[i][j]; - + float R_, G_, B_; + R_ = red[i][j]; + G_ = green[i][j]; + B_ = blue[i][j]; + red[i][j] = (*retinexgamtab)[R_]; green[i][j] = (*retinexgamtab)[G_]; - blue[i][j] = (*retinexgamtab)[B_]; + blue[i][j] = (*retinexgamtab)[B_]; } - } -} + } + } if(useHsl) { #ifdef _OPENMP @@ -2054,7 +2066,7 @@ if(retinexParams.gammaretinex != "none" && retinexParams.str != 0) {//gamma for (int j = border; j < W - border; j++) { float X, Y, Z, L, aa, bb; int pos; - float R_,G_,B_; + float R_, G_, B_; R_ = red[i][j]; G_ = green[i][j]; B_ = blue[i][j]; @@ -2066,9 +2078,10 @@ if(retinexParams.gammaretinex != "none" && retinexParams.str != 0) {//gamma conversionBuffer[0][i - border][j - border] = aa; conversionBuffer[1][i - border][j - border] = bb; conversionBuffer[2][i - border][j - border] = L; - conversionBuffer[3][i - border][j - border] = xatan2f(bb,aa); - // if(R_>40000.f && G_ > 30000.f && B_ > 30000.f) conversionBuffer[3][i - border][j - border] = R_; - // else conversionBuffer[3][i - border][j - border] = 0.f; + conversionBuffer[3][i - border][j - border] = xatan2f(bb, aa); + +// if(R_>40000.f && G_ > 30000.f && B_ > 30000.f) conversionBuffer[3][i - border][j - border] = R_; +// else conversionBuffer[3][i - border][j - border] = 0.f; if(lhist16RETI) { pos = (int) clipretinex(L, 0, 32768); lhist16RETIThr[pos]++;//histogram in Curve Lab @@ -2089,9 +2102,9 @@ if(retinexParams.gammaretinex != "none" && retinexParams.str != 0) {//gamma } } - - - + + + } void RawImageSource::retinexPrepareCurves(RetinexParams retinexParams, LUTf &cdcurve, RetinextransmissionCurve &retinextransmissionCurve, bool &retinexcontlutili, bool &useHsl, LUTu & lhist16RETI, LUTu & histLRETI) @@ -2109,7 +2122,7 @@ void RawImageSource::retinexPrepareCurves(RetinexParams retinexParams, LUTf &cdc //void RawImageSource::retinex(ColorManagementParams cmp, RetinexParams deh, ToneCurveParams Tc, LUTf & cdcurve, const RetinextransmissionCurve & dehatransmissionCurve, multi_array2D &conversionBuffer, bool dehacontlutili, bool useHsl, float &minCD, float &maxCD, float &mini, float &maxi, float &Tmean, float &Tsigma, float &Tmin, float &Tmax, LUTu &histLRETI) void RawImageSource::retinex(ColorManagementParams cmp, RetinexParams deh, ToneCurveParams Tc, LUTf & cdcurve, const RetinextransmissionCurve & dehatransmissionCurve, multi_array2D &conversionBuffer, bool dehacontlutili, bool useHsl, float &minCD, float &maxCD, float &mini, float &maxi, float &Tmean, float &Tsigma, float &Tmin, float &Tmax, LUTu &histLRETI) -{ +{ MyTime t4, t5; t4.set(); @@ -2117,42 +2130,55 @@ void RawImageSource::retinex(ColorManagementParams cmp, RetinexParams deh, ToneC if (settings->verbose) { printf ("Applying Retinex\n"); } - LUTf lutToneireti; - lutToneireti(65536); - - LUTf *retinexigamtab;//gamma before and after Retinex to restore tones - if(deh.gammaretinex == "low") - retinexigamtab = &(Color::igammatab_115_2); - else if(deh.gammaretinex == "mid") - retinexigamtab = &(Color::igammatab_13_2); - else if(deh.gammaretinex == "hig") - retinexigamtab = &(Color::igammatab_145_3); - else if(deh.gammaretinex == "fre"){ - double g_a0, g_a1, g_a2, g_a3, g_a4, g_a5; - double pwr = 1.0 / deh.gam; - double gamm = deh.gam; - double gamm2 = gamm; - double ts = deh.slope; - int mode = 0, imax = 0; - if(gamm2 < 1.) {pwr = 1./pwr; gamm = 1. / gamm;} - - Color::calcGamma(pwr, ts, mode, imax, g_a0, g_a1, g_a2, g_a3, g_a4, g_a5); // call to calcGamma with selected gamma and slope - // printf("g_a0=%f g_a1=%f g_a2=%f g_a3=%f g_a4=%f\n", g_a0,g_a1,g_a2,g_a3,g_a4); - for (int i = 0; i < 65536; i++) { - double val = (i) / 65535.; - double x; - double mul = 1. + g_a4; - double add = g_a4; - double start = g_a2; - if(gamm2 < 1.) {start = g_a3; add = g_a3; - x = Color::gammareti (val, gamm, start, ts, mul , add);} - else - x = Color::igammareti (val, gamm, start, ts, mul , add); - - lutToneireti[i] = CLIP(x * 65535.); - } - retinexigamtab = &lutToneireti; + + LUTf lutToneireti; + lutToneireti(65536); + + LUTf *retinexigamtab;//gamma before and after Retinex to restore tones + + if(deh.gammaretinex == "low") { + retinexigamtab = &(Color::igammatab_115_2); + } else if(deh.gammaretinex == "mid") { + retinexigamtab = &(Color::igammatab_13_2); + } else if(deh.gammaretinex == "hig") { + retinexigamtab = &(Color::igammatab_145_3); + } else if(deh.gammaretinex == "fre") { + double g_a0, g_a1, g_a2, g_a3, g_a4, g_a5; + double pwr = 1.0 / deh.gam; + double gamm = deh.gam; + double gamm2 = gamm; + double ts = deh.slope; + int mode = 0, imax = 0; + + if(gamm2 < 1.) { + pwr = 1. / pwr; + gamm = 1. / gamm; } + + Color::calcGamma(pwr, ts, mode, imax, g_a0, g_a1, g_a2, g_a3, g_a4, g_a5); // call to calcGamma with selected gamma and slope + + // printf("g_a0=%f g_a1=%f g_a2=%f g_a3=%f g_a4=%f\n", g_a0,g_a1,g_a2,g_a3,g_a4); + for (int i = 0; i < 65536; i++) { + double val = (i) / 65535.; + double x; + double mul = 1. + g_a4; + double add = g_a4; + double start = g_a2; + + if(gamm2 < 1.) { + start = g_a3; + add = g_a3; + x = Color::gammareti (val, gamm, start, ts, mul , add); + } else { + x = Color::igammareti (val, gamm, start, ts, mul , add); + } + + lutToneireti[i] = CLIP(x * 65535.); + } + + retinexigamtab = &lutToneireti; + } + // We need a buffer with original L data to allow correct blending // red, green and blue still have original size of raw, but we can't use the borders const int HNew = H - 2 * border; @@ -2172,25 +2198,24 @@ void RawImageSource::retinex(ColorManagementParams cmp, RetinexParams deh, ToneC dLcurve.clear(); } - FlatCurve* chcurve = NULL;//curve c=f(H) - bool chutili = false; + FlatCurve* chcurve = NULL;//curve c=f(H) + bool chutili = false; - if (deh.enabled && deh.retinexMethod == "highli") { - chcurve = new FlatCurve(deh.lhcurve); + if (deh.enabled && deh.retinexMethod == "highli") { + chcurve = new FlatCurve(deh.lhcurve); - if (!chcurve || chcurve->isIdentity()) { - if (chcurve) { - delete chcurve; - chcurve = NULL; - } - } - else { - chutili = true; + if (!chcurve || chcurve->isIdentity()) { + if (chcurve) { + delete chcurve; + chcurve = NULL; } + } else { + chutili = true; } - - - + } + + + #ifdef _OPENMP #pragma omp parallel #endif @@ -2247,30 +2272,34 @@ void RawImageSource::retinex(ColorManagementParams cmp, RetinexParams deh, ToneC histLRETI[hi] += hist16RET[i]; } } + MSR(LBuffer, conversionBuffer[2], conversionBuffer[3], WNew, HNew, deh, dehatransmissionCurve, minCD, maxCD, mini, maxi, Tmean, Tsigma, Tmin, Tmax); - + if(useHsl) { - if(chutili) { + if(chutili) { #ifdef _OPENMP - #pragma omp parallel for -#endif + #pragma omp parallel for +#endif + for (int i = border; i < H - border; i++ ) { int j = border; + for (; j < W - border; j++) { - - float valp; - float chr; - // if(chutili) { // c=f(H) - { - valp = float((chcurve->getVal(conversionBuffer[3][i - border][j - border]) - 0.5f)); - - conversionBuffer[1][i - border][j - border] *= (1.f + 2.f*valp); - } - // } - + + float valp; + float chr; + // if(chutili) { // c=f(H) + { + valp = float((chcurve->getVal(conversionBuffer[3][i - border][j - border]) - 0.5f)); + + conversionBuffer[1][i - border][j - border] *= (1.f + 2.f * valp); + } + // } + } } } + #ifdef _OPENMP #pragma omp parallel for #endif @@ -2309,42 +2338,44 @@ void RawImageSource::retinex(ColorManagementParams cmp, RetinexParams deh, ToneC #ifdef _OPENMP #pragma omp parallel for #endif + for (int i = border; i < H - border; i++ ) { - for (int j= border; j < W - border; j++) { - - float Lprov1 = (LBuffer[i - border][j - border])/327.68f; + for (int j = border; j < W - border; j++) { + + float Lprov1 = (LBuffer[i - border][j - border]) / 327.68f; float Chprov1 = sqrt(SQR(conversionBuffer[0][i - border][j - border]) + SQR(conversionBuffer[1][i - border][j - border])) / 327.68f; float HH = xatan2f(conversionBuffer[1][i - border][j - border], conversionBuffer[0][i - border][j - border]); float2 sincosval; float valp; float chr; - if(chutili) { // c=f(H) - { - valp = float((chcurve->getVal(Color::huelab_to_huehsv2(HH)) - 0.5f)); - Chprov1 *= (1.f + 2.f*valp); - } + + if(chutili) { // c=f(H) + { + valp = float((chcurve->getVal(Color::huelab_to_huehsv2(HH)) - 0.5f)); + Chprov1 *= (1.f + 2.f * valp); } - + } + sincosval = xsincosf(HH); - float R,G,B; + float R, G, B; #ifdef _DEBUG - bool neg = false; - bool more_rgb = false; - //gamut control : Lab values are in gamut - Color::gamutLchonly(HH, sincosval, Lprov1, Chprov1, R, G, B, wip, highlight, 0.15f, 0.96f, neg, more_rgb); + bool neg = false; + bool more_rgb = false; + //gamut control : Lab values are in gamut + Color::gamutLchonly(HH, sincosval, Lprov1, Chprov1, R, G, B, wip, highlight, 0.15f, 0.96f, neg, more_rgb); #else - //gamut control : Lab values are in gamut - Color::gamutLchonly(HH, sincosval, Lprov1, Chprov1, R, G, B, wip, highlight, 0.15f, 0.96f); + //gamut control : Lab values are in gamut + Color::gamutLchonly(HH, sincosval, Lprov1, Chprov1, R, G, B, wip, highlight, 0.15f, 0.96f); #endif - conversionBuffer[0][i - border][j - border] = 327.68f * Chprov1 * sincosval.y; - conversionBuffer[1][i - border][j - border] = 327.68f * Chprov1 * sincosval.x; - LBuffer[i - border][j - border] = Lprov1 * 327.68f; + conversionBuffer[0][i - border][j - border] = 327.68f * Chprov1 * sincosval.y; + conversionBuffer[1][i - border][j - border] = 327.68f * Chprov1 * sincosval.x; + LBuffer[i - border][j - border] = Lprov1 * 327.68f; } - } - + } + //end gamut control #ifdef __SSE2__ vfloat wipv[3][3]; @@ -2368,11 +2399,11 @@ void RawImageSource::retinex(ColorManagementParams cmp, RetinexParams deh, ToneC vfloat R, G, B; Color::Lab2XYZ(LVFU(LBuffer[i - border][j - border]), LVFU(conversionBuffer[0][i - border][j - border]), LVFU(conversionBuffer[1][i - border][j - border]), x_, y_, z_) ; Color::xyz2rgb(x_, y_, z_, R, G, B, wipv); - + _mm_storeu_ps(&red[i][j], R); _mm_storeu_ps(&green[i][j], G); - _mm_storeu_ps(&blue[i][j], B); - + _mm_storeu_ps(&blue[i][j], B); + } #endif @@ -2387,26 +2418,28 @@ void RawImageSource::retinex(ColorManagementParams cmp, RetinexParams deh, ToneC blue[i][j] = B; } } -} - if (chcurve) { - delete chcurve; - } + } -if(deh.gammaretinex != "none" && deh.str !=0){//inverse gamma + if (chcurve) { + delete chcurve; + } + + if(deh.gammaretinex != "none" && deh.str != 0) { //inverse gamma #ifdef _OPENMP #pragma omp parallel for -#endif +#endif + for (int i = border; i < H - border; i++ ) { for (int j = border; j < W - border; j++ ) { - float R_,G_,B_; - R_=red[i][j]; - G_=green[i][j]; - B_=blue[i][j]; + float R_, G_, B_; + R_ = red[i][j]; + G_ = green[i][j]; + B_ = blue[i][j]; red[i][j] = (*retinexigamtab)[R_]; green[i][j] = (*retinexigamtab)[G_]; - blue[i][j] = (*retinexigamtab)[B_]; + blue[i][j] = (*retinexigamtab)[B_]; } - } + } } t5.set(); diff --git a/rtengine/simpleprocess.cc b/rtengine/simpleprocess.cc index f6ea8ad6b..91b7df178 100644 --- a/rtengine/simpleprocess.cc +++ b/rtengine/simpleprocess.cc @@ -627,6 +627,7 @@ IImage16* processImage (ProcessingJob* pjob, int& errorCode, ProgressListener* p Imagefloat* baseImg = new Imagefloat (fw, fh); imgsrc->getImage (currWB, tr, baseImg, pp, params.toneCurve, params.icm, params.raw); + if (pl) { pl->setProgress (0.50); } diff --git a/rtgui/batchtoolpanelcoord.cc b/rtgui/batchtoolpanelcoord.cc index fa057e205..e1d78a19f 100644 --- a/rtgui/batchtoolpanelcoord.cc +++ b/rtgui/batchtoolpanelcoord.cc @@ -577,31 +577,31 @@ void BatchToolPanelCoordinator::initSession () if (options.baBehav[ADDSET_WA_GAMMA]) { pparams.wavelet.gamma = 0; } - + if (options.baBehav[ADDSET_RETI_STR]) { pparams.retinex.str = 0; } - + if (options.baBehav[ADDSET_RETI_SCAL]) { pparams.retinex.scal = 0; } - + if (options.baBehav[ADDSET_RETI_NEIGH]) { pparams.retinex.neigh = 0; } - + if (options.baBehav[ADDSET_RETI_LIMD]) { pparams.retinex.limd = 0; } - + if (options.baBehav[ADDSET_RETI_GAIN]) { pparams.retinex.gain = 0; } - + if (options.baBehav[ADDSET_RETI_OFFS]) { pparams.retinex.offs = 0; } - + if (options.baBehav[ADDSET_RETI_VART]) { pparams.retinex.vart = 0; } @@ -613,7 +613,7 @@ void BatchToolPanelCoordinator::initSession () if (options.baBehav[ADDSET_RETI_SLO]) { pparams.retinex.slope = 0; } - + if (options.baBehav[ADDSET_DIRPYRDN_LUMA]) { pparams.dirpyrDenoise.luma = 0; } diff --git a/rtgui/editorpanel.cc b/rtgui/editorpanel.cc index ef4ec5715..4d1907422 100644 --- a/rtgui/editorpanel.cc +++ b/rtgui/editorpanel.cc @@ -567,6 +567,7 @@ void EditorPanel::open (Thumbnail* tmb, rtengine::InitialImage* isrc) Gtk::Allocation alloc; iareapanel->imageArea->on_resized(alloc); } + history->resetSnapShotNumber(); } diff --git a/rtgui/paramsedited.cc b/rtgui/paramsedited.cc index 81cf57736..08433357c 100644 --- a/rtgui/paramsedited.cc +++ b/rtgui/paramsedited.cc @@ -1053,7 +1053,7 @@ void ParamsEdited::combine (rtengine::procparams::ProcParams& toEdit, const rten if (retinex.lhcurve) { toEdit.retinex.lhcurve = mods.retinex.lhcurve; } - + if (retinex.transmissionCurve) { toEdit.retinex.transmissionCurve = mods.retinex.transmissionCurve; } @@ -1109,10 +1109,10 @@ void ParamsEdited::combine (rtengine::procparams::ProcParams& toEdit, const rten // if (retinex.grbl) { // toEdit.retinex.grbl = mods.retinex.grbl; // } - + if (retinex.gain) { toEdit.retinex.gain = dontforceSet && options.baBehav[ADDSET_RETI_GAIN] ? toEdit.retinex.gain + mods.retinex.gain : mods.retinex.gain; - } + } if (retinex.offs) { toEdit.retinex.offs = dontforceSet && options.baBehav[ADDSET_RETI_OFFS] ? toEdit.retinex.offs + mods.retinex.offs : mods.retinex.offs; diff --git a/rtgui/partialpastedlg.cc b/rtgui/partialpastedlg.cc index 17f23a787..ec2320138 100644 --- a/rtgui/partialpastedlg.cc +++ b/rtgui/partialpastedlg.cc @@ -701,7 +701,7 @@ void PartialPasteDlg::applyPaste (rtengine::procparams::ProcParams* dstPP, Param if (!retinex->get_active ()) { filterPE.retinex = falsePE.retinex; } - + if (!pcvignette->get_active ()) { filterPE.pcvignette = falsePE.pcvignette; } diff --git a/rtgui/preferences.cc b/rtgui/preferences.cc index 8a0250f84..22c53aa00 100644 --- a/rtgui/preferences.cc +++ b/rtgui/preferences.cc @@ -181,7 +181,7 @@ Gtk::Widget* Preferences::getBatchProcPanel () appendBehavList (mi, M("TP_RETINEX_OFFSET"), ADDSET_RETI_OFFS, false); appendBehavList (mi, M("TP_RETINEX_THRESHOLD"), ADDSET_RETI_LIMD, false); appendBehavList (mi, M("TP_RETINEX_VARIANCE"), ADDSET_RETI_VART, false); - + mi = behModel->append (); mi->set_value (behavColumns.label, M("TP_SHADOWSHLIGHTS_LABEL")); appendBehavList (mi, M("TP_SHADOWSHLIGHTS_HIGHLIGHTS"), ADDSET_SH_HIGHLIGHTS, false); diff --git a/rtgui/retinex.cc b/rtgui/retinex.cc index 73e604e2e..2613cf8da 100644 --- a/rtgui/retinex.cc +++ b/rtgui/retinex.cc @@ -321,12 +321,12 @@ Retinex::Retinex () : FoldableToolPanel(this, "retinex", M("TP_RETINEX_LABEL"), baselog->delay = 200; } -/* grbl->setAdjusterListener (this); + /* grbl->setAdjusterListener (this); - if (grbl->delay < 200) { - grbl->delay = 200; - } -*/ + if (grbl->delay < 200) { + grbl->delay = 200; + } + */ pack_start (*retinexVBox); pack_start (*expsettings); pack_start (*neutrHBox); @@ -671,18 +671,21 @@ void Retinex::write (ProcParams* pp, ParamsEdited* pedited) void Retinex::retinexMethodChanged() { - if(retinexMethod->get_active_row_number() == 3) highl->show(); - else highl->hide(); + if(retinexMethod->get_active_row_number() == 3) { + highl->show(); + } else { + highl->hide(); + } if (listener) { - listener->panelChanged (EvretinexMethod, retinexMethod->get_active_text ()); + listener->panelChanged (EvretinexMethod, retinexMethod->get_active_text ()); } } void Retinex::ColorSpaceUpdateUI () { if (!batchMode) { - curveEditorGH->show(); + curveEditorGH->show(); if(retinexcolorspace->get_active_row_number() == 0) { curveEditorGD->show(); @@ -941,9 +944,9 @@ void Retinex::colorForValue (double valX, double valY, enum ColorCaller::ElemTyp float value = (1.f - 0.7f) * float(valX) + 0.7f; - // whole hue range - // Y axis / from 0.15 up to 0.75 (arbitrary values; was 0.45 before) - Color::hsv2rgb01(float(valY), float(valX), value, R, G, B); + // whole hue range + // Y axis / from 0.15 up to 0.75 (arbitrary values; was 0.45 before) + Color::hsv2rgb01(float(valY), float(valX), value, R, G, B); } else if (callerId == 4) { // LH - bottom bar Color::hsv2rgb01(float(valX), 0.5f, float(valY), R, G, B); } else if (callerId == 5) { // HH - bottom bar diff --git a/rtgui/retinex.h b/rtgui/retinex.h index 09912341e..a9b462808 100644 --- a/rtgui/retinex.h +++ b/rtgui/retinex.h @@ -42,7 +42,7 @@ protected: Gtk::HBox* gambox; Gtk::Button* neutral; Gtk::HBox* neutrHBox; - + MyComboBoxText* retinexMethod; MyComboBoxText* retinexcolorspace; MyComboBoxText* gammaretinex; @@ -99,7 +99,7 @@ public: void updateToolState (std::vector &tpOpen); void setAdjusterBehavior (bool strAdd, bool neighAdd, bool scalAdd, bool limdAdd, bool gainAdd, bool offsAdd, bool vartAdd, bool gamAdd, bool slopeAdd); void updateCurveBackgroundHistogram (LUTu & histToneCurve, LUTu & histLCurve, LUTu & histCCurve,/* LUTu & histCLurve, LUTu & histLLCurve,*/ LUTu & histLCAM, LUTu & histCCAM, LUTu & histRed, LUTu & histGreen, LUTu & histBlue, LUTu & histLuma, LUTu & histLRETI); - + virtual void colorForValue (double valX, double valY, enum ColorCaller::ElemType elemType, int callerId, ColorCaller* caller); private: