summaryrefslogtreecommitdiff
path: root/opencl
diff options
context:
space:
mode:
authorAlexia Death <alexiadeath@gmail.com>2014-12-06 23:37:46 +0200
committerAlexia Death <alexiadeath@gmail.com>2014-12-06 23:37:46 +0200
commit12b0aa46ff9683d2f1c65258da763ceedc8993d3 (patch)
treeaf1e75d3ebb48c970bf8506ca6418426b94042f0 /opencl
parent7fea0eefc05bc284db1b192540bdd7050ea19641 (diff)
operations: add preserve luminocity option to mono-mixer op and disable broken CL code
Diffstat (limited to 'opencl')
-rw-r--r--opencl/mono-mixer.cl16
-rw-r--r--opencl/mono-mixer.cl.h16
2 files changed, 28 insertions, 4 deletions
diff --git a/opencl/mono-mixer.cl b/opencl/mono-mixer.cl
index 88b337b7..0a17cac2 100644
--- a/opencl/mono-mixer.cl
+++ b/opencl/mono-mixer.cl
@@ -2,10 +2,22 @@ __kernel void gegl_mono_mixer (__global const float4 *src_buf,
__global float2 *dst_buf,
float red,
float green,
- float blue)
+ float blue,
+ const int preserve_luminocity)
{
int gid = get_global_id(0);
float4 in_v = src_buf[gid];
- dst_buf[gid].x = in_v.x * red + in_v.y * green + in_v.z * blue;
+ float norm_factor = 1.0f;
+
+ if (preserve_luminocity)
+ {
+ float sum = red + green + blue;
+ if (sum == 0.0)
+ norm_factor = 1.0f;
+ else
+ norm_factor = fabs (1.0f / sum);
+ }
+
+ dst_buf[gid].x = (in_v.x * red + in_v.y * green + in_v.z * blue) * norm_factor;
dst_buf[gid].y = in_v.w;
}
diff --git a/opencl/mono-mixer.cl.h b/opencl/mono-mixer.cl.h
index 7b2fbc83..7a655ac1 100644
--- a/opencl/mono-mixer.cl.h
+++ b/opencl/mono-mixer.cl.h
@@ -3,11 +3,23 @@ static const char* mono_mixer_cl_source =
" __global float2 *dst_buf, \n"
" float red, \n"
" float green, \n"
-" float blue) \n"
+" float blue, \n"
+" const int preserve_luminocity) \n"
"{ \n"
" int gid = get_global_id(0); \n"
" float4 in_v = src_buf[gid]; \n"
-" dst_buf[gid].x = in_v.x * red + in_v.y * green + in_v.z * blue; \n"
+" float norm_factor = 1.0f; \n"
+" \n"
+" if (preserve_luminocity) \n"
+" { \n"
+" float sum = red + green + blue; \n"
+" if (sum == 0.0) \n"
+" norm_factor = 1.0f; \n"
+" else \n"
+" norm_factor = fabs (1.0f / sum); \n"
+" } \n"
+" \n"
+" dst_buf[gid].x = (in_v.x * red + in_v.y * green + in_v.z * blue) * norm_factor;\n"
" dst_buf[gid].y = in_v.w; \n"
"} \n"
;