chiark / gitweb /
5371c75b631ac61ea29db285d883ffc99c416875
[ypp-sc-tools.db-live.git] / pctb / ocr.h
1 /*
2  * ocr.c forms a mostly-self-contained bit
3  * so we put its declarations in this separate file
4  */
5
6 #ifndef OCR_H
7 #define OCR_H
8
9
10 #define _GNU_SOURCE
11
12 #include <string.h>
13 #include <stdio.h>
14 #include <errno.h>
15 #include <assert.h>
16 #include <stdint.h>
17 #include <stdlib.h>
18 #include <unistd.h>
19 #include <stdarg.h>
20 #include <inttypes.h>
21
22 #include <sys/types.h>
23 #include <sys/wait.h>
24
25
26 typedef struct {
27   int w,h;
28   char d[];
29 } CanonImage;
30
31 typedef uint32_t Pixcol;
32 #define PSPIXCOL(priscan) priscan##32
33
34 typedef struct {
35   const char *s; /* valid until next call to ocr() */
36   int l,r; /* column numbers */
37   unsigned ctxmap; /* match context index */
38 } OcrResultGlyph;
39
40
41 typedef const struct OcrCellTypeInfo *OcrCellType;
42 extern const struct OcrCellTypeInfo ocr_celltype_text;
43 extern const struct OcrCellTypeInfo ocr_celltype_number;
44
45
46 typedef struct OcrReader OcrReader;
47 OcrReader *ocr_init(int h);
48
49 OcrResultGlyph *ocr(OcrReader *rd, OcrCellType, int w, Pixcol cols[]);
50   /* return value is array terminated by {0,-1,-1}
51    * array is valid until next call to ocr()
52    */
53
54
55 /*----- debugging arrangements, rather contingent -----*/
56
57 #define DEBUG_FLAG_LIST                         \
58    DF(findypp)                                  \
59    DF(pages)                                    \
60    DF(rect)                                     \
61    DF(ocr)                                      \
62    DF(callout)
63
64 enum {
65 #define DF(f) dbg__shift_##f,
66   DEBUG_FLAG_LIST
67 #undef DF
68 };
69 enum {
70 #define DF(f) dbg_##f = 1 << dbg__shift_##f,
71   DEBUG_FLAG_LIST
72 #undef DF
73 };
74
75 unsigned debug_flags;
76
77 #define DEBUGP(f) (!!(debug_flags & dbg_##f))
78
79 void debug_flush(void);
80
81 #define eassert assert
82 #define debug stderr
83
84 const char *get_vardir(void);
85
86 #define DEFINE_VWRAPPERF(decls, funcf)                                  \
87   decls void funcf(const char *fmt, ...) {                              \
88     va_list al;  va_start(al,fmt);  v##funcf(fmt,al);  va_end(al);      \
89   }
90
91 #define DEBUG_DEFINE_SOME_DEBUGF(fl,funcf)                              \
92   static void v##funcf(const char *fmt, va_list al) {                   \
93     if (DEBUGP(fl))                                                     \
94       vfprintf(debug,fmt,al);                                           \
95   }                                                                     \
96   DEFINE_VWRAPPERF(static, funcf)
97
98 #define DEBUG_DEFINE_DEBUGF(fl) DEBUG_DEFINE_SOME_DEBUGF(fl,debugf)
99
100 #endif /*OCR_H*/