[gegl] exposure: refactor to have fewer conditionals
- From: Ãyvind KolÃs <ok src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl] exposure: refactor to have fewer conditionals
- Date: Wed, 30 Jan 2013 00:10:41 +0000 (UTC)
commit f0d53fca5c946faefe160b902286ff748fa5d883
Author: Ãyvind KolÃs <pippin gimp org>
Date: Wed Jan 30 11:04:26 2013 +1100
exposure: refactor to have fewer conditionals
For the C implementation special case gamma == 1.0, GEGL permits negative as
well as positive values, clipping will occur when going to 8bpc or 16bpc
pixelformats.
operations/common/exposure.c | 73 +++++++++++++++++++++--------------------
1 files changed, 37 insertions(+), 36 deletions(-)
---
diff --git a/operations/common/exposure.c b/operations/common/exposure.c
index b586e4f..1b2a16d 100644
--- a/operations/common/exposure.c
+++ b/operations/common/exposure.c
@@ -13,14 +13,14 @@
* You should have received a copy of the GNU Lesser General Public
* License along with GEGL; if not, see <http://www.gnu.org/licenses/>.
*
- * Copyright 2012 Felix Ulber <felix ulber gmx de>
+ * Copyright 2012,2013 Felix Ulber <felix ulber gmx de>
+ * 2013 Ãyvind KolÃs <pippin gimp org>
*/
#include "config.h"
#include <glib/gi18n-lib.h>
-
#ifdef GEGL_CHANT_PROPERTIES
gegl_chant_double_ui (exposure, _("Exposure"), -G_MAXDOUBLE, G_MAXDOUBLE, 0.0, -10.0, 10.0, 1.0,
_("Relative brightness change in stops"))
@@ -70,27 +70,28 @@ process (GeglOperation *op,
in_pixel = in_buf;
out_pixel = out_buf;
- for (i=0; i<n_pixels; i++)
- {
- float c[3];
- c[0] = (in_pixel[0] * gain + offset);
- c[1] = (in_pixel[1] * gain + offset);
- c[2] = (in_pixel[2] * gain + offset);
-
- // ???
- c[0] = fmaxf(0.0, c[0]);
- c[1] = fmaxf(0.0, c[1]);
- c[2] = fmaxf(0.0, c[2]);
-
- out_pixel[0] = powf(c[0], gamma);
- out_pixel[1] = powf(c[1], gamma);
- out_pixel[2] = powf(c[2], gamma);
-
- out_pixel[3] = in_pixel[3];
-
- out_pixel += 4;
- in_pixel += 4;
- }
+ if (gamma == 1.0)
+ for (i=0; i<n_pixels; i++)
+ {
+ out_pixel[0] = (in_pixel[0] * gain + offset);
+ out_pixel[1] = (in_pixel[1] * gain + offset);
+ out_pixel[2] = (in_pixel[2] * gain + offset);
+ out_pixel[3] = in_pixel[3];
+
+ out_pixel += 4;
+ in_pixel += 4;
+ }
+ else
+ for (i=0; i<n_pixels; i++)
+ {
+ out_pixel[0] = powf(in_pixel[0] * gain + offset, gamma);
+ out_pixel[1] = powf(in_pixel[1] * gain + offset, gamma);
+ out_pixel[2] = powf(in_pixel[2] * gain + offset, gamma);
+ out_pixel[3] = in_pixel[3];
+
+ out_pixel += 4;
+ in_pixel += 4;
+ }
return TRUE;
}
@@ -98,19 +99,19 @@ process (GeglOperation *op,
#include "opencl/gegl-cl.h"
static const char* kernel_source =
-"__kernel void kernel_exposure(__global const float4 *in, \n"
-" __global float4 *out, \n"
-" float gain, \n"
-" float offset, \n"
-" float gamma) \n"
-"{ \n"
-" int gid = get_global_id(0); \n"
-" float4 in_v = in[gid]; \n"
-" float4 out_v; \n"
-" out_v.xyz = pow(max((in_v.xyz * gain) + offset, 0.0), 1.0/gamma); \n"
-" out_v.w = in_v.w; \n"
-" out[gid] = out_v; \n"
-"} \n";
+"__kernel void kernel_exposure(__global const float4 *in, \n"
+" __global float4 *out, \n"
+" float gain, \n"
+" float offset, \n"
+" float gamma) \n"
+"{ \n"
+" int gid = get_global_id(0); \n"
+" float4 in_v = in[gid]; \n"
+" float4 out_v; \n"
+" out_v.xyz = pow((in_v.xyz * gain) + offset, 1.0/gamma); \n"
+" out_v.w = in_v.w; \n"
+" out[gid] = out_v; \n"
+"} \n";
static GeglClRunData *cl_data = NULL;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]