[gimp/soc-2011-warp] gimpwarptool: proof of concept code to act on the coords buffer



commit 2b41c59823ef686588ea661754b5bdc2c63c7457
Author: Michael Muré <batolettre gmail com>
Date:   Wed May 25 21:40:47 2011 +0200

    gimpwarptool: proof of concept code to act on the coords buffer

 app/tools/gimpwarptool.c |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 46 insertions(+), 0 deletions(-)
---
diff --git a/app/tools/gimpwarptool.c b/app/tools/gimpwarptool.c
index 868f114..aed2a85 100644
--- a/app/tools/gimpwarptool.c
+++ b/app/tools/gimpwarptool.c
@@ -102,6 +102,9 @@ static void       gimp_warp_tool_create_image_map   (GimpWarpTool          *wt,
 static void       gimp_warp_tool_image_map_flush    (GimpImageMap          *image_map,
                                                      GimpTool              *tool);
 static void       gimp_warp_tool_image_map_update   (GimpWarpTool          *wt);
+static void       gimp_warp_tool_act_on_coords      (GimpWarpTool          *wt,
+                                                     gint                   x,
+                                                     gint                   y);
 
 G_DEFINE_TYPE (GimpWarpTool, gimp_warp_tool, GIMP_TYPE_DRAW_TOOL)
 
@@ -348,6 +351,7 @@ gimp_warp_tool_button_press (GimpTool            *tool,
   if (display != tool->display)
     gimp_warp_tool_start (wt, display);
 
+  gimp_warp_tool_act_on_coords (wt, coords->x, coords->y);
   gimp_warp_tool_image_map_update (wt);
 
   gimp_tool_control_activate (tool->control);
@@ -496,3 +500,45 @@ gimp_warp_tool_image_map_update (GimpWarpTool *wt)
 
   gimp_image_map_apply (wt->image_map, &visible);
 }
+
+static void
+gimp_warp_tool_act_on_coords (GimpWarpTool *wt,
+                              gint x,
+                              gint y)
+{
+  GeglBufferIterator  *it;
+  Babl                *format;
+  GeglRectangle        area = {x - 30,
+                               y - 30,
+                               60,
+                               60};
+
+  format = babl_format_n (babl_type ("float"), 2);
+  it = gegl_buffer_iterator_new (wt->coords_buffer, &area, format, GEGL_BUFFER_READWRITE);
+
+  while (gegl_buffer_iterator_next (it))
+    {
+      /* iterate inside the roi */
+      gint    n_pixels = it->length;
+      gfloat *coords   = it->data[0];
+
+      x = it->roi->x; /* initial x         */
+      y = it->roi->y; /* and y coordinates */
+
+      while (n_pixels--)
+        {
+          coords[0] += 2;
+          coords[1] += 2;
+
+          coords += 2;
+
+          /* update x and y coordinates */
+          x++;
+          if (x >= (it->roi->x + it->roi->width))
+            {
+              x = it->roi->x;
+              y++;
+            }
+        }
+    }
+}



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