I've done a linear motion blur filter, and a simple random noise filter too.I'll send a test for the motion blur if someone can tell me where to. The noise filter I haven't done a test for, because by it's nature the results vary from run to run.
Next up is the radial and zoom blurs.
From 8da480d4af73ff2f9cdf08687b2e751ef3b67e4d Mon Sep 17 00:00:00 2001
From: Andy Gill <andyggill@xxxxxxxxx>
Date: Sat, 29 Jan 2011 18:58:47 +0000
Subject: [PATCH 1/2] added linear motion blur filter
---
operations/common/motion-blur.c | 174 +++++++++++++++++++++++++++++++++++++++
1 files changed, 174 insertions(+), 0 deletions(-)
create mode 100644 operations/common/motion-blur.c
diff --git a/operations/common/motion-blur.c b/operations/common/motion-blur.c
new file mode 100644
index 0000000..baab51b
--- /dev/null
+++ b/operations/common/motion-blur.c
@@ -0,0 +1,174 @@
+/* This file is an image processing operation for GEGL
+ *
+ * GEGL is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * GEGL is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * 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 2006 Ãyvind KolÃs <pippin@xxxxxxxx>
+ */
+
+#include "config.h"
+#include <glib/gi18n-lib.h>
+#include <math.h>
+
+#ifdef GEGL_CHANT_PROPERTIES
+
+
+gegl_chant_double (length, _("Length"), 0.0, 200.0, 10.0,
+ _("Length of blur in pixels"))
+gegl_chant_double (angle, _("Angle"), -360, 360, 0,
+ _("Angle of blur in degrees"))
+
+#else
+
+#define GEGL_CHANT_TYPE_AREA_FILTER
+#define GEGL_CHANT_C_FILE "motion-blur.c"
+
+#include "gegl-chant.h"
+
+static void
+prepare (GeglOperation *operation)
+{
+ GeglOperationAreaFilter* op_area = GEGL_OPERATION_AREA_FILTER (operation);
+ GeglChantO* o = GEGL_CHANT_PROPERTIES (operation);
+
+ gdouble theta = o->angle * M_PI / 180.0;
+ gdouble offset_x = fabs(o->length * cos(theta));
+ gdouble offset_y = fabs(o->length * sin(theta));
+
+ op_area->left =
+ op_area->right = (gint)ceil(0.5 * offset_x);
+ op_area->top =
+ op_area->bottom = (gint)ceil(0.5 * offset_y);
+
+ gegl_operation_set_format (operation, "output", babl_format ("RaGaBaA float"));
+}
+
+static inline gfloat*
+get_pixel_color(gfloat* in_buf,
+ const GeglRectangle* rect,
+ gint x,
+ gint y)
+{
+ gint ix = x - rect->x;
+ gint iy = y - rect->y;
+ ix = CLAMP(ix, 0, rect->width-1);
+ iy = CLAMP(iy, 0, rect->height-1);
+
+ return &in_buf[(iy*rect->width + ix) * 4];
+}
+
+static gboolean
+process (GeglOperation *operation,
+ GeglBuffer *input,
+ GeglBuffer *output,
+ const GeglRectangle *roi)
+{
+ GeglRectangle src_rect;
+ GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
+ GeglOperationAreaFilter *op_area;
+ gfloat* in_buf;
+ gfloat* out_buf;
+ gfloat* out_pixel;
+ gint x,y;
+
+ gdouble theta = o->angle * M_PI / 180.0;
+ gdouble offset_x = o->length * cos(theta);
+ gdouble offset_y = o->length * sin(theta);
+ gint num_steps = (gint)ceil(o->length) + 1;
+ gfloat inv_num_steps = 1.0f / num_steps;
+
+ op_area = GEGL_OPERATION_AREA_FILTER (operation);
+
+ src_rect = *roi;
+ src_rect.x -= op_area->left;
+ src_rect.y -= op_area->top;
+ src_rect.width += op_area->left + op_area->right;
+ src_rect.height += op_area->top + op_area->bottom;
+
+ in_buf = g_new (gfloat, src_rect.width * src_rect.height * 4);
+ out_buf = g_new0 (gfloat, roi->width * roi->height * 4);
+ out_pixel = out_buf;
+
+ gegl_buffer_get (input, 1.0, &src_rect, babl_format ("RaGaBaA float"), in_buf, GEGL_AUTO_ROWSTRIDE);
+
+ for (y=0; y<roi->height; ++y)
+ {
+ for (x=0; x<roi->width; ++x)
+ {
+ gint step;
+ gint c;
+ gint px = x+roi->x;
+ gint py = y+roi->y;
+ gfloat sum[4] = {0,0,0,0};
+ for (step=0; step<num_steps; ++step)
+ {
+ gdouble t = num_steps == 1 ? 0.0 : step / (gdouble)(num_steps-1) - 0.5;
+
+ /* get the interpolated pixel position for this step */
+ gdouble xx = px + t*offset_x;
+ gdouble yy = py + t*offset_y;
+ gint ix = (gint)floor(xx);
+ gint iy = (gint)floor(yy);
+ gdouble dx = xx - floor(xx);
+ gdouble dy = yy - floor(yy);
+
+ /* do bilinear interpolation to get a nice smooth result */
+ gfloat *pix0, *pix1, *pix2, *pix3;
+ gfloat mixy0[4];
+ gfloat mixy1[4];
+
+ pix0 = get_pixel_color(in_buf, &src_rect, ix, iy);
+ pix1 = get_pixel_color(in_buf, &src_rect, ix+1, iy);
+ pix2 = get_pixel_color(in_buf, &src_rect, ix, iy+1);
+ pix3 = get_pixel_color(in_buf, &src_rect, ix+1, iy+1);
+ for (c=0; c<4; ++c)
+ {
+ mixy0[c] = dy*(pix2[c] - pix0[c]) + pix0[c];
+ mixy1[c] = dy*(pix3[c] - pix1[c]) + pix1[c];
+ sum[c] += dx*(mixy1[c] - mixy0[c]) + mixy0[c];
+ }
+ }
+
+ for (c=0; c<4; ++c)
+ *out_pixel++ = sum[c] * inv_num_steps;
+ }
+ }
+
+ gegl_buffer_set (output, roi, babl_format ("RaGaBaA float"), out_buf, GEGL_AUTO_ROWSTRIDE);
+
+ g_free (in_buf);
+ g_free (out_buf);
+
+
+ return TRUE;
+}
+
+
+static void
+gegl_chant_class_init (GeglChantClass *klass)
+{
+ 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->prepare = prepare;
+
+ operation_class->name = "gegl:motion-blur";
+ operation_class->categories = "blur";
+ operation_class->description = _("Linear motion blur");
+}
+
+#endif
--
1.7.0.4
From 874e34026ef9d6ef73807034ea4df6d19fe3bbcf Mon Sep 17 00:00:00 2001
From: Andy Gill <andyggill@xxxxxxxxx>
Date: Sat, 29 Jan 2011 19:00:11 +0000
Subject: [PATCH 2/2] added random noise filter
---
operations/common/add-noise.c | 106 +++++++++++++++++++++++++++++++++++++++++
1 files changed, 106 insertions(+), 0 deletions(-)
create mode 100644 operations/common/add-noise.c
diff --git a/operations/common/add-noise.c b/operations/common/add-noise.c
new file mode 100644
index 0000000..dcd44a2
--- /dev/null
+++ b/operations/common/add-noise.c
@@ -0,0 +1,106 @@
+/* This file is an image processing operation for GEGL
+ *
+ * GEGL is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * GEGL is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * 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 2006 Ãyvind KolÃs <pippin@xxxxxxxx>
+ */
+
+#include "config.h"
+#include <glib/gi18n-lib.h>
+
+#ifdef GEGL_CHANT_PROPERTIES
+
+gegl_chant_double (amount, _("Amount"), 0.0, 1.0, 0.2,
+ _("Amount of noise to add."))
+gegl_chant_double (saturation, _("Saturation"), 0.0, 1.0, 0.0,
+ _("Color saturation of the noise"))
+#else
+
+#define GEGL_CHANT_TYPE_POINT_FILTER
+#define GEGL_CHANT_C_FILE "add-noise.c"
+
+#include "gegl-chant.h"
+
+static void
+prepare (GeglOperation *operation)
+{
+ gegl_operation_set_format (operation, "input", babl_format ("RGBA float"));
+ gegl_operation_set_format (operation, "output", babl_format ("RGBA float"));
+}
+
+static gboolean
+process (GeglOperation *operation,
+ void *in_buf,
+ void *out_buf,
+ glong n_pixels,
+ const GeglRectangle *roi)
+{
+ GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
+ gfloat *in_pixel = in_buf;
+ gfloat *out_pixel = out_buf;
+
+ GRand* noise_gr = g_rand_new();
+
+ gdouble amount = o->amount;
+ gdouble saturation = o->saturation;
+
+ while (n_pixels--)
+ {
+ gdouble noise[3];
+ gdouble monochrome;
+ gint c;
+ for (c=0; c<3; ++c)
+ noise[c] = g_rand_double_range(noise_gr, -1.0, 1.0);
+
+ monochrome = noise[0];
+ for (c=0; c<3; ++c)
+ noise[c] = saturation*(noise[c]-monochrome) + monochrome;
+
+ /* should these be clamped 0-1? */
+ for (c=0; c<3; ++c)
+ {
+ out_pixel[c] = in_pixel[c] + amount*noise[c];
+ out_pixel[c] = MAX(0.0, out_pixel[c]);
+ }
+
+ out_pixel[3] = in_pixel[3];
+
+ in_pixel += 4;
+ out_pixel += 4;
+ }
+
+ g_rand_free(noise_gr);
+
+ return TRUE;
+}
+
+
+static void
+gegl_chant_class_init (GeglChantClass *klass)
+{
+ GeglOperationClass *operation_class;
+ GeglOperationPointFilterClass *point_filter_class;
+
+ operation_class = GEGL_OPERATION_CLASS (klass);
+ point_filter_class = GEGL_OPERATION_POINT_FILTER_CLASS (klass);
+
+ point_filter_class->process = process;
+ operation_class->prepare = prepare;
+
+ operation_class->name = "gegl:add-noise";
+ operation_class->categories = "noise";
+ operation_class->description = _("Add Random noise");
+}
+
+#endif
--
1.7.0.4
_______________________________________________
Gegl-developer mailing list
Gegl-developer@xxxxxxxxxxxxxxxxxxxxxx
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gegl-developer
[Video For Linux]
[Photo]
[Yosemite News]
[Yosemite Photos]
[gtk]
[GIMP Users]
[KDE]
[Scanner]
[Gimp's Home]
[Gimp on Windows]
[Steve's Art]
[Webcams]