Re: [Gimp-developer] GEGL GSOC Application



Hi,

    the destPixVal should be
       destPixVal = 0.5 + 0.5 * sin((srcPixVal * frequency + angle / 180.0 ) * PI);

to keep it's value between 0 to 1. Sorry for my mistake. Please find the attached alien-map.c source file.


   Thanking you,


--
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 = 0.5 + 0.5*sin((v1 * o->redFrequency + o->redAngle / 180.0 ) * G_PI);
				
			if (o->greenMode)
				v2 = 0.5 + 0.5*sin((v2 * o->greenFrequency + o->greenAngle / 180.0) * G_PI);

			if (o->blueMode)
				v3 = 0.5 + 0.5*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]