potracelib.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 #include <stdlib.h>
00006 #include <string.h>
00007 
00008 #include "potracelib.h"
00009 #include "curve.h"
00010 #include "decompose.h"
00011 #include "trace.h"
00012 #include "progress.h"
00013 
00014 #ifdef HAVE_CONFIG_H
00015 #include "config.h"
00016 #endif
00017 
00018 /* default parameters */
00019 static const potrace_param_t param_default = {
00020   2,                             /* turdsize */
00021   POTRACE_TURNPOLICY_MINORITY,   /* turnpolicy */
00022   1.0,                           /* alphamax */
00023   1,                             /* opticurve */
00024   0.2,                           /* opttolerance */
00025   {
00026     NULL,                        /* callback function */
00027     NULL,                        /* callback data */
00028     0.0, 1.0,                    /* progress range */
00029     0.0,                         /* granularity */
00030   },
00031 };
00032 
00033 /* Return a fresh copy of the set of default parameters, or NULL on
00034    failure with errno set. */
00035 potrace_param_t *potrace_param_default(void) {
00036   potrace_param_t *p;
00037 
00038   p = (potrace_param_t *) malloc(sizeof(potrace_param_t));
00039   if (!p) {
00040     return NULL;
00041   }
00042   memcpy(p, &param_default, sizeof(potrace_param_t));
00043   return p;
00044 }
00045 
00046 /* On success, returns a Potrace state st with st->status ==
00047    POTRACE_STATUS_OK. On failure, returns NULL if no Potrace state
00048    could be created (with errno set), or returns an incomplete Potrace
00049    state (with st->status == POTRACE_STATUS_INCOMPLETE). Complete or
00050    incomplete Potrace state can be freed with potrace_state_free(). */
00051 potrace_state_t *potrace_trace(const potrace_param_t *param, const potrace_bitmap_t *bm) {
00052   int r;
00053   path_t *plist = NULL;
00054   potrace_state_t *st;
00055   progress_t prog;
00056   progress_t subprog;
00057   
00058   /* prepare private progress bar state */
00059   prog.callback = param->progress.callback;
00060   prog.data = param->progress.data;
00061   prog.min = param->progress.min;
00062   prog.max = param->progress.max;
00063   prog.epsilon = param->progress.epsilon;
00064   prog.d_prev = param->progress.min;
00065 
00066   /* allocate state object */
00067   st = (potrace_state_t *)malloc(sizeof(potrace_state_t));
00068   if (!st) {
00069     return NULL;
00070   }
00071 
00072   progress_subrange_start(0.0, 0.1, &prog, &subprog);
00073 
00074   /* process the image */
00075   r = bm_to_pathlist(bm, &plist, param, &subprog);
00076   if (r) {
00077     free(st);
00078     return NULL;
00079   }
00080 
00081   st->status = POTRACE_STATUS_OK;
00082   st->plist = plist;
00083   st->priv = NULL;  /* private state currently unused */
00084 
00085   progress_subrange_end(&prog, &subprog);
00086 
00087   progress_subrange_start(0.1, 1.0, &prog, &subprog);
00088 
00089   /* partial success. */
00090   r = process_path(plist, param, &subprog);
00091   if (r) {
00092     st->status = POTRACE_STATUS_INCOMPLETE;
00093   }
00094 
00095   progress_subrange_end(&prog, &subprog);
00096 
00097   return st;
00098 }
00099 
00100 /* free a Potrace state, without disturbing errno. */
00101 void potrace_state_free(potrace_state_t *st) {
00102   pathlist_free(st->plist);
00103   free(st);
00104 }
00105 
00106 /* free a parameter list, without disturbing errno. */
00107 void potrace_param_free(potrace_param_t *p) {
00108   free(p);
00109 }
00110 
00111 char *potrace_version(void) {
00112   return "potracelib "VERSION"";
00113 }
 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