[gegl] ripple: coding style, cleanup
- From: Michael Murà <mmure src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl] ripple: coding style, cleanup
- Date: Sun, 4 Sep 2011 17:36:21 +0000 (UTC)
commit 0f112259a78ae00cca805f0eaf8ba5316979eb1b
Author: Michael Murà <batolettre gmail com>
Date: Fri Sep 2 12:11:37 2011 +0200
ripple: coding style, cleanup
operations/common/{ripple-test.c => ripple.c} | 77 +++++++++++-------------
1 files changed, 35 insertions(+), 42 deletions(-)
---
diff --git a/operations/common/ripple-test.c b/operations/common/ripple.c
similarity index 64%
rename from operations/common/ripple-test.c
rename to operations/common/ripple.c
index dc62973..2b5258d 100644
--- a/operations/common/ripple-test.c
+++ b/operations/common/ripple.c
@@ -4,21 +4,21 @@
#ifdef GEGL_CHANT_PROPERTIES
gegl_chant_int (amplitude, _("Amplitude"), 0, 200, 50,
- _("Amplitude of ripple."))
+ _("Amplitude of the ripple"))
gegl_chant_int (period, _("Period"), 0, 200, 50,
- _("Period of ripple."))
+ _("Period of the ripple"))
gegl_chant_double (phi, _("Phase Shift"), -1.0, 1.0, 0.0,
- _("As proportion of pi."))
+ _("Phase shift"))
-gegl_chant_boolean (antialias, _("Antialiasing"), FALSE,
+gegl_chant_boolean (antialias, _("Antialiasing"), FALSE,
_("Antialiasing"))
#else
#define GEGL_CHANT_TYPE_AREA_FILTER
-#define GEGL_CHANT_C_FILE "ripple-test.c"
+#define GEGL_CHANT_C_FILE "ripple.c"
#include "gegl-chant.h"
#include <stdio.h>
@@ -29,55 +29,53 @@ static gdouble
displace_amount (gint location, gint amplitude, gint period, gdouble phi)
{
return ((gdouble)amplitude *
- sin (2 * G_PI * (((gdouble)location / (gdouble)period) + G_PI*phi)));
+ sin (2 * G_PI * (((gdouble)location / (gdouble)period) + G_PI*phi)));
}
static void
horizontal_shift (GeglBuffer *src,
- const GeglRectangle *src_rect,
- GeglBuffer *dst,
- const GeglRectangle *dst_rect,
- gint amplitude,
- gint period,
- gdouble phi,
- gboolean antialias)
+ const GeglRectangle *src_rect,
+ GeglBuffer *dst,
+ const GeglRectangle *dst_rect,
+ gint amplitude,
+ gint period,
+ gdouble phi,
+ gboolean antialias)
{
gint u,v;
- gint src_offset, dst_offset;
- gfloat *src_buf;
- gfloat *dst_buf;
- 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_offset = 0;
+ gint dst_offset = 0;
+
+ gfloat *src_buf = g_new0 (gfloat, src_rect->width * src_rect->height * 4);
+ gfloat *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);
- src_offset = 0;
- dst_offset = 0;
+
for (v=0; v<dst_rect->height; v++)
{
gdouble shift = displace_amount(v+dst_rect->y, amplitude, period, phi);
gdouble floor_shift = floor(shift);
gdouble remainder = shift-floor_shift;
- gdouble temp_value;
-
+ gdouble acc;
+
for (u=0; u<(dst_rect->width); u++)
{
gint i;
-
+
for (i=0; i<4; i++)
{
gint new_pixel = src_offset + (4*amplitude + 4*amplitude*2*v + 4*(gint)floor_shift);
- //antialias
+ /* antialiasing */
-
- temp_value = src_buf[new_pixel];
+ acc = src_buf[new_pixel];
if(antialias && u>3 && i < 3)
{
gint upper_pixel = new_pixel - 4;
- temp_value = (remainder)*src_buf[new_pixel] + (1.0-remainder)*src_buf[upper_pixel];
-
+ acc = (remainder)*src_buf[new_pixel] + (1.0-remainder)*src_buf[upper_pixel];
}
-
- dst_buf[dst_offset] = temp_value;
+
+ dst_buf[dst_offset] = acc;
src_offset++;
dst_offset++;
}
@@ -97,10 +95,8 @@ static void prepare (GeglOperation *operation)
op_area = GEGL_OPERATION_AREA_FILTER (operation);
o = GEGL_CHANT_PROPERTIES (operation);
- op_area->left =
- op_area->right = o->amplitude;
- //op_area->top =
- //op_area->bottom =
+ op_area->left = o->amplitude;
+ op_area->right = o->amplitude;
gegl_operation_set_format (operation, "output",
babl_format ("RaGaBaA float"));
@@ -113,11 +109,9 @@ process (GeglOperation *operation,
GeglBuffer *output,
const GeglRectangle *result)
{
-
+ GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
+ GeglOperationAreaFilter *op_area = GEGL_OPERATION_AREA_FILTER (operation);
GeglRectangle rect;
- GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
- GeglOperationAreaFilter *op_area;
- op_area = GEGL_OPERATION_AREA_FILTER (operation);
rect = *result;
@@ -140,10 +134,9 @@ gegl_chant_class_init (GeglChantClass *klass)
filter_class->process = process;
operation_class->prepare = prepare;
- operation_class->categories = "blur";
- operation_class->name = "gegl:ripple-test";
- operation_class->description =
- _("Trying out GEGL.");
+ operation_class->categories = "transform";
+ operation_class->name = "gegl:ripple";
+ operation_class->description = _("Transform the buffer with a ripple pattern");
}
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]