[gegl] shadows-highlights-correction: Simplify code
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl] shadows-highlights-correction: Simplify code
- Date: Sun, 24 Dec 2017 12:59:10 +0000 (UTC)
commit 9384338e84d741248541610a6b178dc250a357bb
Author: Debarshi Ray <debarshir gnome org>
Date: Sun Dec 24 13:37:55 2017 +0100
shadows-highlights-correction: Simplify code
Since the code already scales the colour channels to [0.0, 1.0], it is
quite obvious what the maximum, half-maximum and double-maximum values
are. Moreover, variables like lmax aren't used consistently either.
eg., the code had both "1.0f - la" and "lmax - la". So, it's not clear
whether they were making it easy to understand overall algorithm, which
is otherwise undocumented.
Note that Darktable was using some of these variables to clamp the
output within [0.0, 1.0], which isn't relevant because the GEGL
operation always generates unbounded output.
opencl/shadows-highlights-correction.cl | 8 ++------
.../workshop/shadows-highlights-correction.c | 15 ++++-----------
2 files changed, 6 insertions(+), 17 deletions(-)
---
diff --git a/opencl/shadows-highlights-correction.cl b/opencl/shadows-highlights-correction.cl
index a27f21f..9df9a7b 100644
--- a/opencl/shadows-highlights-correction.cl
+++ b/opencl/shadows-highlights-correction.cl
@@ -8,10 +8,6 @@ float3 overlay(const float3 in_a,
/* a contains underlying image; b contains mask */
const float3 scale = (float3)(100.0f, 128.0f, 128.0f);
- const float lmax = 1.0f;
- const float halfmax = 0.5f;
- const float doublemax = 2.0f;
-
float3 a = in_a / scale;
float3 b = in_b / scale;
@@ -21,7 +17,7 @@ float3 overlay(const float3 in_a,
while(opacity2 > 0.0f)
{
float la = a.x;
- float lb = (b.x - halfmax) * sign(opacity)*sign(lmax - la) + halfmax;
+ float lb = (b.x - 0.5f) * sign(opacity)*sign(1.0f - la) + 0.5f;
float lref = copysign(fabs(la) > low_approximation ? 1.0f/fabs(la) : 1.0f/low_approximation, la);
float href = copysign(fabs(1.0f - la) > low_approximation ? 1.0f/fabs(1.0f - la) :
1.0f/low_approximation, 1.0f - la);
@@ -29,7 +25,7 @@ float3 overlay(const float3 in_a,
float optrans = chunk * transform;
opacity2 -= 1.0f;
- a.x = la * (1.0f - optrans) + (la > halfmax ? lmax - (lmax - doublemax * (la - halfmax)) * (lmax-lb) :
doublemax * la * lb) * optrans;
+ a.x = la * (1.0f - optrans) + (la > 0.5f ? 1.0f - (1.0f - 2.0f * (la - 0.5f)) * (1.0f-lb) : 2.0f * la *
lb) * optrans;
a.y = a.y * (1.0f - optrans) + (a.y + b.y) * (a.x*lref * ccorrect + (1.0f - a.x)*href * (1.0f -
ccorrect)) * optrans;
a.z = a.z * (1.0f - optrans) + (a.z + b.z) * (a.x*lref * ccorrect + (1.0f - a.x)*href * (1.0f -
ccorrect)) * optrans;
}
diff --git a/operations/workshop/shadows-highlights-correction.c
b/operations/workshop/shadows-highlights-correction.c
index 1c78128..08b2191 100644
--- a/operations/workshop/shadows-highlights-correction.c
+++ b/operations/workshop/shadows-highlights-correction.c
@@ -95,11 +95,6 @@ process (GeglOperation *operation,
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 };
- gfloat lmax = max[0] + fabsf(min[0]);
- gfloat halfmax = lmax / 2.0f;
- gfloat doublemax = lmax * 2.0f;
gfloat low_approximation = 0.01f;
compress = fminf ((gfloat) o->compress / 100.0f, 0.99f);
@@ -154,7 +149,7 @@ process (GeglOperation *operation,
gfloat chunk, optrans;
gfloat la = ta[0];
- gfloat lb = (tb[0] - halfmax) * SIGN(-highlights) * SIGN(lmax - la) + halfmax;
+ gfloat lb = (tb[0] - 0.5f) * SIGN(-highlights) * SIGN(1.0f - la) + 0.5f;
lref = copysignf(fabsf(la) > low_approximation ? 1.0f / fabsf(la) : 1.0f / low_approximation, la);
href = copysignf(
@@ -165,8 +160,7 @@ process (GeglOperation *operation,
highlights2 -= 1.0f;
ta[0] = la * (1.0 - optrans)
- + (la > halfmax ? lmax - (lmax - doublemax * (la - halfmax)) * (lmax - lb) : doublemax * la
- * lb) *
optrans;
+ + (la > 0.5f ? 1.0f - (1.0f - 2.0f * (la - 0.5f)) * (1.0f - lb) : 2.0f * la * lb) *
optrans;
ta[1] = ta[1] * (1.0f - optrans)
+ (ta[1] + tb[1]) * (ta[0] * lref * (1.0f - highlights_ccorrect)
@@ -186,7 +180,7 @@ process (GeglOperation *operation,
gfloat chunk, optrans;
gfloat la = ta[0];
- gfloat lb = (tb[0] - halfmax) * SIGN(shadows) * SIGN(lmax - la) + halfmax;
+ gfloat lb = (tb[0] - 0.5f) * SIGN(shadows) * SIGN(1.0f - la) + 0.5f;
lref = copysignf(fabsf(la) > low_approximation ? 1.0f / fabsf(la) : 1.0f / low_approximation, la);
href = copysignf(
fabsf(1.0f - la) > low_approximation ? 1.0f / fabsf(1.0f - la) : 1.0f / low_approximation, 1.0f
- la);
@@ -196,8 +190,7 @@ process (GeglOperation *operation,
shadows2 -= 1.0f;
ta[0] = la * (1.0 - optrans)
- + (la > halfmax ? lmax - (lmax - doublemax * (la - halfmax)) * (lmax - lb) : doublemax * la
- * lb) * optrans;
+ + (la > 0.5f ? 1.0f - (1.0f - 2.0f * (la - 0.5f)) * (1.0f - lb) : 2.0f * la * lb) * optrans;
ta[1] = ta[1] * (1.0f - optrans)
+ (ta[1] + tb[1]) * (ta[0] * lref * shadows_ccorrect
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]