From 0118793c0d2608ee7f5888812408ae7351a1c535 Mon Sep 17 00:00:00 2001 From: Emil Martinec Date: Mon, 8 Nov 2010 00:05:56 -0600 Subject: [PATCH] Allow black slider to take negative values, allows shadow lifting. --- rtengine/curves.h | 38 +++++++++++++++++++++++++++++--------- rtengine/improcfun.cc | 6 +++--- rtgui/tonecurve.cc | 2 +- 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/rtengine/curves.h b/rtengine/curves.h index 79aafa319..37f225f24 100644 --- a/rtengine/curves.h +++ b/rtengine/curves.h @@ -27,6 +27,8 @@ #define CURVES_MIN_POLY_POINTS 1000 +#define SQR(x) ((x)*(x)) + namespace rtengine { class CurveFactory { @@ -82,17 +84,35 @@ class CurveFactory { if (xx1 || sr<0.001) + return 1-(1-x)*m; + else + return y1+m*(x-x1)-(1-m)*SQR(SQR(1-x/x1)); + } // tone curve base. a: slope (from exp.comp.), b: black, D: max. x value (can be>1), hr,sr: highlight,shadow recovery static inline double basecurve (double x, double a, double b, double D, double hr, double sr) { - double m = a>1 ? b+0.25*(1-b)/a : b+(1-b)/4; - double y = a>1 ? 0.25 : 0.25*a; - double slope = a/(1-b); - if (x<=m) - return b==0 ? x*a : clower (x/m, slope*m/y, sr) * y; - else if (a>1) - return y+(1.0-y)*cupper2((x-m)/(1-m), slope*(1-m)/(1.0-y), hr); - else - return y+(x-m)*slope; + if (b<0) { + double m = 0.5; + double slope = 1+b; + double y = -b+m*slope; + if (x>m) + return y + (x - m)*slope; + else + return y*clower2(x/m, slope*m/y, 2.0-sr); + } else { + double m = a>1 ? b+0.25*(1-b)/a : b+(1-b)/4; + double y = a>1 ? 0.25 : 0.25*a; + double slope = a/(1-b); + if (x<=m) + return b==0 ? x*a : clower (x/m, slope*m/y, sr) * y; + else if (a>1) + return y+(1.0-y)*cupper2((x-m)/(1-m), slope*(1-m)/(1.0-y), hr); + else + return y+(x-m)*slope; + } } // brightness curve at point x, only positive amount it supported static inline double brightnessbase (double x, double amount) { diff --git a/rtengine/improcfun.cc b/rtengine/improcfun.cc index 4b12c7548..ef040aa3d 100644 --- a/rtengine/improcfun.cc +++ b/rtengine/improcfun.cc @@ -346,9 +346,9 @@ void ImProcFunctions::rgbProc (Image16* working, LabImage* lab, int* hltonecurve b *= tonefactor; //brightness/contrast and user tone curve - r = tonecurve[r]; - g = tonecurve[g]; - b = tonecurve[b]; + r = tonecurve[CLIP(r)]; + g = tonecurve[CLIP(g)]; + b = tonecurve[CLIP(b)]; if (abs(sat)>0.5) { float h, s, v; diff --git a/rtgui/tonecurve.cc b/rtgui/tonecurve.cc index 5fae69720..67bb46329 100644 --- a/rtgui/tonecurve.cc +++ b/rtgui/tonecurve.cc @@ -55,7 +55,7 @@ ToneCurve::ToneCurve () : ToolPanel(), expAdd(false), blackAdd(false), brAdd(fal pack_start (*hlcompr); //----------- Black Level ---------------------------------- - black = Gtk::manage (new Adjuster (M("TP_EXPOSURE_BLACKLEVEL"), 0, 32768, 1, 0)); + black = Gtk::manage (new Adjuster (M("TP_EXPOSURE_BLACKLEVEL"), -16384, 32768, 1, 0)); pack_start (*black); shcompr = Gtk::manage (new Adjuster (M("TP_EXPOSURE_COMPRSHADOWS"), 0, 100, 1, 50)); pack_start (*shcompr);