Re: [Gimp-developer] Sample implementation of a new GEGL op
I've added comments in my code. If still there is anything to do, please let me know. -- Sourav De 2nd Year Student Department of Computer Science and Engineering IIT KHARAGPUR / * Blur: * * Blur applies a (2n+1)x(2n+1) blurring convolution kernel to the specified image. * * Where n is the blur radius specified by the user. * * This works only with RGB and grayscale images. * / #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 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; } /* * * blur() * * Actually mess with the image. * / 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; ydst_rect-height; y++) { for (x=0; xdst_rect-width; x++) { /* creates an array of length 4 first 3 elements are for Red, Green Blue channel last element is for no alpha channel */ 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; /*The parameter radius determines the size of the area of source pixels, that is averaged for each blurred destination pixel. */ for (c=0;c4;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); } /* transfers calculated average pixel values to the destination buffer */ for (c=0; c4;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@lists.XCF.Berkeley.EDU https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer
Re: [Gimp-developer] Sample implementation of a new GEGL op
On Wed, Apr 13, 2011 at 3:21 AM, sourav de souravde1...@gmail.com wrote: On Tue, Apr 12, 2011 at 10:55 PM, sourav de souravde1...@gmail.comwrote: On Thu, Apr 7, 2011 at 5:36 PM, Mukund Sivaraman m...@mukund.org 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 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
Re: [Gimp-developer] Sample implementation of a new GEGL op
On Thu, Apr 7, 2011 at 5:36 PM, Mukund Sivaraman m...@mukund.org 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 #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 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; ydst_rect-height; y++) { for (x=0; xdst_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;c3;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
Re: [Gimp-developer] Sample implementation of a new GEGL op
On Tue, Apr 12, 2011 at 10:55 PM, sourav de souravde1...@gmail.com wrote: On Thu, Apr 7, 2011 at 5:36 PM, Mukund Sivaraman m...@mukund.org 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; ydst_rect-height; y++) { for (x=0; xdst_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;c3;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
Re: [Gimp-developer] Sample implementation of a new GEGL op
On Thu, Apr 7, 2011 at 12:45 AM, Martin Nordholts ense...@gmail.com wrote: On 04/06/2011 06:14 PM, 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. Please attach the patch to GIMP bugzilla and reference the patch in your application. Regards, Martin -- My GIMP Blog: http://www.chromecode.com/ Why GIMP 2.8 is not released yet ___ Gimp-developer mailing list Gimp-developer@lists.XCF.Berkeley.EDU https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer Hi, I tried to submit the patch in bugzilla, but i was unable to create new account there for not getting any email containing confirmation link. I mailed bugmas...@gnome.org also, but in vain. -- Sourav De 2nd Year Student Department of Computer Science and Engineering IIT KHARAGPUR ___ Gimp-developer mailing list Gimp-developer@lists.XCF.Berkeley.EDU https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer
Re: [Gimp-developer] Sample implementation of a new GEGL op
On Thu, Apr 7, 2011 at 5:36 PM, Mukund Sivaraman m...@mukund.org 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 I've revised my code. It compiles and runs successfully. The patch is attached below. If still there is any mistake, kindly let me know it. -- Sourav De 2nd Year Student Department of Computer Science and Engineering IIT KHARAGPUR From 19d005775c6b49f3dbecec17eeaa606aa2a4f7b6 Mon Sep 17 00:00:00 2001 From: Sourav De souravde1...@gmail.com Date: Thu, 7 Apr 2011 20:42:21 +0530 Subject: [PATCH] first commit --- blur.c | 123 1 files changed, 123 insertions(+), 0 deletions(-) create mode 100644 blur.c diff --git a/blur.c b/blur.c new file mode 100644 index 000..b991310 --- /dev/null +++ b/blur.c @@ -0,0 +1,123 @@ +#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 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; ydst_rect-height; y++) +{ +for (x=0; xdst_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;c3;c++) +{ +dst_buf[offset*4+c]=lround( + ((gdouble) (src_pix[c-src_width*4 - 4] * src_pix[c-src_width*4 - c]) ++ (gdouble
[Gimp-developer] Sample implementation of a new GEGL op
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 000..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; ydst_rect-height; y++) +{ +for (x=0; xdst_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;c3;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
Re: [Gimp-developer] Write basic gegl plugin
On Tue, Apr 5, 2011 at 11:11 AM, Madhav yadav mad.cool.sp...@gmail.comwrote: If i have to submit my sample on the gegl master branch then how will i go forthh. On Mon, Apr 4, 2011 at 8:47 PM, Jon Nordby jono...@gmail.com wrote: Get the code, build it on your computer, start working on the plugin. On 4 April 2011 17:02, shivani maheshwari shivani.mah...@gmail.com wrote: Yes i did see that . But I am not able to gather where to begin from?? On Mon, Apr 4, 2011 at 8:09 PM, Tobias Jakobs tobias.jak...@googlemail.com wrote: Have you seen this page? http://wiki.gimp.org/index.php/Users:Beginner_Developer%27s_FAQ On Mon, Apr 4, 2011 at 16:32, Madhav yadav mad.cool.sp...@gmail.com wrote: Hello, I want to write basic gegl pluginCan anybody help me with the same.. ___ Gimp-developer mailing list Gimp-developer@lists.XCF.Berkeley.EDU https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer ___ Gimp-developer mailing list Gimp-developer@lists.XCF.Berkeley.EDU https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer -- Shivani Maheshwari Under Graduation( BTech.) Indian Institute of Information Technology, Allahabad (Amethi Campus) India ___ Gimp-developer mailing list Gimp-developer@lists.XCF.Berkeley.EDU https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer -- Jon Nordby - www.jonnor.com ___ Gimp-developer mailing list Gimp-developer@lists.XCF.Berkeley.EDU https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer ___ Gimp-developer mailing list Gimp-developer@lists.XCF.Berkeley.EDU https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer I'm also facing the same problem. After translating the code using GEGL operations, how am I supposed to create patch file of it and submit it into the master branch. -- Sourav De 2nd Year Student Department of Computer Science and Engineering IIT KHARAGPUR ___ Gimp-developer mailing list Gimp-developer@lists.XCF.Berkeley.EDU https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer
Re: [Gimp-developer] GSoC 2011 Porting GIMP plugins to GEGL operations
On Tue, Mar 29, 2011 at 11:57 PM, sourav de souravde1...@gmail.com wrote: On Tue, Mar 29, 2011 at 1:15 PM, sourav de souravde1...@gmail.com wrote: On Tue, Mar 29, 2011 at 4:11 AM, Mukund Sivaraman m...@banu.com wrote: Hi Sourav On Tue, Mar 29, 2011 at 12:36:04AM +0530, sourav de wrote: Hi, I am a 2nd year student of the department of Computer Science and Engineering at Indian Institute of Technology, Kharagpur ,and I am interested in the plugin for cartoonization of an image in GIMP. I gather you want to modify the cartoon plug-in in GIMP? The plug-in porting task that you have mentioned in the subject is to directly port GIMP plug-ins to GEGL ops. No modification of functionality is necessary. It is described here: http://gimp-wiki.who.ee/index.php?title=Hacking:GSoC_2011/Ideas#Porting_GIMP_plugins_to_GEGL_operations It is not a task of porting only 1 plug-in, but about 6-10 plug-ins per student. 1 plug-in is a very easy task and will not be sufficiently long for a full summer's work. To apply for this task, please present the items mentioned on the linked wiki page. However, if you wish to modify the cartoon plug-in, that sounds interesting too. It can be a different task. Can you describe what is lacking in the current approach in the GIMP plug-in? What is the algorithm that you plan to use ? You say you are doing a project on algorithmic art.. have you published anything on the methods you wish to use in this cartoon plug-in? Are you using any other published works? Note that we _may_ accomodate more tasks if they are of a high quality and we are satisfied with how the student presents it. Mukund Thank you sir, for your comments, I'll come up with the presentation of those plug-ins mentioned in the wiki page and algorithm for the cartoonization plug-in soon. And for the project on algorithmic art, I took this project in my current semester, I'll have to take the course Computer Graphics in my next semester to complete the project. So far I haven't yet publish any paper. -- Sourav De 2nd Year Student Department of Computer Science and Engineering IIT KHARAGPUR I wrote the code review for gaussian blur as it given here http://git.gnome.org/browse/gegl/tree/operations/common/gaussian-blur.c But I'm not familiar with writing code review and algorithmic description. Here goes my code review. ---code review starts here Gaussian blur operation code review: 1. function-1 : static void iir_young_find_constants (gfloat sigma,gdouble *B,gdouble *b) a. the variable sigma is to avoid unexpected ringing at tile boundaries of an image. b. there exists a variable q, whose value must be remained in between 0 - 1.5, and according to the value of sigma there are two procedures to calculate the value of q. c. lastly it sets the value of the variables b[0] to b[3] and B, and then returns. 2. function-2 : static inline void iir_young_blur_1D (gfloat * buf,gint offset,gint delta_offset,gdouble B,gdouble *b,gfloat * w,gint w_len) a. this function blurrifies an image one dimensionally. b. wlen is the length of the 1d array w passed. c. here an image would be blurrified in two steps, applying forward and backward filter for each pixel, a local variable wcount counts the number of pixels each time. d. the filter would be applied to the image according to the passed array w. 3. function-3 : static void iir_young_hor_blur (GeglBuffer *src,const GeglRectangle *src_rect,GeglBuffer *dst,const GeglRectangle *dst_rect,gdouble B,gdouble *b) a. this function blurrifies an image horizontally. b. first it creates an one dimensional array buf whose length is height*width*4, where height and width is height and width of the source image rectangle. c. then it creates another one dimensional array w with the length of the width of the source image. d. after then it fills the values of buf array according to the source image in RaGaBaA format. e. then it applies the iir_young_blur_1D function to the newly generated ractangles. f. lastly it stores the change in a destination array and returns. 4. function-4 : static void iir_young_ver_blur (GeglBuffer *src,const GeglRectangle *src_rect,GeglBuffer *dst,const GeglRectangle *dst_rect,gdouble B, gdouble *b) a. this function blurrifies an image vertically. b. first it creates an one dimensional array buf whose length is height*width*4, where height and width is height and width of the source image rectangle. c. then it creates another one dimensional array w with the length of the height of the source image. d. after then it fills the values of buf array according to the source image in RaGaBaA format. e. then it applies the iir_young_blur_1D function to the newly generated ractangles. f. lastly it stores the change in a destination array and returns. 5. function-5 : static gint fir_calc_convolve_matrix_length
Re: [Gimp-developer] GSoC 2011 Porting GIMP plugins to GEGL operations
On Tue, Mar 29, 2011 at 4:11 AM, Mukund Sivaraman m...@banu.com wrote: Hi Sourav On Tue, Mar 29, 2011 at 12:36:04AM +0530, sourav de wrote: Hi, I am a 2nd year student of the department of Computer Science and Engineering at Indian Institute of Technology, Kharagpur ,and I am interested in the plugin for cartoonization of an image in GIMP. I gather you want to modify the cartoon plug-in in GIMP? The plug-in porting task that you have mentioned in the subject is to directly port GIMP plug-ins to GEGL ops. No modification of functionality is necessary. It is described here: http://gimp-wiki.who.ee/index.php?title=Hacking:GSoC_2011/Ideas#Porting_GIMP_plugins_to_GEGL_operations It is not a task of porting only 1 plug-in, but about 6-10 plug-ins per student. 1 plug-in is a very easy task and will not be sufficiently long for a full summer's work. To apply for this task, please present the items mentioned on the linked wiki page. However, if you wish to modify the cartoon plug-in, that sounds interesting too. It can be a different task. Can you describe what is lacking in the current approach in the GIMP plug-in? What is the algorithm that you plan to use ? You say you are doing a project on algorithmic art.. have you published anything on the methods you wish to use in this cartoon plug-in? Are you using any other published works? Note that we _may_ accomodate more tasks if they are of a high quality and we are satisfied with how the student presents it. Mukund Thank you sir, for your comments, I'll come up with the presentation of those plug-ins mentioned in the wiki page and algorithm for the cartoonization plug-in soon. And for the project on algorithmic art, I took this project in my current semester, I'll have to take the course Computer Graphics in my next semester to complete the project. So far I haven't yet publish any paper. -- Sourav De 2nd Year Student Department of Computer Science and Engineering IIT KHARAGPUR ___ Gimp-developer mailing list Gimp-developer@lists.XCF.Berkeley.EDU https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer
Re: [Gimp-developer] GSoC 2011 Porting GIMP plugins to GEGL operations
On Tue, Mar 29, 2011 at 1:15 PM, sourav de souravde1...@gmail.com wrote: On Tue, Mar 29, 2011 at 4:11 AM, Mukund Sivaraman m...@banu.com wrote: Hi Sourav On Tue, Mar 29, 2011 at 12:36:04AM +0530, sourav de wrote: Hi, I am a 2nd year student of the department of Computer Science and Engineering at Indian Institute of Technology, Kharagpur ,and I am interested in the plugin for cartoonization of an image in GIMP. I gather you want to modify the cartoon plug-in in GIMP? The plug-in porting task that you have mentioned in the subject is to directly port GIMP plug-ins to GEGL ops. No modification of functionality is necessary. It is described here: http://gimp-wiki.who.ee/index.php?title=Hacking:GSoC_2011/Ideas#Porting_GIMP_plugins_to_GEGL_operations It is not a task of porting only 1 plug-in, but about 6-10 plug-ins per student. 1 plug-in is a very easy task and will not be sufficiently long for a full summer's work. To apply for this task, please present the items mentioned on the linked wiki page. However, if you wish to modify the cartoon plug-in, that sounds interesting too. It can be a different task. Can you describe what is lacking in the current approach in the GIMP plug-in? What is the algorithm that you plan to use ? You say you are doing a project on algorithmic art.. have you published anything on the methods you wish to use in this cartoon plug-in? Are you using any other published works? Note that we _may_ accomodate more tasks if they are of a high quality and we are satisfied with how the student presents it. Mukund Thank you sir, for your comments, I'll come up with the presentation of those plug-ins mentioned in the wiki page and algorithm for the cartoonization plug-in soon. And for the project on algorithmic art, I took this project in my current semester, I'll have to take the course Computer Graphics in my next semester to complete the project. So far I haven't yet publish any paper. -- Sourav De 2nd Year Student Department of Computer Science and Engineering IIT KHARAGPUR I wrote the code review for gaussian blur as it given here http://git.gnome.org/browse/gegl/tree/operations/common/gaussian-blur.c But I'm not familiar with writing code review and algorithmic description. Here goes my code review. ---code review starts here Gaussian blur operation code review: 1. function-1 : static void iir_young_find_constants (gfloat sigma,gdouble *B,gdouble *b) a. the variable sigma is to avoid unexpected ringing at tile boundaries of an image. b. there exists a variable q, whose value must be remained in between 0 - 1.5, and according to the value of sigma there are two procedures to calculate the value of q. c. lastly it sets the value of the variables b[0] to b[3] and B, and then returns. 2. function-2 : static inline void iir_young_blur_1D (gfloat * buf,gint offset,gint delta_offset,gdouble B,gdouble *b,gfloat * w,gint w_len) a. this function blurrifies an image one dimensionally. b. wlen is the length of the 1d array w passed. c. here an image would be blurrified in two steps, applying forward and backward filter for each pixel, a local variable wcount counts the number of pixels each time. d. the filter would be applied to the image according to the passed array w. 3. function-3 : static void iir_young_hor_blur (GeglBuffer *src,const GeglRectangle *src_rect,GeglBuffer *dst,const GeglRectangle *dst_rect,gdouble B,gdouble *b) a. this function blurrifies an image horizontally. b. first it creates an one dimensional array buf whose length is height*width*4, where height and width is height and width of the source image rectangle. c. then it creates another one dimensional array w with the length of the width of the source image. d. after then it fills the values of buf array according to the source image in RaGaBaA format. e. then it applies the iir_young_blur_1D function to the newly generated ractangles. f. lastly it stores the change in a destination array and returns. 4. function-4 : static void iir_young_ver_blur (GeglBuffer *src,const GeglRectangle *src_rect,GeglBuffer *dst,const GeglRectangle *dst_rect,gdouble B, gdouble *b) a. this function blurrifies an image vertically. b. first it creates an one dimensional array buf whose length is height*width*4, where height and width is height and width of the source image rectangle. c. then it creates another one dimensional array w with the length of the height of the source image. d. after then it fills the values of buf array according to the source image in RaGaBaA format. e. then it applies the iir_young_blur_1D function to the newly generated ractangles. f. lastly it stores the change in a destination array and returns. 5. function-5 : static gint fir_calc_convolve_matrix_length (gdouble sigma) a. depending upon the value of sigma it returns an integer which partially determines the width and height
[Gimp-developer] GSoC 2011 Porting GIMP plugins to GEGL operations
Hi, I am a 2nd year student of the department of Computer Science and Engineering at Indian Institute of Technology, Kharagpur ,and I am interested in the plugin for cartoonization of an image in GIMP. I have begun to use GIMP some years ago for image editing in ubuntu os (as a substitute of photoshop ), but I’m currently using it for my project on algorithmic art, so this would be a huge opportunity to be able to participate in GSoC. So for the algorithm to implement this plugin, i thought that we need to do this in a step by step manner, like first blur the image to remove noise from it, then improve the clearness of the outline with some threshold, detect the main outlines and then finally fill the regions inside those main borders by picking up an suitable color by comparing it with the original image. As per as the current cartoonization plugin of the Gimp is concerned,the mask radius option can be used to determine the degree of the blurriness, and the percentage black option as to choose the value of upper and lower threshold. Besides there should be options like choosing the scale of the transformation user want to use to cartoonize an image, etc. -- Sourav De 2nd Year Student Department of Computer Science and Engineering IIT KHARAGPUR ___ Gimp-developer mailing list Gimp-developer@lists.XCF.Berkeley.EDU https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer