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