chiark / gitweb /
Adjust colours early so that we don't have to keep all RGBs in RAM
[ypp-sc-tools.main.git] / pctb / rgbimage.c
index d0ba6b797442ef7e7b5c64f6d6d1f557c0c9cafd..81eddf9898e83427a83f7376bef93868e8a4dc56 100644 (file)
@@ -50,9 +50,9 @@
 
 static int identify1(const RgbImage *base, Rect portion,
                    char result[MAXIMGIDENT], const char *what,
-                   const char *which) {
-  char *dbfile_name= masprintf("#%s-pixmap#.txt",which);
-  if (!dbfile_open(dbfile_name))
+                   const char *which, int (*opener)(const char *fn)) {
+  char *dbfile_name= masprintf("_%s-pixmap.txt",which);
+  if (!opener(dbfile_name))
     goto not_found;
 
 #define FGETSLINE (dbfile_getsline(result,MAXIMGIDENT,__FILE__,__LINE__))
@@ -89,7 +89,9 @@ static int identify1(const RgbImage *base, Rect portion,
          int c;
          dbassert( dbfile_scanf("%d",&c) == 1);
          dbassert(c>=0 && c<=255);
-         diff |= (c != RI_PIXEL(base, portion.tl.x + x, portion.tl.y + y)[i]);
+         int px= portion.tl.x + x, py= portion.tl.y + y;
+         diff |= px > portion.br.x || py > portion.br.y ||
+                 (c != RI_PIXEL(base,px,py)[i]);
        }
       }
     }
@@ -109,8 +111,19 @@ static int identify1(const RgbImage *base, Rect portion,
 
 static int identify(const RgbImage *base, Rect portion,
                    char result[MAXIMGIDENT], const char *what) {
-  return identify1(base,portion,result,what, "master") ||
-         identify1(base,portion,result,what, "local");
+  return identify1(base,portion,result,what, "master", dbfile_gzopen) ||
+         identify1(base,portion,result,what, "local",  dbfile_open);
+}
+
+void fwrite_ppmraw(FILE *f, const RgbImage *ri) {
+  fprintf(f,
+         "P6\n"
+         "%d %d\n"
+         "255\n", ri->w, ri->h);
+  int count= ri->w * ri->h * 3;
+  sysassert( fwrite(ri->data, 1, count, f) == count );
+  sysassert(!ferror(f));
+  sysassert(!fflush(f));
 }
 
 static void fwrite_ppm(FILE *f, const RgbImage *base, Rect portion) {
@@ -133,7 +146,8 @@ void identify_rgbimage(const RgbImage *base, Rect portion,
   static int synced;
 
   if (!synced) {
-    fetch_with_rsync("pixmap");
+    if (o_flags & ff_dict_fetch)
+      fetch_with_rsync_gz("pixmap");
     synced++;
   }