| 1 |
– |
/* Copyright (c) 1996 Regents of the University of California */ |
| 2 |
– |
|
| 1 |
|
#ifndef lint |
| 2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
| 2 |
> |
static const char RCSid[] = "$Id$"; |
| 3 |
|
#endif |
| 6 |
– |
|
| 4 |
|
/* |
| 5 |
|
* image.c - routines for image generation. |
| 6 |
+ |
* |
| 7 |
+ |
* External symbols declared in view.h |
| 8 |
|
*/ |
| 9 |
|
|
| 10 |
+ |
#include "copyright.h" |
| 11 |
+ |
|
| 12 |
|
#include "standard.h" |
| 13 |
|
|
| 14 |
|
#include "view.h" |
| 15 |
|
|
| 15 |
– |
#include "resolu.h" |
| 16 |
– |
|
| 16 |
|
#include "paths.h" |
| 17 |
|
|
| 18 |
|
#define FEQ(x,y) (fabs((x)-(y)) <= FTINY) |
| 29 |
|
static char ill_horiz[] = "illegal horizontal view size"; |
| 30 |
|
static char ill_vert[] = "illegal vertical view size"; |
| 31 |
|
|
| 32 |
< |
if (v->vfore < -FTINY || v->vaft < -FTINY || |
| 34 |
< |
(v->vaft > FTINY && v->vaft <= v->vfore)) |
| 32 |
> |
if (v->vaft < -FTINY || (v->vaft > FTINY && v->vaft <= v->vfore)) |
| 33 |
|
return("illegal fore/aft clipping plane"); |
| 34 |
|
|
| 35 |
|
if (normalize(v->vdir) == 0.0) /* normalize direction */ |
| 107 |
|
} |
| 108 |
|
|
| 109 |
|
|
| 110 |
+ |
void |
| 111 |
|
normaspect(va, ap, xp, yp) /* fix pixel aspect or resolution */ |
| 112 |
|
double va; /* view aspect ratio */ |
| 113 |
|
double *ap; /* pixel aspect in (or out if 0) */ |
| 199 |
|
} |
| 200 |
|
|
| 201 |
|
|
| 202 |
+ |
void |
| 203 |
|
viewloc(ip, v, p) /* find image location for point */ |
| 204 |
|
FVECT ip; |
| 205 |
|
register VIEW *v; |
| 246 |
|
d = 1.0/sqrt(d*d + d2*d2); |
| 247 |
|
ip[1] = DOT(disp,v->vvec)*d/v->vn2 + 0.5 - v->voff; |
| 248 |
|
ip[2] = VLEN(disp); |
| 249 |
< |
if (v->vfore > FTINY) |
| 250 |
< |
ip[2] *= (1.0 - v->vfore*d); |
| 249 |
> |
ip[2] *= (1.0 - v->vfore*d); |
| 250 |
|
return; |
| 251 |
|
case VT_ANG: /* angular fisheye */ |
| 252 |
|
ip[0] = 0.5 - v->hoff; |
| 269 |
|
} |
| 270 |
|
|
| 271 |
|
|
| 272 |
+ |
void |
| 273 |
|
pix2loc(loc, rp, px, py) /* compute image location from pixel pos. */ |
| 274 |
< |
FLOAT loc[2]; |
| 274 |
> |
RREAL loc[2]; |
| 275 |
|
register RESOLU *rp; |
| 276 |
|
int px, py; |
| 277 |
|
{ |
| 278 |
|
register int x, y; |
| 279 |
|
|
| 280 |
< |
if (rp->or & YMAJOR) { |
| 280 |
> |
if (rp->rt & YMAJOR) { |
| 281 |
|
x = px; |
| 282 |
|
y = py; |
| 283 |
|
} else { |
| 284 |
|
x = py; |
| 285 |
|
y = px; |
| 286 |
|
} |
| 287 |
< |
if (rp->or & XDECR) |
| 287 |
> |
if (rp->rt & XDECR) |
| 288 |
|
x = rp->xr-1 - x; |
| 289 |
< |
if (rp->or & YDECR) |
| 289 |
> |
if (rp->rt & YDECR) |
| 290 |
|
y = rp->yr-1 - y; |
| 291 |
|
loc[0] = (x+.5)/rp->xr; |
| 292 |
|
loc[1] = (y+.5)/rp->yr; |
| 293 |
|
} |
| 294 |
|
|
| 295 |
|
|
| 296 |
+ |
void |
| 297 |
|
loc2pix(pp, rp, lx, ly) /* compute pixel pos. from image location */ |
| 298 |
|
int pp[2]; |
| 299 |
|
register RESOLU *rp; |
| 303 |
|
|
| 304 |
|
x = lx * rp->xr; |
| 305 |
|
y = ly * rp->yr; |
| 306 |
< |
if (rp->or & XDECR) |
| 306 |
> |
if (rp->rt & XDECR) |
| 307 |
|
x = rp->xr-1 - x; |
| 308 |
< |
if (rp->or & YDECR) |
| 308 |
> |
if (rp->rt & YDECR) |
| 309 |
|
y = rp->yr-1 - y; |
| 310 |
< |
if (rp->or & YMAJOR) { |
| 310 |
> |
if (rp->rt & YMAJOR) { |
| 311 |
|
pp[0] = x; |
| 312 |
|
pp[1] = y; |
| 313 |
|
} else { |
| 394 |
|
int na; |
| 395 |
|
int nvopts = 0; |
| 396 |
|
|
| 397 |
+ |
while (*s == ' ') |
| 398 |
+ |
s++; |
| 399 |
|
if (*s != '-') |
| 400 |
|
s = sskip2(s,1); |
| 401 |
|
while (*s) { |
| 418 |
|
} |
| 419 |
|
|
| 420 |
|
|
| 421 |
+ |
void |
| 422 |
|
fprintview(vp, fp) /* write out view parameters */ |
| 423 |
|
register VIEW *vp; |
| 424 |
|
FILE *fp; |
| 522 |
|
}; |
| 523 |
|
|
| 524 |
|
|
| 525 |
< |
static |
| 525 |
> |
static int |
| 526 |
|
gethview(s, v) /* get view from header */ |
| 527 |
|
char *s; |
| 528 |
|
register struct myview *v; |
| 529 |
|
{ |
| 530 |
|
if (isview(s) && sscanview(v->hv, s) > 0) |
| 531 |
|
v->ok++; |
| 532 |
+ |
return(0); |
| 533 |
|
} |
| 534 |
|
|
| 535 |
|
|
| 542 |
|
struct myview mvs; |
| 543 |
|
FILE *fp; |
| 544 |
|
|
| 545 |
< |
if ((fp = fopen(fname, "r")) == NULL) |
| 545 |
> |
if (fname == NULL || !strcmp(fname, "-")) |
| 546 |
> |
fp = stdin; |
| 547 |
> |
else if ((fp = fopen(fname, "r")) == NULL) |
| 548 |
|
return(-1); |
| 549 |
|
|
| 550 |
|
mvs.hv = vp; |
| 551 |
|
mvs.ok = 0; |
| 552 |
|
|
| 553 |
< |
getheader(fp, gethview, &mvs); |
| 553 |
> |
getheader(fp, (int (*)(char *, char *))&gethview, (char *)&mvs); |
| 554 |
|
|
| 555 |
|
if (rp != NULL && !fgetsresolu(rp, fp)) |
| 556 |
|
mvs.ok = 0; |