}
static void debug_rect(const char *what, int whati, Rect rr) {
+#ifdef DEBUG_RECTANGLES
int y,r,w;
fprintf(debug, "%s %d: %d,%d..%d,%d:\n", what, whati,
rr.tl.x,rr.tl.y, rr.br.x,rr.br.y);
fputc('|',debug);
fputc('\n',debug);
}
+#endif
debug_flush();
}
down.y++;
WALK_UNTIL_MUST(down, y,+1, mainr.br.y, '+');
+#ifdef DEBUG_RECTANGLES
int xscaleunit, y,x;
for (y=0, xscaleunit=1; y<4; y++, xscaleunit*=10) {
fprintf(debug," ");
}
fputc('\n',debug);
}
+#endif
commbasey= up.y;
comminty= down.y - up.y + 2;
- fprintf(debug, "up.y=%d down.y=%d commbasey=%d comminty=%d\n",
- up.y,down.y, commbasey,comminty);
Point across= { mainr.tl.x, commbasey };
int colno=0;
eassert(colno < MAX_COLUMNS);
int colrx= across.x;
if (colrx > mainr.br.x) colrx= mainr.br.x;
- if (colno < INTERESTING_COLUMNS) {
+ if (colno < INTERESTING_COLUMNS)
colrightx[colno]= colrx;
- fprintf(debug,"colrightx[%d]= %d\n",colno,colrx);
- } else {
- fprintf(debug,"extra colr %d %d\n",colno,colrx);
- }
colno++;
break;
}
}
+#ifdef DEBUG_RECTANGLES
fprintf(debug, "%4d ",y);
r= fwrite(image + y*width, 1,width, debug); eassert(r==width);
fputc('\n',debug);
+#endif
}
debug_flush();
}
.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;
nspaces=- w;
ctxmap= ct->initial;
rd->nresults=0;
- fprintf(debug,"OCR h=%d w=%d",rd->h,w);
- for (x=0; x<w; x++) fprintf(debug," %"PSPIXCOL(PRIx),cols[x]);
- fprintf(debug,"\n");
+ debugf("OCR h=%d w=%d",rd->h,w);
+ for (x=0; x<w; x++) debugf(" %"PSPIXCOL(PRIx),cols[x]);
+ debugf("\n");
debug_flush();
x=0;
nspaces++;
x++;
if (nspaces==SPACE_SPACES) {
- fprintf(debug,"OCR x=%x nspaces=%d space\n",x,nspaces);
+ debugf("OCR x=%x nspaces=%d space\n",x,nspaces);
ctxmap= ct->nextword;
}
continue;
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; ctxi<NCONTEXTS; ctxi++) {
DatabaseNode *current= &rd->contexts[ctxi];;
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; i<current->nlinks; 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++;
if (bestmatch) {
if (uniquematch && strcmp(bestmatch->s, uniquematch->s)) {
- fprintf(debug, " ambiguous");
+ debugf( " ambiguous");
uniquematch= 0;
break;
}
}
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; rx<w && cols[rx]; rx++);
- fprintf(debug," x=%d ctxmap=%x %d..%d\n",x, ctxmap, lx,rx);
+ debugf(" x=%d ctxmap=%x %d..%d\n",x, ctxmap, lx,rx);
debug_flush();
callout_unknown(rd, w,cols, lx,rx-1, ctxmap);
goto restart;
}
}
add_result(rd, 0,-1,-1,0);
- fprintf(debug,"OCR finished %d glyphs\n",rd->nresults);
+ debugf("OCR finished %d glyphs\n",rd->nresults);
debug_flush();
return rd->results;
}
set csrh 20
set ctxh 20
+proc debug {m} {
+ puts stderr "SHOW-THING $m"
+}
+
proc init_widgets {} {
# idempotent
global csrh gotsh ctxh
set realcols $cols
set cols [expr {$cols - $chop_l - $chop_r}]
- puts stderr "NOW cols=$cols chop_l,r=$chop_l,$chop_r rows=$rows\
+ debug "NOW cols=$cols chop_l,r=$chop_l,$chop_r rows=$rows\
$unk_l $unk_r $ngd"
set mulcols [expr {$cols*$mul+$inter}]
helptext {{{ Processing }}}
unbind_all_keys
update idletasks
- puts stderr "$how $what"
+ debug "$how $what"
eval update_database/$how $what
done/$mainkind
}
init_widgets
manyset [lrange $l 0 3] unk_l unk_r unk_contexts
set glyphsdone [lrange $l 3 end]
- puts stderr "SHOW-THING GOT $l"
+ debug "GOT $l"
fileevent stdin readable {}