1 /*---------------------------------------------------------------------------*
2 Project: TwlSDK - PRC - include
3 File: prc/algo_common.h
4
5 Copyright 2003-2008 Nintendo. All rights reserved.
6
7 These coded instructions, statements, and computer programs contain
8 proprietary information of Nintendo of America Inc. and/or Nintendo
9 Company Ltd., and are protected by Federal copyright law. They may
10 not be disclosed to third parties or copied or duplicated in any form,
11 in whole or in part, without the prior written consent of Nintendo.
12
13 $Date:: 2008-09-18#$
14 $Rev: 8573 $
15 $Author: okubata_ryoma $
16 *---------------------------------------------------------------------------*/
17
18 #ifndef NITRO_PRC_ALGO_COMMON_H_
19 #define NITRO_PRC_ALGO_COMMON_H_
20
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24
25 #include <nitro/misc.h>
26 #include <nitro/types.h>
27 #include <nitro/prc/types.h>
28 #include <nitro/prc/common.h>
29
30
31 /*===========================================================================*
32 Macros
33 *===========================================================================*/
34
35 //--- For Get*BufferSize
36 #define PRCi_ARRAY_SIZE(type, size, dummy) \
37 sizeof(type) * (size)
38
39 //--- For Set*BufferInfo
40 #define PRCi_ALLOC_ARRAY(dst, type, size, base, offset) \
41 (dst) = (type*)((u8*)(base) + (offset)); \
42 (offset) += sizeof(type) * (size)
43
44
45 /*===========================================================================*
46 Constant Definitions
47 *===========================================================================*/
48
49 #define PRC_RESAMPLE_DEFAULT_METHOD_COMMON PRC_RESAMPLE_METHOD_RECURSIVE
50 #define PRC_RESAMPLE_DEFAULT_THRESHOLD_COMMON 5
51
52 /*===========================================================================*
53 Type Definitions
54 *===========================================================================*/
55
56 /*---------------------------------------------------------------------------*
57 Parameters for Sample DB Expansion
58 *---------------------------------------------------------------------------*/
59 typedef struct PRCPrototypeDBParam_Common
60 {
61 int dummy;
62 }
63 PRCPrototypeDBParam_Common;
64
65 /*---------------------------------------------------------------------------*
66 Parameters for Input Pattern Interpretation
67 normalizeSize Normalization Size
68 resampleMethod type of algorithm used for normalization
69 resampleThreshold post-normalization resample threshold
70 *---------------------------------------------------------------------------*/
71 typedef struct PRCInputPatternParam_Common
72 {
73 union
74 {
75 int normalizeSize;
76 int regularizeSize; // Old name
77 };
78 PRCResampleMethod resampleMethod;
79 int resampleThreshold;
80 }
81 PRCInputPatternParam_Common;
82
83 /*---------------------------------------------------------------------------*
84 Common Parts of Sample DB-Origin and Input-Origin Recognition Patterns
85 *---------------------------------------------------------------------------*/
86 typedef struct PRCiPatternData_Common
87 {
88 u16 strokeCount; // entry, and redundant information
89 u16 pointCount; // entry, and redundant information
90 const PRCPoint *pointArray;
91 int *strokes;
92 int *strokeSizes;
93 fx32 *lineSegmentLengthArray;
94 fx16 *lineSegmentRatioToStrokeArray;
95 // fx16 *lineSegmentRatioToWholeArray;
96 u16 *lineSegmentAngleArray;
97 fx32 *strokeLengths;
98 fx16 *strokeRatios;
99 fx32 wholeLength;
100 PRCBoundingBox *strokeBoundingBoxes;
101 PRCBoundingBox wholeBoundingBox;
102 }
103 PRCiPatternData_Common;
104
105 /*---------------------------------------------------------------------------*
106 Buffer Information for forming pattern dynamically during input.
107 Various recognition algorithms may be extensions of this, so when it is changed you need to check ~BufferInfo_* for these algorithms.
108
109 *---------------------------------------------------------------------------*/
110 typedef struct PRCiPatternBufferInfo_Common
111 {
112 PRCPoint *pointArray;
113 int *strokes;
114 int *strokeSizes;
115 fx32 *lineSegmentLengthArray;
116 fx16 *lineSegmentRatioToStrokeArray;
117 // fx16 *lineSegmentRatioToWholeArray;
118 u16 *lineSegmentAngleArray;
119 fx32 *strokeLengths;
120 fx16 *strokeRatios;
121 PRCBoundingBox *strokeBoundingBoxes;
122 }
123 PRCiPatternBufferInfo_Common;
124
125 /*---------------------------------------------------------------------------*
126 Sample DB-Originating Recognition Pattern
127 *---------------------------------------------------------------------------*/
128 typedef struct PRCiPrototypeEntry_Common
129 {
130 PRCiPatternData_Common data;
131 const PRCPrototypeEntry *entry;
132 }
133 PRCiPrototypeEntry_Common;
134
135 /*---------------------------------------------------------------------------*
136 Input-Originating Recognition Pattern
137 *---------------------------------------------------------------------------*/
138 typedef struct PRCInputPattern_Common
139 {
140 PRCiPatternData_Common data;
141 union
142 {
143 int normalizeSize;
144 int regularizeSize; // Old name
145 };
146
147 void *buffer;
148 u32 bufferSize;
149 }
150 PRCInputPattern_Common;
151
152 /*---------------------------------------------------------------------------*
153 Buffer Information for forming sample DB dynamically during input.
154 Various recognition algorithms may be extensions of this, so when it is changed you need to check ~BufferInfo_* for these algorithms.
155
156 *---------------------------------------------------------------------------*/
157 typedef struct PRCiPrototypeListBufferInfo_Common
158 {
159 PRCiPrototypeEntry_Common *patterns;
160 fx32 *lineSegmentLengthArray;
161 fx16 *lineSegmentRatioToStrokeArray;
162 // fx16 *lineSegmentRatioToWholeArray;
163 u16 *lineSegmentAngleArray;
164 int *strokeArray;
165 int *strokeSizeArray;
166 fx32 *strokeLengthArray;
167 fx16 *strokeRatioArray;
168 PRCBoundingBox *strokeBoundingBoxArray;
169 }
170 PRCiPrototypeListBufferInfo_Common;
171
172 /*---------------------------------------------------------------------------*
173 Sample DB Expanded in Memory
174 *---------------------------------------------------------------------------*/
175 typedef struct PRCPrototypeDB_Common
176 {
177 PRCiPrototypeEntry_Common *patterns;
178 int patternCount;
179
180 fx32 *lineSegmentLengthArray;
181 fx16 *lineSegmentRatioToStrokeArray;
182 // fx16 *lineSegmentRatioToWholeArray;
183 u16 *lineSegmentAngleArray;
184 int wholePointCount;
185
186 int *strokeArray;
187 int *strokeSizeArray;
188 fx32 *strokeLengthArray;
189 fx16 *strokeRatioArray;
190 PRCBoundingBox *strokeBoundingBoxArray;
191 int wholeStrokeCount;
192
193 int maxPointCount;
194 int maxStrokeCount;
195
196 union
197 {
198 int normalizeSize;
199 int regularizeSize; // Old name
200 };
201
202 const PRCPrototypeList *prototypeList;
203 void *buffer;
204 u32 bufferSize;
205 }
206 PRCPrototypeDB_Common;
207
208
209 /*---------------------------------------------------------------------------*
210 Name: PRC_Init_Common
211
212 Description: Initializes pattern recognition API.
213
214 Arguments: None.
215
216 Returns: None.
217 *---------------------------------------------------------------------------*/
PRC_Init_Common(void)218 static inline void PRC_Init_Common(void)
219 {
220 PRCi_Init();
221 }
222
223 /*---------------------------------------------------------------------------*
224 Name: PRC_GetPrototypeDBBufferSizeEx_Common
225
226 Description: Calculates the work area size required for expanding sample DB.
227
228 Arguments: prototypeList sample pattern list
229 kindMask mask for type specification
230 ignoreDisabledEntries Whether sample DB entries with the enabled flag FALSE are ever expanded.
231
232 param parameters for sample DB expansion
233
234 Returns: required memory capacity for expanding sample DB
235 *---------------------------------------------------------------------------*/
236 u32
237
238
239 PRC_GetPrototypeDBBufferSizeEx_Common(const PRCPrototypeList *prototypeList,
240 u32 kindMask,
241 BOOL ignoreDisabledEntries,
242 const PRCPrototypeDBParam_Common *param);
243
244 /*---------------------------------------------------------------------------*
245 Name: PRC_GetPrototypeDBBufferSize_Common
246
247 Description: Calculates the work area size required for expanding sample DB.
248
249 Arguments: prototypeList sample pattern list
250
251 Returns: required memory capacity for expanding sample DB
252 *---------------------------------------------------------------------------*/
PRC_GetPrototypeDBBufferSize_Common(const PRCPrototypeList * prototypeList)253 u32 static inline PRC_GetPrototypeDBBufferSize_Common(const PRCPrototypeList *prototypeList)
254 {
255 return PRC_GetPrototypeDBBufferSizeEx_Common(prototypeList, PRC_KIND_ALL, FALSE, NULL);
256 }
257
258 /*---------------------------------------------------------------------------*
259 Name: PRC_InitPrototypeDBEx_Common
260
261 Description: Creates the PRCPrototypeDB structure.
262 A buffer region larger than the size that PRC_GetPrototypeDBBufferSize returns needs to be set up in the buffer.
263
264 Parameters during expansion can be specified with param.
265
266 Arguments: protoDB sample DB structure to be initialized
267 buffer pointer to memory region used for sample DB expansion
268 (Memory area size >= return value of PRC_GetPrototypeDBBufferSize)
269 prototypeList sample pattern list
270 kindMask mask for type specification
271 ignoreDisabledEntries Whether or not sample DB entries with the enabled flag FALSE are ever expanded.
272
273 param parameters for sample DB expansion
274
275 Returns: TRUE if create succeeded.
276 *---------------------------------------------------------------------------*/
277 BOOL
278
279 PRC_InitPrototypeDBEx_Common(PRCPrototypeDB_Common *protoDB,
280 void *buffer,
281 const PRCPrototypeList *prototypeList,
282 u32 kindMask,
283 BOOL ignoreDisabledEntries, const PRCPrototypeDBParam_Common *param);
284
285 /*---------------------------------------------------------------------------*
286 Name: PRC_InitPrototypeDB_Common
287
288 Description: Creates the PRCPrototypeDB structure.
289 A buffer region larger than the size that PRC_GetPrototypeDBBufferSize returns needs to be set up in the buffer.
290
291
292 Arguments: protoDB sample DB structure to be initialized
293 buffer pointer to memory region used for sample DB expansion
294 (Memory area size >= return value of PRC_GetPrototypeDBBufferSize)
295 prototypeList sample pattern list
296
297 Returns: TRUE if create succeeded.
298 *---------------------------------------------------------------------------*/
299 static inline BOOL
PRC_InitPrototypeDB_Common(PRCPrototypeDB_Common * protoDB,void * buffer,const PRCPrototypeList * prototypeList)300 PRC_InitPrototypeDB_Common(PRCPrototypeDB_Common *protoDB,
301 void *buffer, const PRCPrototypeList *prototypeList)
302 {
303 return PRC_InitPrototypeDBEx_Common(protoDB, buffer, prototypeList, PRC_KIND_ALL, FALSE, NULL);
304 }
305
306 /*---------------------------------------------------------------------------*
307 Name: PRC_GetInputPatternBufferSize_Common
308
309 Description: Calculates work area required for expanding pattern data for comparison.
310
311
312 Arguments: maxPointCount Upper limit of input points (includes stylus up marker)
313 maxStrokeCount Upper limit of stroke count
314
315 Returns: Memory capacity required for expanding pattern
316 *---------------------------------------------------------------------------*/
317 u32 PRC_GetInputPatternBufferSize_Common(int maxPointCount, int maxStrokeCount);
318
319 /*---------------------------------------------------------------------------*
320 Name: PRC_InitInputPatternEx_Common
321
322 Description: Creates PRCInputPattern structure.
323 Specification of parameters for input pattern interpretation can be done with param.
324
325 Arguments: pattern pattern structure to be initialized
326 buffer pointer to memory region used for pattern expansion
327 (Region size >=return value of PRC_GetInputPatternBufferSize)
328 strokes Raw input coordinate value before forming
329 maxPointCount Upper limit of input points (includes stylus up marker)
330 maxStrokeCount Upper limit of stroke count
331 param parameters for input pattern interpretation
332
333 Returns: TRUE if create succeeded.
334 *---------------------------------------------------------------------------*/
335 BOOL
336
337 PRC_InitInputPatternEx_Common(PRCInputPattern_Common *pattern,
338 void *buffer,
339 const PRCStrokes *strokes,
340 int maxPointCount,
341 int maxStrokeCount, const PRCInputPatternParam_Common *param);
342
343 /*---------------------------------------------------------------------------*
344 Name: PRC_InitInputPattern_Common
345
346 Description: Creates PRCInputPattern structure.
347
348 Arguments: pattern pattern structure to be initialized
349 buffer pointer to memory region used for pattern expansion
350 (Region size >=return value of PRC_GetInputPatternBufferSize)
351 strokes Raw input coordinate value before forming
352 maxPointCount Upper limit of input points (includes stylus up marker)
353 maxStrokeCount Upper limit of stroke count
354
355 Returns: TRUE if create succeeded.
356 *---------------------------------------------------------------------------*/
357 static inline BOOL
PRC_InitInputPattern_Common(PRCInputPattern_Common * pattern,void * buffer,const PRCStrokes * strokes,int maxPointCount,int maxStrokeCount)358 PRC_InitInputPattern_Common(PRCInputPattern_Common *pattern,
359 void *buffer,
360 const PRCStrokes *strokes, int maxPointCount, int maxStrokeCount)
361 {
362 return PRC_InitInputPatternEx_Common(pattern, buffer, strokes, maxPointCount, maxStrokeCount,
363 NULL);
364 }
365
366 /*---------------------------------------------------------------------------*
367 Name: PRC_GetInputPatternStrokes_Common
368
369 Description: Gets dot sequence data from PRCInputPattern structure.
370
371 Arguments: strokes: Obtained dot sequence data
372 Overwriting is not permitted.
373 input Input pattern
374
375 Returns: None.
376 *---------------------------------------------------------------------------*/
377 void PRC_GetInputPatternStrokes_Common(PRCStrokes *strokes, const PRCInputPattern_Common *input);
378
379
380 // For debugging
381 void PRCi_PrintPatternData_Common(PRCiPatternData_Common *data);
382
383 /*===========================================================================*
384 Inline Functions
385 *===========================================================================*/
386
387 #ifdef __cplusplus
388 } /* extern "C" */
389 #endif
390
391 /* NITRO_PRC_ALGO_COMMON_H_ */
392 #endif
393