gegl r2878 - in trunk: . bin gegl/property-types
- From: ok svn gnome org
- To: svn-commits-list gnome org
- Subject: gegl r2878 - in trunk: . bin gegl/property-types
- Date: Mon, 19 Jan 2009 01:09:03 +0000 (UTC)
Author: ok
Date: Mon Jan 19 01:09:03 2009
New Revision: 2878
URL: http://svn.gnome.org/viewvc/gegl?rev=2878&view=rev
Log:
* gegl/property-types/gegl-path.[ch]: made
(gegl_path_add_type): register the number of floats not the number of
float pairs for the type.
(gegl_path_get_node): write copy to a target argument instead of
returning internal pathinfo struct.
(gegl_path_type_get_n_items): added.
* bin/gegl-path-smooth.c: adapted to new API
* bin/gegl-path-spiro.c: adapted to new API
Modified:
trunk/ChangeLog
trunk/bin/gegl-path-smooth.c
trunk/bin/gegl-path-spiro.c
trunk/gegl/property-types/gegl-path.c
trunk/gegl/property-types/gegl-path.h
Modified: trunk/bin/gegl-path-smooth.c
==============================================================================
--- trunk/bin/gegl-path-smooth.c (original)
+++ trunk/bin/gegl-path-smooth.c Mon Jan 19 01:09:03 2009
@@ -159,6 +159,6 @@
return;
done = TRUE;
- gegl_path_add_type ('*', 1, "path");
+ gegl_path_add_type ('*', 2, "path");
gegl_path_add_flattener (gegl_path_smooth_flatten);
}
Modified: trunk/bin/gegl-path-spiro.c
==============================================================================
--- trunk/bin/gegl-path-spiro.c (original)
+++ trunk/bin/gegl-path-spiro.c Mon Jan 19 01:09:03 2009
@@ -172,12 +172,11 @@
if (done)
return;
done = TRUE;
- gegl_path_add_type ('v', 1, "spiro corner");
- gegl_path_add_type ('o', 1, "spiro g4");
- gegl_path_add_type ('O', 1, "spiro g2");
- gegl_path_add_type ('[', 1, "spiro left");
- gegl_path_add_type (']', 1, "spiro right");
-
+ gegl_path_add_type ('v', 2, "spiro corner");
+ gegl_path_add_type ('o', 2, "spiro g4");
+ gegl_path_add_type ('O', 2, "spiro g2");
+ gegl_path_add_type ('[', 2, "spiro left");
+ gegl_path_add_type (']', 2, "spiro right");
gegl_path_add_flattener (gegl_path_spiro_flatten);
}
Modified: trunk/gegl/property-types/gegl-path.c
==============================================================================
--- trunk/gegl/property-types/gegl-path.c (original)
+++ trunk/gegl/property-types/gegl-path.c Mon Jan 19 01:09:03 2009
@@ -59,7 +59,7 @@
typedef struct InstructionInfo
{
gchar type;
- gint pairs;
+ gint n_items;
gchar *name;
/* a flatten function pointer is kept for all stored InstructionInfo's but are only
@@ -85,13 +85,13 @@
static InstructionInfo knot_types[64]= /* reserve space for a total of up to 64 types of instructions. */
{
- {'M', 1, "move to", flatten_copy},
- {'L', 1, "line to", flatten_copy},
- {'C', 3, "curve to", flatten_curve},
-
- {'m', 1, "rel move to", flatten_rel_copy},
- {'l', 1, "rel line to", flatten_rel_copy},
- {'c', 3, "rel curve to", flatten_rel_copy},
+ {'M', 2, "move to", flatten_copy},
+ {'L', 2, "line to", flatten_copy},
+ {'C', 6, "curve to", flatten_curve},
+
+ {'m', 2, "rel move to", flatten_rel_copy},
+ {'l', 2, "rel line to", flatten_rel_copy},
+ {'c', 6, "rel curve to", flatten_rel_copy},
{'s', 0, "sentinel", flatten_nop},
{'z', 0, "sentinel", flatten_nop},
@@ -115,7 +115,7 @@
InstructionInfo *dst_info = lookup_instruction_info(dst->type);
gint i;
- for (i=0;i<dst_info->pairs;i++)
+ for (i=0;i<(dst_info->n_items+1)/2;i++)
{
gdouble x = dst->point[i].x;
gdouble y = dst->point[i].y;
@@ -125,26 +125,37 @@
}
}
+/* XXX: copy_data should exit for internal to external conversions */
+
static void copy_data (const GeglPathItem *src,
GeglPathItem *dst)
{
- InstructionInfo *src_info = lookup_instruction_info(src->type);
- InstructionInfo *dst_info = lookup_instruction_info(dst->type);
+ InstructionInfo *src_info;
+ InstructionInfo *dst_info;
gint i;
- g_assert (src_info->pairs <= dst_info->pairs);
+ if (!src)
+ return;
+
+ src_info = lookup_instruction_info(src->type);
+ dst_info = lookup_instruction_info(dst->type);
+
+/*
+ g_assert (src_info->pairs <= dst_info->pairs);*/
dst->type = src->type;
- for (i=0;i<src_info->pairs;i++)
+ for (i=0;i<(src_info->n_items+1)/2;i++)
{
dst->point[i].x = src->point[i].x;
dst->point[i].y = src->point[i].y;
}
}
+
+
void
gegl_path_add_type (gchar type,
- gint pairs,
+ gint n_items,
const gchar *name)
{
gint i;
@@ -155,7 +166,7 @@
return;
}
knot_types[i].type = type;
- knot_types[i].pairs = pairs;
+ knot_types[i].n_items = n_items;
knot_types[i].name = g_strdup (name);
knot_types[i].flatten = flatten_copy;
knot_types[i+1].type = '\0';
@@ -178,14 +189,14 @@
if (iter)
{
iter->next =
- g_slice_alloc0 (sizeof (gpointer) + sizeof (gchar) + sizeof (gfloat)*2 *info->pairs);
+ g_slice_alloc0 (sizeof (gpointer) + sizeof (gchar) + sizeof (gfloat)*2 *(info->n_items+1)/2);
iter->next->d.type = type;
iter = iter->next;
}
else /* creating new path */
{
head =
- g_slice_alloc0 (sizeof (gpointer) + sizeof (gchar) + sizeof (gfloat)*2 *info->pairs);
+ g_slice_alloc0 (sizeof (gpointer) + sizeof (gchar) + sizeof (gfloat)*2 *(info->n_items+1)/2);
head->d.type = type;
iter=head;
}
@@ -229,7 +240,7 @@
head = gegl_path_list_append_item (head, self->d.type, &newp, NULL);
copy_data (&self->d, &newp->d);
info = lookup_instruction_info (self->d.type);
- for (i=0;i<info->pairs;i++)
+ for (i=0;i<(info->n_items+1)/2;i++)
{
newp->d.point[i].x += prev->d.point[0].x;
newp->d.point[i].y += prev->d.point[0].y;
@@ -371,7 +382,7 @@
head = gegl_path_list_append_item (head, type, &iter, NULL);
iter->d.type = type;
- for (pair_no=0;pair_no<info->pairs;pair_no++)
+ for (pair_no=0;pair_no<(info->n_items+2)/2;pair_no++)
{
iter->d.point[pair_no].x = va_arg (var_args, gdouble);
iter->d.point[pair_no].y = va_arg (var_args, gdouble);
@@ -832,7 +843,8 @@
G_TYPE_NONE, /*return type */
1, G_TYPE_POINTER);
- gegl_path_add_type ('_', 1, "linear curve position associated value");
+ /* FIXME: should this just be 2 ? (and is this even currently in use?) */
+ gegl_path_add_type ('_', 2, "linear curve position associated value");
}
static void
@@ -1148,7 +1160,7 @@
InstructionInfo *info = lookup_instruction_info(iter->d.type);
g_string_append_c (str, iter->d.type);
- for (i=0;i<info->pairs;i++)
+ for (i=0;i<(info->n_items+1)/2;i++)
{
gchar buf[16];
gchar *eptr;
@@ -1158,13 +1170,20 @@
*eptr='\0';
if (*eptr=='.')
*eptr='\0';
- g_string_append_printf (str, "%s,", buf);
- sprintf (buf, "%f", iter->d.point[i].y);
+
+ /* FIXME: make this work better also for other odd count
+ * of n_items
+ */
+ if (info->n_items>1)
+ {
+ g_string_append_printf (str, "%s,", buf);
+ sprintf (buf, "%f", iter->d.point[i].y);
- for (eptr = &buf[strlen(buf)-1];eptr != buf && (*eptr=='0');eptr--)
- *eptr='\0';
- if (*eptr=='.')
- *eptr='\0';
+ for (eptr = &buf[strlen(buf)-1];eptr != buf && (*eptr=='0');eptr--)
+ *eptr='\0';
+ if (*eptr=='.')
+ *eptr='\0';
+ }
g_string_append_printf (str, "%s ", buf);
}
@@ -1238,27 +1257,30 @@
if (info)
{
- switch (info->pairs)
+ switch (info->n_items)
{
case 0:
priv->path = gegl_path_list_append (priv->path, type, x0, y0);
/* coordinates are ignored, all of these could have used add3)*/
break;
- case 1:
+ case 2:
p = parse_float_pair (p, &x0, &y0);
priv->path = gegl_path_list_append (priv->path, type, x0, y0);
continue;
- case 2:
+ case 4:
p = parse_float_pair (p, &x0, &y0);
p = parse_float_pair (p, &x1, &y1);
priv->path = gegl_path_list_append (priv->path, type, x0, y0, x1, y1);
continue;
- case 3:
+ case 6:
p = parse_float_pair (p, &x0, &y0);
p = parse_float_pair (p, &x1, &y1);
p = parse_float_pair (p, &x2, &y2);
priv->path = gegl_path_list_append (priv->path, type, x0, y0, x1, y1, x2, y2);
continue;
+ default:
+ g_warning ("parsing of data %i items not implemented\n", info->n_items);
+ continue;
}
previnfo = info;
}
@@ -1298,9 +1320,10 @@
}
-const GeglPathItem *
-gegl_path_get_node (GeglPath *vector,
- gint pos)
+gboolean
+gegl_path_get_node (GeglPath *vector,
+ gint index,
+ GeglPathItem *node)
{
GeglPathPrivate *priv = GEGL_PATH_GET_PRIVATE (vector);
GeglPathList *iter;
@@ -1309,15 +1332,19 @@
for (iter = priv->path; iter; iter=iter->next)
{
last=&iter->d;
- if (count == pos)
- return last;
+ if (count == index)
+ {
+ copy_data (last, node);
+ return TRUE;
+ }
count ++;
}
- if (pos==-1)
+ if (index==-1)
{
- return last;
+ copy_data (last, node);
+ return TRUE;
}
- return NULL;
+ return FALSE;
}
/* -1 means last */
@@ -1329,11 +1356,11 @@
static void gegl_path_item_free (GeglPathList *p)
{
InstructionInfo *info = lookup_instruction_info(p->d.type);
- g_slice_free1 (sizeof (gpointer) + sizeof (gchar) + sizeof (gfloat)*2 *info->pairs, p);
+ g_slice_free1 (sizeof (gpointer) + sizeof (gchar) + sizeof (gfloat)*2 * (info->n_items+1)/2, p);
}
void gegl_path_remove_node (GeglPath *vector,
- gint pos)
+ gint pos)
{
GeglPathPrivate *priv = GEGL_PATH_GET_PRIVATE (vector);
GeglPathList *iter;
@@ -1380,7 +1407,7 @@
{
if (count == pos)
{
- GeglPathList *new = g_slice_alloc0 (sizeof (gpointer) + sizeof (gchar) + sizeof (gfloat)*2 *info->pairs);
+ GeglPathList *new = g_slice_alloc0 (sizeof (gpointer) + sizeof (gchar) + sizeof (gfloat)*2 *(info->n_items+1)/2);
new->d.type=knot->type;
copy_data (knot, &new->d);
new->next = iter->next;
@@ -1397,7 +1424,7 @@
}
if (pos==-1)
{
- GeglPathList *new = g_slice_alloc0 (sizeof (gpointer) + sizeof (gchar) + sizeof (gfloat)*2 *info->pairs);
+ GeglPathList *new = g_slice_alloc0 (sizeof (gpointer) + sizeof (gchar) + sizeof (gfloat)*2 *(info->n_items+1)/2);
new->d.type = knot->type;
copy_data (knot, &new->d);
new->next = NULL;
@@ -1523,7 +1550,7 @@
priv->path = gegl_path_list_append_item (priv->path, type, &iter, ensure_tail(priv));
iter->d.type = type;
- for (pair_no=0;pair_no<info->pairs;pair_no++)
+ for (pair_no=0;pair_no < (info->n_items+1)/2;pair_no++)
{
iter->d.point[pair_no].x = va_arg (var_args, gdouble);
iter->d.point[pair_no].y = va_arg (var_args, gdouble);
@@ -2134,3 +2161,11 @@
if (gegl_buffer_is_shared (buffer))
gegl_buffer_unlock (buffer);
}
+
+gint gegl_path_type_get_n_items (gchar type)
+{
+ InstructionInfo *info = lookup_instruction_info (type);
+ if (!info)
+ return -1;
+ return info->n_items;
+}
Modified: trunk/gegl/property-types/gegl-path.h
==============================================================================
--- trunk/gegl/property-types/gegl-path.h (original)
+++ trunk/gegl/property-types/gegl-path.h Mon Jan 19 01:09:03 2009
@@ -152,15 +152,16 @@
/**
* gegl_path_get_node:
* @path: a #GeglPath
- * @pos: the node number to retrieve
+ * @index: the node number to retrieve
+ * @node: a pointer to a #GeglPathItem record to be written.
*
* Retrieve the node of the path at positiong @pos.
*
- * Return value: pointer to the node of the path at position @pos or NULL if no
- * such node.
+ * Returns TRUE if the node was succesfully retrieved.
*/
-const GeglPathItem * gegl_path_get_node (GeglPath *path,
- gint pos);
+gboolean gegl_path_get_node (GeglPath *path,
+ gint index,
+ GeglPathItem *node);
/**
* gegl_path_to_string:
@@ -397,14 +398,20 @@
#define GEGL_TYPE_PARAM_PATH (gegl_param_path_get_type ())
#define GEGL_IS_PARAM_PATH(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEGL_TYPE_PARAM_PATH))
GType gegl_param_path_get_type (void) G_GNUC_CONST;
+gint gegl_path_type_get_n_items (gchar type);
-
-/* add a new control point type to GeglPath, this new type works in everything
- * from the _add () functions (number of arguments determined automatically)
- * to the string parsing and serialization functions.
+/**
+ * gegl_path_add_type:
+ * @type: a gchar to recognize in path descriptions.
+ * @items: the number of floating point data items the instruction takes
+ * @description: a human readable description of this entry
+ *
+ * Adds a new type to the path system, FIXME this should probably
+ * return something on registration conflicts, for now it expects
+ * all registered paths to be aware of each other.
*/
void gegl_path_add_type (gchar type,
- gint pairs,
+ gint items,
const gchar *description);
/* Linked list used internally, and for the plug-in API for new path
@@ -421,7 +428,6 @@
/* frees up a path list */
GeglPathList * gegl_path_list_destroy (GeglPathList *path);
-
/* Add a new flattener, the flattener should produce a type of path that
* GeglPath already understands, if the flattener is unable to flatten
* the incoming path (doesn't understand the instructions), the original
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]