Commit 39fa5eec authored by Kevin Cozens's avatar Kevin Cozens

Updated to new chanting API.

	* operations/enhance/bilateral-filter.c:
	* operations/enhance/snn-mean.c:
	* operations/render/checkerboard.c:
	* operations/render/color.c:
	* operations/render/FractalExplorer.c:
	* operations/render/introspect.c:
	* operations/render/noise.c:
	* operations/svg/svg_huerotate.c:
	* operations/svg/svg_luminancetoalpha.c:
	* operations/svg/svg_matrix.c:
	* operations/svg/svg_saturate.c:
	* operations/transparency/opacity.c: Updated to new chanting API.

svn path=/trunk/; revision=1914
parent db3a20fe
2008-01-25 Kevin Cozens <kcozens@cvs.gnome.org>
* operations/enhance/bilateral-filter.c:
* operations/enhance/snn-mean.c:
* operations/render/checkerboard.c:
* operations/render/color.c:
* operations/render/FractalExplorer.c:
* operations/render/introspect.c:
* operations/render/noise.c:
* operations/svg/svg_huerotate.c:
* operations/svg/svg_luminancetoalpha.c:
* operations/svg/svg_matrix.c:
* operations/svg/svg_saturate.c:
* operations/transparency/opacity.c: Updated to new chanting API.
2008-01-25 Øyvind Kolås <pippin@gimp.org>
* gegl/gegl-chant.h: fixed mistake in handling of boiler-plate for
......
......@@ -17,22 +17,19 @@
* 2007 Øyvind Kolås <oeyvindk@hig.no>
*/
#if GEGL_CHANT_PROPERTIES
#define MAX_SAMPLES 20000 /* adapted to max level of radius */
#ifdef GEGL_CHANT_PROPERTIES
gegl_chant_double (blur_radius, 0.0, 70.0, 4.0,
"Radius of square pixel region, (width and height will be radius*2+1.")
"Radius of square pixel region, (width and height will be radius*2+1).")
gegl_chant_double (edge_preservation, 0.0, 70.0, 8.0, "Amount of edge preservation")
#else
#define GEGL_CHANT_NAME bilateral_filter
#define GEGL_CHANT_SELF "bilateral-filter.c"
#define GEGL_CHANT_DESCRIPTION "An edge preserving blur filter that can be used for noise reduction. It is a gaussian blur where the contribution of neighbourhood pixels are weighted by the color difference from the center pixel."
#define GEGL_CHANT_CATEGORIES "misc"
#define GEGL_CHANT_TYPE_AREA_FILTER
#define GEGL_CHANT_C_FILE "bilateral-filter.c"
#define GEGL_CHANT_AREA_FILTER
#include "gegl-old-chant.h"
#include "gegl-chant.h"
#include <math.h>
static void
......@@ -43,38 +40,39 @@ bilateral_filter (GeglBuffer *src,
#include <stdio.h>
static void tickle (GeglOperation *operation)
{
GeglOperationAreaFilter *area = GEGL_OPERATION_AREA_FILTER (operation);
GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
area->left = area->right = area->top = area->bottom = ceil (o->blur_radius);
}
static gboolean
process (GeglOperation *operation,
GeglBuffer *input,
GeglBuffer *output,
const GeglRectangle *result)
{
GeglOperationFilter *filter;
GeglChantOperation *self;
GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
GeglBuffer *temp_in;
GeglRectangle compute;
filter = GEGL_OPERATION_FILTER (operation);
self = GEGL_CHANT_OPERATION (operation);
compute = gegl_operation_compute_input_request (operation,
"input", result);
if (o->blur_radius < 1.0)
{
GeglBuffer *temp_in;
GeglRectangle compute;
compute = gegl_operation_compute_input_request (operation,
"input", result);
if (self->blur_radius < 1.0)
{
output = g_object_ref (input);
}
else
{
temp_in = gegl_buffer_create_sub_buffer (input, &compute);
bilateral_filter (temp_in, output, self->blur_radius, self->edge_preservation);
g_object_unref (temp_in);
}
output = g_object_ref (input);
}
else
{
temp_in = gegl_buffer_create_sub_buffer (input, &compute);
bilateral_filter (temp_in, output, o->blur_radius, o->edge_preservation);
g_object_unref (temp_in);
}
return TRUE;
}
......@@ -113,7 +111,7 @@ bilateral_filter (GeglBuffer *src,
gfloat *center_pix = src_buf + (x+(y * gegl_buffer_get_width (src))) * 4;
gfloat accumulated[4]={0,0,0,0};
gfloat count=0.0;
for (v=-radius;v<=radius;v++)
for (u=-radius;u<=radius;u++)
{
......@@ -121,16 +119,16 @@ bilateral_filter (GeglBuffer *src,
y+v >= 0 && y+v < gegl_buffer_get_height (dst))
{
gint c;
gfloat *src_pix = src_buf + ((x+u)+((y+v) * gegl_buffer_get_width (src))) * 4;
gfloat diff_map = exp (- (POW2(center_pix[0] - src_pix[0])+
POW2(center_pix[1] - src_pix[1])+
POW2(center_pix[2] - src_pix[2])) * preserve
POW2(center_pix[2] - src_pix[2])) * preserve
);
gfloat gaussian_weight;
gfloat weight;
gaussian_weight = gauss[u+(int)radius+(v+(int)radius)*width];
weight = diff_map * gaussian_weight;
......@@ -138,7 +136,7 @@ bilateral_filter (GeglBuffer *src,
for (c=0;c<4;c++)
{
accumulated[c] += src_pix[c] * weight;
}
}
count += weight;
}
}
......@@ -153,12 +151,25 @@ bilateral_filter (GeglBuffer *src,
g_free (dst_buf);
}
static void tickle (GeglOperation *operation)
static void
operation_class_init (GeglChantClass *klass)
{
GeglOperationAreaFilter *area = GEGL_OPERATION_AREA_FILTER (operation);
GeglChantOperation *blur = GEGL_CHANT_OPERATION (operation);
area->left = area->right = area->top = area->bottom =
ceil (blur->blur_radius);
GeglOperationClass *operation_class;
GeglOperationFilterClass *filter_class;
operation_class = GEGL_OPERATION_CLASS (klass);
filter_class = GEGL_OPERATION_FILTER_CLASS (klass);
filter_class->process = process;
operation_class->tickle = tickle;
operation_class->name = "bilateral-filter";
operation_class->categories = "misc";
operation_class->description =
"An edge preserving blur filter that can be used for noise reduction."
" It is a gaussian blur where the contribution of neighbourhood pixels"
" are weighted by the color difference from the center pixel.";
}
#endif
......@@ -17,8 +17,7 @@
* 2007 Øyvind Kolås <oeyvindk@hig.no>
*/
#if GEGL_CHANT_PROPERTIES
#define MAX_SAMPLES 20000 /* adapted to mean level of radius */
#ifdef GEGL_CHANT_PROPERTIES
gegl_chant_double (radius, 0.0, 70.0, 8.0,
"Radius of square pixel region, (width and height will be radius*2+1.")
......@@ -26,14 +25,10 @@ gegl_chant_int (pairs, 1, 2, 2, "Number of pairs higher number preserves more ac
#else
#define GEGL_CHANT_NAME snn_mean
#define GEGL_CHANT_SELF "snn-mean.c"
#define GEGL_CHANT_DESCRIPTION "Noise reducing edge enhancing blur filter based on Symmetric Nearest Neighbours"
#define GEGL_CHANT_CATEGORIES "misc"
#define GEGL_CHANT_TYPE_AREA_FILTER
#define GEGL_CHANT_C_FILE "snn-mean.c"
#define GEGL_CHANT_AREA_FILTER
#include "gegl-old-chant.h"
#include "gegl-chant.h"
#include <math.h>
static void
......@@ -43,36 +38,39 @@ snn_mean (GeglBuffer *src,
gint pairs);
static void tickle (GeglOperation *operation)
{
GeglOperationAreaFilter *area = GEGL_OPERATION_AREA_FILTER (operation);
GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
area->left = area->right = area->top = area->bottom = ceil (o->radius);
}
static gboolean
process (GeglOperation *operation,
GeglBuffer *input,
GeglBuffer *output,
const GeglRectangle *result)
{
GeglOperationFilter *filter;
GeglChantOperation *self;
GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
GeglBuffer *temp_in;
GeglRectangle compute;
filter = GEGL_OPERATION_FILTER (operation);
self = GEGL_CHANT_OPERATION (operation);
compute = gegl_operation_compute_input_request (operation,
"input", result);
if (o->radius < 1.0)
{
GeglBuffer *temp_in;
GeglRectangle compute;
compute = gegl_operation_compute_input_request (operation,
"input", result);
if (self->radius < 1.0)
{
output = g_object_ref (input);
}
else
{
temp_in = gegl_buffer_create_sub_buffer (input, &compute);
snn_mean (temp_in, output, self->radius, self->pairs);
g_object_unref (temp_in);
}
output = g_object_ref (input);
}
else
{
temp_in = gegl_buffer_create_sub_buffer (input, &compute);
snn_mean (temp_in, output, o->radius, o->pairs);
g_object_unref (temp_in);
}
return TRUE;
}
......@@ -123,8 +121,8 @@ snn_mean (GeglBuffer *src,
gfloat *center_pix = src_buf + offset * 4;
gfloat accumulated[4]={0,};
gint count=0;
/* iterate through the upper left quater of pixels */
/* iterate through the upper left quater of pixels */
for (v=-radius;v<=0;v++)
for (u=-radius;u<= (pairs==1?radius:0);u++)
{
......@@ -165,7 +163,7 @@ snn_mean (GeglBuffer *src,
for (i=0;i<4;i++)
{
accumulated[i] += selected_pix[i];
}
}
count++;
if (u==0 && v==0)
......@@ -181,12 +179,23 @@ snn_mean (GeglBuffer *src,
g_free (dst_buf);
}
static void tickle (GeglOperation *operation)
static void
operation_class_init (GeglChantClass *klass)
{
GeglOperationAreaFilter *area = GEGL_OPERATION_AREA_FILTER (operation);
GeglChantOperation *filter = GEGL_CHANT_OPERATION (operation);
area->left = area->right = area->top = area->bottom =
ceil (filter->radius);
GeglOperationClass *operation_class;
GeglOperationFilterClass *filter_class;
operation_class = GEGL_OPERATION_CLASS (klass);
filter_class = GEGL_OPERATION_FILTER_CLASS (klass);
filter_class->process = process;
operation_class->tickle = tickle;
operation_class->name = "snn-mean";
operation_class->categories = "misc";
operation_class->description =
"Noise reducing edge enhancing blur filter based on Symmetric Nearest Neighbours";
}
#endif
......@@ -22,7 +22,7 @@
#define MAXNCOLORS 8192
#if GEGL_CHANT_PROPERTIES
#ifdef GEGL_CHANT_PROPERTIES
gegl_chant_int (width, 10, 10000000, 400, "Width")
gegl_chant_int (height, 10, 10000000, 400, "Height")
......@@ -52,17 +52,10 @@ gegl_chant_boolean (useloglog, FALSE, "Use loglog smoothing")
#else
#define GEGL_CHANT_NAME FractalExplorer
#define GEGL_CHANT_SELF "FractalExplorer.c"
#define GEGL_CHANT_DESCRIPTION "Fractal Explorer"
#define GEGL_CHANT_CATEGORIES "render"
#define GEGL_CHANT_TYPE_SOURCE
#define GEGL_CHANT_C_FILE "FractalExplorer.c"
#define GEGL_CHANT_SOURCE
#define GEGL_CHANT_PREPARE
#define GEGL_CHANT_CLASS_INIT
#include "gegl-old-chant.h"
#include "gegl-chant.h"
#include <math.h>
#include <stdio.h>
......@@ -96,12 +89,12 @@ typedef gucharRGB clrmap[MAXNCOLORS];
static void
explorer_render_row (GeglChantOperation *self,
gint col_start,
gint col_end,
gint row,
clrmap colormap,
guchar **dest_row)
explorer_render_row (GeglChantO *o,
gint col_start,
gint col_end,
gint row,
clrmap colormap,
guchar **dest_row)
{
gint fractaltype;
gint col;
......@@ -134,18 +127,18 @@ explorer_render_row (GeglChantOperation *self,
gdouble ydiff;
gdouble log2;
fractaltype = self->fractaltype;
xmin = self->xmin;
ymin = self->ymin;
cx = self->cx;
cy = self->cy;
iteration = self->iter;
ncolors = self->ncolors;
useloglog = self->useloglog;
fractaltype = o->fractaltype;
xmin = o->xmin;
ymin = o->ymin;
cx = o->cx;
cy = o->cy;
iteration = o->iter;
ncolors = o->ncolors;
useloglog = o->useloglog;
log2 = log (2.0);
xdiff = (self->xmax - xmin) / self->width;
ydiff = (self->ymax - ymin) / self->height;
xdiff = (o->xmax - xmin) / o->width;
ydiff = (o->ymax - ymin) / o->height;
for (col = col_start; col < col_end; col++)
{
......@@ -301,7 +294,7 @@ explorer_render_row (GeglChantOperation *self,
}
static void
make_color_map (GeglChantOperation *self, clrmap colormap)
make_color_map (GeglChantO *o, clrmap colormap)
{
gint i;
gint r;
......@@ -312,16 +305,16 @@ make_color_map (GeglChantOperation *self, clrmap colormap)
gdouble bluestretch;
gdouble pi = atan (1) * 4;
redstretch = self->redstretch * 127.5;
greenstretch = self->greenstretch * 127.5;
bluestretch = self->bluestretch * 127.5;
redstretch = o->redstretch * 127.5;
greenstretch = o->greenstretch * 127.5;
bluestretch = o->bluestretch * 127.5;
for (i = 0; i < self->ncolors; i++)
for (i = 0; i < o->ncolors; i++)
{
double x = (i*2.0) / self->ncolors;
double x = (i*2.0) / o->ncolors;
r = gr = bl = 0;
switch (self->redmode)
switch (o->redmode)
{
case SINUS:
r = (int) redstretch *(1.0 + sin((x - 1) * pi));
......@@ -336,7 +329,7 @@ make_color_map (GeglChantOperation *self, clrmap colormap)
break;
}
switch (self->greenmode)
switch (o->greenmode)
{
case SINUS:
gr = (int) greenstretch *(1.0 + sin((x - 1) * pi));
......@@ -351,7 +344,7 @@ make_color_map (GeglChantOperation *self, clrmap colormap)
break;
}
switch (self->bluemode)
switch (o->bluemode)
{
case SINUS:
bl = (int) bluestretch * (1.0 + sin ((x - 1) * pi));
......@@ -370,13 +363,13 @@ make_color_map (GeglChantOperation *self, clrmap colormap)
gr = MIN (gr, 255);
bl = MIN (bl, 255);
if (self->redinvert)
if (o->redinvert)
r = 255 - r;
if (self->greeninvert)
if (o->greeninvert)
gr = 255 - gr;
if (self->blueinvert)
if (o->blueinvert)
bl = 255 - bl;
colormap[i].r = r;
......@@ -385,44 +378,6 @@ make_color_map (GeglChantOperation *self, clrmap colormap)
}
}
static gboolean
process (GeglOperation *operation,
GeglNodeContext *context,
GeglBuffer *output,
const GeglRectangle *result)
{
GeglChantOperation *self = GEGL_CHANT_OPERATION (operation);
{
clrmap colormap;
guchar *buf;
gint pxsize;
make_color_map (self, colormap);
g_object_get (output, "px-size", &pxsize, NULL);
buf = g_new (guchar, result->width * result->height * pxsize);
{
guchar *dst=buf;
gint y;
for (y=0; y < result->height; y++)
{
explorer_render_row (self,
result->x,
result->x + result->width ,
result->y + y,
colormap,
&dst);
}
}
gegl_buffer_set (output, NULL, babl_format ("R'G'B' u8"), buf,
GEGL_AUTO_ROWSTRIDE);
g_free (buf);
}
return TRUE;
}
static void
prepare (GeglOperation *operation)
{
......@@ -432,19 +387,72 @@ prepare (GeglOperation *operation)
static GeglRectangle
get_defined_region (GeglOperation *operation)
{
GeglChantOperation *self = GEGL_CHANT_OPERATION (operation);
GeglRectangle result = {0,0,0,0};
GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
GeglRectangle result = {0,0,0,0};
result.width = self->width;
result.height = self->height;
result.width = o->width;
result.height = o->height;
return result;
}
static void class_init (GeglOperationClass *klass)
static gboolean
process (GeglOperation *operation,
GeglNodeContext *context,
GeglBuffer *output,
const GeglRectangle *result)
{
GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
clrmap colormap;
guchar *buf;
gint pxsize;
make_color_map (o, colormap);
g_object_get (output, "px-size", &pxsize, NULL);
buf = g_new (guchar, result->width * result->height * pxsize);
{
guchar *dst=buf;
gint y;
for (y=0; y < result->height; y++)
{
explorer_render_row (o,
result->x,
result->x + result->width ,
result->y + y,
colormap,
&dst);
}
}
gegl_buffer_set (output, NULL, babl_format ("R'G'B' u8"), buf,
GEGL_AUTO_ROWSTRIDE);
g_free (buf);
return TRUE;
}
static void
operation_class_init (GeglChantClass *klass)
{
klass->adjust_result_region = NULL;
klass->no_cache = FALSE;
GeglOperationClass *operation_class;
GeglOperationSourceClass *source_class;
operation_class = GEGL_OPERATION_CLASS (klass);
source_class = GEGL_OPERATION_SOURCE_CLASS (klass);
source_class->process = process;
operation_class->get_defined_region = get_defined_region;
operation_class->prepare = prepare;
operation_class->name = "FractalExplorer";
operation_class->categories = "render";
operation_class->description = "Fractal Explorer";
operation_class->no_cache = TRUE;
operation_class->adjust_result_region = NULL;
}
#endif
......@@ -15,7 +15,7 @@
*
* Copyright 2006 Øyvind Kolås <pippin@gimp.org>
*/
#if GEGL_CHANT_PROPERTIES
#ifdef GEGL_CHANT_PROPERTIES
gegl_chant_int (x, -G_MAXINT, G_MAXINT, 16, "Horizontal width of cells pixels.")
gegl_chant_int (y, -G_MAXINT, G_MAXINT, 16, "Vertical width of cells in pixels.")
......@@ -26,17 +26,10 @@ gegl_chant_color (color2, "white", "The other cell color (defa
#else
#define GEGL_CHANT_SOURCE
#define GEGL_CHANT_NAME checkerboard
#define GEGL_CHANT_DESCRIPTION "Checkerboard renderer."
#define GEGL_CHANT_TYPE_SOURCE
#define GEGL_CHANT_C_FILE "checkerboard.c"
#define GEGL_CHANT_SELF "checkerboard.c"
#define GEGL_CHANT_CATEGORIES "render"
#define GEGL_CHANT_CLASS_INIT
#define GEGL_CHANT_PREPARE
#include "gegl-old-chant.h"
#include "gegl-chant.h"
static void
prepare (GeglOperation *operation)
......@@ -44,76 +37,90 @@ prepare (GeglOperation *operation)
gegl_operation_set_format (operation, "output", babl_format ("RGBA float"));
}
static GeglRectangle
get_defined_region (GeglOperation *operation)
{
GeglRectangle result = {-10000000, -10000000, 20000000, 20000000};
return result;
}
static gboolean
process (GeglOperation *operation,
GeglNodeContext *context,
GeglBuffer *output,
const GeglRectangle *result)
{
GeglChantOperation *self = GEGL_CHANT_OPERATION (operation);
{
gfloat *buf;
gfloat color1[4];
gfloat color2[4];
gint pxsize;
gint n_pixels;
gegl_color_get_rgba (self->color1,
&color1[0],
&color1[1],
&color1[2],
&color1[3]);
gegl_color_get_rgba (self->color2,
&color2[0],
&color2[1],
&color2[2],
&color2[3]);
g_object_get (output, "px-size", &pxsize,
"pixels", &n_pixels,
NULL);
buf = g_malloc (n_pixels * pxsize);
{
gfloat *dst=buf;
gint y;
for (y=0; y < result->height; y++)
{
gint x;
for (x=0; x < result->width ; x++)
{
gfloat *rgba_color;
gint nx,ny;
nx = ((x + result->x + self->x_offset + 100000 * self->x)/self->x) ;
ny = ((y + result->y + self->y_offset + 100000 * self->y)/self->y) ;
rgba_color = (nx+ny) % 2 == 0 ? color1 : color2;
memcpy(dst, rgba_color, 4*sizeof(gfloat));
dst += 4;
}
}
}
gegl_buffer_set (output, NULL, NULL, buf, GEGL_AUTO_ROWSTRIDE);
g_free (buf);
}
GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
gfloat *buf;
gfloat color1[4];
gfloat color2[4];
gint pxsize;
gint n_pixels;
gegl_color_get_rgba (o->color1,
&color1[0],
&color1[1],
&color1[2],
&color1[3]);
gegl_color_get_rgba (o->color2,
&color2[0],
&color2[1],
&color2[2],
&color2[3]);
g_object_get (output, "px-size", &pxsize,
"pixels", &n_pixels,
NULL);
buf = g_malloc (n_pixels * pxsize);
{
gfloat *dst=buf;
gint y;
for (y=0; y < result->height; y++)
{
gint x;
for (x=0; x < result->width ; x++)
{
gfloat *rgba_color;
gint nx,ny;
nx = ((x + result->x + o->x_offset + 100000 * o->x)/o->x) ;
ny = ((y + result->y + o->y_offset + 100000 * o->y)/o->y) ;
rgba_color = (nx+ny) % 2 == 0 ? color1 : color2;
memcpy (dst, rgba_color, 4*sizeof(gfloat));
dst += 4;
}
}
}
gegl_buffer_set (output, NULL, NULL, buf, GEGL_AUTO_ROWSTRIDE);
g_free (buf);
return TRUE;
}
static GeglRectangle
get_defined_region (GeglOperation *operation)
{
GeglRectangle result = {-10000000,-10000000, 20000000, 20000000};
return result;
}