1
/* Copyright (C) 2001-2005 Peter Selinger.
2
This file is part of potrace. It is free software and it is covered
3
by the GNU General Public License. See the file COPYING for details. */
15
/* default parameters */
16
static const potrace_param_t param_default = {
18
POTRACE_TURNPOLICY_MINORITY, /* turnpolicy */
21
0.2, /* opttolerance */
23
NULL, /* callback function */
24
NULL, /* callback data */
25
0.0, 1.0, /* progress range */
26
0.0, /* granularity */
30
/* Return a fresh copy of the set of default parameters, or NULL on
31
failure with errno set. */
32
potrace_param_t *potrace_param_default() {
35
p = (potrace_param_t *) malloc(sizeof(potrace_param_t));
39
memcpy(p, ¶m_default, sizeof(potrace_param_t));
43
/* On success, returns a potrace state st with st->status ==
44
POTRACE_STATUS_OK. On failure, returns NULL if no potrace state
45
could be created (with errno set), or returns an incomplete potrace
46
state (with st->status == POTRACE_STATUS_INCOMPLETE). Complete or
47
incomplete potrace state can be freed with potrace_state_free(). */
48
potrace_state_t *potrace_trace(const potrace_param_t *param, const potrace_bitmap_t *bm) {
55
/* prepare private progress bar state */
56
prog.callback = param->progress.callback;
57
prog.data = param->progress.data;
58
prog.min = param->progress.min;
59
prog.max = param->progress.max;
60
prog.epsilon = param->progress.epsilon;
61
prog.d_prev = param->progress.min;
63
/* allocate state object */
64
st = (potrace_state_t *)malloc(sizeof(potrace_state_t *));
69
progress_subrange_start(0.0, 0.1, &prog, &subprog);
71
/* process the image */
72
r = bm_to_pathlist(bm, &plist, param, &subprog);
78
st->status = POTRACE_STATUS_OK;
81
progress_subrange_end(&prog, &subprog);
83
progress_subrange_start(0.1, 1.0, &prog, &subprog);
85
/* partial success. */
86
r = process_path(plist, param, &subprog);
88
st->status = POTRACE_STATUS_INCOMPLETE;
91
progress_subrange_end(&prog, &subprog);
96
/* free a potrace state, without disturbing errno. */
97
void potrace_state_free(potrace_state_t *st) {
98
pathlist_free(st->plist);
102
/* free a parameter list, without disturbing errno. */
103
void potrace_param_free(potrace_param_t *p) {
107
char *potrace_version() {
108
return "potracelib "VERSION"";