Go to the documentation of this file.00001
00002
00003
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
00019 static const potrace_param_t param_default = {
00020 2,
00021 POTRACE_TURNPOLICY_MINORITY,
00022 1.0,
00023 1,
00024 0.2,
00025 {
00026 NULL,
00027 NULL,
00028 0.0, 1.0,
00029 0.0,
00030 },
00031 };
00032
00033
00034
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, ¶m_default, sizeof(potrace_param_t));
00043 return p;
00044 }
00045
00046
00047
00048
00049
00050
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
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
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
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;
00084
00085 progress_subrange_end(&prog, &subprog);
00086
00087 progress_subrange_start(0.1, 1.0, &prog, &subprog);
00088
00089
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
00101 void potrace_state_free(potrace_state_t *st) {
00102 pathlist_free(st->plist);
00103 free(st);
00104 }
00105
00106
00107 void potrace_param_free(potrace_param_t *p) {
00108 free(p);
00109 }
00110
00111 char *potrace_version(void) {
00112 return "potracelib "VERSION"";
00113 }