• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  **	Filename:    intproto.h
3  **	Purpose:     Definition of data structures for integer protos.
4  **	Author:      Dan Johnson
5  **	History:     Thu Feb  7 12:58:45 1991, DSJ, Created.
6  **
7  **	(c) Copyright Hewlett-Packard Company, 1988.
8  ** Licensed under the Apache License, Version 2.0 (the "License");
9  ** you may not use this file except in compliance with the License.
10  ** You may obtain a copy of the License at
11  ** http://www.apache.org/licenses/LICENSE-2.0
12  ** Unless required by applicable law or agreed to in writing, software
13  ** distributed under the License is distributed on an "AS IS" BASIS,
14  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  ** See the License for the specific language governing permissions and
16  ** limitations under the License.
17  ******************************************************************************/
18 #ifndef INTPROTO_H
19 #define INTPROTO_H
20 
21 /**----------------------------------------------------------------------------
22           Include Files and Type Defines
23 ----------------------------------------------------------------------------**/
24 #include "matchdefs.h"
25 #include "protos.h"
26 #include "callcpp.h"
27 #include "unicharset.h"
28 
29 /* define order of params in pruners */
30 #define PRUNER_X      0
31 #define PRUNER_Y      1
32 #define PRUNER_ANGLE    2
33 
34 /* definition of coordinate system offsets for each table parameter */
35 #define ANGLE_SHIFT (0.0)
36 #define X_SHIFT   (0.5)
37 #define Y_SHIFT   (0.5)
38 
39 #define MAX_PROTO_INDEX   24
40 #define BITS_PER_WERD   (8 * sizeof (uinT32))
41 /* Script detection: increase this number to 128 */
42 #define MAX_NUM_CONFIGS   64
43 #define MAX_NUM_PROTOS    512
44 #define PROTOS_PER_PROTO_SET  64
45 #define MAX_NUM_PROTO_SETS  (MAX_NUM_PROTOS / PROTOS_PER_PROTO_SET)
46 #define NUM_PP_PARAMS   3
47 #define NUM_PP_BUCKETS    64
48 #define NUM_CP_BUCKETS    24
49 #define CLASSES_PER_CP    32
50 #define NUM_BITS_PER_CLASS  2
51 #define CLASSES_PER_CP_WERD (CLASSES_PER_CP / NUM_BITS_PER_CLASS)
52 #define PROTOS_PER_PP_WERD  BITS_PER_WERD
53 #define BITS_PER_CP_VECTOR  (CLASSES_PER_CP * NUM_BITS_PER_CLASS)
54 #define MAX_NUM_CLASS_PRUNERS	((MAX_NUM_CLASSES + CLASSES_PER_CP - 1) /   \
55 				CLASSES_PER_CP)
56 #define WERDS_PER_CP_VECTOR (BITS_PER_CP_VECTOR / BITS_PER_WERD)
57 #define WERDS_PER_PP_VECTOR	((PROTOS_PER_PROTO_SET+BITS_PER_WERD-1)/    \
58 				BITS_PER_WERD)
59 #define WERDS_PER_PP		(NUM_PP_PARAMS * NUM_PP_BUCKETS *		\
60 				WERDS_PER_PP_VECTOR)
61 #define WERDS_PER_CP		(NUM_CP_BUCKETS * NUM_CP_BUCKETS *		\
62 				NUM_CP_BUCKETS * WERDS_PER_CP_VECTOR)
63 #define WERDS_PER_CONFIG_VEC	((MAX_NUM_CONFIGS + BITS_PER_WERD - 1) /    \
64 				BITS_PER_WERD)
65 
66 /* The first 3 dimensions of the CLASS_PRUNER_STRUCT are the
67  * 3 axes of the quantized feature space.
68  * The position of the the bits recorded for each class in the
69  * 4th dimension is determined by using CPrunerWordIndexFor(c),
70  * where c is the corresponding class id. */
71 typedef uinT32 CLASS_PRUNER_STRUCT
72 [NUM_CP_BUCKETS][NUM_CP_BUCKETS][NUM_CP_BUCKETS][WERDS_PER_CP_VECTOR];
73 
74 typedef
75 uinT32 (*CLASS_PRUNER)[NUM_CP_BUCKETS][NUM_CP_BUCKETS][WERDS_PER_CP_VECTOR];
76 
77 typedef struct
78 {
79   inT8 A;
80   uinT8 B;
81   inT8 C;
82   uinT8 Angle;
83   uinT32 Configs[WERDS_PER_CONFIG_VEC];
84 }
85 
86 
87 INT_PROTO_STRUCT, *INT_PROTO;
88 
89 typedef uinT32 PROTO_PRUNER[NUM_PP_PARAMS][NUM_PP_BUCKETS][WERDS_PER_PP_VECTOR];
90 
91 typedef struct
92 {
93   PROTO_PRUNER ProtoPruner;
94   INT_PROTO_STRUCT Protos[PROTOS_PER_PROTO_SET];
95 }
96 
97 
98 PROTO_SET_STRUCT, *PROTO_SET;
99 
100 typedef uinT32 CONFIG_PRUNER[NUM_PP_PARAMS][NUM_PP_BUCKETS][4];
101 
102 /*
103  * font_properties contains properties about boldness, italicness, fixed pitch,
104  * serif, fraktur
105  */
106 struct FontInfo {
107   char*         name;
108   uinT32        properties;
is_italicFontInfo109   bool is_italic() { return properties & 1; }
is_boldFontInfo110   bool is_bold() { return (properties & 2) != 0; }
is_fixed_pitchFontInfo111   bool is_fixed_pitch() { return (properties & 4) != 0; }
is_serifFontInfo112   bool is_serif() { return (properties & 8) != 0; }
is_frakturFontInfo113   bool is_fraktur() { return (properties & 16) != 0; }
114 };
115 
116 // Every class (character) owns a FontSet that represents all the fonts that can
117 // render this character.
118 // Since almost all the characters from the same script share the same set of
119 // fonts, the sets are shared over multiple classes (see
120 // Classify::fontset_table_). Thus, a class only store an id to a set.
121 // Because some fonts cannot render just one character of a set, there are a
122 // lot of FontSet that differ only by one font. Rather than storing directly
123 // the FontInfo in the FontSet structure, it's better to share FontInfos among
124 // FontSets (Classify::fontinfo_table_).
125 struct FontSet {
126   int           size;
127   int*          configs;  // FontInfo ids
128 };
129 
130 
131 typedef struct
132 {
133   uinT16 NumProtos;
134   uinT8 NumProtoSets;
135   uinT8 NumConfigs;
136   PROTO_SET ProtoSets[MAX_NUM_PROTO_SETS];
137   uinT8 *ProtoLengths;
138   uinT16 ConfigLengths[MAX_NUM_CONFIGS];
139   int font_set_id;  // FontSet id, see above
140 }
141 
142 
143 INT_CLASS_STRUCT, *INT_CLASS;
144 
145 typedef struct
146 {
147   int NumClasses;
148   int NumClassPruners;
149   INT_CLASS Class[MAX_NUM_CLASSES];
150   CLASS_PRUNER ClassPruner[MAX_NUM_CLASS_PRUNERS];
151 }
152 
153 
154 INT_TEMPLATES_STRUCT, *INT_TEMPLATES;
155 
156 /* definitions of integer features*/
157 #define MAX_NUM_INT_FEATURES 512
158 #define INT_CHAR_NORM_RANGE  256
159 
160 struct INT_FEATURE_STRUCT
161 {
162   uinT8 X;
163   uinT8 Y;
164   uinT8 Theta;
165   inT8 CP_misses;
166 };
167 
168 typedef INT_FEATURE_STRUCT *INT_FEATURE;
169 
170 typedef INT_FEATURE_STRUCT INT_FEATURE_ARRAY[MAX_NUM_INT_FEATURES];
171 
172 enum IntmatcherDebugAction {
173   IDA_ADAPTIVE,
174   IDA_STATIC,
175   IDA_BOTH
176 };
177 
178 /**----------------------------------------------------------------------------
179             Macros
180 ----------------------------------------------------------------------------**/
181 
182 #define MaxNumIntProtosIn(C)  (C->NumProtoSets * PROTOS_PER_PROTO_SET)
183 #define SetForProto(P)    (P / PROTOS_PER_PROTO_SET)
184 #define IndexForProto(P)  (P % PROTOS_PER_PROTO_SET)
185 #define ProtoForProtoId(C,P)	(&((C->ProtoSets[SetForProto (P)])->	\
186 					Protos [IndexForProto (P)]))
187 #define PPrunerWordIndexFor(I)	(((I) % PROTOS_PER_PROTO_SET) /		\
188 				PROTOS_PER_PP_WERD)
189 #define PPrunerBitIndexFor(I) ((I) % PROTOS_PER_PP_WERD)
190 #define PPrunerMaskFor(I) (1 << PPrunerBitIndexFor (I))
191 
192 #define MaxNumClassesIn(T)    (T->NumClassPruners * CLASSES_PER_CP)
193 #define LegalClassId(c)   ((c) >= 0 && (c) <= MAX_CLASS_ID)
194 #define UnusedClassIdIn(T,c)  ((T)->Class[c] == NULL)
195 #define ClassForClassId(T,c) ((T)->Class[c])
196 #define ClassPrunersFor(T)  ((T)->ClassPruner)
197 #define CPrunerIdFor(c)   ((c) / CLASSES_PER_CP)
198 #define CPrunerFor(T,c)   ((T)->ClassPruner [CPrunerIdFor (c)])
199 #define CPrunerWordIndexFor(c)  (((c) % CLASSES_PER_CP) / CLASSES_PER_CP_WERD)
200 #define CPrunerBitIndexFor(c) (((c) % CLASSES_PER_CP) % CLASSES_PER_CP_WERD)
201 #define CPrunerMaskFor(L,c) (((L)+1) << CPrunerBitIndexFor (c) * NUM_BITS_PER_CLASS)
202 
203 /* DEBUG macros*/
204 #define PRINT_MATCH_SUMMARY 0x001
205 #define DISPLAY_FEATURE_MATCHES 0x002
206 #define DISPLAY_PROTO_MATCHES 0x004
207 #define PRINT_FEATURE_MATCHES 0x008
208 #define PRINT_PROTO_MATCHES 0x010
209 #define CLIP_MATCH_EVIDENCE 0x020
210 
211 #define MatchDebuggingOn(D)   (D)
212 #define PrintMatchSummaryOn(D)    ((D) & PRINT_MATCH_SUMMARY)
213 #define DisplayFeatureMatchesOn(D)  ((D) & DISPLAY_FEATURE_MATCHES)
214 #define DisplayProtoMatchesOn(D)  ((D) & DISPLAY_PROTO_MATCHES)
215 #define PrintFeatureMatchesOn(D)  ((D) & PRINT_FEATURE_MATCHES)
216 #define PrintProtoMatchesOn(D)    ((D) & PRINT_PROTO_MATCHES)
217 #define ClipMatchEvidenceOn(D)    ((D) & CLIP_MATCH_EVIDENCE)
218 
219 /**----------------------------------------------------------------------------
220           Public Function Prototypes
221 ----------------------------------------------------------------------------**/
222 void AddIntClass(INT_TEMPLATES Templates, CLASS_ID ClassId, INT_CLASS Class);
223 
224 int AddIntConfig(INT_CLASS Class);
225 
226 int AddIntProto(INT_CLASS Class);
227 
228 void AddProtoToClassPruner(PROTO Proto,
229                            CLASS_ID ClassId,
230                            INT_TEMPLATES Templates);
231 
232 void AddProtoToProtoPruner(PROTO Proto, int ProtoId, INT_CLASS Class);
233 
234 int BucketFor(FLOAT32 Param, FLOAT32 Offset, int NumBuckets);
235 
236 int CircBucketFor(FLOAT32 Param, FLOAT32 Offset, int NumBuckets);
237 
238 void UpdateMatchDisplay();
239 
240 void ConvertConfig(BIT_VECTOR Config, int ConfigId, INT_CLASS Class);
241 
242 void ConvertProto(PROTO Proto, int ProtoId, INT_CLASS Class);
243 
244 void DisplayIntFeature(INT_FEATURE Feature, FLOAT32 Evidence);
245 
246 void DisplayIntProto(INT_CLASS Class, PROTO_ID ProtoId, FLOAT32 Evidence);
247 
248 INT_CLASS NewIntClass(int MaxNumProtos, int MaxNumConfigs);
249 
250 INT_TEMPLATES NewIntTemplates();
251 
252 void free_int_templates(INT_TEMPLATES templates);
253 
254 void ShowMatchDisplay();
255 
256 /*----------------------------------------------------------------------------*/
257 
258 void InitIntMatchWindowIfReqd();
259 
260 void InitProtoDisplayWindowIfReqd();
261 
262 void InitFeatureDisplayWindowIfReqd();
263 
264 #endif
265