diff --git a/rtengine/ipsharpen.cc b/rtengine/ipsharpen.cc index 37a1a0010..e328edd1b 100644 --- a/rtengine/ipsharpen.cc +++ b/rtengine/ipsharpen.cc @@ -16,7 +16,7 @@ * You should have received a copy of the GNU General Public License * along with RawTherapee. If not, see . */ -#include "rtengine.h" + #include "improcfun.h" #include "gauss.h" #include "bilateral2.h" @@ -24,7 +24,7 @@ #include "rt_math.h" #include "sleef.c" #include "opthelper.h" -#define BENCHMARK +//#define BENCHMARK #include "StopWatch.h" using namespace std; @@ -322,7 +322,7 @@ void ImProcFunctions::sharpening (LabImage* lab, const SharpeningParams &sharpen deconvsharpening (lab->L, b2, lab->W, lab->H, sharpenParam); return; } - +BENCHFUN // Rest is UNSHARP MASK float** b3 = nullptr; @@ -649,24 +649,15 @@ void ImProcFunctions::MLsharpen (LabImage* lab) //! \param luminance : Luminance channel of image void ImProcFunctions::MLmicrocontrast(float** luminance, int W, int H) { - if (!params->sharpenMicro.enabled || params->sharpenMicro.contrast == 100) { + if (!params->sharpenMicro.enabled || params->sharpenMicro.contrast == 100 || params->sharpenMicro.amount < 1.0) { return; } BENCHFUN const int k = params->sharpenMicro.matrix ? 1 : 2; // k=2 matrix 5x5 k=1 matrix 3x3 const int width = W, height = H; - const float uniform = params->sharpenMicro.uniformity; //between 0 to 100 - const int unif = (int)(uniform / 10.0f); //put unif between 0 to 10 - float amount = params->sharpenMicro.amount / 1500.0f; //amount 2000.0 quasi no artifacts ==> 1500 = maximum, after artifacts - - if (amount < 0.000001f) { - return; - } - - if (k == 1) { - amount *= 2.7f; //25/9 if 3x3 - } + const int unif = params->sharpenMicro.uniformity / 10.0f; //put unif between 0 to 10 + const float amount = (k == 1 ? 2.7f : 1.f) * params->sharpenMicro.amount / 1500.0f; //amount 2000.0 quasi no artifacts ==> 1500 = maximum, after artifacts, 25/9 if 3x3 if (settings->verbose) { printf ("Micro-contrast amount %f\n", amount); @@ -694,7 +685,6 @@ BENCHFUN const float Cont4[11] = {0.8f, 0.85f, 0.9f, 0.95f, 1.0f, 1.05f, 1.10f, 1.150f, 1.2f, 1.25f, 1.40f}; const float Cont5[11] = {1.0f, 1.1f, 1.2f, 1.25f, 1.3f, 1.4f, 1.45f, 1.50f, 1.6f, 1.65f, 1.80f}; - const float s = amount; constexpr float sqrt2 = sqrt(2.0); constexpr float sqrt1d25 = sqrt(1.25); float *LM = new float[width * height]; //allocation for Luminance @@ -734,9 +724,9 @@ BENCHFUN contrast = std::min(contrast, 1.f); //matrix 5x5 - float temp = v + 4.f *( v * (s + sqrt2 * s)); //begin 3x3 - float temp1 = sqrt2 * s *(LM[offset - width - 1] + LM[offset - width + 1] + LM[offset + width - 1] + LM[offset + width + 1]); - temp1 += s * (LM[offset - width] + LM[offset - 1] + LM[offset + 1] + LM[offset + width]); + float temp = v + 4.f *( v * (amount + sqrt2 * amount)); //begin 3x3 + float temp1 = sqrt2 * amount *(LM[offset - width - 1] + LM[offset - width + 1] + LM[offset + width - 1] + LM[offset + width + 1]); + temp1 += amount * (LM[offset - width] + LM[offset - 1] + LM[offset + 1] + LM[offset + width]); temp -= temp1; @@ -749,7 +739,7 @@ BENCHFUN temp2 -= sqrt2 * (LM[offset + 2 * width - 2] + LM[offset + 2 * width + 2] + LM[offset - 2 * width - 2] + LM[offset - 2 * width + 2]); temp2 += 18.601126159f * v ; // 18.601126159 = 4 + 4 * sqrt(2) + 8 * sqrt(1.25) - temp2 *= 2.f * s; + temp2 *= 2.f * amount; temp += temp2; } diff --git a/rtengine/procparams.cc b/rtengine/procparams.cc index ff783369b..dfcb91ebb 100644 --- a/rtengine/procparams.cc +++ b/rtengine/procparams.cc @@ -1007,7 +1007,7 @@ void ColorToningParams::getCurves(ColorGradientCurve& colorCurveLUT, OpacityCurv SharpeningParams::SharpeningParams() : enabled(false), - contrast(0.0), + contrast(20.0), radius(0.5), amount(200), threshold(20, 80, 2000, 1200, false), @@ -1017,10 +1017,10 @@ SharpeningParams::SharpeningParams() : halocontrol(false), halocontrol_amount(85), method("usm"), - deconvamount(75), + deconvamount(100), deconvradius(0.75), deconviter(30), - deconvdamping(20) + deconvdamping(0) { } @@ -3675,7 +3675,14 @@ int ProcParams::load(const Glib::ustring& fname, ParamsEdited* pedited) if (keyFile.has_group ("Sharpening")) { assignFromKeyfile(keyFile, "Sharpening", "Enabled", pedited, sharpening.enabled, pedited->sharpening.enabled); - assignFromKeyfile(keyFile, "Sharpening", "Contrast", pedited, sharpening.contrast, pedited->sharpening.contrast); + if (ppVersion >= 334) { + assignFromKeyfile(keyFile, "Sharpening", "Contrast", pedited, sharpening.contrast, pedited->sharpening.contrast); + } else { + sharpening.contrast = 0; + if (pedited) { + pedited->sharpening.contrast = true; + } + } assignFromKeyfile(keyFile, "Sharpening", "Radius", pedited, sharpening.radius, pedited->sharpening.radius); assignFromKeyfile(keyFile, "Sharpening", "Amount", pedited, sharpening.amount, pedited->sharpening.amount);