4 cellwriter -- a character recognition input method
5 Copyright (C) 2007 Michael Levin <risujin@risujin.org>
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27 /* Maximum number of points a stroke can have */
28 #define POINTS_MAX 256
30 /* Scale of the point coordinates */
32 #define MAX_DIST 362 /* sqrt(2) * SCALE */
34 /* Maximum number of strokes a sample can have */
35 #define STROKES_MAX 32
37 /* Largest value the gluable matrix entries can take */
38 #define GLUABLE_MAX 255
48 int len, size, spread;
49 unsigned char processed,
50 gluable_start[STROKES_MAX], gluable_end[STROKES_MAX];
51 signed char min_x, max_x, min_y, max_y;
55 /* Stroke allocation */
56 Stroke *stroke_new(int size);
57 Stroke *stroke_clone(const Stroke *src, int reverse);
58 void stroke_free(Stroke *stroke);
59 void clear_stroke(Stroke *stroke);
61 /* Stroke manipulation */
62 void process_stroke(Stroke *stroke);
63 void draw_stroke(Stroke **stroke, int x, int y);
64 void smooth_stroke(Stroke *s);
65 void simplify_stroke(Stroke *s);
66 Stroke *sample_stroke(Stroke *out, Stroke *in, int points, int size);
67 void sample_strokes(Stroke *a, Stroke *b, Stroke **as, Stroke **bs);
68 void glue_stroke(Stroke **a, const Stroke *b, int reverse);
69 void dump_stroke(Stroke *stroke);
75 /* This will prevent the word frequency table from loading */
76 /* #define DISABLE_WORDFREQ */
78 /* Largest allowed engine weight */
81 /* Range of the scale value for engines */
82 #define ENGINE_SCALE STROKES_MAX
84 /* Minimum stroke spread distance for angle measurements */
85 #define DOT_SPREAD (SCALE / 10)
87 /* Maximum distance between glue points */
88 #define GLUE_DIST (SCALE / 6)
94 #ifndef DISABLE_WORDFREQ
103 int range, ignore_zeros, scale, average, max;
106 typedef struct Cell Cell;
108 /* Generalized measure function */
109 typedef float (*MeasureFunc)(Stroke *a, int i, Stroke *b, int j, void *extra);
111 extern int ignore_stroke_order, ignore_stroke_dir, ignore_stroke_num,
112 elasticity, no_latin_alpha, wordfreq_enable;
113 extern Engine engines[ENGINES];
115 void engine_average(void);
116 void engine_wordfreq(void);
117 void load_wordfreq(void);
118 float measure_distance(const Stroke *a, int i, const Stroke *b, int j,
120 float measure_strokes(Stroke *a, Stroke *b, MeasureFunc func,
121 void *extra, int points, int elasticity);
124 Samples and characters
127 /* Highest range a rating can have */
128 #define RATING_MAX 32767
129 #define RATING_MIN -32767
131 /* Maximum number of samples we can have per character */
132 #define SAMPLES_MAX 16
134 /* Fine sampling parameters */
135 #define FINE_RESOLUTION 8.f
136 #define FINE_ELASTICITY 2
138 /* Rough sampling parameters */
139 #define ROUGH_RESOLUTION 24.f
140 #define ROUGH_ELASTICITY 0
143 unsigned char valid, order[STROKES_MAX], reverse[STROKES_MAX],
152 short rating, ratings[ENGINES];
153 unsigned char enabled, disqualified, processed;
156 float distance, penalty;
157 Stroke *strokes[STROKES_MAX], *roughs[STROKES_MAX];
160 extern Sample *input;
161 extern int num_disqualified, training_block, samples_max;
163 /* Sample list iteration */
164 void sampleiter_reset(void);
165 Sample *sampleiter_next(void);
168 void process_sample(Sample *sample);
169 void center_samples(Vec2 *ac_to_bc, Sample *a, Sample *b);
170 int sample_disqualified(const Sample *sample);
171 int sample_valid(const Sample *sample, int used);
172 int char_trained(int ch);
173 int char_disabled(int ch);
176 void clear_sample(Sample *sample);
177 void recognize_sample(Sample *cell, Sample **alts, int num_alts);
178 void train_sample(const Sample *cell, int trusted);
179 void untrain_char(int ch);
180 void update_enabled_samples(void);
181 void promote_sample(Sample *sample);
182 void demote_sample(Sample *sample);
183 Stroke *transform_stroke(Sample *src, Transform *tfm, int i);