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