--- ray/src/px/x11image.c 1991/05/23 12:00:38 1.24 +++ ray/src/px/x11image.c 1992/04/28 09:40:32 2.4 @@ -1,4 +1,4 @@ -/* Copyright (c) 1990 Regents of the University of California */ +/* Copyright (c) 1991 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -30,10 +30,11 @@ static char SCCSid[] = "$SunId$ LBL"; #include "pic.h" #include "x11raster.h" #include "random.h" +#include "resolu.h" #define FONTNAME "8x13" /* text font we'll use */ -#define CTRL(c) ('c'-'@') +#define CTRL(c) ((c)-'@') #define BORWIDTH 5 /* border width */ @@ -70,7 +71,8 @@ int gotview = 0; /* got parameters from file */ COLR *scanline; /* scan line buffer */ -int xmax, ymax; /* picture resolution */ +RESOLU inpres; /* input resolution and ordering */ +int xmax, ymax; /* picture dimensions */ int width, height; /* window size */ char *fname = NULL; /* input file name */ FILE *fin = stdin; /* input file */ @@ -103,7 +105,7 @@ extern long ftell(); extern char *malloc(), *calloc(); -extern double atof(), pow(), log(); +extern double pow(), log(); Display *thedisplay; @@ -165,8 +167,10 @@ char *argv[]; /* get header */ getheader(fin, headline, NULL); /* get picture dimensions */ - if (wrongformat || fgetresolu(&xmax, &ymax, fin) != (YMAJOR|YDECR)) + if (wrongformat || !fgetsresolu(&inpres, fin)) quiterr("bad picture format"); + xmax = scanlen(&inpres); + ymax = numscans(&inpres); /* set view parameters */ if (gotview && setview(&ourview) != NULL) gotview = 0; @@ -188,8 +192,6 @@ userr: headline(s) /* get relevant info from header */ char *s; { - static char *altname[] = {"rview","rpict","pinterp",VIEWSTR,NULL}; - register char **an; char fmt[32]; if (isexpos(s)) @@ -197,13 +199,8 @@ char *s; 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) - gotview++; - return; - } + } else if (isview(s) && sscanview(&ourview, s) > 0) + gotview++; } @@ -406,6 +403,7 @@ XKeyPressedEvent *ekey; XColor cvx; int com, n; double comp; + FLOAT hv[2]; FVECT rorg, rdir; n = XLookupString(ekey, buf, sizeof(buf), NULL, NULL); @@ -414,7 +412,7 @@ XKeyPressedEvent *ekey; com = buf[0]; switch (com) { /* interpret command */ case 'q': - case CTRL(D): /* quit */ + case CTRL('D'): /* quit */ quit(0); case '\n': case '\r': @@ -454,7 +452,9 @@ XKeyPressedEvent *ekey; XStoreColor(thedisplay, ourras->cmap, &cvx); return(0); case 'p': /* position */ - sprintf(buf, "(%d,%d)", ekey->x-xoff, ymax-1-ekey->y+yoff); + pix2loc(hv, &inpres, ekey->x-xoff, ekey->y-yoff); + sprintf(buf, "(%d,%d)", (int)(hv[0]*inpres.xr), + (int)(hv[1]*inpres.yr)); XDrawImageString(thedisplay, wind, ourgc, ekey->x, ekey->y, buf, strlen(buf)); return(0); @@ -463,9 +463,8 @@ XKeyPressedEvent *ekey; XBell(thedisplay, 0); return(-1); } - if (viewray(rorg, rdir, &ourview, - (ekey->x-xoff+.5)/xmax, - (ymax-1-ekey->y+yoff+.5)/ymax) < 0) + pix2loc(hv, &inpres, ekey->x-xoff, ekey->y-yoff); + if (viewray(rorg, rdir, &ourview, hv[0], hv[1]) < 0) return(-1); printf("%e %e %e ", rorg[0], rorg[1], rorg[2]); printf("%e %e %e\n", rdir[0], rdir[1], rdir[2]); @@ -487,8 +486,8 @@ XKeyPressedEvent *ekey; free_raster(ourras); getras(); /* fall through */ - case CTRL(R): /* redraw */ - case CTRL(L): + case CTRL('R'): /* redraw */ + case CTRL('L'): unmap_rcolors(ourras); XClearWindow(thedisplay, wind); map_rcolors(ourras, wind); @@ -580,6 +579,8 @@ int x0, y0, x1, y1; avgbox(clr) /* average color over current box */ COLOR clr; { + static COLOR lc; + static int ll, lr, lt, lb; int left, right, top, bottom; int y; double d; @@ -603,6 +604,10 @@ COLOR clr; bottom = ymax; if (top >= bottom) return(-1); + if (left == ll && right == lr && top == lt && bottom == lb) { + copycolor(clr, lc); + return; + } for (y = top; y < bottom; y++) { if (getscan(y) == -1) return(-1); @@ -613,6 +618,8 @@ COLOR clr; } d = 1.0/((right-left)*(bottom-top)); scalecolor(clr, d); + ll = left; lr = right; lt = top; lb = bottom; + copycolor(lc, clr); return(0); }