1 |
< |
/* Copyright (c) 1991 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1993 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 |
|
|
28 |
|
|
29 |
|
#define PACKSIZ 256 /* max. calculation packet size */ |
30 |
|
|
31 |
< |
#define RTCOM "rtrace -h- -ovl -fff" |
31 |
> |
#define RTCOM "rtrace -h- -ovl -fff " |
32 |
|
|
33 |
|
#define ABS(x) ((x)>0?(x):-(x)) |
34 |
|
|
155 |
|
vresolu = atoi(argv[++i]); |
156 |
|
break; |
157 |
|
case 'p': /* pixel aspect */ |
158 |
< |
check(2,"f"); |
158 |
> |
if (argv[i][2] != 'a') |
159 |
> |
goto badopt; |
160 |
> |
check(3,"f"); |
161 |
|
pixaspect = atof(argv[++i]); |
162 |
|
break; |
163 |
|
case 'v': /* view file */ |
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); |
175 |
< |
} 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); |
192 |
|
} |
193 |
|
normaspect(viewaspect(&ourview), &pixaspect, &hresolu, &vresolu); |
194 |
|
/* allocate frame */ |
195 |
< |
ourpict = (COLR *)malloc(hresolu*vresolu*sizeof(COLR)); |
196 |
< |
ourzbuf = (float *)calloc(hresolu*vresolu,sizeof(float)); |
195 |
> |
ourpict = (COLR *)bmalloc(hresolu*vresolu*sizeof(COLR)); |
196 |
> |
ourzbuf = (float *)bmalloc(hresolu*vresolu*sizeof(float)); |
197 |
|
if (ourpict == NULL || ourzbuf == NULL) |
198 |
< |
syserror(); |
198 |
> |
syserror(progname); |
199 |
> |
bzero((char *)ourzbuf, hresolu*vresolu*sizeof(float)); |
200 |
> |
/* new header */ |
201 |
> |
newheader("RADIANCE", stdout); |
202 |
|
/* get input */ |
203 |
|
for ( ; i < argc; i += 2) |
204 |
|
addpicture(argv[i], argv[i+1]); |
241 |
|
headline(s) /* process header string */ |
242 |
|
char *s; |
243 |
|
{ |
246 |
– |
static char *altname[] = {VIEWSTR,"rpict","rview","pinterp",NULL}; |
247 |
– |
register char **an; |
244 |
|
char fmt[32]; |
245 |
|
|
246 |
< |
if (isformat(s)) { |
247 |
< |
formatval(fmt, s); |
246 |
> |
if (isheadid(s)) |
247 |
> |
return; |
248 |
> |
if (formatval(fmt, s)) { |
249 |
|
wrongformat = strcmp(fmt, COLRFMT); |
250 |
|
return; |
251 |
|
} |
256 |
|
theirexp *= exposval(s); |
257 |
|
return; |
258 |
|
} |
259 |
< |
for (an = altname; *an != NULL; an++) |
260 |
< |
if (!strncmp(*an, s, strlen(*an))) { |
264 |
< |
if (sscanview(&theirview, s+strlen(*an)) > 0) |
265 |
< |
gotview++; |
266 |
< |
break; |
267 |
< |
} |
259 |
> |
if (isview(s) && sscanview(&theirview, s) > 0) |
260 |
> |
gotview++; |
261 |
|
} |
262 |
|
|
263 |
|
|
272 |
|
struct position *plast; |
273 |
|
int y; |
274 |
|
/* open picture file */ |
275 |
< |
if ((pfp = fopen(pfile, "r")) == NULL) { |
276 |
< |
perror(pfile); |
284 |
< |
exit(1); |
285 |
< |
} |
275 |
> |
if ((pfp = fopen(pfile, "r")) == NULL) |
276 |
> |
syserror(pfile); |
277 |
|
/* get header with exposure and view */ |
278 |
|
theirexp = 1.0; |
279 |
|
gotview = 0; |
299 |
|
plast = (struct position *)calloc(scanlen(&tresolu), |
300 |
|
sizeof(struct position)); |
301 |
|
if (scanin == NULL || zin == NULL || plast == NULL) |
302 |
< |
syserror(); |
302 |
> |
syserror(progname); |
303 |
|
/* get z specification or file */ |
304 |
|
if ((zfd = open(zspec, O_RDONLY)) == -1) { |
305 |
|
double zvalue; |
306 |
|
register int x; |
307 |
< |
if (!isfloat(zspec) || (zvalue = atof(zspec)) <= 0.0) { |
308 |
< |
perror(zspec); |
318 |
< |
exit(1); |
319 |
< |
} |
307 |
> |
if (!isfloat(zspec) || (zvalue = atof(zspec)) <= 0.0) |
308 |
> |
syserror(zspec); |
309 |
|
for (x = scanlen(&tresolu); x-- > 0; ) |
310 |
|
zin[x] = zvalue; |
311 |
|
} |
380 |
|
float *zline; |
381 |
|
struct position *lasty; /* input/output */ |
382 |
|
{ |
394 |
– |
extern double sqrt(); |
383 |
|
FVECT pos; |
384 |
|
struct position lastx, newpos; |
385 |
|
register int x; |
516 |
|
/* get back buffer */ |
517 |
|
yback = (int *)malloc(hresolu*sizeof(int)); |
518 |
|
if (yback == NULL) |
519 |
< |
syserror(); |
519 |
> |
syserror(progname); |
520 |
|
for (x = 0; x < hresolu; x++) |
521 |
|
yback[x] = -2; |
522 |
|
/* |
620 |
|
fprtresolu(hresolu, vresolu, stdout); |
621 |
|
for (y = vresolu-1; y >= 0; y--) |
622 |
|
if (fwritecolrs(pscan(y), hresolu, stdout) < 0) |
623 |
< |
syserror(); |
623 |
> |
syserror(progname); |
624 |
|
} |
625 |
|
|
626 |
|
|
627 |
|
writedistance(fname) /* write out z file */ |
628 |
|
char *fname; |
629 |
|
{ |
642 |
– |
extern double sqrt(); |
630 |
|
int donorm = normdist && ourview.type == VT_PER; |
631 |
|
int fd; |
632 |
|
int y; |
633 |
|
float *zout; |
634 |
|
|
635 |
< |
if ((fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1) { |
636 |
< |
perror(fname); |
650 |
< |
exit(1); |
651 |
< |
} |
635 |
> |
if ((fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1) |
636 |
> |
syserror(fname); |
637 |
|
if (donorm |
638 |
|
&& (zout = (float *)malloc(hresolu*sizeof(float))) == NULL) |
639 |
< |
syserror(); |
639 |
> |
syserror(progname); |
640 |
|
for (y = vresolu-1; y >= 0; y--) { |
641 |
|
if (donorm) { |
642 |
|
double vx, yzn2; |
651 |
|
} else |
652 |
|
zout = zscan(y); |
653 |
|
if (write(fd, (char *)zout, hresolu*sizeof(float)) |
654 |
< |
< hresolu*sizeof(float)) { |
655 |
< |
perror(fname); |
671 |
< |
exit(1); |
672 |
< |
} |
654 |
> |
< hresolu*sizeof(float)) |
655 |
> |
syserror(fname); |
656 |
|
} |
657 |
|
if (donorm) |
658 |
|
free((char *)zout); |
698 |
|
cp = combuf; |
699 |
|
wp = argv; |
700 |
|
for ( ; ; ) { |
701 |
< |
while (isspace(*cp)) cp++; |
702 |
< |
if (!*cp) break; |
703 |
< |
*wp++ = cp; |
704 |
< |
while (!isspace(*cp)) |
705 |
< |
if (!*cp++) goto done; |
706 |
< |
*cp++ = '\0'; |
701 |
> |
while (isspace(*cp)) /* nullify spaces */ |
702 |
> |
*cp++ = '\0'; |
703 |
> |
if (!*cp) /* all done? */ |
704 |
> |
break; |
705 |
> |
*wp++ = cp; /* add argument to list */ |
706 |
> |
while (*++cp && !isspace(*cp)) |
707 |
> |
; |
708 |
|
} |
725 |
– |
done: |
709 |
|
*wp = NULL; |
710 |
|
/* start process */ |
711 |
|
if ((rval = open_process(PDesc, argv)) < 0) |
712 |
< |
syserror(); |
712 |
> |
syserror(progname); |
713 |
|
if (rval == 0) { |
714 |
|
fprintf(stderr, "%s: command not found\n", argv[0]); |
715 |
|
exit(1); |
750 |
|
register float *fbp; |
751 |
|
register int i; |
752 |
|
|
753 |
+ |
if (queuesiz == 0) |
754 |
+ |
return; |
755 |
|
fbp = fbuf; |
756 |
|
for (i = 0; i < queuesiz; i++) { |
757 |
|
viewray(orig, dir, &ourview, |
785 |
|
} |
786 |
|
|
787 |
|
|
788 |
< |
syserror() /* report error and exit */ |
788 |
> |
syserror(s) /* report error and exit */ |
789 |
> |
char *s; |
790 |
|
{ |
791 |
< |
perror(progname); |
791 |
> |
perror(s); |
792 |
|
exit(1); |
793 |
|
} |