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 52f57d6..210f23a 100644 (file)
@@ -49,7 +49,7 @@
 
 typedef struct {
   int w,h;
-  struct RgbImage *rgb;
+  const struct RgbImage *rgb;
   char d[];
 } CanonImage;
 
index 9fcbd58..8386c16 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 6601b77..ba13c43 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 c504c95..0102999 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 a0b1060..967de1e 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 ec7b4bf..84fdcae 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)) {                                      \