Debian Codegraph @

converter/other/pamtosvg/autotrace.h

raw symbols SCIP
1 /* autotrace.h --- Autotrace API
2
3 Copyright (C) 2000, 2001, 2002 Martin Weber
4
5 The author can be contacted at <[email protected]>
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
20
21 #ifndef AUTOTRACE_H
22 #define AUTOTRACE_H
23
24 #include <stdio.h>
25
26 #include "point.h"
27 #include "pm_c_util.h"
28 #include "ppm.h"
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif /* __cplusplus */
33
34 /* ===================================================================== *
35 * Typedefs
36 * ===================================================================== */
37
38 typedef struct _at_fitting_opts_type at_fitting_opts_type;
39 typedef struct _at_input_opts_type at_input_opts_type;
40 typedef struct _at_output_opts_type at_output_opts_type;
41 typedef struct _at_bitmap_type at_bitmap_type;
42 typedef struct _at_spline_type at_spline_type;
43 typedef struct _at_spline_list_type at_spline_list_type;
44 typedef struct _at_spline_list_array_type at_spline_list_array_type;
45
46 /* Third degree is the highest we deal with. */
47 typedef enum _at_polynomial_degree
48 {
49 AT_LINEARTYPE = 1,
50 AT_QUADRATICTYPE = 2,
51 AT_CUBICTYPE = 3,
52 AT_PARALLELELLIPSETYPE = 4,
53 AT_ELLIPSETYPE = 5,
54 AT_CIRCLETYPE = 6
55 /* not the real number of points to define a
56 circle but to distinguish between a cubic spline */
57 } at_polynomial_degree;
58
59 /* A Bezier spline can be represented as four points in the real plane:
60 a starting point, ending point, and two control points. The
61 curve always lies in the convex hull defined by the four points. It
62 is also convenient to save the divergence of the spline from the
63 straight line defined by the endpoints. */
64 struct _at_spline_type
65 {
66 Point v[4]; /* The control points. */
67 at_polynomial_degree degree;
68 float linearity;
69 };
70
71 /* Each outline in a character is typically represented by many
72 splines. So, here is a list structure for that: */
73 struct _at_spline_list_type
74 {
75 at_spline_type *data;
76 unsigned length;
77 bool clockwise;
78 pixel color;
79 bool open;
80 };
81
82 /* Each character is in general made up of many outlines. So here is one
83 more list structure. */
84 struct _at_spline_list_array_type
85 {
86 at_spline_list_type *data;
87 unsigned length;
88
89 /* splines bbox */
90 unsigned short height, width;
91
92 /* the values for following members are inherited from
93 at_fitting_opts_type */
94 bool backgroundSpec;
95 pixel background_color;
96 bool centerline;
97 bool preserve_width;
98 float width_weight_factor;
99
100 };
101
102
103 /* Fitting option.
104 With using at_fitting_opts_doc macro, the description of
105 each option could be get. e.g. at_fitting_opts_doc(background_color) */
106 struct _at_fitting_opts_type {
107 bool backgroundSpec;
108 pixel background_color;
109 float corner_always_threshold;
110 unsigned corner_surround;
111 float corner_threshold;
112 float error_threshold;
113 unsigned filter_iterations;
114 float line_reversion_threshold;
115 float line_threshold;
116 bool remove_adjacent_corners;
117 unsigned tangent_surround;
118 bool centerline;
119 bool preserve_width;
120 float width_weight_factor;
121 };
122
123 struct _at_output_opts_type
124 {
125 int dpi; /* DPI is used only in MIF output.*/
126 };
127
128 struct _at_bitmap_type
129 {
130 unsigned short height;
131 unsigned short width;
132 unsigned char *bitmap;
133 unsigned int np;
134 };
135
136 typedef enum _at_msg_type
137 {
138 AT_MSG_FATAL = 1,
139 AT_MSG_WARNING
140 } at_msg_type;
141
142 typedef
143 void (* at_msg_func) (const char * const msg,
144 at_msg_type const msg_type,
145 void * const client_data);
146
147 typedef
148 int (*at_output_write_func) (FILE * const file,
149 const char * const name,
150 int const llx,
151 int const lly,
152 int const urx,
153 int const ury,
154 at_output_opts_type * const opts,
155 at_spline_list_array_type const shape,
156 at_msg_func msg_func,
157 void * const msg_data);
158
159 /*
160 * Progress handler typedefs
161 * 0.0 <= percentage <= 1.0
162 */
163 typedef
164 void (*at_progress_func) (float const percentage,
165 void * const client_data);
166
167 /*
168 * Test cancel
169 * Return true if auto-tracing should be stopped.
170 */
171 typedef
172 bool (*at_testcancel_func) (void * const client_data);
173
174 /* ===================================================================== *
175 * Functions
176 * ===================================================================== */
177
178 /* --------------------------------------------------------------------- *
179 * Fitting option related
180 *
181 * TODO: internal data access, copy
182 * --------------------------------------------------------------------- */
183 at_fitting_opts_type * at_fitting_opts_new(void);
184 at_fitting_opts_type * at_fitting_opts_copy (at_fitting_opts_type * original);
185 void at_fitting_opts_free(at_fitting_opts_type * opts);
186
187 /* TODO: Gettextize */
188 #define at_fitting_opts_doc(opt) _(at_doc__##opt)
189
190 /* --------------------------------------------------------------------- *
191 * Output option related
192 *
193 * TODO: internal data access
194 * --------------------------------------------------------------------- */
195 at_output_opts_type * at_output_opts_new(void);
196 at_output_opts_type * at_output_opts_copy(at_output_opts_type * original);
197 void at_output_opts_free(at_output_opts_type * opts);
198
199 /* --------------------------------------------------------------------- *
200 * Spline related
201 *
202 * TODO: internal data access
203 * --------------------------------------------------------------------- */
204 /* at_splines_new_full
205
206 args:
207
208 NOTIFY_PROGRESS is called repeatedly inside at_splines_new_full
209 to notify the progress of the execution. This might be useful for
210 interactive applications. NOTIFY_PROGRESS is called following
211 format:
212
213 NOTIFY_PROGRESS (percentage, progress_data);
214
215 test_cancel is called repeatedly inside at_splines_new_full
216 to test whether the execution is canceled or not.
217 If test_cancel returns TRUE, execution of at_splines_new_full
218 is stopped as soon as possible and returns NULL. If test_cancel
219 returns FALSE, nothing happens. test_cancel is called following
220 format:
221
222 TEST_CANCEL (testcancel_data);
223
224 NULL is valid value for notify_progress and/or test_cancel if
225 you don't need to know the progress of the execution and/or
226 cancel the execution */
227
228 at_spline_list_array_type *
229 at_splines_new_full(at_bitmap_type * const bitmap,
230 at_fitting_opts_type * const opts,
231 at_msg_func msg_func,
232 void * const msg_data,
233 at_progress_func notify_progress,
234 void * const progress_data,
235 at_testcancel_func test_cancel,
236 void * const testcancel_data);
237
238 void
239 at_splines_write(at_output_write_func output_writer,
240 FILE * const writeto,
241 at_output_opts_type * const opts,
242 at_spline_list_array_type * const splines,
243 at_msg_func msg_func,
244 void * const msg_data);
245
246 void
247 at_splines_free(at_spline_list_array_type * const splines);
248
249
250 /* --------------------------------------------------------------------- *
251 * Misc
252 * --------------------------------------------------------------------- */
253
254 #ifdef __cplusplus
255 }
256 #endif /* __cplusplus */
257
258 #endif