Commit 12b0aa46 authored by Alexia Death's avatar Alexia Death

operations: add preserve luminocity option to mono-mixer op and disable broken CL code

parent 7fea0eef
......@@ -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;
}
......@@ -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"
;
......@@ -19,9 +19,11 @@
#include "config.h"
#include <glib/gi18n-lib.h>
#include <math.h>
#ifdef GEGL_PROPERTIES
property_boolean (preserve_luminosity, _("Preserve luminosity"), FALSE)
property_double (red, _("Amount of red"), 0.5)
value_range (-10.0, 10.0)
......@@ -57,10 +59,12 @@ process (GeglOperation *op,
const GeglRectangle *roi,
gint level)
{
GeglProperties *o = GEGL_PROPERTIES (op);
gfloat red = o->red;
gfloat green = o->green;
gfloat blue = o->blue;
GeglProperties *o = GEGL_PROPERTIES (op);
gfloat red = o->red;
gfloat green = o->green;
gfloat blue = o->blue;
gboolean normalize = o->preserve_luminosity;
gfloat norm_factor = 1.0;
gfloat * GEGL_ALIGNED in_pixel;
gfloat * GEGL_ALIGNED out_pixel;
glong i;
......@@ -68,17 +72,35 @@ process (GeglOperation *op,
in_pixel = in_buf;
out_pixel = out_buf;
if (normalize)
{
gdouble sum = red + green + blue;
if (sum == 0.0)
norm_factor = 1.0;
else
norm_factor = fabs (1 / sum);
}
for (i=0; i<n_pixels; i++)
{
out_pixel[0] = in_pixel[0] * red + in_pixel[1] * green + in_pixel[2] * blue;
out_pixel[0] = (in_pixel[0] * red +
in_pixel[1] * green +
in_pixel[2] * blue) * norm_factor;
out_pixel[1] = in_pixel[3];
in_pixel += 4;
out_pixel += 2;
}
return TRUE;
}
/* FIXME!
* CL variant of the operation gives a different
* result than the non-cl code even without the luminoscity preservation code
* that seems to have no effect, as if toggle parameter never changes.
* Disabling for now. */
/*
#include "opencl/mono-mixer.cl.h"
*/
static void
gegl_op_class_init (GeglOpClass *klass)
......@@ -97,7 +119,7 @@ gegl_op_class_init (GeglOpClass *klass)
"title", _("Mono Mixer"),
"categories", "color",
"description", _("Monochrome channel mixer"),
"cl-source", mono_mixer_cl_source,
/* "cl-source", mono_mixer_cl_source, */
NULL);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment