chiark / gitweb /
constify CanonImage->rgb and make a copy in find_islandname
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sun, 5 Jul 2009 19:09:57 +0000 (20:09 +0100)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sun, 5 Jul 2009 19:09:57 +0000 (20:09 +0100)
pctb/common.h
pctb/convert.c
pctb/convert.h
pctb/pages.c
pctb/structure.c
pctb/structure.h

index 52f57d699c4cefd959d300bc44349038d7e4e5a8..210f23ac4834baa516d8b707025ca956e93e3083 100644 (file)
@@ -49,7 +49,7 @@
 
 typedef struct {
   int w,h;
-  struct RgbImage *rgb;
+  const struct RgbImage *rgb;
   char d[];
 } CanonImage;
 
index 9fcbd58483fb08587a040fd25cd33c4aecdec571..8386c1609a0f68f85a0936a0df953b26c120f2c2 100644 (file)
@@ -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) );
index 6601b77386c20a8fa3a5c1f23db7e69179735887..ba13c433f3e4340d02b8b0c0522551587750481a 100644 (file)
@@ -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);
index c504c951e75956e77b2a3c2ad6e9504d169bab62..010299948d929d3f1ce247d683de11b900bb6697 100644 (file)
@@ -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++;
index a0b1060d9c48475c053c16ef35c88d1806cf03a0..967de1e990a778049f4aaaad2d32823a4812b54c 100644 (file)
@@ -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];
 
index ec7b4bf5b2490411141b66eb2e996d0423b80fe3..84fdcae2e2a1fb75c004634301b008e4c859cba4 100644 (file)
@@ -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)) {                                      \