From 09b319fe0b15a57263a4c5c1f81332add5072494 Mon Sep 17 00:00:00 2001 From: heckflosse Date: Sat, 22 Oct 2016 00:21:01 +0200 Subject: [PATCH 1/4] Speedup for Vignette and Graduated Filter --- rtengine/iptransform.cc | 141 ++++++++++++++++++++++++++++------------ 1 file changed, 101 insertions(+), 40 deletions(-) diff --git a/rtengine/iptransform.cc b/rtengine/iptransform.cc index d22fe08f2..92cbcbccb 100644 --- a/rtengine/iptransform.cc +++ b/rtengine/iptransform.cc @@ -24,8 +24,68 @@ #include "mytime.h" #include "rt_math.h" #include "sleef.c" +#define BENCHMARK +#include "StopWatch.h" using namespace std; +namespace +{ + +float pow3(float x) +{ + return x * x * x; +} + +float pow4(float x) +{ + return (x * x) * (x * x); +} + +float pown(float x, int n) +{ + + switch (n) { + case 0: + return 1; + + case 2: + return x * x; + + case 4: + return pow4(x); + + case 6: + return (x * x) * pow4(x); + + case 8: + return pow4(x) * pow4(x); + + default: + return pow_F(x, n); + } +} + +float normn(float a, float b, int n) +{ + switch (n) { + case 2: + return sqrtf(a * a + b * b); + + case 4: + return sqrtf(sqrtf(pow4(a) + pow4(b))); + + case 6: + return sqrtf(xcbrtf(pow3(a) * pow3(a) + pow3(b) * pow3(b))); + + case 8: + return sqrtf(sqrtf(sqrtf(pow4(a) * pow4(a) + pow4(b) * pow4(b)))); + + default: + return pow_F(pown(a, n) + pown(b, n), 1.f / n); + } +} +} + namespace rtengine { #undef CLIPTOC @@ -382,13 +442,15 @@ static float calcGradientFactor(const struct grad_params& gp, int x, int y) float val = ((float)(gy - gp.top_edge_0) * gp.ys_inv); if (gp.bright_top) { - val = 1.0 - val; + val = 1.f - val; } - if (gp.scale < 1.0) { - val = pow(xsinf(val * M_PI / 2), 3); + val *= (M_PI / 2); + + if (gp.scale < 1.f) { + val = pow3(xsinf(val)); } else { - val = 1.0 - pow(xcosf(val * M_PI / 2), 3); + val = 1.f - pow3(xcosf(val)); } return gp.scale + val * (1.0 - gp.scale); @@ -396,7 +458,7 @@ static float calcGradientFactor(const struct grad_params& gp, int x, int y) } else { int gy = gp.transpose ? x : y; int gx = gp.transpose ? gp.h - y - 1 : x; - float top_edge = gp.yc - gp.ys / 2.0 - gp.ta * (gx - gp.xc); + float top_edge = gp.top_edge_0 - gp.ta * (gx - gp.xc); if (gy < top_edge) { return gp.topmul; @@ -405,14 +467,14 @@ static float calcGradientFactor(const struct grad_params& gp, int x, int y) } else { float val = ((float)(gy - top_edge) * gp.ys_inv); - if (gp.bright_top) { - val = 1.0 - val; - } + val = gp.bright_top ? 1.f - val : val; - if (gp.scale < 1.0) { - val = pow(xsinf(val * M_PI / 2), 3); + val *= (M_PI / 2); + + if (gp.scale < 1.f) { + val = pow3(xsinf(val)); } else { - val = 1.0 - pow(xcosf(val * M_PI / 2), 3); + val = 1.f - pow3(xcosf(val)); } return gp.scale + val * (1.0 - gp.scale); @@ -459,7 +521,7 @@ static void calcPCVignetteParams(int fW, int fH, int oW, int oH, const PCVignett pcv.sepmix = 0; pcv.oe_a = sqrt(2.0) * long_side * 0.5; pcv.oe_b = pcv.oe_a * short_side / long_side; - pcv.ie_mul = 1.0 / sqrt(2.0); + pcv.ie_mul = (1.0 / sqrt(2.0)) * (1.0 - pcv.feather); pcv.is_super_ellipse_mode = false; pcv.is_portrait = (pcv.w < pcv.h); @@ -471,10 +533,10 @@ static void calcPCVignetteParams(int fW, int fH, int oW, int oH, const PCVignett pcv.sepmix = (sepf - pcv.sep) * 0.5; // 0.0 to 1.0 pcv.oe1_a = powf(2.0, 1.0 / pcv.sep) * long_side * 0.5; pcv.oe1_b = pcv.oe1_a * short_side / long_side; - pcv.ie1_mul = 1.0 / powf(2.0, 1.0 / pcv.sep); + pcv.ie1_mul = (1.0 / powf(2.0, 1.0 / pcv.sep)) * (1.0 - pcv.feather); pcv.oe2_a = powf(2.0, 1.0 / (pcv.sep + 2)) * long_side * 0.5; pcv.oe2_b = pcv.oe2_a * short_side / long_side; - pcv.ie2_mul = 1.0 / powf(2.0, 1.0 / (pcv.sep + 2)); + pcv.ie2_mul = (1.0 / powf(2.0, 1.0 / (pcv.sep + 2))) * (1.0 - pcv.feather); } if (roundness > 0.5) { @@ -496,7 +558,7 @@ static void calcPCVignetteParams(int fW, int fH, int oW, int oH, const PCVignett static float calcPCVignetteFactor(const struct pcv_params& pcv, int x, int y) { - float fo = 1.0; + float fo = 1.f; if (x < pcv.x1 || x > pcv.x2 || y < pcv.y1 || y > pcv.y2) { /* @@ -517,22 +579,18 @@ static float calcPCVignetteFactor(const struct pcv_params& pcv, int x, int y) fo = sqrtf(dist_x * dist_x + dist_y * dist_y) * pcv.fadeout_mul; - if (fo >= 1.0) { - return 1.0; + if (fo >= 1.f) { + return 1.f; } } - float val, a, b; + float a = fabs((x - pcv.x1) - pcv.w * 0.5f); + float b = fabs((y - pcv.y1) - pcv.h * 0.5f); - if (pcv.is_portrait) { - a = fabs((y - pcv.y1) - pcv.h * 0.5); - b = fabs((x - pcv.x1) - pcv.w * 0.5); - } else { - a = fabs((x - pcv.x1) - pcv.w * 0.5); - b = fabs((y - pcv.y1) - pcv.h * 0.5); + if(pcv.is_portrait) { + std::swap(a, b); } - float angle = xatan2f(b, a); float dist = sqrtf(a * a + b * b); float dist_oe, dist_ie; float2 sincosval; @@ -546,37 +604,39 @@ static float calcPCVignetteFactor(const struct pcv_params& pcv, int x, int y) } if (pcv.is_super_ellipse_mode) { - float dist_oe1 = pcv.oe1_a * pcv.oe1_b / pow_F(pow(pcv.oe1_b * sincosval.y, pcv.sep) + pow(pcv.oe1_a * sincosval.x, pcv.sep), 1.0 / pcv.sep); - float dist_oe2 = pcv.oe2_a * pcv.oe2_b / pow_F(pow(pcv.oe2_b * sincosval.y, pcv.sep + 2) + pow(pcv.oe2_a * sincosval.x, pcv.sep + 2), 1.0 / (pcv.sep + 2)); - float dist_ie1 = pcv.ie1_mul * dist_oe1 * (1.0 - pcv.feather); - float dist_ie2 = pcv.ie2_mul * dist_oe2 * (1.0 - pcv.feather); - dist_oe = dist_oe1 * (1.0 - pcv.sepmix) + dist_oe2 * pcv.sepmix; - dist_ie = dist_ie1 * (1.0 - pcv.sepmix) + dist_ie2 * pcv.sepmix; + float dist_oe1 = pcv.oe1_a * pcv.oe1_b / normn(pcv.oe1_b * sincosval.y, pcv.oe1_a * sincosval.x, pcv.sep); + float dist_oe2 = pcv.oe2_a * pcv.oe2_b / normn(pcv.oe2_b * sincosval.y, pcv.oe2_a * sincosval.x, pcv.sep + 2); + float dist_ie1 = pcv.ie1_mul * dist_oe1; + float dist_ie2 = pcv.ie2_mul * dist_oe2; + dist_oe = dist_oe1 * (1.f - pcv.sepmix) + dist_oe2 * pcv.sepmix; + dist_ie = dist_ie1 * (1.f - pcv.sepmix) + dist_ie2 * pcv.sepmix; } else { dist_oe = pcv.oe_a * pcv.oe_b / sqrtf(SQR(pcv.oe_b * sincosval.y) + SQR(pcv.oe_a * sincosval.x)); - dist_ie = pcv.ie_mul * dist_oe * (1.0 - pcv.feather); + dist_ie = pcv.ie_mul * dist_oe; } if (dist <= dist_ie) { - return 1.0; + return 1.f; } + float val; + if (dist >= dist_oe) { val = pcv.scale; } else { - val = (dist - dist_ie) / (dist_oe - dist_ie); + val = (M_PI / 2) * (dist - dist_ie) / (dist_oe - dist_ie); - if (pcv.scale < 1.0) { - val = pow(xcosf(val * M_PI / 2), 4); + if (pcv.scale < 1.f) { + val = pow4(xcosf(val)); } else { - val = 1 - pow(xsinf(val * M_PI / 2), 4); + val = 1 - pow4(xsinf(val)); } - val = pcv.scale + val * (1.0 - pcv.scale); + val = pcv.scale + val * (1.f - pcv.scale); } - if (fo < 1.0) { - val = 1.0 * fo + val * (1.0 - fo); + if (fo < 1.f) { + val = fo + val * (1.f - fo); } return val; @@ -584,6 +644,7 @@ static float calcPCVignetteFactor(const struct pcv_params& pcv, int x, int y) void ImProcFunctions::transformLuminanceOnly (Imagefloat* original, Imagefloat* transformed, int cx, int cy, int oW, int oH, int fW, int fH) { + BENCHFUN const bool applyVignetting = needsVignetting(); const bool applyGradient = needsGradient(); const bool applyPCVignetting = needsPCVignetting(); From 2c7325b2fd470583a1a664dcb9033b2ab3fab0ba Mon Sep 17 00:00:00 2001 From: heckflosse Date: Sat, 22 Oct 2016 18:11:14 +0200 Subject: [PATCH 2/4] Removed StopWatch --- rtengine/iptransform.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/rtengine/iptransform.cc b/rtengine/iptransform.cc index 92cbcbccb..594753526 100644 --- a/rtengine/iptransform.cc +++ b/rtengine/iptransform.cc @@ -24,8 +24,7 @@ #include "mytime.h" #include "rt_math.h" #include "sleef.c" -#define BENCHMARK -#include "StopWatch.h" + using namespace std; namespace @@ -644,7 +643,7 @@ static float calcPCVignetteFactor(const struct pcv_params& pcv, int x, int y) void ImProcFunctions::transformLuminanceOnly (Imagefloat* original, Imagefloat* transformed, int cx, int cy, int oW, int oH, int fW, int fH) { - BENCHFUN + const bool applyVignetting = needsVignetting(); const bool applyGradient = needsGradient(); const bool applyPCVignetting = needsPCVignetting(); From db2c01af023a3cfc7985442149b98897e63f39be Mon Sep 17 00:00:00 2001 From: heckflosse Date: Tue, 13 Dec 2016 15:13:03 +0100 Subject: [PATCH 3/4] Further small speedup for vignette and gradient --- rtengine/iptransform.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rtengine/iptransform.cc b/rtengine/iptransform.cc index 594753526..fce599d8a 100644 --- a/rtengine/iptransform.cc +++ b/rtengine/iptransform.cc @@ -444,7 +444,7 @@ static float calcGradientFactor(const struct grad_params& gp, int x, int y) val = 1.f - val; } - val *= (M_PI / 2); + val *= M_PIf_2; if (gp.scale < 1.f) { val = pow3(xsinf(val)); @@ -468,7 +468,7 @@ static float calcGradientFactor(const struct grad_params& gp, int x, int y) val = gp.bright_top ? 1.f - val : val; - val *= (M_PI / 2); + val *= M_PIf_2; if (gp.scale < 1.f) { val = pow3(xsinf(val)); @@ -590,7 +590,7 @@ static float calcPCVignetteFactor(const struct pcv_params& pcv, int x, int y) std::swap(a, b); } - float dist = sqrtf(a * a + b * b); + float dist = normn(a, b, 2); float dist_oe, dist_ie; float2 sincosval; @@ -623,7 +623,7 @@ static float calcPCVignetteFactor(const struct pcv_params& pcv, int x, int y) if (dist >= dist_oe) { val = pcv.scale; } else { - val = (M_PI / 2) * (dist - dist_ie) / (dist_oe - dist_ie); + val = M_PIf_2 * (dist - dist_ie) / (dist_oe - dist_ie); if (pcv.scale < 1.f) { val = pow4(xcosf(val)); From aead4c5488977bcd6eda444554d463f53dbabc0a Mon Sep 17 00:00:00 2001 From: Morgan Hardwood Date: Mon, 19 Dec 2016 17:00:04 +0100 Subject: [PATCH 4/4] Removed TP_DIRPYRDENOISE_LUMAFR_TOOLTIP again. This was removed in master in commit 0ba62 but somehow slipped through into gtk3. --- rtgui/dirpyrdenoise.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/rtgui/dirpyrdenoise.cc b/rtgui/dirpyrdenoise.cc index 6f4a2cc97..1871d4ab0 100644 --- a/rtgui/dirpyrdenoise.cc +++ b/rtgui/dirpyrdenoise.cc @@ -39,7 +39,6 @@ DirPyrDenoise::DirPyrDenoise () : FoldableToolPanel(this, "dirpyrdenoise", M("TP std::vector defaultCurve; Gtk::Frame* lumaFrame = Gtk::manage (new Gtk::Frame (M("TP_DIRPYRDENOISE_LUMAFR")) ); - lumaFrame->set_tooltip_text(M("TP_DIRPYRDENOISE_LUMAFR_TOOLTIP")); lumaFrame->set_label_align(0.025, 0.5); Gtk::VBox * lumaVBox = Gtk::manage ( new Gtk::VBox());