[gegl] operations/workshop/shadows-highlights-correction: Simplify code
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl] operations/workshop/shadows-highlights-correction: Simplify code
- Date: Mon, 11 Dec 2017 18:22:13 +0000 (UTC)
commit 315a19696940cd9ace9f7914ec642eada208d8bc
Author: Debarshi Ray <debarshir gnome org>
Date: Mon Dec 11 19:06:28 2017 +0100
operations/workshop/shadows-highlights-correction: Simplify code
It is hard to follow a maze of nested fminf and fmaxf calls. CLAMP is a
more readable way to achieve the same. However, the values are already
bounded by the limits imposed by the operation's properties. So,
calling a function to re-impose the limit needlessly complicates
things - wasteful at run-time and harder to read.
It is better to use G_LIKELY annotated assertions instead.
.../workshop/shadows-highlights-correction.c | 35 +++++++++++++++----
1 files changed, 27 insertions(+), 8 deletions(-)
---
diff --git a/operations/workshop/shadows-highlights-correction.c
b/operations/workshop/shadows-highlights-correction.c
index ffac603..9bcf96a 100644
--- a/operations/workshop/shadows-highlights-correction.c
+++ b/operations/workshop/shadows-highlights-correction.c
@@ -82,16 +82,18 @@ process (GeglOperation *operation,
gfloat *dst = out_buf;
gfloat *aux = aux_buf;
- gfloat shadows = 2.f * fminf (fmaxf (-1.0, ((gfloat) o->shadows / 100.f)), 1.f);
- gfloat highlights = 2.f * fminf (fmaxf (-1.0, ((gfloat) o->highlights / 100.f)), 1.f);
- gfloat whitepoint = fmaxf (1.f - (gfloat) o->whitepoint / 100.f, 0.01f);
- gfloat compress = fminf (fmaxf (0, ((gfloat) o->compress / 100.f)), 0.99f);
+ gfloat shadows;
+ gfloat shadows_100 = (gfloat) o->shadows / 100.0f;
+ gfloat highlights;
+ gfloat highlights_100 = (gfloat) o->highlights / 100.0f;
+ gfloat whitepoint = 1.0f - (gfloat) o->whitepoint / 100.0f;
+ gfloat compress;
- gfloat shadows_ccorrect = (fminf (fmaxf (0.0f, ((gfloat) o->shadows_ccorrect / 100.f)), 1.f) - 0.5f)
- * SIGN(shadows) + 0.5f;
+ gfloat shadows_ccorrect;
+ gfloat shadows_ccorrect_100 = (gfloat) o->shadows_ccorrect / 100.0f;
- gfloat highlights_ccorrect = (fminf (fmaxf (0.0f, ((gfloat) o->highlights_ccorrect / 100.f)), 1.f) - 0.5f)
- * SIGN(-highlights) + 0.5f;
+ gfloat highlights_ccorrect;
+ gfloat highlights_ccorrect_100 = (gfloat) o->highlights_ccorrect / 100.0f;
gfloat max[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
gfloat min[4] = { 0.0f, -1.0f, -1.0f, 0.0f };
@@ -100,6 +102,23 @@ process (GeglOperation *operation,
gfloat doublemax = lmax * 2.0f;
gfloat low_approximation = 0.01f;
+ compress = fminf ((gfloat) o->compress / 100.0f, 0.99f);
+ g_return_val_if_fail (compress >= 0.0f, FALSE);
+
+ g_return_val_if_fail (-1.0f <= highlights_100 && highlights_100 <= 1.0f, FALSE);
+ highlights = 2.0f * highlights_100;
+
+ g_return_val_if_fail (0.0f <= highlights_ccorrect_100 && highlights_ccorrect_100 <= 1.0f, FALSE);
+ highlights_ccorrect = (highlights_ccorrect_100 - 0.5f) * SIGN (-highlights) + 0.5f;
+
+ g_return_val_if_fail (-1.0f <= shadows_100 && shadows_100 <= 1.0f, FALSE);
+ shadows = 2.0f * shadows_100;
+
+ g_return_val_if_fail (0.0f <= shadows_ccorrect_100 && shadows_ccorrect_100 <= 1.0f, FALSE);
+ shadows_ccorrect = (shadows_ccorrect_100 - 0.5f) * SIGN (shadows) + 0.5f;
+
+ g_return_val_if_fail (whitepoint >= 0.01f, FALSE);
+
if (!aux)
{
memcpy (out_buf, in_buf, sizeof (gfloat) * 4 * n_pixels);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]