--- ray/src/px/x11image.c 1990/12/21 17:20:11 1.12 +++ ray/src/px/x11image.c 1991/05/03 09:49:02 1.18 @@ -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) @@ -77,6 +79,8 @@ int cury = 0; /* current scan location */ double exposure = 1.0; /* exposure compensation used */ +int wrongformat = 0; /* input in another format? */ + GC revgc; /* graphics context with GXinvert */ XRASTER *ourras; /* our stored image */ @@ -88,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]; @@ -156,10 +163,10 @@ char *argv[]; } else if (i != argc) goto userr; /* get header */ - getheader(fin, headline); + getheader(fin, headline, NULL); /* get picture dimensions */ - if (fgetresolu(&xmax, &ymax, fin) != (YMAJOR|YDECR)) - quiterr("bad picture size"); + if (wrongformat || fgetresolu(&xmax, &ymax, fin) != (YMAJOR|YDECR)) + quiterr("bad picture format"); /* set view parameters */ if (gotview && setview(&ourview) != NULL) gotview = 0; @@ -183,10 +190,14 @@ char *s; { static char *altname[] = {"rview","rpict","pinterp",VIEWSTR,NULL}; register char **an; + char fmt[32]; if (isexpos(s)) exposure *= exposval(s); - else + else if (isformat(s)) { + formatval(fmt, s); + wrongformat = strcmp(fmt, COLRFMT); + } else for (an = altname; *an != NULL; an++) if (!strncmp(*an, s, strlen(*an))) { if (sscanview(&ourview, s+strlen(*an)) > 0) @@ -198,6 +209,7 @@ char *s; init() /* get data and open window */ { + XWMHints ourxwmhints; XSetWindowAttributes ourwinattr; XSizeHints oursizhints; register int i; @@ -260,6 +272,11 @@ 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); @@ -411,7 +428,7 @@ XKeyPressedEvent *ekey; sprintf(buf, "%.3f", intens(cval)/exposure); break; case 'l': /* luminance */ - sprintf(buf, "%.0fn", bright(cval)*683.0/exposure); + sprintf(buf, "%.0fL", luminance(cval)/exposure); break; case 'c': /* color */ comp = pow(2.0, (double)scale); @@ -614,6 +631,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)) @@ -630,6 +648,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; @@ -645,6 +706,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]; @@ -712,6 +774,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];