gegl r2642 - in trunk: . bin



Author: ok
Date: Sun Oct 19 21:52:20 2008
New Revision: 2642
URL: http://svn.gnome.org/viewvc/gegl?rev=2642&view=rev

Log:
* bin/Makefile.am: build gegl-spiro if spiro is available.
* bin/gegl-spiro.c: file to initialize GeglVector with knowledge about
spiro knot types as well as logic to flatten a spiro path to a
piece-wize linear path (through beziers).
* bin/gegl-spiro.h: 
* bin/gegl.c: (main): initialize gegl-spiro


Added:
   trunk/bin/gegl-spiro.c
   trunk/bin/gegl-spiro.h
Modified:
   trunk/ChangeLog
   trunk/bin/Makefile.am
   trunk/bin/gegl.c

Modified: trunk/bin/Makefile.am
==============================================================================
--- trunk/bin/Makefile.am	(original)
+++ trunk/bin/Makefile.am	Sun Oct 19 21:52:20 2008
@@ -29,12 +29,18 @@
 	gegl-view.h
 endif
 
+
 gegl_SOURCES =			\
 	gegl.c			\
 	gegl-options.c		\
 	gegl-options.h		\
         $(gui_sources)
 
+
+if HAVE_GTK
+gegl_SOURCES += gegl-spiro.h gegl-spiro.c
+endif
+
 INCLUDES = \
 	-I$(top_srcdir)	-I$(top_srcdir)/gegl -I$(top_srcdir)/gegl/buffer \
 	-I$(top_srcdir)/gegl/property-types \
@@ -45,4 +51,4 @@
 
 AM_LDFLAGS =  \
 	-no-undefined ../gegl/libgegl- GEGL_API_VERSION@.la \
-	@DEP_LIBS@ @GTK_LIBS@ @BABL_LIBS@ @PNG_LIBS@
+	@DEP_LIBS@ @GTK_LIBS@ @BABL_LIBS@ @PNG_LIBS@ @LIBSPIRO@

Added: trunk/bin/gegl-spiro.c
==============================================================================
--- (empty file)
+++ trunk/bin/gegl-spiro.c	Sun Oct 19 21:52:20 2008
@@ -0,0 +1,174 @@
+/* This file is part of GEGL editor -- a gtk frontend for GEGL
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright (C) 2003, 2004, 2006, 2007, 2008 Ãyvind KolÃs
+ */
+
+#include "gegl-spiro.h"
+#include <gegl/gegl.h>
+#include "gegl-vector.h"
+
+#include <spiroentrypoints.h>
+
+struct {
+	/* Called by spiro to start a contour */
+    void (*moveto)(bezctx *bc, double x, double y, int is_open);
+
+	/* Called by spiro to move from the last point to the next one on a straight line */
+    void (*lineto)(bezctx *bc, double x, double y);
+
+	/* Called by spiro to move from the last point to the next along a quadratic bezier spline */
+	/* (x1,y1) is the quadratic bezier control point and (x2,y2) will be the new end point */
+    void (*quadto)(bezctx *bc, double x1, double y1, double x2, double y2);
+
+	/* Called by spiro to move from the last point to the next along a cubic bezier spline */
+	/* (x1,y1) and (x2,y2) are the two off-curve control point and (x3,y3) will be the new end point */
+    void (*curveto)(bezctx *bc, double x1, double y1, double x2, double y2,
+		    double x3, double y3);
+
+	/* I'm not entirely sure what this does -- I just leave it blank */
+    void (*mark_knot)(bezctx *bc, int knot_idx);
+    GeglVectorPath *path;
+} bezcontext;
+
+static void moveto (bezctx *bc, double x, double y, int is_open)
+{
+  bezcontext.path = gegl_vector_path_add1 (bezcontext.path, 'M', x, y);
+}
+static void lineto (bezctx *bc, double x, double y)
+{
+  bezcontext.path = gegl_vector_path_add1 (bezcontext.path, 'L', x, y);
+}
+static void quadto (bezctx *bc, double x1, double y1, double x2, double y2)
+{
+  g_print ("%s\n", G_STRFUNC);
+}
+static void curveto(bezctx *bc,
+                    double x1, double y1,
+                    double x2, double y2,
+ 		    double x3, double y3)
+{
+  bezcontext.path = gegl_vector_path_add3 (bezcontext.path, 'C', x1, y1, x2, y2, x3, y3);
+}
+
+static GeglVectorPath *gegl_vector_spiro_flatten (GeglVectorPath *original)
+{
+  GeglVectorPath *ret;
+  GeglVectorPath *iter;
+  spiro_cp *points;
+  gboolean is_spiro = TRUE;
+  gint count;
+  gint i;
+  /* first we do a run through the path checking it's length
+   * and determining whether we can flatten the incoming path
+   */
+  for (count=0,iter = original; iter; iter=iter->next)
+    {
+      switch (iter->d.type)
+        {
+          case 'v':
+          case 'o':
+          case 'O':
+          case '[':
+          case ']':
+          case 'z':
+          case '{':
+            break;
+          default:
+            is_spiro=FALSE;
+            break;
+        }
+      count ++;
+    }
+
+
+  if (!is_spiro)
+    {
+      return gegl_vector_path_flatten (original);
+    }
+
+
+  points = g_new0 (spiro_cp, count);
+  for (i=0, iter = original; iter; iter=iter->next, i++)
+    {
+      points[i].x = iter->d.point[0].x;
+      points[i].y = iter->d.point[0].y;
+      switch (iter->d.type)
+        {
+          case 'C':
+            points[i].x = iter->d.point[2].x;
+            points[i].y = iter->d.point[2].y;
+            points[i].ty = SPIRO_G4;
+            break;
+          case 'L':
+            points[i].ty = SPIRO_G4;
+            break;
+          case 'v':
+            points[i].ty = SPIRO_CORNER;
+            break;
+          case 'o':
+            points[i].ty = SPIRO_G4;
+            break;
+          case 'O':
+            points[i].ty = SPIRO_G2;
+            break;
+          case '[':
+            points[i].ty = SPIRO_LEFT;
+            break;
+          case ']':
+            points[i].ty = SPIRO_RIGHT;
+            break;
+          case 'z':
+            points[i].ty = SPIRO_END;
+            break;
+          case '{':
+            points[i].ty = SPIRO_OPEN_CONTOUR;
+            break;
+          /*case '}':
+            points[i].ty = SPIRO_END_CONTOUR;
+            break;*/
+          default:
+            points[i].ty = SPIRO_G4;
+            break;
+        }
+    }
+
+  bezcontext.moveto = moveto;
+  bezcontext.lineto = lineto;
+  bezcontext.curveto = curveto;
+  bezcontext.quadto = quadto;
+  bezcontext.path = NULL;
+  SpiroCPsToBezier(points,count, FALSE, (void*)&bezcontext);
+  g_free (points);
+
+  ret = gegl_vector_path_flatten (bezcontext.path);
+  /* XXX :free path */
+  return ret;
+}
+
+void gegl_spiro_init (void)
+{
+  static gboolean done = FALSE;
+  if (done)
+    return;
+  done = TRUE;
+  gegl_vector_add_knot_type ('v', 1, "spiro corner");
+  gegl_vector_add_knot_type ('o', 1, "spiro g4");
+  gegl_vector_add_knot_type ('O', 1, "spiro g2");
+  gegl_vector_add_knot_type ('[', 1, "spiro left");
+  gegl_vector_add_knot_type (']', 1, "spiro right");
+
+  gegl_vector_add_flattener (gegl_vector_spiro_flatten);
+}

Added: trunk/bin/gegl-spiro.h
==============================================================================
--- (empty file)
+++ trunk/bin/gegl-spiro.h	Sun Oct 19 21:52:20 2008
@@ -0,0 +1,7 @@
+#ifndef _GEGL_SPIRO__H
+#define _GEGL_SPIRO__H
+
+
+void gegl_spiro_init (void);
+
+#endif

Modified: trunk/bin/gegl.c
==============================================================================
--- trunk/bin/gegl.c	(original)
+++ trunk/bin/gegl.c	Sun Oct 19 21:52:20 2008
@@ -13,7 +13,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, see <http://www.gnu.org/licenses/>.
  *
- * Copyright (C) 2003, 2004, 2006 Ãyvind KolÃs
+ * Copyright (C) 2003, 2004, 2006, 2007, 2008 Ãyvind KolÃs
  */
 
 #include "config.h"
@@ -29,6 +29,9 @@
 
 #include "gegl-options.h"
 #include "gegl-dot.h"
+#ifdef HAVE_SPIRO
+#include "gegl-spiro.h"
+#endif
 
 #ifdef G_OS_WIN32
 #include <direct.h>
@@ -77,6 +80,9 @@
 
   o = gegl_options_parse (argc, argv);
   gegl_init (&argc, &argv);
+#ifdef HAVE_SPIRO
+  gegl_spiro_init ();
+#endif
 
   if (o->xml)
     {



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