chiark / gitweb /
Merge branch 'twomack'
[ypp-sc-tools.db-live.git] / pctb / structure.c
index fba7670a3b510e105dff978f1d21350928c0963f..1f3c743319de029d342bbdbaa9bce1ec920047cb 100644 (file)
@@ -133,20 +133,23 @@ static void mustfail2(void) {
 #define REQUIRE_RECTANGLE(tlx,tly,brx,bry,ok) \
  require_rectangle(tlx, tly, brx, bry, ok, __LINE__);
 
-static void require_rectangle(int tlx, int tly, int brx, int bry,
-                             const char *ok, int lineno) {
+#define FOR_P_RECT(p,rect)                             \
+  for ((p).x=(rr).tl.x; (p).x<=(rr).br.x; (p).x++)     \
+    for ((p).y=(rr).tl.y; (p).y<=(rr).br.y; (p).y++)
+
+static void require_rectangle_r(Rect rr, const char *ok, int lineno) {
   Point p;
-  for (p.x=tlx; p.x<=brx; p.x++)
-    for (p.y=tly; p.y<=bry; p.y++) {
-      int c= get_p(p);
-      MUST( strchr(ok,c), ({
-            Rect rm={{tlx,tly},{brx,bry}};
-            MI(lineno),MR(rm);MP(p);MS(ok);
-      }));
-    }
+  FOR_P_RECT(p,rr) {
+    int c= get_p(p);
+    MUST( strchr(ok,c), ({
+      MI(lineno),MR(rr);MP(p);MS(ok);
+    }));
+  }
 }
-static void require_rectangle_r(Rect rr, const char *ok, int lineno) {
-  require_rectangle(rr.tl.x,rr.tl.y, rr.br.x,rr.br.y, ok, lineno);
+static void require_rectangle(int tlx, int tly, int brx, int bry,
+                             const char *ok, int lineno) {
+  Rect rr= {{tlx,tly},{brx,bry}};
+  require_rectangle_r(rr, ok, lineno);
 }
 
 static void debug_rect(const char *what, int whati, Rect rr) {
@@ -375,7 +378,6 @@ 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 &&
@@ -383,9 +385,6 @@ 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));
@@ -396,8 +395,6 @@ static void file_read_image_ppm(FILE *f) {
        ((unsigned long)rgb_buf[1]<<8) |
                       (rgb_buf[2]);
 
-    if (ri)
-      CANONIMG_ALSO_STORERGB(ri);
   });
 
   sysassert(!ferror(screenshot_file));
@@ -560,7 +557,7 @@ void find_islandname(RgbImage *ri) {
 
   const unsigned char *srcp;
   unsigned char *destp, *endp;
-  for (srcp=page0_rgbimage->data, destp=ri->data,
+  for (srcp=page_images[0]->rgb->data, destp=ri->data,
         endp= ri->data + 3 * ri->w * ri->h;
        destp < endp;
        srcp++, destp++) {
@@ -692,7 +689,7 @@ void find_islandname(RgbImage *ri) {
 
   char *delim= strstr(archisland," - ");
   assert(delim);
-  archipelago= masprintf("%.*s", delim-archisland, archisland);
+  archipelago= masprintf("%.*s", (int)(delim-archisland), archisland);
   island= masprintf("%s", delim+3);
 
   free(ri);