2 * ocr.c forms a mostly-self-contained bit
3 * so we put its declarations in this separate file
6 * This is part of ypp-sc-tools, a set of third-party tools for assisting
7 * players of Yohoho Puzzle Pirates.
9 * Copyright (C) 2009 Ian Jackson <ijackson@chiark.greenend.org.uk>
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * Yohoho and Puzzle Pirates are probably trademarks of Three Rings and
25 * are used without permission. This program is not endorsed or
26 * sponsored by Three Rings.
36 #define AAMAXVAL ((1<<AADEPTH)-1)
37 /* Change this ? Also change in
38 * dictionary-manager set aadepth
39 * dictionary-update-receiver my $aadepth
43 typedef uint32_t Pixcolv;
44 #define PIXCOL_P_PER_WORD (32 / AADEPTH)
47 #define PIXCOL_WORDS ((OCR_MAX_H + PIXCOL_P_PER_WORD - 1) / PIXCOL_P_PER_WORD)
49 typedef struct { Pixcolv w[PIXCOL_WORDS]; } Pixcol;
51 static inline int pixcol_p_word(int y) {
52 return y / PIXCOL_P_PER_WORD;
54 static inline int pixcol_p_shift(int y) {
55 return (y % PIXCOL_P_PER_WORD)*AADEPTH;
57 static inline void pixcol_p_add(Pixcol *pixcol, int y, unsigned pixval) {
58 pixcol->w[pixcol_p_word(y)] |= pixval << pixcol_p_shift(y);
60 static inline unsigned int pixcol_p_get(const Pixcol *pixcol, int y) {
61 return (pixcol->w[pixcol_p_word(y)] >> pixcol_p_shift(y)) & AAMAXVAL;
63 static inline int pixcol_cmp(const Pixcol *pixcol1, const Pixcol *pixcol2) {
64 return memcmp(pixcol1, pixcol2, sizeof(*pixcol1));
66 static inline int pixcol_nonzero(const Pixcol *pixcol) {
67 static const Pixcol zero;
68 return pixcol_cmp(pixcol, &zero);
72 # define PRPIXCOL1 "%0*" PRIo32
73 # define PIXCOL_P_PER_FMT 1
75 # define PRPIXCOL1 "%0*" PRIx32
76 # define PIXCOL_P_PER_FMT 2
78 # error need to implement PRPIXCOL1 for this AADEPTH
81 # define PIXCOL_FMT_PER_WORD (PIXCOL_P_PER_WORD / PIXCOL_P_PER_FMT)
84 # define PIXCOL_PRFMT \
87 # define PIXCOL_PRVAL(pixcol) \
88 PIXCOL_FMT_PER_WORD, (pixcol).w[1], \
89 PIXCOL_FMT_PER_WORD, (pixcol).w[0]
91 # define PIXCOL_PRFMT \
95 # define PIXCOL_PRVAL(pixcol) \
96 PIXCOL_FMT_PER_WORD, (pixcol).w[2], \
97 PIXCOL_FMT_PER_WORD, (pixcol).w[1], \
98 PIXCOL_FMT_PER_WORD, (pixcol).w[0]
100 # error need to implement PIXCOL_PR{FMT,VAL} for this PIXCOL_WORDS
104 const char *s; /* valid until next call to ocr() */
105 int l,r; /* column numbers */
106 int match; /* match context index */
107 unsigned ctxmap; /* possible match contexts */
111 typedef const struct OcrCellTypeInfo *OcrCellType;
112 extern const struct OcrCellTypeInfo ocr_celltype_text;
113 extern const struct OcrCellTypeInfo ocr_celltype_number;
114 const char *ocr_celltype_name(OcrCellType ct);
117 typedef struct OcrReader OcrReader;
118 OcrReader *ocr_init(int h);
119 void ocr_showcharsets(void);
121 OcrResultGlyph *ocr(OcrReader *rd, OcrCellType, int w, const Pixcol cols[]);
122 /* return value is array terminated by {0,-1,-1}
123 * array is valid until next call to ocr()
127 extern const char *o_resolver;
129 FILE *resolve_start(void);
130 void resolve_finish(void);