X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?p=ypp-sc-tools.db-live.git;a=blobdiff_plain;f=yarrg%2Fstructure.c;h=ba7ba0dedc5b9208fa1ec195bde7490e9f19d08a;hp=99042d0c74961c5b064c19875b8af0c89ce37dca;hb=9df0d91b280265faa669aea7d1501787eeb932da;hpb=fceed60843f6a7c037b908eb529b542ad263c500 diff --git a/yarrg/structure.c b/yarrg/structure.c index 99042d0..ba7ba0d 100644 --- a/yarrg/structure.c +++ b/yarrg/structure.c @@ -37,7 +37,7 @@ DEBUG_DEFINE_DEBUGF(struct) struct PageStruct { Rect mr; - int commbasey, comminty; + int commbasey, comminty, pagerheight; int colrightx[INTERESTING_COLUMNS]; }; @@ -401,6 +401,13 @@ void find_structure(const CanonImage *im, ADJUST_BOX(pager, "o",>=,RECT_W(pager)-2, s.mr.tl.y,LIMIT_QUITEQ, tl,y,-1); debug_rect("pager",__LINE__,pager); + pager.br.y= pager.tl.y; + pager.tl.y= pager.tl.y-1; + if (pager.tl.y > s.mr.tl.y) + ADJUST_BOX(pager, "+",>,1, s.mr.tl.y,LIMIT_QUITEQ, tl,y,-1); + debug_rect("pager",__LINE__,pager); + s.pagerheight= pager.br.y - pager.tl.y; + #define SET_ONCE(var,val) do{ \ int v= (val); \ if ((var)==-1) (var)= v; \ @@ -430,7 +437,7 @@ void find_structure(const CanonImage *im, } if (commod_page_point_r) { commod_page_point_r->x= (pager.tl.x + pager.br.x) / 2; - commod_page_point_r->y= pager.tl.y - 1; + commod_page_point_r->y= pager.br.y - 1; } MUST( text_h <= OCR_MAX_H, MI(text_h) ); @@ -472,6 +479,19 @@ void check_correct_commodities(void) { "??____X_____?_X_?X__?X_______________________", "???__?_______?__?___?_______________________?", }; + static const char *all_fuzzy[]= { + "???___________________________________???", + "??_______???___X__X____________________??", + "?_______????__?X_?X_____XXXXXXXXXXX_____?", + "________?????_?X_?X______XXXXXXXXX_______", + "________?????_?X_?X_______XXXXXXX________", + "_______??????_?X_?X________XXXXX_________", + "_______??_?????X_?X_________XXX__________", + "______??XXXXX??X_?X__________X___________", + "?_____?????????X_?X______________________", + "??___???____???X_?X______________________", + "???__??_____???__?______________________?", + }; #define COMMOD_SELECTOR_MATCHES(all) \ commod_selector_matches(search, all, \ @@ -479,7 +499,8 @@ void check_correct_commodities(void) { strlen((all)[0])) if (!(COMMOD_SELECTOR_MATCHES(all_small) || - COMMOD_SELECTOR_MATCHES(all_big))) + COMMOD_SELECTOR_MATCHES(all_big) || + COMMOD_SELECTOR_MATCHES(all_fuzzy))) fatal("Commodities selector not set to `All'."); } @@ -533,6 +554,7 @@ void store_current_page(CanonImage *ci, PageStruct *pstruct, RgbImage *rgb) { else free(rgb); page_images[npages]= cim; page_structs[npages]= *pstruct; + debugf("STORED page %d pagerheight=%d\n", npages, pstruct->pagerheight); free(pstruct); } @@ -560,6 +582,12 @@ void read_screenshots(void) { } sysassert(!ferror(screenshot_file)); progress_log("read %d screenshots.",npages); + + check_pager_motion(1,npages); + /* When we are reading screenshots, the pages file contains the + * `determine where we're to click' page as well as the first + * actual data page, which we have to skip. + */ } #define FIXPT_SHIFT 15 @@ -1010,3 +1038,55 @@ void find_islandname(void) { island= masprintf("%s", delim+3); } + +void check_pager_motion(int first, int stop) { + /* We check that the pager moved by an appropriate amount. + * The last gap can be smaller but not bigger. + */ + int count= stop-first; + +#define PH(p) (page_structs[(p)].pagerheight) + + debugf("CHECK_PAGER_MOTION %d..%d count=%d\n", first,stop,count); + + if (count <= 1) return; /* only one page */ + + double firstheight= PH(first); + double max= count>2 ? firstheight / (count-2) : 0; + double min= firstheight / (count-1); + max *= 1.1; + min /= 1.1; + max += 1.0; + min -= 1.0; + debugf("CHECK_PAGER_MOTION min=%g max=%g\n", min,max); + assert(max>min); + + int skips=0, firstskip=1; + int stops=0, firststop=1; + +#define REPORT(skipstop,msg) do{ \ + skipstop##s++; \ + if (first##skipstop<0) first##skipstop= page; \ + if (skipstop##s<5) \ + fprintf(stderr,msg " (page %d)\n",page); \ + }while(0) + + int page; + for (page=first+1; pagemax) + REPORT(skip, "scrollbar motion probable page skip detected!"); + if (gap