On Tue, Apr 12, 2011 at 10:55 PM, sourav de <souravde1991@xxxxxxxxx> wrote:
On Thu, Apr 7, 2011 at 5:36 PM, Mukund Sivaraman <muks@xxxxxxxxxx> wrote:Hi Sourav
> +{
On Wed, Apr 06, 2011 at 09:44:31PM +0530, sourav de wrote:
> 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.
>
> +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;
Did this code work for you? Were you able to use this inside GEGL to
perform a blur?
You can help me review this code if you clean it up and comment it.
Mukund
Hi,
I changed the code little bit.
I placed the blur.c file in gegl-0.1.2/operations/common folder & followed these steps to compile GEGL.
1. configure
2. make
3. make install
it compiled successfully. But I don't know how to check whether it runs or not. Please help me finding this out & cleaning it up. Sorry for replying late.
--
Sourav De
2nd Year Student
Department of Computer Science and Engineering
IIT KHARAGPUR
I overlooked the option in GIMP to run GEGL operation. Now I have checked it, and it works.
--
Sourav De
2nd Year Student
Department of Computer Science and Engineering
IIT KHARAGPUR
#include "config.h" #include <glib/gi18n-lib.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 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; gint i,j; gfloat *src_buf,*dst_buf; gint offset; src_buf = g_new0 (gfloat, src_rect->width * src_rect->height * 4); dst_buf = g_new0 (gfloat, dst_rect->width * dst_rect->height * 4); gint src_width=src_rect->width; gegl_buffer_get (src, 1.0, src_rect, babl_format ("RGBA float"), src_buf, GEGL_AUTO_ROWSTRIDE); offset=0; for(y=0; y<dst_rect->height; y++) { for (x=0; x<dst_rect->width; x++) { gint c; 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]=lround( ((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 - 4] * 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
_______________________________________________ Gimp-developer mailing list Gimp-developer@xxxxxxxxxxxxxxxxxxxxxx https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer