I tried to implement the blur operation in GEGL. The algorithm is same as of
the blur plug-in in GIMP. The patch file for GEGL operation and the blur.c
file for the plug-in are attached below. Kindly let me know if there is any
mistake in my implementation.

-- 
Sourav De
2nd Year Student
Department of Computer Science and Engineering
IIT KHARAGPUR
From 56ce24982d5ec4384ed4eb912d24b4018e9fff4d Mon Sep 17 00:00:00 2001
From: Sourav De <souravde1...@gmail.com>
Date: Wed, 6 Apr 2011 20:34:15 +0530
Subject: [PATCH] first commit in the branch

---
 blur.c |  122 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 122 insertions(+), 0 deletions(-)
 create mode 100644 blur.c

diff --git a/blur.c b/blur.c
new file mode 100644
index 0000000..e82109a
--- /dev/null
+++ b/blur.c
@@ -0,0 +1,122 @@
+#include "config.h"
+#include <string.h>
+
+#ifdef GEGL_CHANT_PROPERTIES
+
+#else
+
+#define GEGL_CHANT_TYPE_AREA_FILTER
+#define GEGL_CHANT_C_FILE  "blur.c"
+
+#include <gegl-chant.h>
+#include <math.h>
+#include <stdio.h>
+
+#define BLUR_RADIUS 1;
+
+static void blur(GeglBuffer *src,const GeglRectangle *src_rect,GeglBuffer *dst,const GeglRectangle *dst_rect);
+
+static inline void  blur_prepare(GeglOperation *operation)
+{
+GeglOperationAreaFilter *area = GEGL_OPERATION_AREA_FILTER (operation);
+area->left = area->right = area->top = area->bottom=BLUR_RADIUS;
+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, GeglBuffer *input, GeglBuffer *output, const GeglRectangle *result)
+{
+GeglChantO   *o = GEGL_CHANT_PROPERTIES (operation);
+GeglRectangle compute;
+compute = gegl_operation_get_required_for_output (operation, "input",result);
+blur(input, &compute, output, result);
+return TRUE;
+}
+
+
+static void blur (GeglBuffer *src,const GeglRectangle *src_rect,GeglBuffer *dst,const GeglRectangle *dst_rect)
+{
+gint x,y;
+gfloat *src_buf,*dst_buf;
+guchar       *prev_row, *pr;
+  guchar       *cur_row, *cr;
+  guchar       *next_row, *nr;
+gint ind,offset;
+
+gint width = src_rect->width;
+gint height = src_rect->height;
+
+src_buf = g_new0 (gfloat, src_rect->width * src_rect->height * 4);
+dst_buf = g_new0 (gfloat, dst_rect->width * dst_rect->height * 4);
+
+offset=0;
+for(y=0; y<dst_rect->height; y++)
+{
+for (x=0; x<dst_rect->width; x++)
+{
+
+gint c;
+gint i=x+BLUR_RADIUS, j=y+BLUR_RADIUS;
+gfloat *src_pix = src_buf + (i + j * src_width) * 4;
+
+for (c=0;c<3;c++)
+{
+dst_buf[offset*4+c]=ROUND(
+                           ((gdouble) (src_pix[c-src_width*4 - 4] * src_pix[c-src_width*4 - c])
+                            + (gdouble) (src_pix[c-src_width*4] * src_pix[c-src_width*4 + 4 - c])
+                            + (gdouble) (src_pix[c-src_width*4 + 4] * src_pix[c-src_width*4 + 2*4 - c])
+                            + (gdouble) (src_pix[c - bytes] * src_pix[c - c])
+                            + (gdouble) (src_pix[c] * src_pix[c + 4 - c])
+                            + (gdouble) (src_pix[c + 4] * src_pix[c + 2*4 - c])
+                            + (gdouble) (src_pix[c+src_width*4 - 4] * src_pix[c+src_width*4 - c])
+                            + (gdouble) (src_pix[c+src_width*4] * src_pix[c+src_width*4 + 4 - c])
+                            + (gdouble) (src_pix[c+src_width*4 + 4] * src_pix[c+src_width*4 + 2*4 - c]))
+                           / ((gdouble) src_pix[c-src_width*4 - c]
+                              + (gdouble) src_pix[c-src_width*4 + 4 - c]
+                              + (gdouble) src_pix[c-src_width*4 + 2*4 - c]
+                              + (gdouble) src_pix[c -c]
+                              + (gdouble) src_pix[c + 4 - c]
+                              + (gdouble) src_pix[c + 2*4 - c]
+                              + (gdouble) src_pix[c+src_width*4 - c]
+                              + (gdouble) src_pix[c+src_width*4 + 4 - c]
+                              + (gdouble) src_pix[c+src_width*4 + 2*4 - c]));
+
+}
+
+dst_buf[offset*4+3]= ((gint)src_pix[c-4-src_width*4]+(gint)src_pix[c-src_width*4]+(gint)src_pix[c+4-src_width*4] +
+	(gint)src_pix[c-4]+(gint)src_pix[c]+(gint)src_pix[c+4]+
+	(gint)src_pix[c-4+src_width*4]+(gint)src_pix[c+src_width*4]+(gint)src_pix[c+4+src_width*4]+4)/9;
+
+
+
+offset++;
+}
+
+}
+
+gegl_buffer_set (dst, dst_rect, babl_format ("RGBA float"), dst_buf,GEGL_AUTO_ROWSTRIDE);
+
+g_free (src_buf);
+g_free (dst_buf);
+
+}
+
+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->categories  = "blur";
+  operation_class->name        = "gegl:blur";
+  operation_class->description =
+       _("Performs an averaging of pixels.");
+}
+
+#endif
-- 
1.7.0.4

#include <gegl.h>

#include <glib/gprintf.h>

#include <time.h>

gint main (gint argc,gchar **argv)
{

g_thread_init (NULL);



gegl_init (&argc, &argv); 
{

GeglNode *gegl = gegl_node_new ();

GeglNode *load = gegl_node_new_child (gegl,"operation","gegl:load","path",argv[1],NULL);
GeglNode *blur = gegl_node_new_child (gegl,"operation","gegl:blur","radius",argv[2],NULL);
GeglNode *save = gegl_node_new_child (gegl,"operation","gegl:save","path", argv[3],NULL);

gegl_node_link_many (blur,save,NULL);
gegl_node_link(load,blur);

gegl_node_process (save);

g_object_unref (gegl);

}	

gegl_exit ();

return 0;

}
_______________________________________________
Gimp-developer mailing list
Gimp-developer@lists.XCF.Berkeley.EDU
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer

Reply via email to