From: Ian Jackson Date: Sun, 5 Jul 2009 19:09:57 +0000 (+0100) Subject: constify CanonImage->rgb and make a copy in find_islandname X-Git-Tag: 1.9.3~1 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?a=commitdiff_plain;ds=sidebyside;h=e78d72697e53d276737fae8519c921c70f0709f7;p=ypp-sc-tools.web-live.git constify CanonImage->rgb and make a copy in find_islandname --- diff --git a/pctb/common.h b/pctb/common.h index 52f57d6..210f23a 100644 --- a/pctb/common.h +++ b/pctb/common.h @@ -49,7 +49,7 @@ typedef struct { int w,h; - struct RgbImage *rgb; + const struct RgbImage *rgb; char d[]; } CanonImage; diff --git a/pctb/convert.c b/pctb/convert.c index 9fcbd58..8386c16 100644 --- a/pctb/convert.c +++ b/pctb/convert.c @@ -311,7 +311,7 @@ int main(int argc, char **argv) { } if (o_mode & mf_analyse) { if (o_flags & ff_needisland) { - find_islandname(page_images[0]->rgb); + find_islandname(); if (o_flags & ff_printisland) printf("%s, %s\n", archipelago, island); sysassert(! setenv("YPPSC_ISLAND",island,1) ); diff --git a/pctb/convert.h b/pctb/convert.h index 6601b77..ba13c43 100644 --- a/pctb/convert.h +++ b/pctb/convert.h @@ -73,7 +73,7 @@ void find_structure(CanonImage *im, int *max_relevant_y_r); Rect find_sunshine_widget(void); void canon_colour_prepare(void); -void find_islandname(RgbImage *ri); +void find_islandname(void); void check_correct_commodities(void); void read_screenshots(void); void read_one_screenshot(void); diff --git a/pctb/pages.c b/pctb/pages.c index c504c95..0102999 100644 --- a/pctb/pages.c +++ b/pctb/pages.c @@ -516,12 +516,12 @@ static void set_focus_commodity(void) { debugf("PAGING raise_and_set_focus done.\n"); } -static CanonImage *convert_page(Snapshot *sn) { +static CanonImage *convert_page(const Snapshot *sn) { CanonImage *im; fwrite_ppmraw(screenshot_file, sn); - unsigned char *pixel= sn->data; + const unsigned char *pixel= sn->data; CANONICALISE_IMAGE(im, sn->w, sn->h, { r= *pixel++; g= *pixel++; diff --git a/pctb/structure.c b/pctb/structure.c index a0b1060..967de1e 100644 --- a/pctb/structure.c +++ b/pctb/structure.c @@ -543,7 +543,7 @@ static void find_table_entry(Rect commod, int colno, Rect *cell) { MUST( !!dark_count != !!light_count, MR(*cell);MIL(total_count);MIL(bg_count); - MIL(light_count);MIL(dark_count) ); + MIL(light_count);MIL(dark_count);MRGB(background); ); debugf("TABLEENTRY col=%d %d,%d..%d,%d bg=%ld light=%ld dark=%ld\n", colno, cell->tl.x,cell->tl.y, cell->br.x,cell->br.y, @@ -663,9 +663,13 @@ Rect find_sunshine_widget(void) { return sunshiner; } -void find_islandname(RgbImage *ri) { +void find_islandname(void) { find_structure(page_images[0], 0); + RgbImage *ri= alloc_rgb_image(page_images[0]->rgb->w, + page_images[0]->rgb->h); + memcpy(ri->data, page_images[0]->rgb->data, ri->w * ri->h * 3); + Rect sunshiner= find_sunshine_widget(); char sunshine[MAXIMGIDENT], archisland[MAXIMGIDENT]; diff --git a/pctb/structure.h b/pctb/structure.h index ec7b4bf..84fdcae 100644 --- a/pctb/structure.h +++ b/pctb/structure.h @@ -61,14 +61,15 @@ static inline char canon_lookup_colour(unsigned char r, * each pixel in reading order. \ */ \ (im)= alloc_canon_image((w), (h)); \ - (im)->rgb= alloc_rgb_image((w), (h)); \ + RgbImage *rgb_save; \ + (im)->rgb= rgb_save= alloc_rgb_image((w), (h)); \ \ int x,y; \ for (y=0; y<(h); y++) { \ for (x=0; x<(w); x++) { \ unsigned char r,g,b; \ COMPUTE_RGB; \ - CANONIMG_ALSO_STORERGB((im)->rgb); \ + CANONIMG_ALSO_STORERGB(rgb_save); \ (im)->d[y*(w) + x]= canon_lookup_colour(r,g,b); \ } \ if (DEBUGP(rect)) { \