[gimp] app: add gimp_bezier_desc_new_from_bound_segs() to GimpBezierDesc



commit eda5cdf6662fd87e309bc4922dde239ddef51882
Author: Michael Natterer <mitch gimp org>
Date:   Mon Apr 4 22:06:32 2011 +0200

    app: add gimp_bezier_desc_new_from_bound_segs() to GimpBezierDesc
    
    and remove that code from gimpbrush-boundary.c

 app/core/gimpbezierdesc.c     |  101 ++++++++++++++++++++++++++++++++++++++
 app/core/gimpbezierdesc.h     |   18 +++++--
 app/core/gimpbrush-boundary.c |  107 ++++------------------------------------
 3 files changed, 124 insertions(+), 102 deletions(-)
---
diff --git a/app/core/gimpbezierdesc.c b/app/core/gimpbezierdesc.c
index a21608e..79850d5 100644
--- a/app/core/gimpbezierdesc.c
+++ b/app/core/gimpbezierdesc.c
@@ -25,6 +25,8 @@
 
 #include "core-types.h"
 
+#include "base/boundary.h"
+
 #include "gimpbezierdesc.h"
 
 
@@ -58,6 +60,105 @@ gimp_bezier_desc_new (cairo_path_data_t *data,
   return desc;
 }
 
+static void
+add_polyline (GArray            *path_data,
+              const GimpVector2 *points,
+              guint              n_points)
+{
+  GimpVector2       prev = { 0.0, 0.0, };
+  cairo_path_data_t pd;
+  gint              i;
+
+  for (i = 0; i < n_points; i++)
+    {
+      /* compress multiple identical coordinates */
+      if (i == 0 ||
+          prev.x != points[i].x ||
+          prev.y != points[i].y)
+        {
+          pd.header.type   = (i == 0) ? CAIRO_PATH_MOVE_TO : CAIRO_PATH_LINE_TO;
+          pd.header.length = 2;
+
+          g_array_append_val (path_data, pd);
+
+          pd.point.x = points[i].x;
+          pd.point.y = points[i].y;
+
+          g_array_append_val (path_data, pd);
+
+          prev = points[i];
+        }
+    }
+
+  /* close the polyline */
+  pd.header.type   = CAIRO_PATH_CLOSE_PATH;
+  pd.header.length = 1;
+
+  g_array_append_val (path_data, pd);
+}
+
+GimpBezierDesc *
+gimp_bezier_desc_new_from_bound_segs (BoundSeg *bound_segs,
+                                      gint      n_bound_segs,
+                                      gint      n_bound_groups)
+{
+  GArray      *path_data;
+  GimpVector2 *points;
+  gint         n_points;
+  gint         seg;
+  gint         i;
+
+  g_return_val_if_fail (bound_segs != NULL, NULL);
+  g_return_val_if_fail (n_bound_segs > 0, NULL);
+
+  path_data = g_array_new (FALSE, FALSE, sizeof (cairo_path_data_t));
+
+  points = g_new0 (GimpVector2, n_bound_segs + 4);
+
+  seg = 0;
+  n_points = 0;
+
+  points[n_points].x = (gdouble) (bound_segs[0].x1);
+  points[n_points].y = (gdouble) (bound_segs[0].y1);
+
+  n_points++;
+
+  for (i = 0; i < n_bound_groups; i++)
+    {
+      while (bound_segs[seg].x1 != -1 ||
+             bound_segs[seg].x2 != -1 ||
+             bound_segs[seg].y1 != -1 ||
+             bound_segs[seg].y2 != -1)
+        {
+          points[n_points].x = (gdouble) (bound_segs[seg].x1);
+          points[n_points].y = (gdouble) (bound_segs[seg].y1);
+
+          n_points++;
+          seg++;
+        }
+
+      /* Close the stroke points up */
+      points[n_points] = points[0];
+
+      n_points++;
+
+      add_polyline (path_data, points, n_points);
+
+      n_points = 0;
+      seg++;
+
+      points[n_points].x = (gdouble) (bound_segs[seg].x1);
+      points[n_points].y = (gdouble) (bound_segs[seg].y1);
+
+      n_points++;
+    }
+
+  g_free (points);
+
+  return gimp_bezier_desc_new ((cairo_path_data_t *) g_array_free (path_data, FALSE),
+                               path_data->len);
+}
+
 GimpBezierDesc *
 gimp_bezier_desc_copy (const GimpBezierDesc *desc)
 {
diff --git a/app/core/gimpbezierdesc.h b/app/core/gimpbezierdesc.h
index a5f26d3..3acbc14 100644
--- a/app/core/gimpbezierdesc.h
+++ b/app/core/gimpbezierdesc.h
@@ -22,16 +22,22 @@
 #define __GIMP_BEZIER_DESC_H__
 
 
-#define             GIMP_TYPE_BEZIER_DESC     (gimp_bezier_desc_get_type ())
+#define          GIMP_TYPE_BEZIER_DESC     (gimp_bezier_desc_get_type ())
 
-GType               gimp_bezier_desc_get_type (void) G_GNUC_CONST;
+GType            gimp_bezier_desc_get_type (void) G_GNUC_CONST;
 
 
 /* takes ownership of "data" */
-GimpBezierDesc    * gimp_bezier_desc_new      (cairo_path_data_t    *data,
-                                               gint                  n_data);
-GimpBezierDesc    * gimp_bezier_desc_copy     (const GimpBezierDesc *desc);
-void                gimp_bezier_desc_free     (GimpBezierDesc       *desc);
+GimpBezierDesc * gimp_bezier_desc_new                 (cairo_path_data_t    *data,
+                                                       gint                  n_data);
+
+/* expects sorted BoundSegs */
+GimpBezierDesc * gimp_bezier_desc_new_from_bound_segs (BoundSeg             *bound_segs,
+                                                       gint                  n_bound_segs,
+                                                       gint                  n_bound_groups);
+
+GimpBezierDesc * gimp_bezier_desc_copy                (const GimpBezierDesc *desc);
+void             gimp_bezier_desc_free                (GimpBezierDesc       *desc);
 
 
 #endif /* __GIMP_BEZIER_DESC_H__ */
diff --git a/app/core/gimpbrush-boundary.c b/app/core/gimpbrush-boundary.c
index 0adbcac..ac64b92 100644
--- a/app/core/gimpbrush-boundary.c
+++ b/app/core/gimpbrush-boundary.c
@@ -31,43 +31,6 @@
 #include "gimpbrush-boundary.h"
 
 
-static void
-add_polyline (GArray            *path_data,
-              const GimpVector2 *points,
-              guint              n_points)
-{
-  GimpVector2       prev = { 0.0, 0.0, };
-  cairo_path_data_t pd;
-  gint              i;
-
-  for (i = 0; i < n_points; i++)
-    {
-      /* compress multiple identical coordinates */
-      if (i == 0 ||
-          prev.x != points[i].x ||
-          prev.y != points[i].y)
-        {
-          pd.header.type   = (i == 0) ? CAIRO_PATH_MOVE_TO : CAIRO_PATH_LINE_TO;
-          pd.header.length = 2;
-
-          g_array_append_val (path_data, pd);
-
-          pd.point.x = points[i].x;
-          pd.point.y = points[i].y;
-
-          g_array_append_val (path_data, pd);
-
-          prev = points[i];
-        }
-    }
-
-  /* close the polyline */
-  pd.header.type   = CAIRO_PATH_CLOSE_PATH;
-  pd.header.length = 1;
-
-  g_array_append_val (path_data, pd);
-}
-
 static GimpBezierDesc *
 gimp_brush_transform_boundary_exact (GimpBrush *brush,
                                      gdouble    scale,
@@ -82,12 +45,12 @@ gimp_brush_transform_boundary_exact (GimpBrush *brush,
 
   if (mask)
     {
-      PixelRegion   maskPR;
-      BoundSeg     *bound_segs;
-      gint          n_bound_segs;
-      BoundSeg     *stroke_segs;
-      gint          n_stroke_segs;
-      GArray       *path_data;
+      PixelRegion     maskPR;
+      BoundSeg       *bound_segs;
+      gint            n_bound_segs;
+      BoundSeg       *stroke_segs;
+      gint            n_stroke_groups;
+      GimpBezierDesc *path;
 
       pixel_region_init_temp_buf (&maskPR, mask,
                                   0, 0, mask->width, mask->height);
@@ -102,68 +65,20 @@ gimp_brush_transform_boundary_exact (GimpBrush *brush,
       if (! bound_segs)
         return NULL;
 
-      stroke_segs = boundary_sort (bound_segs, n_bound_segs, &n_stroke_segs);
+      stroke_segs = boundary_sort (bound_segs, n_bound_segs, &n_stroke_groups);
 
       g_free (bound_segs);
 
       if (! stroke_segs)
         return NULL;
 
-      path_data = g_array_new (FALSE, FALSE, sizeof (cairo_path_data_t));
-
-      {
-        GimpVector2 *points;
-        gint         n_points;
-        gint         seg;
-        gint         i;
-
-        points = g_new0 (GimpVector2, n_bound_segs + 4);
-
-        seg = 0;
-        n_points = 0;
-
-        points[n_points].x = (gdouble) (stroke_segs[0].x1);
-        points[n_points].y = (gdouble) (stroke_segs[0].y1);
-
-        n_points++;
-
-        for (i = 0; i < n_stroke_segs; i++)
-          {
-            while (stroke_segs[seg].x1 != -1 ||
-                   stroke_segs[seg].x2 != -1 ||
-                   stroke_segs[seg].y1 != -1 ||
-                   stroke_segs[seg].y2 != -1)
-              {
-                points[n_points].x = (gdouble) (stroke_segs[seg].x1);
-                points[n_points].y = (gdouble) (stroke_segs[seg].y1);
-
-                n_points++;
-                seg++;
-              }
-
-            /* Close the stroke points up */
-            points[n_points] = points[0];
-
-            n_points++;
-
-            add_polyline (path_data, points, n_points);
-
-            n_points = 0;
-            seg++;
-
-            points[n_points].x = (gdouble) (stroke_segs[seg].x1);
-            points[n_points].y = (gdouble) (stroke_segs[seg].y1);
-
-            n_points++;
-          }
-
-        g_free (points);
-      }
+      path = gimp_bezier_desc_new_from_bound_segs (stroke_segs,
+                                                   n_bound_segs,
+                                                   n_stroke_groups);
 
       g_free (stroke_segs);
 
-      return gimp_bezier_desc_new ((cairo_path_data_t *) g_array_free (path_data, FALSE),
-                                   path_data->len);
+      return path;
     }
 
   return NULL;



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