On Wed, Apr 13, 2011 at 3:21 AM, sourav de <souravde1991@xxxxxxxxx> wrote:
I overlooked the option in GIMP to run GEGL operation. Now I have checked it, and it works.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
--
Sourav De
2nd Year Student
Department of Computer Science and Engineering
IIT KHARAGPUR
I've revised my code. It performs blur operation successfully.
Regards,
--
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 gegl_chant_int (radius, _("Radius"), 0, 50, 3, _("Blur Radius")) #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,gint radius); static inline void prepare(GeglOperation *operation) { GeglChantO *o = GEGL_CHANT_PROPERTIES (operation); GeglOperationAreaFilter *area = GEGL_OPERATION_AREA_FILTER (operation); area->left = area->right = area->top = area->bottom=o->radius; gegl_operation_set_format (operation, "input", babl_format ("RaGaBaA float")); gegl_operation_set_format (operation, "output", babl_format ("RaGaBaA float")); } static gboolean process (GeglOperation *operation, GeglBuffer *input, GeglBuffer *output, const GeglRectangle *result) { GeglChantO *o = GEGL_CHANT_PROPERTIES (operation); GeglRectangle rect; GeglOperationAreaFilter *op_area; op_area = GEGL_OPERATION_AREA_FILTER (operation); rect.x = result->x - op_area->left; rect.width = result->width + op_area->left + op_area->right; rect.y = result->y - op_area->top; rect.height = result->height + op_area->top + op_area->bottom; blur(input, &rect, output, result,o->radius); return TRUE; } static void blur (GeglBuffer *src,const GeglRectangle *src_rect,GeglBuffer *dst,const GeglRectangle *dst_rect,gint radius) { gint x,y; gint i,j; gint a,b; 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); gegl_buffer_get (src, 1.0, src_rect, babl_format ("RaGaBaA float"), src_buf, GEGL_AUTO_ROWSTRIDE); gint src_width=src_rect->width; offset=0; for(y=0; y<dst_rect->height; y++) { for (x=0; x<dst_rect->width; x++) { gfloat gradient[4] = {0.0f, 0.0f, 0.0f, 0.0f}; gint c; i=x+radius; j=y+radius; gfloat *src_pix = src_buf + (i + j * src_width) * 4; for (c=0;c<4;c++) { for (a = -radius; a <= radius; ++a) { for (b = -radius; b <= radius; ++b) { gradient[c]+= src_pix[c+a*src_width*4+4*b]; } } gradient[c]/=pow((radius * 2 + 1),2); } for (c=0; c<4;c++) dst_buf[offset*4+c] = gradient[c]; offset++; } } gegl_buffer_set (dst, dst_rect, babl_format ("RaGaBaA 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