Re: [Gimp-developer] GEGL GSOC Application



Hi,

    Thank you for your compliment. Please find the attached alien-map.c source code which I build using GEGL-0.1.8 version. I've tested it, and it's working fine with my GIMP-2.7.5 version. Please tell me if it doesn't work for you or if there is some mistake in my implementation.

   Here goes my alien-map code review,


alien-map code review
a) for each pixel in the source image it checks for the red, green and blue mode
b) for each mode if its turned on,
set the pixel value of the corresponding channel of the pixel in destination image as,
destPixVal = sin((srcPixVal * frequency + angle / 180.0 ) * PI);
where frequency is the corresponding channel frequency,
                                and angle is the corresponding channel phase shift angle

the original GIMP operation was

destPixVal = ROUND (127.5 * (1.0 + sin (((srcPixVal / 127.5 - 1.0) * frequency + angle / 180.0) * PI)));

          where pixel values vary from 0 to 255, but using gfloat in GEGL these values can only vary between 0 to 1, so I changed the equation accordingly.


          Thanking you in anticipation of response,



--
Sourav De
3rd Year Undergraduate Student
Department of Computer Science and Engineering
IIT KHARAGPUR

#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


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]