diff --git a/rtengine/curves.cc b/rtengine/curves.cc index 62fa4bc23..4d144fd72 100644 --- a/rtengine/curves.cc +++ b/rtengine/curves.cc @@ -37,8 +37,6 @@ #include "ciecam02.h" #include "color.h" #include "iccstore.h" -#undef CLIPD -#define CLIPD(a) ((a)>0.0f?((a)<1.0f?(a):1.0f):0.0f) using namespace std; @@ -578,7 +576,7 @@ void CurveFactory::localLCurve(double br, double contr, /*const std::vectorgetVal(val); // store result in a temporary array - dcurve[i] = CLIPD(val); + dcurve[i] = val; } delete brightcurve; @@ -898,33 +896,37 @@ void CurveFactory::complexCurve(double ecomp, double black, double hlcompr, doub //%%%%%%%%%%%%%%%%%%%%%%%%%% // 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 / 65535.f; - float val2 = simplebasecurve(val, black, 0.015 * shcompr); - shCurve[0] = CLIPD(val2) / val; + if (black == 0.0) { + shCurve.makeConstant(1.f); + } else { + const float val = 1.f / 65535.f; + shCurve[0] = simplebasecurve(val, black, 0.015 * shcompr) / val; + } // gamma correction - val = Color::gammatab_srgb[0] / 65535.f; + float val = Color::gammatab_srgb1[0]; // apply brightness curve if (brightcurve) { - val = brightcurve->getVal(val); // TODO: getVal(double) is very slow! Optimize with a LUTf + val = brightcurve->getVal(val); // TODO: getVal(double) is very slow! Optimize with a LUTf } // store result in a temporary array - dcurve[0] = CLIPD(val); + dcurve[0] = LIM01(val); for (int i = 1; i < 0x10000; i++) { - float val = i / 65535.f; - float val2 = simplebasecurve(val, black, 0.015 * shcompr); - shCurve[i] = val2 / val; + if (black != 0.0) { + const float val = i / 65535.f; + shCurve[i] = simplebasecurve(val, black, 0.015 * shcompr) / val; + } // gamma correction - val = Color::gammatab_srgb[i] / 65535.f; + float val = Color::gammatab_srgb1[i]; // apply brightness curve if (brightcurve) { - val = CLIPD(brightcurve->getVal(val)); // TODO: getVal(double) is very slow! Optimize with a LUTf + val = LIM01(brightcurve->getVal (val)); // TODO: getVal(double) is very slow! Optimize with a LUTf } // store result in a temporary array @@ -1110,7 +1112,7 @@ void CurveFactory::complexCurvelocal(double ecomp, double black, double hlcompr, val = brightcurve.getVal(val); // store result in a temporary array - lightCurveloc[i] = CLIPD(val); + lightCurveloc[i] = val; } @@ -1249,21 +1251,31 @@ void CurveFactory::complexCurvelocal(double ecomp, double black, double hlcompr, //%%%%%%%%%%%%%%%%%%%%%%%%%% // 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; + 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. + if (black == 0.0) { + shCurve.makeConstant(1.f); + } else { + const float val = 1.f / (maxran - 1.f); + shCurve[0] = simplebasecurve(val, black, 0.015 * shcompr) / val; + } + + + // gamma correction - val = Color::gammatab_bt709[0] / maxran; + float val = Color::gammatab_bt709[0] / maxran; // store result in a temporary array - dcurve[0] = CLIPD(val); + dcurve[0] = LIM01(val); 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; +// float val2 = simplebasecurve(val, black, 0.015 * shcompr); +// shCurve[i] = val2 / val; + if (black != 0.0) { + const float val = i / 65535.f; + shCurve[i] = simplebasecurve(val, black, 0.015 * shcompr) / val; + } // gamma correction val = Color::gammatab_bt709[i] / maxran; @@ -1360,7 +1372,7 @@ void CurveFactory::complexLCurve(double br, double contr, const std::vector(val); } } else { diff --git a/rtengine/improcfun.cc b/rtengine/improcfun.cc index f43567024..440c6c5ac 100644 --- a/rtengine/improcfun.cc +++ b/rtengine/improcfun.cc @@ -77,7 +77,7 @@ void shadowToneCurve(const LUTf &shtonecurve, float *rtemp, float *gtemp, float //shadow tone curve vfloat Yv = cr * rv + cg * gv + cb * bv; - vfloat tonefactorv = shtonecurve(Yv); + vfloat tonefactorv = shtonecurve[Yv]; STVF(rtemp[ti * tileSize + tj], rv * tonefactorv); STVF(gtemp[ti * tileSize + tj], gv * tonefactorv); STVF(btemp[ti * tileSize + tj], bv * tonefactorv); @@ -2500,7 +2500,9 @@ void ImProcFunctions::rgbProc(Imagefloat* working, LabImage* lab, PipetteBuffer } highlightToneCurve(hltonecurve, rtemp, gtemp, btemp, istart, tH, jstart, tW, TS, exp_scale, comp, hlrange); - shadowToneCurve(shtonecurve, rtemp, gtemp, btemp, istart, tH, jstart, tW, TS); + if (params->toneCurve.black != 0.0) { + shadowToneCurve(shtonecurve, rtemp, gtemp, btemp, istart, tH, jstart, tW, TS); + } if (dcpProf) { dcpProf->step2ApplyTile(rtemp, gtemp, btemp, tW - jstart, tH - istart, TS, asIn);