curve.c
Go to the documentation of this file.
00001 /* Copyright (C) 2001-2007 Peter Selinger.
00002    This file is part of Potrace. It is free software and it is covered
00003    by the GNU General Public License. See the file COPYING for details. */
00004 
00005 /* $Id: curve.c 147 2007-04-09 00:44:09Z selinger $ */
00006 /* private part of the path and curve data structures */
00007 
00008 #include <stdio.h>
00009 #include <stdlib.h>
00010 #include <string.h>
00011 
00012 #include "potracelib.h"
00013 #include "lists.h"
00014 #include "curve.h"
00015 
00016 #define SAFE_MALLOC(var, n, typ) \
00017   if ((var = (typ *)malloc((n)*sizeof(typ))) == NULL) goto malloc_error 
00018 
00019 /* ---------------------------------------------------------------------- */
00020 /* allocate and free path objects */
00021 
00022 path_t *path_new(void) {
00023   path_t *p = NULL;
00024   privpath_t *priv = NULL;
00025 
00026   SAFE_MALLOC(p, 1, path_t);
00027   memset(p, 0, sizeof(path_t));
00028   SAFE_MALLOC(priv, 1, privpath_t);
00029   memset(priv, 0, sizeof(privpath_t));
00030   p->priv = priv;
00031   return p;
00032 
00033  malloc_error:
00034   free(p);
00035   free(priv);
00036   return NULL;
00037 }
00038 
00039 /* free the members of the given curve structure. Leave errno unchanged. */
00040 static void privcurve_free_members(privcurve_t *curve) {
00041   free(curve->tag);
00042   free(curve->c);
00043   free(curve->vertex);
00044   free(curve->alpha);
00045   free(curve->alpha0);
00046   free(curve->beta);
00047 }
00048 
00049 /* free a path. Leave errno untouched. */
00050 void path_free(path_t *p) {
00051   if (p) {
00052     if (p->priv) {
00053       free(p->priv->pt);
00054       free(p->priv->lon);
00055       free(p->priv->sums);
00056       free(p->priv->po);
00057       privcurve_free_members(&p->priv->curve);
00058       privcurve_free_members(&p->priv->ocurve);
00059     }
00060     free(p->priv);
00061     /* do not free p->fcurve ! */
00062   }
00063   free(p);
00064 }  
00065 
00066 /* free a pathlist, leaving errno untouched. */
00067 void pathlist_free(path_t *plist) {
00068   path_t *p;
00069 
00070   list_forall_unlink(p, plist) {
00071     path_free(p);
00072   }
00073 }
00074 
00075 /* ---------------------------------------------------------------------- */
00076 /* initialize and finalize curve structures */
00077 
00078 typedef dpoint_t dpoint3_t[3];
00079 
00080 /* initialize the members of the given curve structure to size m.
00081    Return 0 on success, 1 on error with errno set. */
00082 int privcurve_init(privcurve_t *curve, int n) {
00083   memset(curve, 0, sizeof(privcurve_t));
00084   curve->n = n;
00085   SAFE_MALLOC(curve->tag, n, int);
00086   SAFE_MALLOC(curve->c, n, dpoint3_t);
00087   SAFE_MALLOC(curve->vertex, n, dpoint_t);
00088   SAFE_MALLOC(curve->alpha, n, double);
00089   SAFE_MALLOC(curve->alpha0, n, double);
00090   SAFE_MALLOC(curve->beta, n, double);
00091   return 0;
00092 
00093  malloc_error:
00094   free(curve->tag);
00095   free(curve->c);
00096   free(curve->vertex);
00097   free(curve->alpha);
00098   free(curve->alpha0);
00099   free(curve->beta);
00100   return 1;
00101 }
00102 
00103 /* copy private to public curve structure */
00104 void privcurve_to_curve(privcurve_t *pc, potrace_curve_t *c) {
00105   c->n = pc->n;
00106   c->tag = pc->tag;
00107   c->c = pc->c;
00108 }
00109     
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines


portrait_painter
Author(s): Niklas Meinzer, Ina Baumgarten
autogenerated on Wed Dec 26 2012 16:00:43