[gimp/soc-2011-warp] gimpoperationwarp: make stamp round shapped



commit b3a35e016a5d29657fad5df664634ad77bfc57b8
Author: Michael Murà <batolettre gmail com>
Date:   Sat Jun 18 18:59:09 2011 +0200

    gimpoperationwarp: make stamp round shapped

 app/gegl/gimpoperationwarp.c |   32 +++++++++++++++++++++++++-------
 1 files changed, 25 insertions(+), 7 deletions(-)
---
diff --git a/app/gegl/gimpoperationwarp.c b/app/gegl/gimpoperationwarp.c
index 2b3d3bc..57f66af 100644
--- a/app/gegl/gimpoperationwarp.c
+++ b/app/gegl/gimpoperationwarp.c
@@ -23,6 +23,7 @@
 #include <gegl-buffer-iterator.h>
 
 #include "libgimpconfig/gimpconfig.h"
+#include "libgimpmath/gimpmath.h"
 
 #include "gimp-gegl-types.h"
 
@@ -52,9 +53,11 @@ static gboolean     gimp_operation_warp_process         (GeglOperation       *op
                                                          GeglBuffer          *in_buf,
                                                          GeglBuffer          *out_buf,
                                                          const GeglRectangle *roi);
-void                gimp_operation_warp_affect          (const GeglPathItem  *knot,
+static void         gimp_operation_warp_affect          (const GeglPathItem  *knot,
                                                          gpointer             data);
-
+static gdouble      gimp_operation_warp_get_influence   (GimpOperationWarp   *ow,
+                                                         gfloat               x,
+                                                         gfloat               y);
 
 G_DEFINE_TYPE (GimpOperationWarp, gimp_operation_warp,
                       GEGL_TYPE_OPERATION_FILTER)
@@ -208,9 +211,10 @@ gimp_operation_warp_affect (const GeglPathItem *knot,
 
   GeglBufferIterator  *it;
   Babl                *format;
+  gfloat               influence;
   gint                 x, y;
-  GeglRectangle        area = {knot->point->x - 20,
-                               knot->point->y - 20,
+  GeglRectangle        area = {knot->point->x - ow->size / 2.0,
+                               knot->point->y - ow->size / 2.0,
                                ow->size,
                                ow->size};
 
@@ -236,8 +240,12 @@ gimp_operation_warp_affect (const GeglPathItem *knot,
 
       while (n_pixels--)
         {
-          coords[0] += (ow->last_point.x - knot->point->x);
-          coords[1] += (ow->last_point.y - knot->point->y);
+          influence = gimp_operation_warp_get_influence (ow,
+                                                         x - knot->point->x,
+                                                         y - knot->point->y);
+
+          coords[0] += influence * (ow->last_point.x - knot->point->x);
+          coords[1] += influence * (ow->last_point.y - knot->point->y);
 
           coords += 2;
 
@@ -252,4 +260,14 @@ gimp_operation_warp_affect (const GeglPathItem *knot,
     }
 
   ow->last_point = *(knot->point);
-}
\ No newline at end of file
+}
+
+static gdouble
+gimp_operation_warp_get_influence (GimpOperationWarp *ow,
+                                   gfloat             x,
+                                   gfloat             y)
+{
+  gfloat radius = sqrt(x*x+y*y);
+
+  return (radius < ow->size / 2.0) ? ow->strength : 0.0;
+}



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