chiark / gitweb /
Faster, by more in-bulk processing of incoming pixels
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sun, 28 Jun 2009 17:18:01 +0000 (18:18 +0100)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sun, 28 Jun 2009 17:18:01 +0000 (18:18 +0100)
pctb/convert.h
pctb/pages.c
pctb/rgbimage.c

index 0abdf93c5c48e5ee986a1b50cec5fef03963b26e..80979ec2e885829f8d15faccd887c9c63a6812b0 100644 (file)
@@ -54,6 +54,7 @@ typedef struct RgbImage {
 void identify_rgbimage(const RgbImage *base, Rect portion,
                       char result[MAXIMGIDENT], const char *what);
 RgbImage *alloc_rgb_image(int w, int h);
+void fwrite_ppmraw(FILE *f, const RgbImage *ri);
 
 #define RI_PIXEL(ri,x,y) ((ri)->data + ((y)*(ri)->w + (x)) * 3)
 
index a0a52b45e4da60e653a73dc76d67bef6226399de..d298ac4597cd7096e7f733b65d97228fdc25a52a 100644 (file)
@@ -497,24 +497,18 @@ static void set_focus_commodity(void) {
 static CanonImage *convert_page(Snapshot *sn, RgbImage *ri) {
   CanonImage *im;
 
-  fprintf(screenshot_file,
-         "P6\n"
-         "%d %d\n"
-         "255\n", sn->w, sn->h);
+  fwrite_ppmraw(screenshot_file, sn);
+  if (ri) memcpy(ri->data, sn->data, ri->h * ri->w * 3);
 
+  unsigned char *pixel= sn->data;
   CANONICALISE_IMAGE(im, sn->w, sn->h, {
-    int i;
-    rgb= 0;
-    for (i=0; i<3; i++) {
-      rgb <<= 8;
-      unsigned long sample= RI_PIXEL(sn,x,y)[i];
-      rgb |= sample;
-      fputc(sample, screenshot_file);
-    }
-    if (ri)
-      CANONIMG_ALSO_STORERGB(ri);
+    rgb=
+      (pixel[0] << 16) |
+      (pixel[1] <<  8) |
+      (pixel[2]      );
+    pixel += 3;
   });
-
+    
   sysassert(!ferror(screenshot_file));
   sysassert(!fflush(screenshot_file));
 
index c4fd11d470c9a06ea39cbf81eb647a4fe26b0698..720e5dce78d398ed7f8fdfc8f1dde353a1532cf4 100644 (file)
@@ -115,6 +115,17 @@ static int identify(const RgbImage *base, Rect portion,
          identify1(base,portion,result,what, "local");
 }
 
+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) {
   int x,y,i;
   fprintf(f,"P3\n%d %d\n255\n", RECT_W(portion), RECT_H(portion));