[gegl] ripple: add sawtooth wave type using an enum property
- From: Michael Murà <mmure src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl] ripple: add sawtooth wave type using an enum property
- Date: Sun, 4 Sep 2011 17:37:32 +0000 (UTC)
commit 4447d8deadb553057571116651f9f00f5959dc92
Author: Michael Murà <batolettre gmail com>
Date: Sun Sep 4 19:11:30 2011 +0200
ripple: add sawtooth wave type using an enum property
gegl/gegl-enums.c | 15 +++++++++++++++
gegl/gegl-enums.h | 12 ++++++++++++
operations/workshop/ripple.c | 30 +++++++++++++++++++++++++-----
3 files changed, 52 insertions(+), 5 deletions(-)
---
diff --git a/gegl/gegl-enums.c b/gegl/gegl-enums.c
index acfd319..57cefdc 100644
--- a/gegl/gegl-enums.c
+++ b/gegl/gegl-enums.c
@@ -26,6 +26,21 @@ gegl_sampler_type_get_type (void)
return etype;
}
+GType
+gegl_ripple_wave_type_get_type (void)
+{
+ static GType etype = 0;
+ if (etype == 0) {
+ static const GEnumValue values[] = {
+ { GEGl_RIPPLE_WAVE_TYPE_SINE, "sine", "sine" },
+ { GEGl_RIPPLE_WAVE_TYPE_SAWTOOTH, "sawtooth", "sawtooth" },
+ { 0, NULL, NULL }
+ };
+ etype = g_enum_register_static ("GeglRippleWaveType", values);
+ }
+ return etype;
+}
+
/* Generated data ends here */
diff --git a/gegl/gegl-enums.h b/gegl/gegl-enums.h
index 9bc8242..a20bfef 100644
--- a/gegl/gegl-enums.h
+++ b/gegl/gegl-enums.h
@@ -41,6 +41,18 @@ typedef enum {
GType gegl_sampler_type_get_type (void) G_GNUC_CONST;
#define GEGL_TYPE_SAMPLER_TYPE (gegl_sampler_type_get_type())
+/*
+ * Operation specific enum
+ */
+
+typedef enum {
+ GEGl_RIPPLE_WAVE_TYPE_SINE,
+ GEGl_RIPPLE_WAVE_TYPE_SAWTOOTH
+} GeglRippleWaveType;
+GType gegl_ripple_wave_type_get_type (void) G_GNUC_CONST;
+#define GEGL_RIPPLE_WAVE_TYPE (gegl_ripple_wave_type_get_type())
+
+
G_END_DECLS
#endif /* __GEGL_ENUMS_H__ */
\ No newline at end of file
diff --git a/operations/workshop/ripple.c b/operations/workshop/ripple.c
index d40d296..8e45be2 100644
--- a/operations/workshop/ripple.c
+++ b/operations/workshop/ripple.c
@@ -39,6 +39,9 @@ gegl_chant_double (angle, _("Angle"), -180.0, 180.0, 0.0,
gegl_chant_enum (sampler_type, _("Sampler"), GeglSamplerType, GEGL_TYPE_SAMPLER_TYPE,
GEGL_SAMPLER_CUBIC, _("Sampler used internaly"))
+gegl_chant_enum (wave_type, _("Wave type"), GeglRippleWaveType, GEGL_RIPPLE_WAVE_TYPE,
+ GEGl_RIPPLE_WAVE_TYPE_SINE, _("Type of wave"))
+
#else
#define GEGL_CHANT_TYPE_AREA_FILTER
@@ -47,6 +50,7 @@ gegl_chant_enum (sampler_type, _("Sampler"), GeglSamplerType, GEGL_TYPE_SAMPLER_
#include "gegl-chant.h"
#include <stdio.h>
#include <math.h>
+#include <stdlib.h>
static void prepare (GeglOperation *operation)
{
@@ -90,14 +94,30 @@ process (GeglOperation *operation,
while (n_pixels--)
{
- gdouble angle_rad = o->angle / 180.0 * G_PI;
+ gdouble shift;
+ gdouble coordsx;
+ gdouble coordsy;
+ gdouble lambda;
+ gdouble angle_rad = o->angle / 180.0 * G_PI;
gdouble nx = x * cos (angle_rad) + y * sin (angle_rad);
- gdouble shift = o->amplitude * sin (2.0 * G_PI * nx / o->period + 2.0 * G_PI * o->phi);
+ switch (o->wave_type)
+ {
+ case GEGl_RIPPLE_WAVE_TYPE_SINE:
+ shift = o->amplitude * sin (2.0 * G_PI * nx / o->period + 2.0 * G_PI * o->phi);
+ break;
+
+ case GEGl_RIPPLE_WAVE_TYPE_SAWTOOTH:
+ lambda = div (nx,o->period).rem - o->phi * o->period;
+ if (lambda < 0)
+ lambda += o->period;
+ shift = o->amplitude * (fabs (((lambda / o->period) * 4) - 2) - 1);
+ break;
+ }
- gdouble coordsx = x + shift * sin (angle_rad);
- gdouble coordsy = y + shift * cos (angle_rad);
+ coordsx = x + shift * sin (angle_rad);
+ coordsy = y + shift * cos (angle_rad);
gegl_sampler_get (sampler,
coordsx,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]