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. */
5 #ifndef POTRACELIB_H
6 #define POTRACELIB_H
8 /* this file defines the API for the core potrace library. For a more
9 detailed description of the API, see doc/potracelib.txt */
11 /* ---------------------------------------------------------------------- */
12 /* tracing parameters */
14 /* turn policies */
15 #define POTRACE_TURNPOLICY_BLACK 0
16 #define POTRACE_TURNPOLICY_WHITE 1
17 #define POTRACE_TURNPOLICY_LEFT 2
18 #define POTRACE_TURNPOLICY_RIGHT 3
19 #define POTRACE_TURNPOLICY_MINORITY 4
20 #define POTRACE_TURNPOLICY_MAJORITY 5
21 #define POTRACE_TURNPOLICY_RANDOM 6
23 /* structure to hold progress bar callback data */
24 struct potrace_progress_s {
25 void (*callback)(double progress, void *privdata); /* callback fn */
26 void *data; /* callback function's private data */
27 double min, max; /* desired range of progress, e.g. 0.0 to 1.0 */
28 double epsilon; /* granularity: can skip smaller increments */
29 };
30 typedef struct potrace_progress_s potrace_progress_t;
32 /* structure to hold tracing parameters */
33 struct potrace_param_s {
34 int turdsize; /* area of largest path to be ignored */
35 int turnpolicy; /* resolves ambiguous turns in path decomposition */
36 double alphamax; /* corner threshold */
37 int opticurve; /* use curve optimization? */
38 double opttolerance; /* curve optimization tolerance */
39 potrace_progress_t progress; /* progress callback function */
40 };
41 typedef struct potrace_param_s potrace_param_t;
43 /* ---------------------------------------------------------------------- */
44 /* bitmaps */
46 /* native word size */
47 typedef unsigned long potrace_word;
49 /* Internal bitmap format. The n-th scanline starts at scanline(n) =
50 (map + n*dy). Raster data is stored as a sequence of potrace_words
51 (NOT bytes). The leftmost bit of scanline n is the most significant
52 bit of scanline(n)[0]. */
53 struct potrace_bitmap_s {
54 int w, h; /* width and height, in pixels */
55 int dy; /* words per scanline (not bytes) */
56 potrace_word *map; /* raw data, dy*h words */
57 };
58 typedef struct potrace_bitmap_s potrace_bitmap_t;
60 /* ---------------------------------------------------------------------- */
61 /* curves */
63 /* point */
64 struct potrace_dpoint_s {
65 double x, y;
66 };
67 typedef struct potrace_dpoint_s potrace_dpoint_t;
69 /* segment tags */
70 #define POTRACE_CURVETO 1
71 #define POTRACE_CORNER 2
73 /* closed curve segment */
74 struct potrace_curve_s {
75 int n; /* number of segments */
76 int *tag; /* tag[n]: POTRACE_CURVETO or POTRACE_CORNER */
77 potrace_dpoint_t (*c)[3]; /* c[n][3]: control points.
78 c[n][0] is unused for tag[n]=POTRACE_CORNER */
79 };
80 typedef struct potrace_curve_s potrace_curve_t;
82 /* Linked list of signed curve segments. Also carries a tree structure. */
83 struct potrace_path_s {
84 int area; /* area of the bitmap path */
85 int sign; /* '+' or '-', depending on orientation */
86 potrace_curve_t curve; /* this path's vector data */
88 struct potrace_path_s *next; /* linked list structure */
90 struct potrace_path_s *childlist; /* tree structure */
91 struct potrace_path_s *sibling; /* tree structure */
93 struct potrace_privpath_s *priv; /* private state */
94 };
95 typedef struct potrace_path_s potrace_path_t;
97 /* ---------------------------------------------------------------------- */
98 /* Potrace state */
100 #define POTRACE_STATUS_OK 0
101 #define POTRACE_STATUS_INCOMPLETE 1
103 struct potrace_state_s {
104 int status;
105 potrace_path_t *plist; /* vector data */
107 struct potrace_privstate_s *priv; /* private state */
108 };
109 typedef struct potrace_state_s potrace_state_t;
111 /* ---------------------------------------------------------------------- */
112 /* API functions */
114 /* get default parameters */
115 potrace_param_t *potrace_param_default();
117 /* free parameter set */
118 void potrace_param_free(potrace_param_t *p);
120 /* trace a bitmap*/
121 potrace_state_t *potrace_trace(const potrace_param_t *param,
122 const potrace_bitmap_t *bm);
124 /* free a potrace state */
125 void potrace_state_free(potrace_state_t *st);
127 /* return a static plain text version string identifying this version
128 of potracelib */
129 char *potrace_version();
131 #endif /* POTRACELIB_H */