[gegl] ripple: Don't linearize buffer



commit 64aacbe3ae3e25b43ea3aa84b2fe160910cc59c4
Author: Daniel Sabo <DanielSabo gmail com>
Date:   Wed Mar 19 19:33:50 2014 -0700

    ripple: Don't linearize buffer

 operations/common/ripple.c |  109 ++++++++++++++++++++------------------------
 1 files changed, 50 insertions(+), 59 deletions(-)
---
diff --git a/operations/common/ripple.c b/operations/common/ripple.c
index 697ee54..bc1c269 100644
--- a/operations/common/ripple.c
+++ b/operations/common/ripple.c
@@ -95,71 +95,62 @@ process (GeglOperation       *operation,
          const GeglRectangle *result,
          gint                 level)
 {
-  GeglChantO *o                    = GEGL_CHANT_PROPERTIES (operation);
-
-  gint x = result->x; /* initial x                   */
-  gint y = result->y; /*           and y coordinates */
-
-  gfloat *dst_buf = g_slice_alloc (result->width * result->height * 4 * sizeof(gfloat));
-
-  gfloat *out_pixel = dst_buf;
-
-  GeglSampler *sampler = gegl_buffer_sampler_new (input,
-                                                  babl_format ("RGBA float"),
-                                                  o->sampler_type);
-
-  gint n_pixels = result->width * result->height;
+  GeglChantO         *o       = GEGL_CHANT_PROPERTIES (operation);
+  GeglSampler        *sampler = gegl_buffer_sampler_new (input,
+                                                         babl_format ("RGBA float"),
+                                                         o->sampler_type);
+  GeglBufferIterator *iter;
 
   GeglAbyssPolicy abyss = o->tileable ? GEGL_ABYSS_LOOP : GEGL_ABYSS_NONE;
 
-  while (n_pixels--)
+  iter = gegl_buffer_iterator_new (output, result, 0, babl_format ("RGBA float"),
+                                   GEGL_BUFFER_WRITE, GEGL_ABYSS_NONE);
+
+  while (gegl_buffer_iterator_next (iter))
     {
-      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);
-
-      switch (o->wave_type)
-        {
-          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;
-          case GEGl_RIPPLE_WAVE_TYPE_SINE:
-          default:
-            shift = o->amplitude * sin (2.0 * G_PI * nx / o->period + 2.0 * G_PI * o->phi);
-            break;
-        }
-
-      coordsx = x + shift * sin (angle_rad);
-      coordsy = y + shift * cos (angle_rad);
-
-      gegl_sampler_get (sampler,
-                        coordsx,
-                        coordsy,
-                        NULL,
-                        out_pixel,
-                        abyss);
-
-      out_pixel += 4;
-
-      /* update x and y coordinates */
-      x++;
-      if (x>=result->x + result->width)
-        {
-          x=result->x;
-          y++;
-        }
+      gint x = result->x;
+      gint y = result->y;
+      gfloat *out_pixel = iter->data[0];
+
+      for (y = iter->roi[0].y; y < iter->roi[0].y + iter->roi[0].height; ++y)
+        for (x = iter->roi[0].x; x < iter->roi[0].x + iter->roi[0].width; ++x)
+          {
+            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);
+
+            switch (o->wave_type)
+              {
+                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;
+                case GEGl_RIPPLE_WAVE_TYPE_SINE:
+                default:
+                  shift = o->amplitude * sin (2.0 * G_PI * nx / o->period + 2.0 * G_PI * o->phi);
+                  break;
+              }
+
+            coordsx = x + shift * sin (angle_rad);
+            coordsy = y + shift * cos (angle_rad);
+
+            gegl_sampler_get (sampler,
+                              coordsx,
+                              coordsy,
+                              NULL,
+                              out_pixel,
+                              abyss);
+
+            out_pixel += 4;
+          }
     }
 
-  gegl_buffer_set (output, result, 0, babl_format ("RGBA float"), dst_buf, GEGL_AUTO_ROWSTRIDE);
-  g_slice_free1 (result->width * result->height * 4 * sizeof(gfloat), dst_buf);
-
   g_object_unref (sampler);
 
   return  TRUE;


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