--- ray/src/px/x11image.c 1990/08/30 11:21:34 1.7 +++ ray/src/px/x11image.c 1991/05/01 12:40:00 1.16 @@ -30,6 +30,7 @@ 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 */ @@ -77,6 +78,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 */ @@ -156,10 +159,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 +186,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 +205,7 @@ char *s; init() /* get data and open window */ { + XWMHints ourxwmhints; XSetWindowAttributes ourwinattr; XSizeHints oursizhints; register int i; @@ -240,7 +248,8 @@ init() /* get data and open window */ if (geometry != NULL) { bzero((char *)&oursizhints, sizeof(oursizhints)); i = XParseGeometry(geometry, &oursizhints.x, &oursizhints.y, - &oursizhints.width, &oursizhints.height); + (unsigned *)&oursizhints.width, + (unsigned *)&oursizhints.height); if ((i&(WidthValue|HeightValue)) == (WidthValue|HeightValue)) oursizhints.flags |= USSize; else { @@ -259,6 +268,11 @@ init() /* get data and open window */ } XSetNormalHints(thedisplay, wind, &oursizhints); } + ourxwmhints.flags = InputHint|IconPixmapHint; + ourxwmhints.input = True; + ourxwmhints.icon_pixmap = XCreateBitmapFromData(thedisplay, + wind, x11icon_bits, x11icon_width, x11icon_height); + XSetWMHints(thedisplay, wind, &ourxwmhints); XSelectInput(thedisplay, wind, ButtonPressMask|ButtonReleaseMask |ButtonMotionMask|StructureNotifyMask |KeyPressMask|ExposureMask); @@ -336,7 +350,7 @@ getras() /* get raster file */ } return; fail: - quit("could not create raster image"); + quiterr("could not create raster image"); } @@ -410,7 +424,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); @@ -445,9 +459,10 @@ XKeyPressedEvent *ekey; XBell(thedisplay, 0); return(-1); } - viewray(rorg, rdir, &ourview, + if (viewray(rorg, rdir, &ourview, (ekey->x-xoff+.5)/xmax, - (ymax-1-ekey->y+yoff+.5)/ymax); + (ymax-1-ekey->y+yoff+.5)/ymax) < 0) + return(-1); printf("%e %e %e ", rorg[0], rorg[1], rorg[2]); printf("%e %e %e\n", rdir[0], rdir[1], rdir[2]); fflush(stdout); @@ -603,20 +618,20 @@ getmono() /* get monochrome data */ register unsigned char *dp; register int x, err; int y; - rgbpixel *inl; short *cerr; - if ((inl = (rgbpixel *)malloc(xmax*sizeof(rgbpixel))) == NULL - || (cerr = (short *)calloc(xmax,sizeof(short))) == NULL) - quit("out of memory in getmono"); + if ((cerr = (short *)calloc(xmax,sizeof(short))) == NULL) + quiterr("out of memory in getmono"); dp = ourdata - 1; for (y = 0; y < ymax; y++) { - picreadline3(y, inl); + if (getscan(y) < 0) + quiterr("seek error in getmono"); + normcolrs(scanline, xmax, scale); err = 0; for (x = 0; x < xmax; x++) { if (!(x&7)) *++dp = 0; - err += rgb_bright(&inl[x]) + cerr[x]; + err += normbright(scanline[x]) + cerr[x]; if (err > 127) err -= 255; else @@ -624,7 +639,6 @@ getmono() /* get monochrome data */ cerr[x] = err >>= 1; } } - free((char *)inl); free((char *)cerr); } @@ -632,9 +646,24 @@ getmono() /* get monochrome data */ getfull() /* get full (24-bit) data */ { int y; - - for (y = 0; y < ymax; y++) - picreadline3(y, (rgbpixel *)(ourdata+y*xmax*3)); + register unsigned char *dp; + register int x; + /* set gamma correction */ + setcolrgam(gamcor); + /* read and convert file */ + dp = ourdata; + for (y = 0; y < ymax; y++) { + if (getscan(y) < 0) + quiterr("seek error in getfull"); + if (scale) + shiftcolrs(scanline, xmax, scale); + colrs_gambs(scanline, xmax); + for (x = 0; x < xmax; x++) { + *dp++ = scanline[x][RED]; + *dp++ = scanline[x][GRN]; + *dp++ = scanline[x][BLU]; + } + } } @@ -673,7 +702,7 @@ int y; if (scanpos == NULL || scanpos[y] == -1) return(-1); if (fseek(fin, scanpos[y], 0) == -1) - quit("fseek error"); + quiterr("fseek error"); cury = y; } else if (scanpos != NULL) scanpos[y] = ftell(fin); @@ -719,7 +748,7 @@ colormap map; register int i, val; for (i = 0; i < 256; i++) { - val = pow(i/256.0, 1.0/gamcor) * 256.0; + val = pow((i+0.5)/256.0, 1.0/gamcor) * 256.0; map[0][i] = map[1][i] = map[2][i] = val; } }