From dac0bb3ca1c725ef968a07bb89fa96ebdc7fb0b9 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 28 Jun 2009 18:18:01 +0100 Subject: [PATCH] Faster, by more in-bulk processing of incoming pixels --- pctb/convert.h | 1 + pctb/pages.c | 24 +++++++++--------------- pctb/rgbimage.c | 11 +++++++++++ 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/pctb/convert.h b/pctb/convert.h index 0abdf93..80979ec 100644 --- a/pctb/convert.h +++ b/pctb/convert.h @@ -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) diff --git a/pctb/pages.c b/pctb/pages.c index a0a52b4..d298ac4 100644 --- a/pctb/pages.c +++ b/pctb/pages.c @@ -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)); diff --git a/pctb/rgbimage.c b/pctb/rgbimage.c index c4fd11d..720e5dc 100644 --- a/pctb/rgbimage.c +++ b/pctb/rgbimage.c @@ -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)); -- 2.30.2