From 7f9df3a472dda7008366c3fdf865adeb3467b66b Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Fri, 28 Aug 2009 23:16:51 +0100 Subject: [PATCH] New paging arrangements: - check pager motion to detect multi-paging - do not duplicate first page This is the bugfix `checkpager' --- yarrg/Commods.pm | 2 +- yarrg/convert.h | 1 + yarrg/pages.c | 15 ++++------ yarrg/structure.c | 70 +++++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 76 insertions(+), 12 deletions(-) diff --git a/yarrg/Commods.pm b/yarrg/Commods.pm index f81e1b8..f282313 100644 --- a/yarrg/Commods.pm +++ b/yarrg/Commods.pm @@ -214,7 +214,7 @@ sub parse_pctb_commodmap () { sub get_our_version ($$) { my ($aref,$prefix) = @_; $aref->{"${prefix}name"}= 'ypp-sc-tools yarrg'; - $aref->{"${prefix}fixes"}= 'lastpage'; + $aref->{"${prefix}fixes"}= 'lastpage checkpager'; my $version= `git-describe --tags HEAD || echo 0unknown`; $? and die $?; chomp($version); diff --git a/yarrg/convert.h b/yarrg/convert.h index 82ea369..fadfe93 100644 --- a/yarrg/convert.h +++ b/yarrg/convert.h @@ -76,6 +76,7 @@ void store_current_page(CanonImage *ci /*pointer saved*/, void adjust_colours(CanonImage *ci, const RgbImage *rgb); void select_page(int page); +void check_pager_motion(int first, int stop); Rect find_sunshine_widget(void); diff --git a/yarrg/pages.c b/yarrg/pages.c index 8f1332c..02cacd9 100644 --- a/yarrg/pages.c +++ b/yarrg/pages.c @@ -605,28 +605,24 @@ void take_screenshots(void) { for (;;) { debugf("page %d paging\n",npages); + pgdown_by_mouse(); + if (!(npages < MAX_PAGES)) fatal("Paging down seems to generate too many pages - max is %d.", MAX_PAGES); convert_store_page(current); free_snapshot(&last); last=current; current=0; - debugf("PAGING page %d converted\n",npages); + npages++; wait_for_stability(¤t,last, 0, "page %d collecting ...", - npages+1); - - if (npages && /* first pagedown doesn't do much */ - identical(current,last)) { - npages++; + npages); + if (identical(current,last)) { free_snapshot(¤t); break; } - - pgdown_by_mouse(); - npages++; } progress("finishing with the YPP client..."); send_mouse_1_updown(commod_focuslast_point.x, commod_focuslast_point.y); @@ -636,6 +632,7 @@ void take_screenshots(void) { debugf("PAGING all done.\n"); progress_log("collected %d screenshots.",npages); + check_pager_motion(0,npages); } void take_one_screenshot(void) { diff --git a/yarrg/structure.c b/yarrg/structure.c index 99042d0..8aae1c4 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) ); @@ -533,6 +540,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 +568,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 +1024,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