# [Gimp-developer] GEGL GSOC Application

• From: Sourav De <souravde1991 gmail com>
• To: gimp-developer-list gnome org
• Subject: [Gimp-developer] GEGL GSOC Application
• Date: Wed, 28 Mar 2012 04:31:27 +0530

Hi,

I am Sourav De, 3rd year undergraduate student of the department of Computer Science and Engineering at Indian Institute of Technology, Kharagpur. I'd like to participate in the GEGL implementation project for G'Soc 2012. I've applied for this last year too. I'm very interested in Computer Graphics, Image Processing and have done some project works on Artistic Rendition (basically on Image Segmentation, Object Detection, Stroke Orientation determination).

Code Review and Algorithmic Description of GIMP Plug-ins (Cubism, Fractal-trace, Plasma)

1. Cubism:-

cubism Function:
a) fill the image with its background colour.
b) calculate number of tiles and randomize indices for each of them.
c) initializes the source image rectangle.
d) for each tile calculate its width, height, rotational angle randomly using tile size and tile saturation values.
e) initialize a polygon for the corresponding tile and translate it to its starting indices after rotating.
f) clamp the polygon into the original image frame and fill it with corresponding source image colors.

fill_poly_color Function:
a) calculate distance between two points in the polygon, and define x & y vectors.
b) get the extreme positions of it by polygon_extents.
c) compute minimum and maximum number of scanlines for it.
d) for every 2 points computes the extent of their corresponding scanline segment.
d) assign color to each pixel by checking corresponding pixel value of the source image.

2. Fractal-trace:-

pixels_init Function:
a) allocate source and destination image rectangle, initialize the former row wise.

pixels_get_biliner Function:
a) return mean pixel value of 2*2 neighborhood.
pixels_store Function:
a) row wise store pixel values at the selection area.
mandelbrot Function:
a) iteratively calculate pixel coordinate.
filter Function:
a) for each pixel calculate its final position by mandelbrot function.
b) if the final position is inside the image assign corresponding pixel value.
c) else depending upon the outside type assign pixel value.
3. Plasma:-

plasma Function:
a) after initialization put seed pixels at each corner, at the center of each edge and at the center of the image.
c) keep doing plasma operation by recurse through the image to go further depths as much as possible.

do_plasma Function:
a) calculate the medians for each depth.
b) if depth=-1, generate random colors and put them at the corners and center of the image.
c) otherwise calculate average pixel value and for every pixel randomly increase it using the turbulance value.
d) recursively go to higher depths.

Code Review and Algorithmic Description of GEGL op Gaussian Blur:-

iir_young_find_constants Function:
a) prevent unexpected ringing at tile boundaries for different values of sigma parameter.

iir_young_blur_1D Function:
a) blurify image by applying one-dimentional forward and backward filter.

iir_young_hor_blur Function:
a) blurify image horizontally by applying iir_young_blur_1D filter horizontally.

iir_young_ver_blur Function:
a) blurify image vertically by applying iir_young_blur_1D filter vertically.

fir_gen_convolve_matrix Function:
a) compute matrix length for a given sigma.
b) generate the convolution matrix and perform convolution.

fir_hor_blur Function:
a) blurify padded(not vertically) image horizontally.

fir_ver_blur Function:
a) blurify padded(not horizontally) image vertically.
Basic Algorithm:
a) generate gaussian matrix for given sigma and median.
b) perform two way convolution with it.

Please find the attached patch file for alien-filter I've experimented with and let me know if there is any mistake in my code review or patch file. Thanking you,

--
Sourav De
Department of Computer Science and Engineering
IIT KHARAGPUR

```commit 9588f5aed0fc76ca6c13d0982fa669c58d825d8e
Author: Sourav De <souravde1991 gmail com>
Date:   Mon Mar 26 21:36:41 2012 +0530

Sourav Changes

diff --git a/operations/common/alien-map.c b/operations/common/alien-map.c
new file mode 100644
index 0000000..f947c2b
--- /dev/null
+++ b/operations/common/alien-map.c
@@ -0,0 +1,100 @@
+#include "config.h"
+#include <glib/gi18n-lib.h>
+
+#ifdef GEGL_CHANT_PROPERTIES
+
+gegl_chant_boolean (redMode, _("Modify Red Channel"), 1,_("blah blah"))
+gegl_chant_boolean (greenMode, _("Modify Green Channel"), 1,_("blah blah"))
+gegl_chant_boolean (blueMode, _("Modify Blue Channel"), 1,_("blah blah"))
+
+gegl_chant_double (redFrequency, _("Red Frequency"), 0.0, 20.0, 1.0,_("blah blah"))
+gegl_chant_double (redAngle, _("Red Phase Shift"), 0.0, 360.0, 0.0,_("blah blah"))
+gegl_chant_double (greenFrequency, _("Green Frequency"), 0.0, 20.0, 1.0,_("blah blah"))
+gegl_chant_double (greenAngle, _("Green Phase Shift"), 0.0, 360.0, 0.0,_("blah blah"))
+gegl_chant_double (blueFrequency, _("Blue Frequency"), 0.0, 20.0, 1.0,_("blah blah"))
+gegl_chant_double (blueAngle, _("Blue Phase Shift"), 0.0, 360.0, 0.0,_("blah blah"))
+
+#else
+#define GEGL_CHANT_TYPE_AREA_FILTER
+#define GEGL_CHANT_C_FILE "alien-map.c"
+
+#include "gegl-chant.h"
+#include <math.h>
+#include <stdio.h>
+
+static void alien_map_filter(GeglBuffer *src, const GeglRectangle *src_rect, GeglBuffer *dst,const GeglRectangle *dst_rect,GeglOperation *operation)
+{
+	gint x,y;
+  gfloat *src_buf;
+  gfloat *dst_buf;
+	gint src_width = src_rect->width;
+
+	GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
+
+  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 ("RGBA float"), src_buf, GEGL_AUTO_ROWSTRIDE);
+
+	for (y=0; y<dst_rect->height; y++)
+	{
+    for (x=0; x<dst_rect->width; x++)
+    {
+    	gint k = (x + y*src_width)*4;
+
+    	gfloat v1 = src_buf[k];
+    	gfloat v2 = src_buf[k+1];
+    	gfloat v3 = src_buf[k+2];
+
+    	if (o->redMode)
+				v1 = sin((v1 * o->redFrequency + o->redAngle / 180.0 ) * G_PI);
+
+			if (o->greenMode)
+				v2 = sin((v2 * o->greenFrequency + o->greenAngle / 180.0) * G_PI);
+
+			if (o->blueMode)
+				v3 = sin((v3 * o->blueFrequency + o->blueAngle / 180.0) * G_PI);
+
+    	dst_buf[k] = v1;
+    	dst_buf[k+1] = v2;
+    	dst_buf[k+2] = v3;
+    	dst_buf[k+3] = src_buf[k+3];
+    }
+  }
+
+	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 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, GeglBuffer *input, GeglBuffer *output, const GeglRectangle *result)
+{
+  GeglRectangle compute = gegl_operation_get_required_for_output (operation, "input",result);
+  alien_map_filter (input, &compute, output, result, operation);
+  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:alien-map";
+  operation_class->categories  = "misc";
+  operation_class->description = _("Alien Color Map");
+}
+
+#endif
```