X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?p=ypp-sc-tools.db-test.git;a=blobdiff_plain;f=pctb%2Focr.c;h=7eb871a68844acc1d802747e67346aed760b3729;hp=bb9576769e10a1d633ed6ebb7786d75e3bfcf585;hb=d3eaa28d304c5b0639bc0f7e29b3285317d5c1e7;hpb=e684cf18e3fc8ce4024a6a258033d38f67f5aef0 diff --git a/pctb/ocr.c b/pctb/ocr.c index bb95767..7eb871a 100644 --- a/pctb/ocr.c +++ b/pctb/ocr.c @@ -286,6 +286,15 @@ const struct OcrCellTypeInfo ocr_celltype_text= { .midword=1 /* Lower only */ }; +static void vdebugf(const char *fmt, va_list al) { +#ifdef DEBUG_OCR + vfprintf(debug,fmt,al); +#endif +} +static void debugf(const char *fmt, ...) { + va_list al; va_start(al,fmt); vdebugf(fmt,al); va_end(al); +} + OcrResultGlyph *ocr(OcrReader *rd, OcrCellType ct, int w, Pixcol cols[]) { int nspaces; unsigned ctxmap; @@ -296,9 +305,9 @@ OcrResultGlyph *ocr(OcrReader *rd, OcrCellType ct, int w, Pixcol cols[]) { nspaces=- w; ctxmap= ct->initial; rd->nresults=0; - fprintf(debug,"OCR h=%d w=%d",rd->h,w); - for (x=0; xh,w); + for (x=0; xnextword; } continue; @@ -329,7 +338,7 @@ OcrResultGlyph *ocr(OcrReader *rd, OcrCellType ct, int w, Pixcol cols[]) { DatabaseNode *uniquematch= 0; int uniquematch_rx=-1; - fprintf(debug,"OCR lx=%d ctxmap=%x ",lx,ctxmap); + debugf("OCR lx=%d ctxmap=%x ",lx,ctxmap); for (ctxi=0; ctxicontexts[ctxi];; @@ -338,29 +347,29 @@ OcrResultGlyph *ocr(OcrReader *rd, OcrCellType ct, int w, Pixcol cols[]) { x= lx; if (!(ctxmap & (1u << ctxi))) continue; - fprintf(debug," || %s",context_names[ctxi]); + debugf(" || %s",context_names[ctxi]); for (;;) { debug_flush(); - fprintf(debug," | x=%d",x); + debugf(" | x=%d",x); if (x>w) break; Pixcol cv= cols[x]; - fprintf(debug," cv=%"PSPIXCOL(PRIx),cv); + debugf(" cv=%"PSPIXCOL(PRIx),cv); for (i=0; inlinks; i++) if (current->links[i].col == cv) goto found; /* not found */ - fprintf(debug," ?"); + debugf(" ?"); break; found: current= current->links[i].then; if (current->s[0]) { - fprintf(debug," \"%s\"",current->s); + debugf(" \"%s\"",current->s); bestmatch= current; bestmatch_rx= x; } else { - fprintf(debug," ..."); + debugf(" ..."); } x++; @@ -368,7 +377,7 @@ OcrResultGlyph *ocr(OcrReader *rd, OcrCellType ct, int w, Pixcol cols[]) { if (bestmatch) { if (uniquematch && strcmp(bestmatch->s, uniquematch->s)) { - fprintf(debug, " ambiguous"); + debugf( " ambiguous"); uniquematch= 0; break; } @@ -378,22 +387,22 @@ OcrResultGlyph *ocr(OcrReader *rd, OcrCellType ct, int w, Pixcol cols[]) { } if (uniquematch) { - fprintf(debug," || YES\n"); + debugf(" || YES\n"); add_result(rd, uniquematch->s, lx, uniquematch_rx, ctxmap); x= uniquematch_rx+1; ctxmap= ct->midword; } else { int rx; - fprintf(debug," || UNKNOWN"); + debugf(" || UNKNOWN"); for (rx=lx; rxnresults); + debugf("OCR finished %d glyphs\n",rd->nresults); debug_flush(); return rd->results; }