X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?a=blobdiff_plain;f=pctb%2Frgbimage.c;h=dc9fa68996069fbc3518b5d445f6b1766622cf20;hb=9d525e44bd9642a72eb7acd81bd9956b014e3872;hp=798a1043decc6c8badbf5370a9b9df49ba55c5f9;hpb=4c375a59891a4161e30bd67709a1ad5d1950a850;p=ypp-sc-tools.main.git diff --git a/pctb/rgbimage.c b/pctb/rgbimage.c index 798a104..dc9fa68 100644 --- a/pctb/rgbimage.c +++ b/pctb/rgbimage.c @@ -48,9 +48,12 @@ #include "convert.h" -static int identify(const RgbImage *base, Rect portion, - char result[MAXIMGIDENT], const char *what) { - sysassert( dbfile_open("pixmaps.txt") ); +static int identify1(const RgbImage *base, Rect portion, + char result[MAXIMGIDENT], const char *what, + 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__)) @@ -82,12 +85,16 @@ static int identify(const RgbImage *base, Rect portion, int x,y,i; for (y=0; y=0 && c<=255); - diff |= (c != RI_PIXEL(base, portion.tl.x + x, portion.tl.y + y)[i]); + rgb |= (Rgb)c << (i*8); } + int px= portion.tl.x + x, py= portion.tl.y + y; + diff |= px > portion.br.x || py > portion.br.y || + rgb != ri_rgb(base,px,py); } } if (!diff) { @@ -95,21 +102,46 @@ static int identify(const RgbImage *base, Rect portion, goto found; } } + not_found: result[0]= 0; -found: + found: dbfile_close(); + free(dbfile_name); return !!result[0]; } +static int identify(const RgbImage *base, Rect portion, + char result[MAXIMGIDENT], const char *what) { + 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) { + int i; + fprintf(f, + "P6\n" + "%d %d\n" + "255\n", ri->w, ri->h); + for (i=0; i < ri->w * ri->h; i++) { + Rgb rgb= ri->data[i]; + fputc_unlocked(rgb >> 0, f); + fputc_unlocked(rgb >> 8, f); + fputc_unlocked(rgb >> 16, f); + } + 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)); for (y=portion.tl.y; y<=portion.br.y; y++) { for (x=portion.tl.x; x<=portion.br.x; x++) { putc(' ',f); + Rgb rgb= ri_rgb(base,x,y); for (i=0; i<3; i++) - fprintf(f," %3d", RI_PIXEL(base,x,y)[i]); + fprintf(f," %3d", (rgb>>(i*8)) & 0xff); } putc('\n',f); } @@ -119,6 +151,14 @@ static void fwrite_ppm(FILE *f, const RgbImage *base, Rect portion) { void identify_rgbimage(const RgbImage *base, Rect portion, char result[MAXIMGIDENT], const char *what) { + static int synced; + + if (!synced) { + if (o_flags & ff_dict_fetch) + fetch_with_rsync_gz("pixmap"); + synced++; + } + for (;;) { int ok= identify(base, portion, result, what); if (ok) return; @@ -141,7 +181,7 @@ void identify_rgbimage(const RgbImage *base, Rect portion, RgbImage *alloc_rgb_image(int w, int h) { RgbImage *ri; - ri= mmalloc(sizeof(*ri) + w*h*3); + ri= mmalloc(sizeof(*ri) + w*h*sizeof(ri->data[0])); ri->w= w; ri->h= h; return ri;