X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?a=blobdiff_plain;f=pctb%2Fconvert.c;h=4784c653994e8e4bd0c675389075cca391b23cf4;hb=5d58a08423953756871493042a9cfff032b66e18;hp=3a2b79fed91f6d50ed7141ddf262fd395c0bc440;hpb=2f6ec1e7e5b3649a58ae20211eb18511550246ae;p=ypp-sc-tools.db-test.git diff --git a/pctb/convert.c b/pctb/convert.c index 3a2b79f..4784c65 100644 --- a/pctb/convert.c +++ b/pctb/convert.c @@ -1,11 +1,6 @@ #include "ocr.h" -typedef struct { - unsigned long rgb; /* on screen */ - char c; /* canonical */ -} CanonColourInfo; - static CanonImage *cim; void debug_flush(void) { @@ -38,7 +33,7 @@ static int colrightx[INTERESTING_COLUMNS]; static int text_h; static OcrReader *rd; -static const CanonColourInfo canoncolourinfos[]= { +const CanonColourInfo canoncolourinfos[]= { { 0x475A5E, '*' }, /* edge */ { 0x2C5F7A, '*' }, /* edge just under box heading shadow */ { 0x7D9094, '+' }, /* interbox */ @@ -221,44 +216,33 @@ static void find_table_entry(Rect commod, int colno, Rect *cellr) { require_rectangle_r(*cellr, " o"); } +CanonImage *alloc_canon_image(int w, int h) { + CanonImage *im= malloc(sizeof(CanonImage) + w*h); + eassert(im); + im->w= w; + im->h= h; + memset(im->d,'?',w*h); + return im; +} + CanonImage *file_read_image(FILE *f) { struct pam inpam; - unsigned char rgb[3]; - int x,y,r; - const CanonColourInfo *cci; + unsigned char rgb_buf[3]; + CanonImage *im; pnm_readpaminit(f, &inpam, sizeof(inpam)); eassert(inpam.maxval == 255); eassert(inpam.bytes_per_sample == 1); - CanonImage *im= malloc(sizeof(CanonImage) + inpam.width*inpam.height); - eassert(im); - im->h= inpam.height; - im->w= inpam.width; - - memset(im->d,'?',inpam.width*inpam.height); - - for (y=0; yc; cci++) - if (cci->rgb == rgb_l) { - im->d[y*inpam.width + x]= cci->c; - break; - } - } -#ifdef DEBUG_RECTANGLES - fprintf(debug, "%4d ",y); - r= fwrite(im->d + y*inpam.width, 1,inpam.width, debug); - eassert(r==inpam.width); - fputc('\n',debug); -#endif - } - debug_flush(); + CANONICALISE_IMAGE(im, inpam.width, inpam.height, { + r= fread(&rgb_buf,1,3,f); eassert(r==3); + + rgb= + ((unsigned long)rgb_buf[0]<<16) | + ((unsigned long)rgb_buf[1]<<8) | + (rgb_buf[2]); + }); + return im; }