--- ray/src/px/x11image.c 1991/05/01 12:40:00 1.16 +++ ray/src/px/x11image.c 1991/05/23 12:00:38 1.24 @@ -30,7 +30,6 @@ static char SCCSid[] = "$SunId$ LBL"; #include "pic.h" #include "x11raster.h" #include "random.h" -#include "x11icon.h" #define FONTNAME "8x13" /* text font we'll use */ @@ -38,6 +37,8 @@ static char SCCSid[] = "$SunId$ LBL"; #define BORWIDTH 5 /* border width */ +#define ICONSIZ (8*10) /* maximum icon dimension (even 8) */ + #define ourscreen DefaultScreen(thedisplay) #define ourblack BlackPixel(thedisplay,ourscreen) #define ourwhite WhitePixel(thedisplay,ourscreen) @@ -91,6 +92,9 @@ struct { char *geometry = NULL; /* geometry specification */ +char icondata[ICONSIZ*ICONSIZ/8]; /* icon bitmap data */ +int iconwidth = 0, iconheight = 0; + char *progname; char errmsg[128]; @@ -242,9 +246,9 @@ init() /* get data and open window */ XSetFont(thedisplay, ourgc, fontid); revgc = XCreateGC(thedisplay, wind, 0, 0); XSetFunction(thedisplay, revgc, GXinvert); - XStoreName(thedisplay, wind, fname == NULL ? progname : fname); XDefineCursor(thedisplay, wind, XCreateFontCursor(thedisplay, XC_diamond_cross)); + XStoreName(thedisplay, wind, fname == NULL ? progname : fname); if (geometry != NULL) { bzero((char *)&oursizhints, sizeof(oursizhints)); i = XParseGeometry(geometry, &oursizhints.x, &oursizhints.y, @@ -271,7 +275,7 @@ init() /* get data and open window */ ourxwmhints.flags = InputHint|IconPixmapHint; ourxwmhints.input = True; ourxwmhints.icon_pixmap = XCreateBitmapFromData(thedisplay, - wind, x11icon_bits, x11icon_width, x11icon_height); + wind, icondata, iconwidth, iconheight); XSetWMHints(thedisplay, wind, &ourxwmhints); XSelectInput(thedisplay, wind, ButtonPressMask|ButtonReleaseMask |ButtonMotionMask|StructureNotifyMask @@ -617,7 +621,7 @@ getmono() /* get monochrome data */ { register unsigned char *dp; register int x, err; - int y; + int y, errp; short *cerr; if ((cerr = (short *)calloc(xmax,sizeof(short))) == NULL) @@ -627,22 +631,74 @@ getmono() /* get monochrome data */ if (getscan(y) < 0) quiterr("seek error in getmono"); normcolrs(scanline, xmax, scale); + add2icon(y, scanline); err = 0; for (x = 0; x < xmax; x++) { if (!(x&7)) *++dp = 0; + errp = err; err += normbright(scanline[x]) + cerr[x]; if (err > 127) err -= 255; else *dp |= 1<<(7-(x&07)); - cerr[x] = err >>= 1; + err /= 3; + cerr[x] = err + errp; } } free((char *)cerr); } +add2icon(y, scan) /* add a scanline to our icon data */ +int y; +COLR *scan; +{ + static short cerr[ICONSIZ]; + static int ynext; + static char *dp; + register int err; + register int x, ti; + int errp; + + if (iconheight == 0) { /* initialize */ + if (xmax <= ICONSIZ && ymax <= ICONSIZ) { + iconwidth = xmax; + iconheight = ymax; + } else if (xmax > ymax) { + iconwidth = ICONSIZ; + iconheight = ICONSIZ*ymax/xmax; + if (iconheight < 1) + iconheight = 1; + } else { + iconwidth = ICONSIZ*xmax/ymax; + if (iconwidth < 1) + iconwidth = 1; + iconheight = ICONSIZ; + } + ynext = 0; + dp = icondata - 1; + } + if (y < ynext*ymax/iconheight) /* skip this one */ + return; + err = 0; + for (x = 0; x < iconwidth; x++) { + if (!(x&7)) + *++dp = 0; + errp = err; + ti = x*xmax/iconwidth; + err += normbright(scan[ti]) + cerr[x]; + if (err > 127) + err -= 255; + else + *dp |= 1<<(x&07); + err /= 3; + cerr[x] = err + errp; + } + ynext++; +} + + getfull() /* get full (24-bit) data */ { int y; @@ -658,6 +714,7 @@ getfull() /* get full (24-bit) data */ if (scale) shiftcolrs(scanline, xmax, scale); colrs_gambs(scanline, xmax); + add2icon(y, scanline); for (x = 0; x < xmax; x++) { *dp++ = scanline[x][RED]; *dp++ = scanline[x][GRN]; @@ -725,6 +782,7 @@ register rgbpixel *l3; quiterr("cannot seek for picreadline"); /* convert scanline */ normcolrs(scanline, xmax, scale); + add2icon(y, scanline); for (i = 0; i < xmax; i++) { l3[i].r = scanline[i][RED]; l3[i].g = scanline[i][GRN];