| 30 |
|
#include "pic.h" |
| 31 |
|
#include "x11raster.h" |
| 32 |
|
#include "random.h" |
| 33 |
+ |
#include "resolu.h" |
| 34 |
|
|
| 35 |
|
#define FONTNAME "8x13" /* text font we'll use */ |
| 36 |
|
|
| 37 |
< |
#define CTRL(c) ('c'-'@') |
| 37 |
> |
#define CTRL(c) ((c)-'@') |
| 38 |
|
|
| 39 |
|
#define BORWIDTH 5 /* border width */ |
| 40 |
|
|
| 71 |
|
|
| 72 |
|
COLR *scanline; /* scan line buffer */ |
| 73 |
|
|
| 74 |
< |
int xmax, ymax; /* picture resolution */ |
| 74 |
> |
RESOLU inpres; /* input resolution and ordering */ |
| 75 |
> |
int xmax, ymax; /* picture dimensions */ |
| 76 |
|
int width, height; /* window size */ |
| 77 |
|
char *fname = NULL; /* input file name */ |
| 78 |
|
FILE *fin = stdin; /* input file */ |
| 105 |
|
|
| 106 |
|
extern char *malloc(), *calloc(); |
| 107 |
|
|
| 108 |
< |
extern double atof(), pow(), log(); |
| 108 |
> |
extern double pow(), log(); |
| 109 |
|
|
| 110 |
|
Display *thedisplay; |
| 111 |
|
|
| 167 |
|
/* get header */ |
| 168 |
|
getheader(fin, headline, NULL); |
| 169 |
|
/* get picture dimensions */ |
| 170 |
< |
if (wrongformat || fgetresolu(&xmax, &ymax, fin) != (YMAJOR|YDECR)) |
| 170 |
> |
if (wrongformat || !fgetsresolu(&inpres, fin)) |
| 171 |
|
quiterr("bad picture format"); |
| 172 |
+ |
xmax = scanlen(&inpres); |
| 173 |
+ |
ymax = numscans(&inpres); |
| 174 |
|
/* set view parameters */ |
| 175 |
|
if (gotview && setview(&ourview) != NULL) |
| 176 |
|
gotview = 0; |
| 192 |
|
headline(s) /* get relevant info from header */ |
| 193 |
|
char *s; |
| 194 |
|
{ |
| 191 |
– |
static char *altname[] = {"rview","rpict","pinterp",VIEWSTR,NULL}; |
| 192 |
– |
register char **an; |
| 195 |
|
char fmt[32]; |
| 196 |
|
|
| 197 |
|
if (isexpos(s)) |
| 199 |
|
else if (isformat(s)) { |
| 200 |
|
formatval(fmt, s); |
| 201 |
|
wrongformat = strcmp(fmt, COLRFMT); |
| 202 |
< |
} else |
| 203 |
< |
for (an = altname; *an != NULL; an++) |
| 202 |
< |
if (!strncmp(*an, s, strlen(*an))) { |
| 203 |
< |
if (sscanview(&ourview, s+strlen(*an)) > 0) |
| 204 |
< |
gotview++; |
| 205 |
< |
return; |
| 206 |
< |
} |
| 202 |
> |
} else if (isview(s) && sscanview(&ourview, s) > 0) |
| 203 |
> |
gotview++; |
| 204 |
|
} |
| 205 |
|
|
| 206 |
|
|
| 403 |
|
XColor cvx; |
| 404 |
|
int com, n; |
| 405 |
|
double comp; |
| 406 |
+ |
FLOAT hv[2]; |
| 407 |
|
FVECT rorg, rdir; |
| 408 |
|
|
| 409 |
|
n = XLookupString(ekey, buf, sizeof(buf), NULL, NULL); |
| 412 |
|
com = buf[0]; |
| 413 |
|
switch (com) { /* interpret command */ |
| 414 |
|
case 'q': |
| 415 |
< |
case CTRL(D): /* quit */ |
| 415 |
> |
case CTRL('D'): /* quit */ |
| 416 |
|
quit(0); |
| 417 |
|
case '\n': |
| 418 |
|
case '\r': |
| 452 |
|
XStoreColor(thedisplay, ourras->cmap, &cvx); |
| 453 |
|
return(0); |
| 454 |
|
case 'p': /* position */ |
| 455 |
< |
sprintf(buf, "(%d,%d)", ekey->x-xoff, ymax-1-ekey->y+yoff); |
| 455 |
> |
pix2loc(hv, &inpres, ekey->x-xoff, ekey->y-yoff); |
| 456 |
> |
sprintf(buf, "(%d,%d)", (int)(hv[0]*inpres.xr), |
| 457 |
> |
(int)(hv[1]*inpres.yr)); |
| 458 |
|
XDrawImageString(thedisplay, wind, ourgc, ekey->x, ekey->y, |
| 459 |
|
buf, strlen(buf)); |
| 460 |
|
return(0); |
| 463 |
|
XBell(thedisplay, 0); |
| 464 |
|
return(-1); |
| 465 |
|
} |
| 466 |
< |
if (viewray(rorg, rdir, &ourview, |
| 467 |
< |
(ekey->x-xoff+.5)/xmax, |
| 468 |
< |
(ymax-1-ekey->y+yoff+.5)/ymax) < 0) |
| 466 |
> |
pix2loc(hv, &inpres, ekey->x-xoff, ekey->y-yoff); |
| 467 |
> |
if (viewray(rorg, rdir, &ourview, hv[0], hv[1]) < 0) |
| 468 |
|
return(-1); |
| 469 |
|
printf("%e %e %e ", rorg[0], rorg[1], rorg[2]); |
| 470 |
|
printf("%e %e %e\n", rdir[0], rdir[1], rdir[2]); |
| 486 |
|
free_raster(ourras); |
| 487 |
|
getras(); |
| 488 |
|
/* fall through */ |
| 489 |
< |
case CTRL(R): /* redraw */ |
| 490 |
< |
case CTRL(L): |
| 489 |
> |
case CTRL('R'): /* redraw */ |
| 490 |
> |
case CTRL('L'): |
| 491 |
|
unmap_rcolors(ourras); |
| 492 |
|
XClearWindow(thedisplay, wind); |
| 493 |
|
map_rcolors(ourras, wind); |