1 |
< |
/* Copyright (c) 1992 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 "ray.h" |
14 |
|
|
15 |
+ |
#include <sys/types.h> |
16 |
+ |
|
17 |
+ |
#ifndef NIX |
18 |
|
#ifdef BSD |
19 |
|
#include <sys/time.h> |
20 |
|
#include <sys/resource.h> |
21 |
+ |
#else |
22 |
+ |
#include <sys/times.h> |
23 |
+ |
#include <sys/utsname.h> |
24 |
+ |
#include <unistd.h> |
25 |
|
#endif |
26 |
+ |
#endif |
27 |
|
|
28 |
+ |
extern time_t time(); |
29 |
+ |
|
30 |
|
#include <signal.h> |
21 |
– |
#include <fcntl.h> |
31 |
|
|
32 |
|
#include "view.h" |
33 |
|
|
37 |
|
|
38 |
|
#include "paths.h" |
39 |
|
|
40 |
+ |
#define RFTEMPLATE "rfXXXXXX" |
41 |
+ |
|
42 |
+ |
#ifndef SIGCONT |
43 |
+ |
#define SIGCONT SIGIO |
44 |
+ |
#endif |
45 |
+ |
|
46 |
|
int dimlist[MAXDIM]; /* sampling dimensions */ |
47 |
|
int ndims = 0; /* number of sampling dimensions */ |
48 |
|
int samplendx; /* sample index number */ |
50 |
|
VIEW ourview = STDVIEW; /* view parameters */ |
51 |
|
int hresolu = 512; /* horizontal resolution */ |
52 |
|
int vresolu = 512; /* vertical resolution */ |
53 |
< |
double pixaspect = 1.0; /* pixel aspect ratio */ |
53 |
> |
double pixaspect = 1.0; /* pixel aspect ratio */ |
54 |
|
|
55 |
|
int psample = 4; /* pixel sample size */ |
56 |
< |
double maxdiff = .05; /* max. difference for interpolation */ |
57 |
< |
double dstrpix = 0.67; /* square pixel distribution */ |
56 |
> |
double maxdiff = .05; /* max. difference for interpolation */ |
57 |
> |
double dstrpix = 0.67; /* square pixel distribution */ |
58 |
|
|
59 |
< |
double dstrsrc = 0.0; /* square source distribution */ |
60 |
< |
double shadthresh = .05; /* shadow threshold */ |
61 |
< |
double shadcert = .5; /* shadow certainty */ |
59 |
> |
double dstrsrc = 0.0; /* square source distribution */ |
60 |
> |
double shadthresh = .05; /* shadow threshold */ |
61 |
> |
double shadcert = .5; /* shadow certainty */ |
62 |
|
int directrelay = 1; /* number of source relays */ |
63 |
|
int vspretest = 512; /* virtual source pretest density */ |
64 |
< |
int directinvis = 0; /* sources invisible? */ |
65 |
< |
double srcsizerat = .25; /* maximum ratio source size/dist. */ |
64 |
> |
int directvis = 1; /* sources visible? */ |
65 |
> |
double srcsizerat = .25; /* maximum ratio source size/dist. */ |
66 |
|
|
67 |
< |
double specthresh = .15; /* specular sampling threshold */ |
68 |
< |
double specjitter = 1.; /* specular sampling jitter */ |
67 |
> |
double specthresh = .15; /* specular sampling threshold */ |
68 |
> |
double specjitter = 1.; /* specular sampling jitter */ |
69 |
|
|
70 |
|
int maxdepth = 6; /* maximum recursion depth */ |
71 |
< |
double minweight = 5e-3; /* minimum ray weight */ |
71 |
> |
double minweight = 5e-3; /* minimum ray weight */ |
72 |
|
|
73 |
|
COLOR ambval = BLKCOLOR; /* ambient value */ |
74 |
< |
double ambacc = 0.2; /* ambient accuracy */ |
74 |
> |
double ambacc = 0.2; /* ambient accuracy */ |
75 |
|
int ambres = 32; /* ambient resolution */ |
76 |
|
int ambdiv = 128; /* ambient divisions */ |
77 |
|
int ambssamp = 0; /* ambient super-samples */ |
79 |
|
char *amblist[128]; /* ambient include/exclude list */ |
80 |
|
int ambincl = -1; /* include == 1, exclude == 0 */ |
81 |
|
|
82 |
+ |
#ifdef MSDOS |
83 |
+ |
int ralrm = 60; /* seconds between reports */ |
84 |
+ |
#else |
85 |
|
int ralrm = 0; /* seconds between reports */ |
86 |
+ |
#endif |
87 |
|
|
88 |
< |
double pctdone = 0.0; /* percentage done */ |
88 |
> |
double pctdone = 0.0; /* percentage done */ |
89 |
|
|
90 |
< |
long tlastrept = 0L; /* time at last report */ |
90 |
> |
time_t tlastrept = 0L; /* time at last report */ |
91 |
|
|
92 |
< |
extern long time(); |
74 |
< |
extern long tstart; /* starting time */ |
92 |
> |
extern time_t tstart; /* starting time */ |
93 |
|
|
94 |
< |
extern long nrays; /* number of rays traced */ |
94 |
> |
extern unsigned long nrays; /* number of rays traced */ |
95 |
|
|
96 |
< |
#define MAXDIV 16 /* maximum sample size */ |
96 |
> |
#define MAXDIV 16 /* maximum sample size */ |
97 |
|
|
98 |
< |
#define pixjitter() (.5+dstrpix*(.5-frandom())) |
98 |
> |
#define pixjitter() (.5+dstrpix*(.5-frandom())) |
99 |
|
|
82 |
– |
#define RFTEMPLATE "rfXXXXXX" |
83 |
– |
#define HFTEMPLATE TEMPLATE |
84 |
– |
|
85 |
– |
static char *hfname = NULL; /* header file name */ |
86 |
– |
static FILE *hfp = NULL; /* header file pointer */ |
87 |
– |
|
100 |
|
static int hres, vres; /* resolution for this frame */ |
101 |
|
|
102 |
|
extern char *mktemp(); |
103 |
|
|
104 |
< |
double pixvalue(); |
104 |
> |
double pixvalue(); |
105 |
|
|
106 |
+ |
#ifdef NIX |
107 |
+ |
#define file_exists(f) (access(f,F_OK)==0) |
108 |
+ |
#else |
109 |
+ |
#include <sys/types.h> |
110 |
+ |
#include <sys/stat.h> |
111 |
+ |
int |
112 |
+ |
file_exists(fname) /* ordinary file exists? */ |
113 |
+ |
char *fname; |
114 |
+ |
{ |
115 |
+ |
struct stat sbuf; |
116 |
+ |
if (stat(fname, &sbuf) < 0) return(0); |
117 |
+ |
return((sbuf.st_mode & S_IFREG) != 0); |
118 |
+ |
} |
119 |
+ |
#endif |
120 |
|
|
121 |
+ |
|
122 |
|
quit(code) /* quit program */ |
123 |
|
int code; |
124 |
|
{ |
125 |
|
if (code) /* report status */ |
126 |
|
report(); |
127 |
< |
if (hfname != NULL) { /* delete header file */ |
128 |
< |
if (hfp != NULL) |
102 |
< |
fclose(hfp); |
103 |
< |
unlink(hfname); |
104 |
< |
} |
127 |
> |
headclean(); /* delete header file */ |
128 |
> |
pfclean(); /* clean up persist files */ |
129 |
|
exit(code); |
130 |
|
} |
131 |
|
|
132 |
|
|
133 |
< |
#ifdef BSD |
133 |
> |
#ifndef NIX |
134 |
|
report() /* report progress */ |
135 |
|
{ |
136 |
+ |
double u, s; |
137 |
+ |
#ifdef BSD |
138 |
+ |
char hostname[257]; |
139 |
|
struct rusage rubuf; |
140 |
< |
double t; |
140 |
> |
#else |
141 |
> |
struct tms tbuf; |
142 |
> |
struct utsname nambuf; |
143 |
> |
double period; |
144 |
> |
#define hostname nambuf.nodename |
145 |
> |
#endif |
146 |
|
|
147 |
+ |
tlastrept = time((time_t *)NULL); |
148 |
+ |
#ifdef BSD |
149 |
|
getrusage(RUSAGE_SELF, &rubuf); |
150 |
< |
t = (rubuf.ru_utime.tv_usec + rubuf.ru_stime.tv_usec) / 1e6; |
151 |
< |
t += rubuf.ru_utime.tv_sec + rubuf.ru_stime.tv_sec; |
150 |
> |
u = rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec/1e6; |
151 |
> |
s = rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec/1e6; |
152 |
|
getrusage(RUSAGE_CHILDREN, &rubuf); |
153 |
< |
t += (rubuf.ru_utime.tv_usec + rubuf.ru_stime.tv_usec) / 1e6; |
154 |
< |
t += rubuf.ru_utime.tv_sec + rubuf.ru_stime.tv_sec; |
153 |
> |
u += rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec/1e6; |
154 |
> |
s += rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec/1e6; |
155 |
> |
gethostname(hostname, sizeof(hostname)); |
156 |
> |
#else |
157 |
> |
times(&tbuf); |
158 |
> |
#ifdef _SC_CLK_TCK |
159 |
> |
period = 1.0 / sysconf(_SC_CLK_TCK); |
160 |
> |
#else |
161 |
> |
period = 1.0 / 60.0; |
162 |
> |
#endif |
163 |
> |
u = ( tbuf.tms_utime + tbuf.tms_cutime ) * period; |
164 |
> |
s = ( tbuf.tms_stime + tbuf.tms_cstime ) * period; |
165 |
> |
uname(&nambuf); |
166 |
> |
#endif |
167 |
|
|
168 |
< |
sprintf(errmsg, "%ld rays, %4.2f%% done after %5.4f CPU hours\n", |
169 |
< |
nrays, pctdone, t/3600.0); |
168 |
> |
sprintf(errmsg, |
169 |
> |
"%lu rays, %4.2f%% after %.3fu %.3fs %.3fr hours on %s\n", |
170 |
> |
nrays, pctdone, u/3600., s/3600., |
171 |
> |
(tlastrept-tstart)/3600., hostname); |
172 |
|
eputs(errmsg); |
173 |
< |
tlastrept = time((long *)0); |
173 |
> |
#ifndef BSD |
174 |
> |
signal(SIGCONT, report); |
175 |
> |
#undef hostname |
176 |
> |
#endif |
177 |
|
} |
178 |
|
#else |
179 |
|
report() /* report progress */ |
180 |
|
{ |
181 |
< |
tlastrept = time((long *)0); |
182 |
< |
sprintf(errmsg, "%ld rays, %4.2f%% done after %5.4f hours\n", |
181 |
> |
tlastrept = time((time_t *)NULL); |
182 |
> |
sprintf(errmsg, "%lu rays, %4.2f%% after %5.4f hours\n", |
183 |
|
nrays, pctdone, (tlastrept-tstart)/3600.0); |
184 |
|
eputs(errmsg); |
134 |
– |
signal(SIGALRM, report); |
185 |
|
} |
186 |
|
#endif |
187 |
|
|
188 |
|
|
139 |
– |
openheader() /* save standard output to header file */ |
140 |
– |
{ |
141 |
– |
hfname = mktemp(HFTEMPLATE); |
142 |
– |
if (freopen(hfname, "w", stdout) == NULL) { |
143 |
– |
sprintf(errmsg, "cannot open header file \"%s\"", hfname); |
144 |
– |
error(SYSTEM, errmsg); |
145 |
– |
} |
146 |
– |
} |
147 |
– |
|
148 |
– |
|
149 |
– |
closeheader() /* done with header output */ |
150 |
– |
{ |
151 |
– |
if (hfname == NULL) |
152 |
– |
return; |
153 |
– |
if (fflush(stdout) == EOF || (hfp = fopen(hfname, "r")) == NULL) |
154 |
– |
error(SYSTEM, "error reopening header file"); |
155 |
– |
} |
156 |
– |
|
157 |
– |
|
158 |
– |
dupheader() /* repeat header on standard output */ |
159 |
– |
{ |
160 |
– |
register int c; |
161 |
– |
|
162 |
– |
if (fseek(hfp, 0L, 0) < 0) |
163 |
– |
error(SYSTEM, "seek error on header file"); |
164 |
– |
while ((c = getc(hfp)) != EOF) |
165 |
– |
putchar(c); |
166 |
– |
} |
167 |
– |
|
168 |
– |
|
189 |
|
rpict(seq, pout, zout, prvr) /* generate image(s) */ |
190 |
|
int seq; |
191 |
|
char *pout, *zout, *prvr; |
201 |
|
* sequenced file naming. |
202 |
|
*/ |
203 |
|
{ |
204 |
< |
extern char *rindex(), *strncpy(), *strcat(); |
204 |
> |
extern char *rindex(), *strncpy(), *strcat(), *strcpy(); |
205 |
|
char fbuf[128], fbuf2[128]; |
206 |
+ |
int npicts; |
207 |
|
register char *cp; |
208 |
< |
RESOLU rs; |
209 |
< |
double pa; |
189 |
< |
/* finished writing header */ |
190 |
< |
closeheader(); |
208 |
> |
RESOLU rs; |
209 |
> |
double pa; |
210 |
|
/* check sampling */ |
211 |
|
if (psample < 1) |
212 |
|
psample = 1; |
230 |
|
error(USER, "unexpected EOF on view input"); |
231 |
|
prvr = fbuf; /* mark for renaming */ |
232 |
|
} |
233 |
< |
if (pout != NULL) { |
233 |
> |
if (pout != NULL & prvr != NULL) { |
234 |
|
sprintf(fbuf, pout, seq); |
235 |
< |
if (prvr != NULL && !strcmp(prvr, fbuf)) { /* rename */ |
236 |
< |
fbuf2[0] = '\0'; |
237 |
< |
if ((cp = rindex(fbuf, '/')) != NULL) |
238 |
< |
strncpy(fbuf2, fbuf, cp-fbuf+1); |
239 |
< |
strcat(fbuf2, RFTEMPLATE); |
235 |
> |
if (!strcmp(prvr, fbuf)) { /* rename */ |
236 |
> |
strcpy(fbuf2, fbuf); |
237 |
> |
for (cp = fbuf2; *cp; cp++) |
238 |
> |
; |
239 |
> |
while (cp > fbuf2 && !ISDIRSEP(cp[-1])) |
240 |
> |
cp--; |
241 |
> |
strcpy(cp, RFTEMPLATE); |
242 |
|
prvr = mktemp(fbuf2); |
243 |
< |
if (rename(fbuf, prvr) < 0 && errno != ENOENT) { |
244 |
< |
sprintf(errmsg, |
243 |
> |
if (rename(fbuf, prvr) < 0) |
244 |
> |
if (errno == ENOENT) { /* ghost file */ |
245 |
> |
sprintf(errmsg, |
246 |
> |
"new output file \"%s\"", |
247 |
> |
fbuf); |
248 |
> |
error(WARNING, errmsg); |
249 |
> |
prvr = NULL; |
250 |
> |
} else { /* serious error */ |
251 |
> |
sprintf(errmsg, |
252 |
|
"cannot rename \"%s\" to \"%s\"", |
253 |
|
fbuf, prvr); |
254 |
< |
error(SYSTEM, errmsg); |
255 |
< |
} |
254 |
> |
error(SYSTEM, errmsg); |
255 |
> |
} |
256 |
|
} |
257 |
|
} |
258 |
< |
/* render sequence */ |
258 |
> |
npicts = 0; /* render sequence */ |
259 |
|
do { |
260 |
|
if (seq && nextview(stdin) == EOF) |
261 |
|
break; |
262 |
+ |
pctdone = 0.0; |
263 |
|
if (pout != NULL) { |
264 |
|
sprintf(fbuf, pout, seq); |
265 |
+ |
if (file_exists(fbuf)) { |
266 |
+ |
if (prvr != NULL || !strcmp(fbuf, pout)) { |
267 |
+ |
sprintf(errmsg, |
268 |
+ |
"output file \"%s\" exists", |
269 |
+ |
fbuf); |
270 |
+ |
error(USER, errmsg); |
271 |
+ |
} |
272 |
+ |
continue; /* don't clobber */ |
273 |
+ |
} |
274 |
|
if (freopen(fbuf, "w", stdout) == NULL) { |
275 |
|
sprintf(errmsg, |
276 |
|
"cannot open output file \"%s\"", fbuf); |
277 |
|
error(SYSTEM, errmsg); |
278 |
|
} |
279 |
+ |
#ifdef MSDOS |
280 |
+ |
setmode(fileno(stdout), O_BINARY); |
281 |
+ |
#endif |
282 |
|
dupheader(); |
283 |
|
} |
284 |
|
hres = hresolu; vres = vresolu; pa = pixaspect; |
318 |
|
cp = NULL; |
319 |
|
render(cp, prvr); |
320 |
|
prvr = NULL; |
321 |
+ |
npicts++; |
322 |
|
} while (seq++); |
323 |
+ |
/* check that we did something */ |
324 |
+ |
if (npicts == 0) |
325 |
+ |
error(WARNING, "no output produced"); |
326 |
|
} |
327 |
|
|
328 |
|
|
368 |
|
sampdens[i] = hstep; |
369 |
|
} else |
370 |
|
sampdens = NULL; |
371 |
< |
/* open z file */ |
371 |
> |
/* open z-file */ |
372 |
|
if (zfile != NULL) { |
373 |
|
if ((zfd = open(zfile, O_WRONLY|O_CREAT, 0666)) == -1) { |
374 |
< |
sprintf(errmsg, "cannot open z file \"%s\"", zfile); |
374 |
> |
sprintf(errmsg, "cannot open z-file \"%s\"", zfile); |
375 |
|
error(SYSTEM, errmsg); |
376 |
|
} |
377 |
+ |
#ifdef MSDOS |
378 |
+ |
setmode(zfd, O_BINARY); |
379 |
+ |
#endif |
380 |
|
for (i = 0; i <= psample; i++) { |
381 |
|
zbar[i] = (float *)malloc(hres*sizeof(float)); |
382 |
|
if (zbar[i] == NULL) |
393 |
|
i = salvage(oldfile); |
394 |
|
if (zfd != -1 && i > 0 && |
395 |
|
lseek(zfd, (long)i*hres*sizeof(float), 0) == -1) |
396 |
< |
error(SYSTEM, "z file seek error in render"); |
396 |
> |
error(SYSTEM, "z-file seek error in render"); |
397 |
|
pctdone = 100.0*i/vres; |
398 |
|
if (ralrm > 0) /* report init stats */ |
399 |
|
report(); |
400 |
< |
#ifndef BSD |
400 |
> |
#ifndef BSD |
401 |
|
else |
402 |
|
#endif |
403 |
< |
signal(SIGALRM, report); |
403 |
> |
signal(SIGCONT, report); |
404 |
|
ypos = vres-1 - i; |
405 |
|
fillscanline(scanbar[0], zbar[0], sampdens, hres, ypos, hstep); |
406 |
|
/* compute scanlines */ |
422 |
|
/* fill bar */ |
423 |
|
fillscanbar(scanbar, zbar, hres, ypos, ystep); |
424 |
|
/* write it out */ |
425 |
< |
#ifndef BSD |
426 |
< |
signal(SIGALRM, SIG_IGN); /* don't interrupt writes */ |
425 |
> |
#ifndef BSD |
426 |
> |
signal(SIGCONT, SIG_IGN); /* don't interrupt writes */ |
427 |
|
#endif |
428 |
|
for (i = ystep; i > 0; i--) { |
429 |
|
if (zfd != -1 && write(zfd, (char *)zbar[i], |
437 |
|
goto writerr; |
438 |
|
/* record progress */ |
439 |
|
pctdone = 100.0*(vres-1-ypos)/vres; |
440 |
< |
if (ralrm > 0 && time((long *)0) >= tlastrept+ralrm) |
440 |
> |
if (ralrm > 0 && time((time_t *)NULL) >= tlastrept+ralrm) |
441 |
|
report(); |
442 |
< |
#ifndef BSD |
442 |
> |
#ifndef BSD |
443 |
|
else |
444 |
< |
signal(SIGALRM, report); |
444 |
> |
signal(SIGCONT, report); |
445 |
|
#endif |
446 |
|
} |
447 |
|
/* clean up */ |
448 |
< |
signal(SIGALRM, SIG_IGN); |
448 |
> |
signal(SIGCONT, SIG_IGN); |
449 |
|
if (zfd != -1) { |
450 |
|
if (write(zfd, (char *)zbar[0], hres*sizeof(float)) |
451 |
|
< hres*sizeof(float)) |
463 |
|
if (sampdens != NULL) |
464 |
|
free(sampdens); |
465 |
|
pctdone = 100.0; |
466 |
+ |
if (ralrm > 0) |
467 |
+ |
report(); |
468 |
+ |
signal(SIGCONT, SIG_DFL); |
469 |
|
return; |
470 |
|
writerr: |
471 |
|
error(SYSTEM, "write error in render"); |
475 |
|
|
476 |
|
|
477 |
|
fillscanline(scanline, zline, sd, xres, y, xstep) /* fill scan at y */ |
478 |
< |
register COLOR *scanline; |
479 |
< |
register float *zline; |
478 |
> |
register COLOR *scanline; |
479 |
> |
register float *zline; |
480 |
|
register char *sd; |
481 |
|
int xres, y, xstep; |
482 |
|
{ |
483 |
|
static int nc = 0; /* number of calls */ |
484 |
|
int bl = xstep, b = xstep; |
485 |
< |
double z; |
485 |
> |
double z; |
486 |
|
register int i; |
487 |
|
|
488 |
|
z = pixvalue(scanline[0], 0, y); |
500 |
|
b = fillsample(scanline, zline, 0, y, i, 0, b/2); |
501 |
|
else |
502 |
|
b = fillsample(scanline+i-xstep, |
503 |
< |
zline ? zline+i-xstep : NULL, |
503 |
> |
zline ? zline+i-xstep : (float *)NULL, |
504 |
|
i-xstep, y, xstep, 0, b/2); |
505 |
|
if (sd) *sd++ = nc & 1 ? bl : b; |
506 |
|
bl = b; |
510 |
|
|
511 |
|
|
512 |
|
fillscanbar(scanbar, zbar, xres, y, ysize) /* fill interior */ |
513 |
< |
register COLOR *scanbar[]; |
514 |
< |
register float *zbar[]; |
513 |
> |
register COLOR *scanbar[]; |
514 |
> |
register float *zbar[]; |
515 |
|
int xres, y, ysize; |
516 |
|
{ |
517 |
|
COLOR vline[MAXDIV+1]; |
528 |
|
zline[ysize] = zbar[ysize][i]; |
529 |
|
} |
530 |
|
|
531 |
< |
b = fillsample(vline, zbar[0] ? zline : NULL, |
531 |
> |
b = fillsample(vline, zbar[0] ? zline : (float *)NULL, |
532 |
|
i, y, 0, ysize, b/2); |
533 |
|
|
534 |
|
for (j = 1; j < ysize; j++) |
541 |
|
|
542 |
|
|
543 |
|
int |
544 |
< |
fillsample(colline, zline, x, y, xlen, ylen, b) /* fill interior points */ |
545 |
< |
register COLOR *colline; |
546 |
< |
register float *zline; |
544 |
> |
fillsample(colline, zline, x, y, xlen, ylen, b) /* fill interior points */ |
545 |
> |
register COLOR *colline; |
546 |
> |
register float *zline; |
547 |
|
int x, y; |
548 |
|
int xlen, ylen; |
549 |
|
int b; |
550 |
|
{ |
551 |
< |
extern double fabs(); |
552 |
< |
double ratio; |
502 |
< |
double z; |
551 |
> |
double ratio; |
552 |
> |
double z; |
553 |
|
COLOR ctmp; |
554 |
|
int ncut; |
555 |
|
register int len; |
586 |
|
/* recurse */ |
587 |
|
ncut += fillsample(colline, zline, x, y, xlen>>1, ylen>>1, (b-1)/2); |
588 |
|
|
589 |
< |
ncut += fillsample(colline+(len>>1), zline ? zline+(len>>1) : NULL, |
589 |
> |
ncut += fillsample(colline+(len>>1), |
590 |
> |
zline ? zline+(len>>1) : (float *)NULL, |
591 |
|
x+(xlen>>1), y+(ylen>>1), |
592 |
|
xlen-(xlen>>1), ylen-(ylen>>1), b/2); |
593 |
|
|
602 |
|
{ |
603 |
|
static RAY thisray; |
604 |
|
|
605 |
< |
if (viewray(thisray.rorg, thisray.rdir, &ourview, |
606 |
< |
(x+pixjitter())/hres, (y+pixjitter())/vres) < 0) { |
605 |
> |
if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir, &ourview, |
606 |
> |
(x+pixjitter())/hres, (y+pixjitter())/vres)) < -FTINY) { |
607 |
|
setcolor(col, 0.0, 0.0, 0.0); |
608 |
|
return(0.0); |
609 |
|
} |
629 |
|
int x, y; |
630 |
|
|
631 |
|
if (oldfile == NULL) |
632 |
< |
return(0); |
633 |
< |
|
632 |
> |
goto gotzip; |
633 |
> |
|
634 |
|
if ((fp = fopen(oldfile, "r")) == NULL) { |
635 |
|
sprintf(errmsg, "cannot open recover file \"%s\"", oldfile); |
636 |
|
error(WARNING, errmsg); |
637 |
< |
return(0); |
637 |
> |
goto gotzip; |
638 |
|
} |
639 |
+ |
#ifdef MSDOS |
640 |
+ |
setmode(fileno(fp), O_BINARY); |
641 |
+ |
#endif |
642 |
|
/* discard header */ |
643 |
< |
getheader(fp, NULL); |
643 |
> |
getheader(fp, NULL, NULL); |
644 |
|
/* get picture size */ |
645 |
|
if (!fscnresolu(&x, &y, fp)) { |
646 |
< |
sprintf(errmsg, "bad recover file \"%s\"", oldfile); |
646 |
> |
sprintf(errmsg, "bad recover file \"%s\" - not removed", |
647 |
> |
oldfile); |
648 |
|
error(WARNING, errmsg); |
649 |
|
fclose(fp); |
650 |
< |
return(0); |
650 |
> |
goto gotzip; |
651 |
|
} |
652 |
|
|
653 |
|
if (x != hres || y != vres) { |
671 |
|
fclose(fp); |
672 |
|
unlink(oldfile); |
673 |
|
return(y); |
674 |
+ |
gotzip: |
675 |
+ |
if (fflush(stdout) == EOF) |
676 |
+ |
error(SYSTEM, "error writing picture header"); |
677 |
+ |
return(0); |
678 |
|
writerr: |
679 |
|
sprintf(errmsg, "write error during recovery of \"%s\"", oldfile); |
680 |
|
error(SYSTEM, errmsg); |