X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?p=ypp-sc-tools.db-test.git;a=blobdiff_plain;f=pctb%2Fstructure.c;h=0c9750c5f5bd45c4222db71686816dee5b86b464;hp=ce24da971f0157dd2b8d15dc302fffb2ac614265;hb=9c4bd3b7b5dde4ec8f37ffde2793437a299b3f2b;hpb=c70c2c7701a7777524881f3f88ab2db2851f932a diff --git a/pctb/structure.c b/pctb/structure.c index ce24da9..0c9750c 100644 --- a/pctb/structure.c +++ b/pctb/structure.c @@ -27,7 +27,7 @@ #include "structure.h" -static CanonImage *cim; +static const CanonImage *cim; static inline char get(int x, int y) { return cim->d[y * cim->w + x]; } static inline char get_p(Point p) { return get(p.x,p.y); } @@ -54,6 +54,7 @@ const CanonColourInfo canoncolourinfos[]= { { 0x2C5F7A, '*' }, /* edge just under box heading shadow */ { 0xC5C7AE, '*' }, /* blank area of partial commodities list */ { 0x6B828C, '*' }, /* background of ship status meter area */ + { 0x934405, '*' }, /* border of ship meter area */ { 0x7D9094, '+' }, /* interbox */ { 0xBDC5BF, ' ' }, /* background - pale Sugar cane, etc. */ @@ -92,7 +93,8 @@ static void mustfail1(const char *file, int line, const char *what) { " Check that your client is logged in has the correct display.\n" " If that isn't the problem, please report this as a fault.\n\n" "Technical details:" - " %s:%d: requirement failed: %s\n", + " %s:%d: requirement failed:\n" + " %s\n", file, line, what); } static void mustfail2(void) NORET; @@ -172,9 +174,9 @@ static void debug_rect(const char *what, int whati, Rect rr) { LIMIT_MUST( (search).tl.XY != (search).br.XY && \ (search).tl.XY != (lim), \ MR((search));MSB(#TLBR);MSB(#XY) ); \ - int got; \ - Point p; \ - for (p=(search).tl, got=0; \ + int got=0; \ + Point p=(search).tl; \ + for (p.XY=(search).TLBR.XY; \ p.OTHERCOORD_##XY <= (search).br.OTHERCOORD_##XY; \ p.OTHERCOORD_##XY++) \ got += !!strchr(insidechrs, get_p(p)); \ @@ -183,7 +185,7 @@ static void debug_rect(const char *what, int whati, Rect rr) { (search).TLBR.XY += increm; \ } -void find_structure_commod(CanonImage *im, int *max_relevant_y_r) { +void find_structure(const CanonImage *im, int *max_relevant_y_r) { cim= im; Rect whole = { {0,0}, {cim->w-1,cim->h-1} }; @@ -341,6 +343,7 @@ static void file_read_image_ppm(FILE *f) { struct pam inpam; unsigned char rgb_buf[3]; CanonImage *im; + RgbImage *ri=0; pnm_readpaminit(f, &inpam, sizeof(inpam)); if (!(inpam.maxval == 255 && @@ -348,6 +351,9 @@ static void file_read_image_ppm(FILE *f) { inpam.format == RPPM_FORMAT)) fatal("PNM screenshot(s) file must be 8bpp 1 byte per sample RGB"); + if (!npages) + page0_rgbimage= ri= alloc_rgb_image(inpam.width, inpam.height); + CANONICALISE_IMAGE(im, inpam.width, inpam.height, { int r= fread(&rgb_buf,1,3,f); sysassert(!ferror(f)); @@ -357,6 +363,9 @@ static void file_read_image_ppm(FILE *f) { ((unsigned long)rgb_buf[0]<<16) | ((unsigned long)rgb_buf[1]<<8) | (rgb_buf[2]); + + if (ri) + CANONIMG_ALSO_STORERGB(ri); }); sysassert(!ferror(screenshot_file)); @@ -451,7 +460,7 @@ void analyse(FILE *tsv_output) { int page, tryrect, colno; for (page=0; pagew, page0_rgbimage->h); + const unsigned char *srcp; + unsigned char *destp, *endp; + for (srcp=page0_rgbimage->data, destp=ri->data, + endp= ri->data + 3 * ri->w * ri->h; + destp < endp; + srcp++, destp++) { + unsigned char c= *srcp & 0xf0; + *destp= c | (c>>4); + } + cim= page_images[0]; + sunshiner.tl.x= cim->w - 1034 + 885; sunshiner.br.x= cim->w - 1034 + 1020; sunshiner.tl.y= 227; - sunshiner.br.y= 227; + sunshiner.br.y= 228; - ADJUST_BOX(sunshiner,"o",30, 100,MUST, tl,y,-1); - ADJUST_BOX(sunshiner,"o",30, 100,MUST, tl,y,-1); - + ADJUST_BOX(sunshiner,"o*",30, 100,MUST, tl,y,-1); + ADJUST_BOX(sunshiner,"o*",30, 100,MUST, br,y,+1); + debug_rect("sunshiner",0, sunshiner); - islandnamer.tl.x= cim->w - 1034 + 885; - islandnamer.br.x= cim->w - 1034 + 1020; - islandnamer.tl.y= 128; - islandnamer.br.y= 156; + MUST(sunshiner.br.y - sunshiner.tl.y > 20, MR(sunshiner)); + sunshiner.br.y--; -#define IR_VSHRINK_MUST(CONDMUST,PRWHY) \ - do{ if (!(CONDMUST)) goto not_in_radar; }while(0) + ADJUST_BOX(sunshiner,"o",20, (cim->w - 1034 + 700), MUST, tl,x,-1); + ADJUST_BOX(sunshiner,"o",20, cim->w, MUST, br,x,+1); + debug_rect("sunshiner",1, sunshiner); + + identify_rgbimage(ri, sunshiner, sunshine, "sunshine widget"); + fprintf(stderr,"sunshine: `%s'\n",sunshine); + + if (!memcmp(sunshine,"Ship ",5)) { + Rect islandnamer; + + islandnamer.tl.x= cim->w - 1034 + 885; + islandnamer.br.x= cim->w - 1034 + 1020; + islandnamer.tl.y= 128; + islandnamer.br.y= 156; - ADJUST_BOX(islandnamer,"o",5, IR_VSHRINK_MUST, tl,y,+1); - ADJUST_BOX(islandnamer,"o",5, IR_VSHRINK_MUST, br,y,-1); +#define IR_VSHRINK_MUST(CONDMUST,PRWHY) \ + do{ if (!(CONDMUST)) goto not_in_radar; }while(0) + + ADJUST_BOX(islandnamer,"o",5, 0, IR_VSHRINK_MUST, tl,y,+1); + ADJUST_BOX(islandnamer,"o",5, cim->h, IR_VSHRINK_MUST, br,y,-1); + + debug_rect("islandnamer",0, islandnamer); +// int larger_islandnamebry= islandnamer.tl.y + 25; +// MUST(islandnamer.br.y < larger_islandnamebry, +// MR(islandnamer);MI(larger_islandnamebry)); +// islandnamer.br.y = larger_islandnamebry; + debug_rect("islandnamer",1, islandnamer); + + int x,y,i; + for (x=islandnamer.tl.x; x<=islandnamer.br.x; x++) + for (y=islandnamer.tl.y; y<=islandnamer.br.y; y++) { + if (RI_PIXEL(ri,x,y)[0] < 0x40) { + for (i=0; i<3; i++) { + RI_PIXEL(ri,x,y)[i]= 0; + } + } + } - debug_rect("islandnamer",0, islandnamer); - static int larger_islandnamebry= islandname.tl.y + 25; - if (islandnamer.br.y < larger_islandnamebry) - goto not_in_radar; - islandnamer.br.y = larger_islandnamebry; - debug_rect("islandnamer",1, islandnamer); + identify_rgbimage(ri, islandnamer, archisland, "island"); + fprintf(stderr,"radar: `%s'\n",archisland); - debug_ppmrect("islandnamer",2, islandnamer,ri); - - not_in_radar: + assert(!"radar ok"); + not_in_radar: + assert(!"not in radar?"); + } else { + assert(!"not vessel"); + } - - abort(); + free(ri); } - -#endif