--- ray/src/px/x11image.c 1991/04/18 14:35:49 1.14 +++ ray/src/px/x11image.c 1991/05/03 09:54:31 1.19 @@ -37,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) @@ -90,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]; @@ -204,6 +209,7 @@ char *s; init() /* get data and open window */ { + XWMHints ourxwmhints; XSetWindowAttributes ourwinattr; XSizeHints oursizhints; register int i; @@ -240,7 +246,6 @@ 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)); if (geometry != NULL) { @@ -266,10 +271,17 @@ init() /* get data and open window */ } XSetNormalHints(thedisplay, wind, &oursizhints); } + ourxwmhints.flags = InputHint|IconPixmapHint; + ourxwmhints.input = True; + ourxwmhints.icon_pixmap = XCreateBitmapFromData(thedisplay, + wind, icondata, iconwidth, iconheight); + XSetWMHints(thedisplay, wind, &ourxwmhints); XSelectInput(thedisplay, wind, ButtonPressMask|ButtonReleaseMask |ButtonMotionMask|StructureNotifyMask |KeyPressMask|ExposureMask); XMapWindow(thedisplay, wind); + /* store name last as ready signal */ + XStoreName(thedisplay, wind, fname == NULL ? progname : fname); return; memerr: quiterr("out of memory"); @@ -417,7 +429,7 @@ XKeyPressedEvent *ekey; sprintf(buf, "%.3f", intens(cval)/exposure); break; case 'l': /* luminance */ - sprintf(buf, "%.0fn", luminance(cval)/exposure); + sprintf(buf, "%.0fL", luminance(cval)/exposure); break; case 'c': /* color */ comp = pow(2.0, (double)scale); @@ -620,6 +632,7 @@ 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)) @@ -636,6 +649,49 @@ getmono() /* get monochrome data */ } +add2icon(y, scan) /* add a scanline to our icon data */ +int y; +COLR *scan; +{ + static char *dp = NULL; + static short cerr[ICONSIZ]; + register int err; + register int x, xi; + + if (iconheight == 0) { /* initialize */ + if (xmax <= ICONSIZ && ymax <= ICONSIZ) { + iconwidth = xmax; + iconheight = ymax; + } else if (xmax > ymax) { + iconwidth = ICONSIZ; + iconheight = ICONSIZ*ymax/xmax; + } else { + iconwidth = ICONSIZ*xmax/ymax; + iconheight = ICONSIZ; + } + dp = icondata - 1; + } + if (dp == NULL) /* done already */ + return; + if (y % (ymax/iconheight)) /* skip this one */ + return; + err = 0; + for (x = 0; x < iconwidth; x++) { + if (!(x&7)) + *++dp = 0; + xi = x*xmax/iconwidth; + err += normbright(scan[xi]) + cerr[x]; + if (err > 127) + err -= 255; + else + *dp |= 1<<(x&07); + cerr[x] = err >>= 1; + } + if (y >= ymax - ymax/iconheight) /* all done */ + dp = NULL; +} + + getfull() /* get full (24-bit) data */ { int y; @@ -651,6 +707,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]; @@ -718,6 +775,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];