diff --git a/rtengine/color.cc b/rtengine/color.cc index 6e1afe35a..670f0fb85 100644 --- a/rtengine/color.cc +++ b/rtengine/color.cc @@ -179,7 +179,7 @@ void Color::init() cachefy[i] = 327.68 * (kappa * i / MAXVALF); } - for(; i < maxindex; i++) + for (; i < maxindex; i++) { cachefy[i] = 327.68 * (116.0 * std::cbrt((double)i / MAXVALF) - 16.0); } @@ -379,13 +379,15 @@ void Color::cleanup() } } -void Color::rgb2lab01 (const Glib::ustring &profile, const Glib::ustring &profileW, float r, float g, float b, float &LAB_l, float &LAB_a, float &LAB_b, bool workingSpace) -{ // do not use this function in a loop. It really eats processing time caused by Glib::ustring comparisons +void Color::rgb2lab01(const Glib::ustring &profile, const Glib::ustring &profileW, float r, float g, float b, float &LAB_l, float &LAB_a, float &LAB_b, bool workingSpace) +{ + // do not use this function in a loop. It really eats processing time caused by Glib::ustring comparisons Glib::ustring profileCalc = "sRGB"; //default if (workingSpace) {//display working profile profileCalc = profileW; + if (profileW == "sRGB") { //apply sRGB inverse gamma if (r > 0.04045f) { @@ -499,9 +501,9 @@ void Color::rgb2lab01 (const Glib::ustring &profile, const Glib::ustring &profil const TMatrix wprof = rtengine::ICCStore::getInstance()->workingSpaceMatrix(profileCalc); const float xyz_rgb[3][3] = { {static_cast(wprof[0][0]), static_cast(wprof[0][1]), static_cast(wprof[0][2])}, - {static_cast(wprof[1][0]), static_cast(wprof[1][1]), static_cast(wprof[1][2])}, - {static_cast(wprof[2][0]), static_cast(wprof[2][1]), static_cast(wprof[2][2])} - }; + {static_cast(wprof[1][0]), static_cast(wprof[1][1]), static_cast(wprof[1][2])}, + {static_cast(wprof[2][0]), static_cast(wprof[2][1]), static_cast(wprof[2][2])} + }; const float var_X = (xyz_rgb[0][0] * r + xyz_rgb[0][1] * g + xyz_rgb[0][2] * b) / Color::D50x; const float var_Y = (xyz_rgb[1][0] * r + xyz_rgb[1][1] * g + xyz_rgb[1][2] * b); @@ -2348,7 +2350,7 @@ void Color::gamutLchonly(float HH, float &Lprov1, float &Chprov1, float &R, floa float bprov1 = Chprov1 * sincosval.x; //conversion Lab RGB to limit Lab values - this conversion is useful before Munsell correction - float fy = (c1By116 * Lprov1 ) + c16By116; + float fy = (c1By116 * Lprov1) + c16By116; float fx = (0.002f * aprov1) + fy; float fz = fy - (0.005f * bprov1); @@ -2468,7 +2470,7 @@ void Color::gamutLchonly(float HH, float2 sincosval, float &Lprov1, float &Chpro float bprov1 = Chprov1 * sincosval.x; //conversion Lab RGB to limit Lab values - this conversion is useful before Munsell correction - float fy = (c1By116 * Lprov1 ) + c16By116; + float fy = (c1By116 * Lprov1) + c16By116; float fx = (0.002f * aprov1) + fy; float fz = fy - (0.005f * bprov1); @@ -2577,7 +2579,7 @@ void Color::gamutLchonly(float2 sincosval, float &Lprov1, float &Chprov1, const float bprov1 = Chprov1 * sincosval.x; //conversion Lab RGB to limit Lab values - this conversion is useful before Munsell correction - float fy = (c1By116 * Lprov1 ) + c16By116; + float fy = (c1By116 * Lprov1) + c16By116; float fx = (0.002f * aprov1) + fy; float fz = fy - (0.005f * bprov1); diff --git a/rtengine/color.h b/rtengine/color.h index 35a6d1e71..3b7165a78 100644 --- a/rtengine/color.h +++ b/rtengine/color.h @@ -215,7 +215,7 @@ public: * @param workingSpace true: compute the Lab value using the Working color space ; false: use the Output color space */ // do not use this function in a loop. It really eats processing time caused by Glib::ustring comparisons - static void rgb2lab01 (const Glib::ustring &profile, const Glib::ustring &profileW, float r, float g, float b, float &LAB_l, float &LAB_a, float &LAB_b, bool workingSpace); + static void rgb2lab01(const Glib::ustring &profile, const Glib::ustring &profileW, float r, float g, float b, float &LAB_l, float &LAB_a, float &LAB_b, bool workingSpace); /** * @brief Convert red/green/blue to hue/saturation/luminance @@ -269,9 +269,9 @@ public: s = C / (131070.f - (M + m)); // 131070.f = 2.f * 65535.f } - if ( r == M ) { + if (r == M) { h = (g - b); - } else if ( g == M ) { + } else if (g == M) { h = (2.f * C) + (b - r); } else { h = (4.f * C) + (r - g); @@ -279,7 +279,7 @@ public: h /= (6.f * C); - if ( h < 0.f ) { + if (h < 0.f) { h += 1.f; } } @@ -300,7 +300,7 @@ public: */ static void hsl2rgb(float h, float s, float l, float &r, float &g, float &b); - static inline void hsl2rgbfloat (float h, float s, float l, float &r, float &g, float &b) + static inline void hsl2rgbfloat(float h, float s, float l, float &r, float &g, float &b) { if (s == 0.f) { @@ -316,9 +316,9 @@ public: float m1 = 2.f * l - m2; - r = 65535.f * hue2rgbfloat (m1, m2, h * 6.f + 2.f); - g = 65535.f * hue2rgbfloat (m1, m2, h * 6.f); - b = 65535.f * hue2rgbfloat (m1, m2, h * 6.f - 2.f); + r = 65535.f * hue2rgbfloat(m1, m2, h * 6.f + 2.f); + g = 65535.f * hue2rgbfloat(m1, m2, h * 6.f); + b = 65535.f * hue2rgbfloat(m1, m2, h * 6.f - 2.f); } } @@ -358,7 +358,7 @@ public: * @param s saturation channel [0 ; 1] (return value) * @param v value channel [0 ; 1] (return value) */ - static void rgb2hsv01 (float r, float g, float b, float &h, float &s, float &v); + static void rgb2hsv01(float r, float g, float b, float &h, float &s, float &v); static inline float rgb2s(float r, float g, float b) // fast version if only saturation is needed { diff --git a/rtengine/curves.cc b/rtengine/curves.cc index 77c20cc7d..a4bf4c81e 100644 --- a/rtengine/curves.cc +++ b/rtengine/curves.cc @@ -756,8 +756,8 @@ void CurveFactory::complexCurve(double ecomp, double black, double hlcompr, doub const float slope = 1.055 * powf(start, 1.0 / gamma_ - 1) - 0.055 / start; const float mul = 1.055; const float add = 0.055; - - + + // a: slope of the curve, black: starting point at the x axis const float a = powf(2.0, ecomp); @@ -1036,7 +1036,7 @@ void CurveFactory::complexCurvelocal(double ecomp, double black, double hlcompr, // check if brightness curve is needed if (br > 0.00001 || br < -0.00001) { - // utili = true; + // utili = true; std::vector brightcurvePoints; brightcurvePoints.resize(9); @@ -1077,19 +1077,21 @@ void CurveFactory::complexCurvelocal(double ecomp, double black, double hlcompr, // store result in a temporary array lightCurveloc[i] = CLIPD(val); } - lightCurveloc *= 32767.f; - for (int i = 32768; i < 32770; i++) { // set last two elements of lut to 32768 and 32769 to allow linear interpolation - lightCurveloc[i] = (float)i; - } - + + lightCurveloc *= 32767.f; + + for (int i = 32768; i < 32770; i++) { // set last two elements of lut to 32768 and 32769 to allow linear interpolation + lightCurveloc[i] = (float)i; + } + } else { lightCurveloc.makeIdentity(32767.f); } - - + + // a: slope of the curve, black: starting point at the x axis const float a = powf(2.0f, ecomp); @@ -1157,7 +1159,6 @@ void CurveFactory::complexCurvelocal(double ecomp, double black, double hlcompr, // curve without contrast - // LUTf dcurve (0x10000); LUTf dcurve(maxran); //%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -1169,12 +1170,9 @@ void CurveFactory::complexCurvelocal(double ecomp, double black, double hlcompr, // gamma correction val = Color::gammatab_srgb[0] / maxran; - // val = Color::gammatab_srgb327[0] / 32767.f; // store result in a temporary array dcurve[0] = CLIPD(val); -// for (int i = 1; i < 0x10000; i++) { -// float val = i / 65535.f; for (int i = 1; i < maxran; i++) { float val = i / (maxran - 1.f); @@ -1183,7 +1181,6 @@ void CurveFactory::complexCurvelocal(double ecomp, double black, double hlcompr, // gamma correction val = Color::gammatab_srgb[i] / maxran; - // val = Color::gammatab_srgb327[i] / 32767.f; // store result in a temporary array dcurve[i] = val; } @@ -1198,7 +1195,6 @@ void CurveFactory::complexCurvelocal(double ecomp, double black, double hlcompr, // vfloat c65535v = F2V (65535.f); vfloat c65535v = F2V(maxran - 1.f); - // for (int i = 0; i <= 0xffff; i += 4) { for (int i = 0; i <= (maxran - 1.f); i += 4) { vfloat valv = LVFU(dcurve[i]); valv = igamma(valv, gamma_v, startv, slopev, mulv, addv); @@ -1207,186 +1203,18 @@ void CurveFactory::complexCurvelocal(double ecomp, double black, double hlcompr, #else - // for (int i = 0; i <= 0xffff; i++) { for (int i = 0; i <= (maxran - 1.f); i++) { float val = dcurve[i]; val = igamma(val, gamma_, start, slope, mul, add); - // outCurve[i] = (65535.f * val); outCurve[i] = ((maxran - 1.) * val); } -//outcurve not used now #endif } - - -/* -void CurveFactory::complexCurvelocal(double ecomp, double black, double hlcompr, double hlcomprthresh, - double shcompr, double br, - LUTf & hlCurve, LUTf & shCurve, LUTf & outCurve, - int skip) -{ - float maxran = 65536.f; //65536 - - ecomp /= 100.;//for mip files in integer * 100 - - // a: slope of the curve, black: starting point at the x axis - const float a = powf(2.0f, ecomp); - - - //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - // tone curve base. a: slope (from exp.comp.), b: black, def_mul: max. x value (can be>1), hr,sr: highlight,shadow recovery - //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - - if (br > 0.00001 || br < -0.00001) { - // utili = true; - - std::vector brightcurvePoints; - brightcurvePoints.resize(9); - brightcurvePoints.at(0) = double (DCT_NURBS); - - brightcurvePoints.at(1) = 0.; // black point. Value in [0 ; 1] range - brightcurvePoints.at(2) = 0.; // black point. Value in [0 ; 1] range - - if (br > 0) { - brightcurvePoints.at(3) = 0.1; // toe point - brightcurvePoints.at(4) = 0.1 + br / 150.0; //value at toe point - - brightcurvePoints.at(5) = 0.7; // shoulder point - brightcurvePoints.at(6) = min(1.0, 0.7 + br / 300.0); //value at shoulder point - } else { - brightcurvePoints.at(3) = 0.1 - br / 150.0; // toe point - brightcurvePoints.at(4) = 0.1; // value at toe point - - brightcurvePoints.at(5) = min(1.0, 0.7 - br / 300.0); // shoulder point - brightcurvePoints.at(6) = 0.7; // value at shoulder point - } - - brightcurvePoints.at(7) = 1.; // white point - brightcurvePoints.at(8) = 1.; // value at white point - - DiagonalCurve brightcurve(brightcurvePoints, CURVES_MIN_POLY_POINTS / skip); - //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - - // Applying brightness curve - for (int i = 0; i < 32768; i++) { // L values range up to 32767, higher values are for highlight overflow - - // change to [0,1] range - float val = (float)i / 32767.0; - - // apply brightness curve - val = brightcurve.getVal(val); - - // store result in a temporary array - outCurve[i] = CLIPD(val); - } - - } else { - outCurve.makeIdentity(32767.f); - } - - - - hlCurve.setClip(LUT_CLIP_BELOW); // used LUT_CLIP_BELOW, because we want to have a baseline of 2^expcomp in this curve. If we don't clip the lut we get wrong values, see Issue 2621 #14 for details - float exp_scale = a; -// float scale = 65536.0; - float scale = maxran; - float comp = (max(0.0, ecomp) + 1.0) * hlcompr / 100.0; - float shoulder = ((scale / max(1.0f, exp_scale)) * (hlcomprthresh / 200.0)) + 0.1; - - if (comp <= 0.0f) { - hlCurve.makeConstant(exp_scale); - } else { - hlCurve.makeConstant(exp_scale, shoulder + 1); - - float scalemshoulder = scale - shoulder; - -#ifdef __SSE2__ - int i = shoulder + 1; - - if (i & 1) { // original formula, slower than optimized formulas below but only used once or none, so I let it as is for reference - // change to [0,1] range - float val = (float)i - shoulder; - float R = val * comp / (scalemshoulder); - hlCurve[i] = xlog(1.0f + R * exp_scale) / R; // don't use xlogf or 1.f here. Leads to errors caused by too low precision - i++; - } - - vdouble onev = _mm_set1_pd(1.0); - vdouble Rv = _mm_set_pd((i + 1 - shoulder) * (double)comp / scalemshoulder, (i - shoulder) * (double)comp / scalemshoulder); - vdouble incrementv = _mm_set1_pd(2.0 * comp / scalemshoulder); - vdouble exp_scalev = _mm_set1_pd(exp_scale); - - // for (; i < 0x10000; i += 2) { - for (; i < maxran; i += 2) { - // change to [0,1] range - vdouble resultv = xlog(onev + Rv * exp_scalev) / Rv; - vfloat resultfv = _mm_cvtpd_ps(resultv); - _mm_store_ss(&hlCurve[i], resultfv); - resultfv = PERMUTEPS(resultfv, _MM_SHUFFLE(1, 1, 1, 1)); - _mm_store_ss(&hlCurve[i + 1], resultfv); - Rv += incrementv; - } - -#else - float R = comp / scalemshoulder; - float increment = R; - - // for (int i = shoulder + 1; i < 0x10000; i++) { - for (int i = shoulder + 1; i < maxran; i++) { - // change to [0,1] range - hlCurve[i] = xlog(1.0f + R * exp_scale) / R; // don't use xlogf or 1.f here. Leads to errors caused by too low precision - R += increment; - } - -#endif - - } - - - // curve without contrast - // LUTf dcurve (0x10000); - LUTf dcurve(maxran); - - //%%%%%%%%%%%%%%%%%%%%%%%%%% - // change to [0,1] range - shCurve.setClip(LUT_CLIP_ABOVE); // used LUT_CLIP_ABOVE, because the curve converges to 1.0 at the upper end and we don't want to exceed this value. - float val = 1.f / (maxran - 1.f); - float val2 = simplebasecurve(val, black, 0.015 * shcompr); - shCurve[0] = CLIPD(val2) / val; - // gamma correction - - val = Color::gammatab_srgb[0] / maxran; - // val = 0.f / maxran; - - // val = Color::gammatab_srgb327[0] / 32767.f; - // store result in a temporary array - dcurve[0] = CLIPD(val); - -// for (int i = 1; i < 0x10000; i++) { -// float val = i / 65535.f; - for (int i = 1; i < maxran; i++) { - float val = i / (maxran - 1.f); - - float val2 = simplebasecurve(val, black, 0.015 * shcompr); - shCurve[i] = val2 / val; - - // gamma correction - val = Color::gammatab_srgb[i] / maxran; - // val = i / maxran; - - // val = Color::gammatab_srgb327[i] / 32767.f; - // store result in a temporary array - dcurve[i] = val; - } - -} -*/ - //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% void CurveFactory::complexLCurve(double br, double contr, const std::vector& curvePoints, diff --git a/rtengine/dcrop.cc b/rtengine/dcrop.cc index 84624604f..73b1b33b3 100644 --- a/rtengine/dcrop.cc +++ b/rtengine/dcrop.cc @@ -1296,7 +1296,7 @@ void Crop::update(int todo) double hlcompr = params.locallab.hlcompr; double hlcomprthresh = params.locallab.hlcomprthresh; double shcompr = params.locallab.shcompr; - double br = params.locallab.lightness; + double br = params.locallab.lightness; CurveFactory::complexCurvelocal(ecomp, black / 65535., hlcompr, hlcomprthresh, shcompr, br, hltonecurveloc2, shtonecurveloc2, tonecurveloc2, lightCurveloc2, @@ -1787,10 +1787,10 @@ void Crop::update(int todo) double hlcompr = params.locallab.hlcompr; double hlcomprthresh = params.locallab.hlcomprthresh; double shcompr = params.locallab.shcompr; - double br = params.locallab.lightness; + double br = params.locallab.lightness; - CurveFactory::complexCurvelocal(ecomp, black / 65535., hlcompr, hlcomprthresh, shcompr, br, - hltonecurveloc2, shtonecurveloc2, tonecurveloc2,lightCurveloc2, + CurveFactory::complexCurvelocal(ecomp, black / 65535., hlcompr, hlcomprthresh, shcompr, br, + hltonecurveloc2, shtonecurveloc2, tonecurveloc2, lightCurveloc2, sca); params.locallab.huerefblur = (parent->huerefblurs[sp]) / 100.f; diff --git a/rtengine/improccoordinator.cc b/rtengine/improccoordinator.cc index 378cdbf13..83853cef5 100644 --- a/rtengine/improccoordinator.cc +++ b/rtengine/improccoordinator.cc @@ -2689,7 +2689,7 @@ void ImProcCoordinator::updatePreviewImage(int todo, Crop* cropCall) double hlcompr = params.locallab.hlcompr; double hlcomprthresh = params.locallab.hlcomprthresh; double shcompr = params.locallab.shcompr; - double br = params.locallab.lightness; + double br = params.locallab.lightness; CurveFactory::complexCurvelocal(ecomp, black / 65535., hlcompr, hlcomprthresh, shcompr, br, hltonecurveloc, shtonecurveloc, tonecurveloc, lightCurveloc, sca); @@ -3365,10 +3365,10 @@ void ImProcCoordinator::updatePreviewImage(int todo, Crop* cropCall) double hlcompr = params.locallab.hlcompr; double hlcomprthresh = params.locallab.hlcomprthresh; double shcompr = params.locallab.shcompr; - double br = params.locallab.lightness; + double br = params.locallab.lightness; CurveFactory::complexCurvelocal(ecomp, black / 65535., hlcompr, hlcomprthresh, shcompr, br, - hltonecurveloc, shtonecurveloc, tonecurveloc,lightCurveloc, + hltonecurveloc, shtonecurveloc, tonecurveloc, lightCurveloc, sca); CurveFactory::curveLocal(locallutili, params.locallab.llcurve, lllocalcurve, sca); diff --git a/rtengine/improccoordinator.h b/rtengine/improccoordinator.h index c3666ccc0..c1f076bd2 100644 --- a/rtengine/improccoordinator.h +++ b/rtengine/improccoordinator.h @@ -122,7 +122,7 @@ protected: LUTf shtonecurveloc; LUTf tonecurveloc; LUTf lightCurveloc; - + // ToneCurve customToneCurve1loc; LUTf cl2Toningcurve; @@ -244,7 +244,7 @@ protected: bool curveutili; int **dataspot; - int maxdata; + int maxdata; std::string *retistr; std::string *llstr; std::string *lhstr; @@ -445,29 +445,29 @@ public: } DetailedCrop* createCrop(::EditDataProvider *editDataProvider, bool isDetailWindow); -/* -<<<<<<< HEAD + /* + <<<<<<< HEAD + bool getAutoWB(double& temp, double& green, double equal, double tempBias); + void getCamWB(double& temp, double& green); + void getSpotWB(int x, int y, int rectSize, double& temp, double& green); + void getAutoCrop(double ratio, int &x, int &y, int &w, int &h); + + void setMonitorProfile(const Glib::ustring& profile, RenderingIntent intent); + void getMonitorProfile(Glib::ustring& profile, RenderingIntent& intent) const; + void setSoftProofing(bool softProof, bool gamutCheck); + void getSoftProofing(bool &softProof, bool &gamutCheck); + ======= + */ bool getAutoWB(double& temp, double& green, double equal, double tempBias); void getCamWB(double& temp, double& green); void getSpotWB(int x, int y, int rectSize, double& temp, double& green); void getAutoCrop(double ratio, int &x, int &y, int &w, int &h); - + bool getHighQualComputed(); + void setHighQualComputed(); void setMonitorProfile(const Glib::ustring& profile, RenderingIntent intent); void getMonitorProfile(Glib::ustring& profile, RenderingIntent& intent) const; void setSoftProofing(bool softProof, bool gamutCheck); void getSoftProofing(bool &softProof, bool &gamutCheck); -======= -*/ - bool getAutoWB (double& temp, double& green, double equal, double tempBias); - void getCamWB (double& temp, double& green); - void getSpotWB (int x, int y, int rectSize, double& temp, double& green); - void getAutoCrop (double ratio, int &x, int &y, int &w, int &h); - bool getHighQualComputed(); - void setHighQualComputed(); - void setMonitorProfile (const Glib::ustring& profile, RenderingIntent intent); - void getMonitorProfile (Glib::ustring& profile, RenderingIntent& intent) const; - void setSoftProofing (bool softProof, bool gamutCheck); - void getSoftProofing (bool &softProof, bool &gamutCheck); //>>>>>>> dev bool updateTryLock() diff --git a/rtengine/iplocallab.cc b/rtengine/iplocallab.cc index 8b86fba9d..3cffbafa4 100644 --- a/rtengine/iplocallab.cc +++ b/rtengine/iplocallab.cc @@ -1741,14 +1741,13 @@ void ImProcFunctions::exlabLocal(const local_params& lp, int bfh, int bfw, LabIm for (int i = istart, ti = 0; i < tH; i++, ti++) { for (int j = jstart, tj = 0; j < tW; j++, tj++) { - - //brightness/contrast not used + Ltemp[ti * TSE + tj] = tonecurve[Ltemp[ti * TSE + tj] ]; } } - +/* if (lp.chro != 0) { for (int i = istart, ti = 0; i < tH; i++, ti++) { for (int j = jstart, tj = 0; j < tW; j++, tj++) { @@ -1762,7 +1761,7 @@ void ImProcFunctions::exlabLocal(const local_params& lp, int bfh, int bfw, LabIm } } } - +*/ bool vasy = true; @@ -4845,7 +4844,7 @@ void ImProcFunctions::InverseContrast_Local(float ave, struct local_contra & lco static void calclight(float lum, float koef, float & lumnew, bool inv, LUTf & lightCurveloc) //replace L-curve that does not work in local or bad { - +/* float blac = 0.3f; if (inv == false) { @@ -4855,7 +4854,7 @@ static void calclight(float lum, float koef, float & lumnew, bool inv, LUTf & l blac = -0.069f * koef - 5.91f; } } - +*/ if (koef >= 0.f) { // lumnew = lum + 0.2f * (33000.f - lum) * koef / 100.f; lumnew = lightCurveloc[lum]; diff --git a/rtengine/simpleprocess.cc b/rtengine/simpleprocess.cc index 6cc3c93c2..aecafa4c9 100644 --- a/rtengine/simpleprocess.cc +++ b/rtengine/simpleprocess.cc @@ -2157,10 +2157,10 @@ private: double hlcompr = params.locallab.hlcompr; double hlcomprthresh = params.locallab.hlcomprthresh; double shcompr = params.locallab.shcompr; - double br = params.locallab.lightness; + double br = params.locallab.lightness; - CurveFactory::complexCurvelocal(ecomp, black / 65535., hlcompr, hlcomprthresh, shcompr, br, - hltonecurveloc, shtonecurveloc, tonecurveloc, lightCurveloc, + CurveFactory::complexCurvelocal(ecomp, black / 65535., hlcompr, hlcomprthresh, shcompr, br, + hltonecurveloc, shtonecurveloc, tonecurveloc, lightCurveloc, 1);