| 1 |
< |
/* Copyright (c) 1991 Regents of the University of California */ |
| 1 |
> |
/* Copyright (c) 1994 Regents of the University of California */ |
| 2 |
|
|
| 3 |
|
#ifndef lint |
| 4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
| 12 |
|
|
| 13 |
|
#include "standard.h" |
| 14 |
|
|
| 15 |
– |
#include <fcntl.h> |
| 16 |
– |
|
| 15 |
|
#include <ctype.h> |
| 16 |
|
|
| 17 |
|
#include "view.h" |
| 20 |
|
|
| 21 |
|
#include "resolu.h" |
| 22 |
|
|
| 25 |
– |
#ifndef BSD |
| 26 |
– |
#define vfork fork |
| 27 |
– |
#endif |
| 28 |
– |
|
| 23 |
|
#define pscan(y) (ourpict+(y)*hresolu) |
| 24 |
|
#define zscan(y) (ourzbuf+(y)*hresolu) |
| 25 |
|
|
| 165 |
|
goto badopt; |
| 166 |
|
check(3,"s"); |
| 167 |
|
gotvfile = viewfile(argv[++i], &ourview, 0, 0); |
| 168 |
< |
if (gotvfile < 0) { |
| 169 |
< |
perror(argv[i]); |
| 170 |
< |
exit(1); |
| 177 |
< |
} else if (gotvfile == 0) { |
| 168 |
> |
if (gotvfile < 0) |
| 169 |
> |
syserror(argv[i]); |
| 170 |
> |
else if (gotvfile == 0) { |
| 171 |
|
fprintf(stderr, "%s: bad view file\n", |
| 172 |
|
argv[i]); |
| 173 |
|
exit(1); |
| 186 |
|
if (fillsamp == 1) |
| 187 |
|
fillo &= ~F_BACK; |
| 188 |
|
/* set view */ |
| 189 |
< |
if (err = setview(&ourview)) { |
| 189 |
> |
if (ourview.vaft > FTINY) |
| 190 |
> |
err = "no aft clipping plane allowed"; |
| 191 |
> |
else |
| 192 |
> |
err = setview(&ourview); |
| 193 |
> |
if (err != NULL) { |
| 194 |
|
fprintf(stderr, "%s: %s\n", progname, err); |
| 195 |
|
exit(1); |
| 196 |
|
} |
| 199 |
|
ourpict = (COLR *)bmalloc(hresolu*vresolu*sizeof(COLR)); |
| 200 |
|
ourzbuf = (float *)bmalloc(hresolu*vresolu*sizeof(float)); |
| 201 |
|
if (ourpict == NULL || ourzbuf == NULL) |
| 202 |
< |
syserror(); |
| 202 |
> |
syserror(progname); |
| 203 |
|
bzero((char *)ourzbuf, hresolu*vresolu*sizeof(float)); |
| 204 |
+ |
/* new header */ |
| 205 |
+ |
newheader("RADIANCE", stdout); |
| 206 |
|
/* get input */ |
| 207 |
|
for ( ; i < argc; i += 2) |
| 208 |
|
addpicture(argv[i], argv[i+1]); |
| 247 |
|
{ |
| 248 |
|
char fmt[32]; |
| 249 |
|
|
| 250 |
< |
if (isformat(s)) { |
| 251 |
< |
formatval(fmt, s); |
| 250 |
> |
if (isheadid(s)) |
| 251 |
> |
return; |
| 252 |
> |
if (formatval(fmt, s)) { |
| 253 |
|
wrongformat = strcmp(fmt, COLRFMT); |
| 254 |
|
return; |
| 255 |
|
} |
| 276 |
|
struct position *plast; |
| 277 |
|
int y; |
| 278 |
|
/* open picture file */ |
| 279 |
< |
if ((pfp = fopen(pfile, "r")) == NULL) { |
| 280 |
< |
perror(pfile); |
| 281 |
< |
exit(1); |
| 282 |
< |
} |
| 279 |
> |
if ((pfp = fopen(pfile, "r")) == NULL) |
| 280 |
> |
syserror(pfile); |
| 281 |
|
/* get header with exposure and view */ |
| 282 |
|
theirexp = 1.0; |
| 283 |
|
gotview = 0; |
| 303 |
|
plast = (struct position *)calloc(scanlen(&tresolu), |
| 304 |
|
sizeof(struct position)); |
| 305 |
|
if (scanin == NULL || zin == NULL || plast == NULL) |
| 306 |
< |
syserror(); |
| 306 |
> |
syserror(progname); |
| 307 |
|
/* get z specification or file */ |
| 308 |
|
if ((zfd = open(zspec, O_RDONLY)) == -1) { |
| 309 |
|
double zvalue; |
| 310 |
|
register int x; |
| 311 |
< |
if (!isfloat(zspec) || (zvalue = atof(zspec)) <= 0.0) { |
| 312 |
< |
perror(zspec); |
| 315 |
< |
exit(1); |
| 316 |
< |
} |
| 311 |
> |
if (!isfloat(zspec) || (zvalue = atof(zspec)) <= 0.0) |
| 312 |
> |
syserror(zspec); |
| 313 |
|
for (x = scanlen(&tresolu); x-- > 0; ) |
| 314 |
|
zin[x] = zvalue; |
| 315 |
|
} |
| 384 |
|
float *zline; |
| 385 |
|
struct position *lasty; /* input/output */ |
| 386 |
|
{ |
| 391 |
– |
extern double sqrt(); |
| 387 |
|
FVECT pos; |
| 388 |
|
struct position lastx, newpos; |
| 389 |
|
register int x; |
| 498 |
|
pos[1] += .5 - ourview.voff; |
| 499 |
|
return(0); |
| 500 |
|
} |
| 501 |
< |
if (viewray(pt, direc, &theirview, pos[0], pos[1]) < 0) |
| 501 |
> |
if (viewray(pt, direc, &theirview, pos[0], pos[1]) < -FTINY) |
| 502 |
|
return(-1); |
| 503 |
|
pt[0] += direc[0]*pos[2]; |
| 504 |
|
pt[1] += direc[1]*pos[2]; |
| 520 |
|
/* get back buffer */ |
| 521 |
|
yback = (int *)malloc(hresolu*sizeof(int)); |
| 522 |
|
if (yback == NULL) |
| 523 |
< |
syserror(); |
| 523 |
> |
syserror(progname); |
| 524 |
|
for (x = 0; x < hresolu; x++) |
| 525 |
|
yback[x] = -2; |
| 526 |
|
/* |
| 624 |
|
fprtresolu(hresolu, vresolu, stdout); |
| 625 |
|
for (y = vresolu-1; y >= 0; y--) |
| 626 |
|
if (fwritecolrs(pscan(y), hresolu, stdout) < 0) |
| 627 |
< |
syserror(); |
| 627 |
> |
syserror(progname); |
| 628 |
|
} |
| 629 |
|
|
| 630 |
|
|
| 631 |
|
writedistance(fname) /* write out z file */ |
| 632 |
|
char *fname; |
| 633 |
|
{ |
| 639 |
– |
extern double sqrt(); |
| 634 |
|
int donorm = normdist && ourview.type == VT_PER; |
| 635 |
|
int fd; |
| 636 |
|
int y; |
| 637 |
|
float *zout; |
| 638 |
|
|
| 639 |
< |
if ((fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1) { |
| 640 |
< |
perror(fname); |
| 647 |
< |
exit(1); |
| 648 |
< |
} |
| 639 |
> |
if ((fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1) |
| 640 |
> |
syserror(fname); |
| 641 |
|
if (donorm |
| 642 |
|
&& (zout = (float *)malloc(hresolu*sizeof(float))) == NULL) |
| 643 |
< |
syserror(); |
| 643 |
> |
syserror(progname); |
| 644 |
|
for (y = vresolu-1; y >= 0; y--) { |
| 645 |
|
if (donorm) { |
| 646 |
|
double vx, yzn2; |
| 655 |
|
} else |
| 656 |
|
zout = zscan(y); |
| 657 |
|
if (write(fd, (char *)zout, hresolu*sizeof(float)) |
| 658 |
< |
< hresolu*sizeof(float)) { |
| 659 |
< |
perror(fname); |
| 668 |
< |
exit(1); |
| 669 |
< |
} |
| 658 |
> |
< hresolu*sizeof(float)) |
| 659 |
> |
syserror(fname); |
| 660 |
|
} |
| 661 |
|
if (donorm) |
| 662 |
|
free((char *)zout); |
| 702 |
|
cp = combuf; |
| 703 |
|
wp = argv; |
| 704 |
|
for ( ; ; ) { |
| 705 |
< |
while (isspace(*cp)) cp++; |
| 706 |
< |
if (!*cp) break; |
| 707 |
< |
*wp++ = cp; |
| 708 |
< |
while (!isspace(*cp)) |
| 709 |
< |
if (!*cp++) goto done; |
| 710 |
< |
*cp++ = '\0'; |
| 705 |
> |
while (isspace(*cp)) /* nullify spaces */ |
| 706 |
> |
*cp++ = '\0'; |
| 707 |
> |
if (!*cp) /* all done? */ |
| 708 |
> |
break; |
| 709 |
> |
*wp++ = cp; /* add argument to list */ |
| 710 |
> |
while (*++cp && !isspace(*cp)) |
| 711 |
> |
; |
| 712 |
|
} |
| 722 |
– |
done: |
| 713 |
|
*wp = NULL; |
| 714 |
|
/* start process */ |
| 715 |
|
if ((rval = open_process(PDesc, argv)) < 0) |
| 716 |
< |
syserror(); |
| 716 |
> |
syserror(progname); |
| 717 |
|
if (rval == 0) { |
| 718 |
|
fprintf(stderr, "%s: command not found\n", argv[0]); |
| 719 |
|
exit(1); |
| 754 |
|
register float *fbp; |
| 755 |
|
register int i; |
| 756 |
|
|
| 757 |
+ |
if (queuesiz == 0) |
| 758 |
+ |
return; |
| 759 |
|
fbp = fbuf; |
| 760 |
|
for (i = 0; i < queuesiz; i++) { |
| 761 |
|
viewray(orig, dir, &ourview, |
| 789 |
|
} |
| 790 |
|
|
| 791 |
|
|
| 792 |
< |
syserror() /* report error and exit */ |
| 792 |
> |
syserror(s) /* report error and exit */ |
| 793 |
> |
char *s; |
| 794 |
|
{ |
| 795 |
< |
perror(progname); |
| 795 |
> |
perror(s); |
| 796 |
|
exit(1); |
| 797 |
|
} |