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)
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));
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));