--- ray/src/px/ximage.c 1989/10/20 20:36:10 1.12 +++ ray/src/px/ximage.c 1990/01/18 23:58:26 1.22 @@ -29,6 +29,8 @@ static char SCCSid[] = "$SunId$ LBL"; #include "pic.h" +#include "random.h" + #define controlshift(e) (((XButtonEvent *)(e))->detail & (ShiftMask|ControlMask)) #define FONTNAME "9x15" /* text font we'll use */ @@ -56,7 +58,7 @@ int scale = 0; /* scalefactor; power of two */ int xoff = 0; /* x image offset */ int yoff = 0; /* y image offset */ -VIEW ourview = STDVIEW(0); /* image view parameters */ +VIEW ourview = STDVIEW; /* image view parameters */ int gotview = 0; /* got parameters from file */ COLR *scanline; /* scan line buffer */ @@ -144,10 +146,8 @@ char *argv[]; if (fgetresolu(&xmax, &ymax, fin) != (YMAJOR|YDECR)) quiterr("bad picture size"); /* set view parameters */ - if (gotview) - if (setview(&ourview) != NULL) - gotview = 0; - + if (gotview && setview(&ourview) != NULL) + gotview = 0; if ((scanline = (COLR *)malloc(xmax*sizeof(COLR))) == NULL) quiterr("out of memory"); @@ -169,28 +169,18 @@ char *s; static char *altname[] = {"rview","rpict",VIEWSTR,NULL}; register char **an; - if (!strncmp(s, "EXPOSURE=", 9)) - exposure *= atof(s+9); + if (isexpos(s)) + exposure *= exposval(s); else for (an = altname; *an != NULL; an++) if (!strncmp(*an, s, strlen(*an))) { - if (sscanview(&ourview, s+strlen(*an)) == 0) + if (sscanview(&ourview, s+strlen(*an)) > 0) gotview++; return; } } -char * -sskip(s) /* skip a word */ -register char *s; -{ - while (isspace(*s)) s++; - while (*s && !isspace(*s)) s++; - return(s); -} - - init() /* get data and open window */ { register int i; @@ -358,6 +348,7 @@ XKeyEvent *ekey; { char buf[80]; COLOR cval; + Color cvx; char *cp; int n; double comp; @@ -368,7 +359,7 @@ XKeyEvent *ekey; return(0); switch (*cp) { /* interpret command */ case 'q': - case CTRL(D): /* quiterr */ + case CTRL(D): /* quit */ quit(0); case '\n': case '\r': @@ -379,10 +370,10 @@ XKeyEvent *ekey; switch (*cp) { case '\n': case '\r': /* radiance */ - sprintf(buf, "%-3g", intens(cval)/exposure); + sprintf(buf, "%.3f", intens(cval)/exposure); break; case 'l': /* luminance */ - sprintf(buf, "%-3gL", bright(cval)*683.0/exposure); + sprintf(buf, "%.0fn", bright(cval)*683.0/exposure); break; case 'c': /* color */ comp = pow(2.0, (double)scale); @@ -395,6 +386,17 @@ XKeyEvent *ekey; XText(wind, box.xmin, box.ymin, buf, strlen(buf), fontid, BlackPixel, WhitePixel); return(0); + case 'i': /* identify (contour) */ + if (ourras->pixels == NULL) + return(-1); + n = ourras->data.bz[ekey->x-xoff+BZPixmapSize(xmax,ekey->y-yoff)]; + n = ourras->pmap[n]; + cvx.pixel = ourras->cdefs[n].pixel; + cvx.red = random() & 65535; + cvx.green = random() & 65535; + cvx.blue = random() & 65535; + XStoreColor(&cvx); + return(0); case 'p': /* position */ sprintf(buf, "(%d,%d)", ekey->x-xoff, ymax-1-ekey->y+yoff); XText(wind, ekey->x, ekey->y, buf, strlen(buf), @@ -405,8 +407,8 @@ XKeyEvent *ekey; XFeep(0); return(-1); } - rayview(rorg, rdir, &ourview, - ekey->x-xoff + .5, ymax-1-ekey->y+yoff + .5); + viewray(rorg, rdir, &ourview, (ekey->x-xoff+.5)/xmax, + (ymax-1-ekey->y+yoff+.5)/ymax); printf("%e %e %e ", rorg[0], rorg[1], rorg[2]); printf("%e %e %e\n", rdir[0], rdir[1], rdir[2]); fflush(stdout); @@ -428,6 +430,7 @@ XKeyEvent *ekey; /* fall through */ case CTRL(R): /* redraw */ case CTRL(L): + unmap_rcolors(ourras); XClear(wind); return(redraw(0, 0, width, height)); case ' ': /* clear */ @@ -601,24 +604,26 @@ register XRASTER *xr; double sf; { register int i; - int maxv; + long maxv; + if (xr->pixels == NULL) + return; + sf = pow(sf, 1.0/gamcor); - maxv = (1<<16) / sf; + maxv = 65535/sf; for (i = xr->ncolors; i--; ) { - xr->cdefs[i].red = xr->cdefs[i].red >= maxv ? - (1<<16)-1 : + xr->cdefs[i].red = xr->cdefs[i].red > maxv ? + 65535 : xr->cdefs[i].red * sf; - xr->cdefs[i].green = xr->cdefs[i].green >= maxv ? - (1<<16)-1 : + xr->cdefs[i].green = xr->cdefs[i].green > maxv ? + 65535 : xr->cdefs[i].green * sf; - xr->cdefs[i].blue = xr->cdefs[i].blue >= maxv ? - (1<<16)-1 : + xr->cdefs[i].blue = xr->cdefs[i].blue > maxv ? + 65535 : xr->cdefs[i].blue * sf; } - if (xr->pixels != NULL) - XStoreColors(xr->ncolors, xr->cdefs); + XStoreColors(xr->ncolors, xr->cdefs); } @@ -651,6 +656,10 @@ register rgbpixel *l3; if (getscan(y) < 0) quiterr("cannot seek for picreadline"); /* convert scanline */ + if (scale) + for (i = 0; i < xmax; i++) + if (scanline[i][EXP]) + scanline[i][EXP] += scale; normcolrs(scanline, xmax); for (i = 0; i < xmax; i++) { l3[i].r = scanline[i][RED]; @@ -664,7 +673,7 @@ picwriteline(y, l) /* add 8-bit scanline to image */ int y; pixel *l; { - bcopy(l, ourras->data.bz+BZPixmapSize(xmax,y), BZPixmapSize(xmax,1)); + bcopy((char *)l, (char *)ourras->data.bz+BZPixmapSize(xmax,y), BZPixmapSize(xmax,1)); }