1 |
< |
/* Copyright (c) 1991 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1995 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 <signal.h> |
22 |
> |
#include <sys/times.h> |
23 |
> |
#include <sys/utsname.h> |
24 |
> |
#include <unistd.h> |
25 |
|
#endif |
26 |
< |
#include <fcntl.h> |
26 |
> |
#endif |
27 |
|
|
28 |
+ |
extern time_t time(); |
29 |
+ |
|
30 |
+ |
#include <signal.h> |
31 |
+ |
|
32 |
|
#include "view.h" |
33 |
|
|
34 |
+ |
#include "resolu.h" |
35 |
+ |
|
36 |
|
#include "random.h" |
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 */ |
62 |
< |
int directrelay = 0; /* number of source relays */ |
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 directvis = 1; /* sources visible? */ |
65 |
> |
double srcsizerat = .25; /* maximum ratio source size/dist. */ |
66 |
|
|
67 |
+ |
COLOR cextinction = BLKCOLOR; /* global extinction coefficient */ |
68 |
+ |
double salbedo = 0.; /* global scattering albedo */ |
69 |
+ |
double seccg = 0.; /* global scattering eccentricity */ |
70 |
+ |
double ssampdist = 0.; /* scatter sampling distance */ |
71 |
+ |
|
72 |
+ |
double specthresh = .15; /* specular sampling threshold */ |
73 |
+ |
double specjitter = 1.; /* specular sampling jitter */ |
74 |
+ |
|
75 |
+ |
int backvis = 1; /* back face visibility */ |
76 |
+ |
|
77 |
|
int maxdepth = 6; /* maximum recursion depth */ |
78 |
< |
double minweight = 5e-3; /* minimum ray weight */ |
78 |
> |
double minweight = 5e-3; /* minimum ray weight */ |
79 |
|
|
80 |
|
COLOR ambval = BLKCOLOR; /* ambient value */ |
81 |
< |
double ambacc = 0.2; /* ambient accuracy */ |
81 |
> |
double ambacc = 0.2; /* ambient accuracy */ |
82 |
|
int ambres = 32; /* ambient resolution */ |
83 |
|
int ambdiv = 128; /* ambient divisions */ |
84 |
|
int ambssamp = 0; /* ambient super-samples */ |
86 |
|
char *amblist[128]; /* ambient include/exclude list */ |
87 |
|
int ambincl = -1; /* include == 1, exclude == 0 */ |
88 |
|
|
89 |
+ |
#ifdef MSDOS |
90 |
+ |
int ralrm = 60; /* seconds between reports */ |
91 |
+ |
#else |
92 |
|
int ralrm = 0; /* seconds between reports */ |
93 |
+ |
#endif |
94 |
|
|
95 |
< |
double pctdone = 0.0; /* percentage done */ |
95 |
> |
double pctdone = 0.0; /* percentage done */ |
96 |
|
|
97 |
< |
long tlastrept = 0L; /* time at last report */ |
97 |
> |
time_t tlastrept = 0L; /* time at last report */ |
98 |
|
|
99 |
< |
extern long time(); |
64 |
< |
extern long tstart; /* starting time */ |
99 |
> |
extern time_t tstart; /* starting time */ |
100 |
|
|
101 |
< |
extern long nrays; /* number of rays traced */ |
101 |
> |
extern unsigned long nrays; /* number of rays traced */ |
102 |
|
|
103 |
< |
#define MAXDIV 15 /* maximum sample size */ |
103 |
> |
#define MAXDIV 16 /* maximum sample size */ |
104 |
|
|
105 |
< |
#define pixjitter() (.5+dstrpix*(.5-frandom())) |
105 |
> |
#define pixjitter() (.5+dstrpix*(.5-frandom())) |
106 |
|
|
107 |
< |
double pixvalue(); |
107 |
> |
static int hres, vres; /* resolution for this frame */ |
108 |
|
|
109 |
+ |
extern char *mktemp(); |
110 |
|
|
111 |
+ |
double pixvalue(); |
112 |
+ |
|
113 |
+ |
#ifdef NIX |
114 |
+ |
#define file_exists(f) (access(f,F_OK)==0) |
115 |
+ |
#else |
116 |
+ |
#include <sys/types.h> |
117 |
+ |
#include <sys/stat.h> |
118 |
+ |
int |
119 |
+ |
file_exists(fname) /* ordinary file exists? */ |
120 |
+ |
char *fname; |
121 |
+ |
{ |
122 |
+ |
struct stat sbuf; |
123 |
+ |
if (stat(fname, &sbuf) < 0) return(0); |
124 |
+ |
return((sbuf.st_mode & S_IFREG) != 0); |
125 |
+ |
} |
126 |
+ |
#endif |
127 |
+ |
|
128 |
+ |
|
129 |
|
quit(code) /* quit program */ |
130 |
|
int code; |
131 |
|
{ |
132 |
< |
if (code || ralrm > 0) /* report status */ |
132 |
> |
if (code) /* report status */ |
133 |
|
report(); |
134 |
< |
|
134 |
> |
headclean(); /* delete header file */ |
135 |
> |
pfclean(); /* clean up persist files */ |
136 |
|
exit(code); |
137 |
|
} |
138 |
|
|
139 |
|
|
140 |
< |
#ifdef BSD |
140 |
> |
#ifndef NIX |
141 |
|
report() /* report progress */ |
142 |
|
{ |
143 |
+ |
double u, s; |
144 |
+ |
#ifdef BSD |
145 |
+ |
char hostname[257]; |
146 |
|
struct rusage rubuf; |
147 |
< |
double t; |
147 |
> |
#else |
148 |
> |
struct tms tbuf; |
149 |
> |
struct utsname nambuf; |
150 |
> |
double period; |
151 |
> |
#define hostname nambuf.nodename |
152 |
> |
#endif |
153 |
|
|
154 |
+ |
tlastrept = time((time_t *)NULL); |
155 |
+ |
#ifdef BSD |
156 |
|
getrusage(RUSAGE_SELF, &rubuf); |
157 |
< |
t = (rubuf.ru_utime.tv_usec + rubuf.ru_stime.tv_usec) / 1e6; |
158 |
< |
t += rubuf.ru_utime.tv_sec + rubuf.ru_stime.tv_sec; |
157 |
> |
u = rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec/1e6; |
158 |
> |
s = rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec/1e6; |
159 |
|
getrusage(RUSAGE_CHILDREN, &rubuf); |
160 |
< |
t += (rubuf.ru_utime.tv_usec + rubuf.ru_stime.tv_usec) / 1e6; |
161 |
< |
t += rubuf.ru_utime.tv_sec + rubuf.ru_stime.tv_sec; |
160 |
> |
u += rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec/1e6; |
161 |
> |
s += rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec/1e6; |
162 |
> |
gethostname(hostname, sizeof(hostname)); |
163 |
> |
#else |
164 |
> |
times(&tbuf); |
165 |
> |
#ifdef _SC_CLK_TCK |
166 |
> |
period = 1.0 / sysconf(_SC_CLK_TCK); |
167 |
> |
#else |
168 |
> |
period = 1.0 / 60.0; |
169 |
> |
#endif |
170 |
> |
u = ( tbuf.tms_utime + tbuf.tms_cutime ) * period; |
171 |
> |
s = ( tbuf.tms_stime + tbuf.tms_cstime ) * period; |
172 |
> |
uname(&nambuf); |
173 |
> |
#endif |
174 |
|
|
175 |
< |
sprintf(errmsg, "%ld rays, %4.2f%% done after %5.4f CPU hours\n", |
176 |
< |
nrays, pctdone, t/3600.0); |
175 |
> |
sprintf(errmsg, |
176 |
> |
"%lu rays, %4.2f%% after %.3fu %.3fs %.3fr hours on %s\n", |
177 |
> |
nrays, pctdone, u/3600., s/3600., |
178 |
> |
(tlastrept-tstart)/3600., hostname); |
179 |
|
eputs(errmsg); |
180 |
< |
tlastrept = time((long *)0); |
180 |
> |
#ifndef BSD |
181 |
> |
signal(SIGCONT, report); |
182 |
> |
#undef hostname |
183 |
> |
#endif |
184 |
|
} |
185 |
|
#else |
186 |
|
report() /* report progress */ |
187 |
|
{ |
188 |
< |
signal(SIGALRM, report); |
189 |
< |
tlastrept = time((long *)0); |
108 |
< |
sprintf(errmsg, "%ld rays, %4.2f%% done after %5.4f hours\n", |
188 |
> |
tlastrept = time((time_t *)NULL); |
189 |
> |
sprintf(errmsg, "%lu rays, %4.2f%% after %5.4f hours\n", |
190 |
|
nrays, pctdone, (tlastrept-tstart)/3600.0); |
191 |
|
eputs(errmsg); |
192 |
|
} |
193 |
|
#endif |
194 |
|
|
195 |
|
|
196 |
+ |
rpict(seq, pout, zout, prvr) /* generate image(s) */ |
197 |
+ |
int seq; |
198 |
+ |
char *pout, *zout, *prvr; |
199 |
+ |
/* |
200 |
+ |
* If seq is greater than zero, then we will render a sequence of |
201 |
+ |
* images based on view parameter strings read from the standard input. |
202 |
+ |
* If pout is NULL, then all images will be sent to the standard ouput. |
203 |
+ |
* If seq is greater than zero and prvr is an integer, then it is the |
204 |
+ |
* frame number at which rendering should begin. Preceeding view parameter |
205 |
+ |
* strings will be skipped in the input. |
206 |
+ |
* If pout and prvr are the same, prvr is renamed to avoid overwriting. |
207 |
+ |
* Note that pout and zout should contain %d format specifications for |
208 |
+ |
* sequenced file naming. |
209 |
+ |
*/ |
210 |
+ |
{ |
211 |
+ |
extern char *rindex(), *strncpy(), *strcat(), *strcpy(); |
212 |
+ |
char fbuf[128], fbuf2[128]; |
213 |
+ |
int npicts; |
214 |
+ |
register char *cp; |
215 |
+ |
RESOLU rs; |
216 |
+ |
double pa; |
217 |
+ |
/* check sampling */ |
218 |
+ |
if (psample < 1) |
219 |
+ |
psample = 1; |
220 |
+ |
else if (psample > MAXDIV) { |
221 |
+ |
sprintf(errmsg, "pixel sampling reduced from %d to %d", |
222 |
+ |
psample, MAXDIV); |
223 |
+ |
error(WARNING, errmsg); |
224 |
+ |
psample = MAXDIV; |
225 |
+ |
} |
226 |
+ |
/* get starting frame */ |
227 |
+ |
if (seq <= 0) |
228 |
+ |
seq = 0; |
229 |
+ |
else if (prvr != NULL && isint(prvr)) { |
230 |
+ |
register int rn; /* skip to specified view */ |
231 |
+ |
if ((rn = atoi(prvr)) < seq) |
232 |
+ |
error(USER, "recover frame less than start frame"); |
233 |
+ |
if (pout == NULL) |
234 |
+ |
error(USER, "missing output file specification"); |
235 |
+ |
for ( ; seq < rn; seq++) |
236 |
+ |
if (nextview(stdin) == EOF) |
237 |
+ |
error(USER, "unexpected EOF on view input"); |
238 |
+ |
prvr = fbuf; /* mark for renaming */ |
239 |
+ |
} |
240 |
+ |
if (pout != NULL & prvr != NULL) { |
241 |
+ |
sprintf(fbuf, pout, seq); |
242 |
+ |
if (!strcmp(prvr, fbuf)) { /* rename */ |
243 |
+ |
strcpy(fbuf2, fbuf); |
244 |
+ |
for (cp = fbuf2; *cp; cp++) |
245 |
+ |
; |
246 |
+ |
while (cp > fbuf2 && !ISDIRSEP(cp[-1])) |
247 |
+ |
cp--; |
248 |
+ |
strcpy(cp, RFTEMPLATE); |
249 |
+ |
prvr = mktemp(fbuf2); |
250 |
+ |
if (rename(fbuf, prvr) < 0) |
251 |
+ |
if (errno == ENOENT) { /* ghost file */ |
252 |
+ |
sprintf(errmsg, |
253 |
+ |
"new output file \"%s\"", |
254 |
+ |
fbuf); |
255 |
+ |
error(WARNING, errmsg); |
256 |
+ |
prvr = NULL; |
257 |
+ |
} else { /* serious error */ |
258 |
+ |
sprintf(errmsg, |
259 |
+ |
"cannot rename \"%s\" to \"%s\"", |
260 |
+ |
fbuf, prvr); |
261 |
+ |
error(SYSTEM, errmsg); |
262 |
+ |
} |
263 |
+ |
} |
264 |
+ |
} |
265 |
+ |
npicts = 0; /* render sequence */ |
266 |
+ |
do { |
267 |
+ |
if (seq && nextview(stdin) == EOF) |
268 |
+ |
break; |
269 |
+ |
pctdone = 0.0; |
270 |
+ |
if (pout != NULL) { |
271 |
+ |
sprintf(fbuf, pout, seq); |
272 |
+ |
if (file_exists(fbuf)) { |
273 |
+ |
if (prvr != NULL || !strcmp(fbuf, pout)) { |
274 |
+ |
sprintf(errmsg, |
275 |
+ |
"output file \"%s\" exists", |
276 |
+ |
fbuf); |
277 |
+ |
error(USER, errmsg); |
278 |
+ |
} |
279 |
+ |
continue; /* don't clobber */ |
280 |
+ |
} |
281 |
+ |
if (freopen(fbuf, "w", stdout) == NULL) { |
282 |
+ |
sprintf(errmsg, |
283 |
+ |
"cannot open output file \"%s\"", fbuf); |
284 |
+ |
error(SYSTEM, errmsg); |
285 |
+ |
} |
286 |
+ |
#ifdef MSDOS |
287 |
+ |
setmode(fileno(stdout), O_BINARY); |
288 |
+ |
#endif |
289 |
+ |
dupheader(); |
290 |
+ |
} |
291 |
+ |
hres = hresolu; vres = vresolu; pa = pixaspect; |
292 |
+ |
if (prvr != NULL) |
293 |
+ |
if (viewfile(prvr, &ourview, &rs) <= 0 |
294 |
+ |
|| rs.or != PIXSTANDARD) { |
295 |
+ |
sprintf(errmsg, |
296 |
+ |
"cannot recover view parameters from \"%s\"", prvr); |
297 |
+ |
error(WARNING, errmsg); |
298 |
+ |
} else { |
299 |
+ |
pa = 0.0; |
300 |
+ |
hres = scanlen(&rs); |
301 |
+ |
vres = numscans(&rs); |
302 |
+ |
} |
303 |
+ |
if ((cp = setview(&ourview)) != NULL) |
304 |
+ |
error(USER, cp); |
305 |
+ |
normaspect(viewaspect(&ourview), &pa, &hres, &vres); |
306 |
+ |
if (seq) { |
307 |
+ |
if (ralrm > 0) { |
308 |
+ |
fprintf(stderr, "FRAME %d:", seq); |
309 |
+ |
fprintview(&ourview, stderr); |
310 |
+ |
putc('\n', stderr); |
311 |
+ |
fflush(stderr); |
312 |
+ |
} |
313 |
+ |
printf("FRAME=%d\n", seq); |
314 |
+ |
} |
315 |
+ |
fputs(VIEWSTR, stdout); |
316 |
+ |
fprintview(&ourview, stdout); |
317 |
+ |
putchar('\n'); |
318 |
+ |
if (pa < .99 || pa > 1.01) |
319 |
+ |
fputaspect(pa, stdout); |
320 |
+ |
fputformat(COLRFMT, stdout); |
321 |
+ |
putchar('\n'); |
322 |
+ |
if (zout != NULL) |
323 |
+ |
sprintf(cp=fbuf, zout, seq); |
324 |
+ |
else |
325 |
+ |
cp = NULL; |
326 |
+ |
render(cp, prvr); |
327 |
+ |
prvr = NULL; |
328 |
+ |
npicts++; |
329 |
+ |
} while (seq++); |
330 |
+ |
/* check that we did something */ |
331 |
+ |
if (npicts == 0) |
332 |
+ |
error(WARNING, "no output produced"); |
333 |
+ |
} |
334 |
+ |
|
335 |
+ |
|
336 |
+ |
nextview(fp) /* get next view from fp */ |
337 |
+ |
FILE *fp; |
338 |
+ |
{ |
339 |
+ |
char linebuf[256]; |
340 |
+ |
|
341 |
+ |
while (fgets(linebuf, sizeof(linebuf), fp) != NULL) |
342 |
+ |
if (isview(linebuf) && sscanview(&ourview, linebuf) > 0) |
343 |
+ |
return(0); |
344 |
+ |
return(EOF); |
345 |
+ |
} |
346 |
+ |
|
347 |
+ |
|
348 |
|
render(zfile, oldfile) /* render the scene */ |
349 |
|
char *zfile, *oldfile; |
350 |
|
{ |
351 |
|
extern long lseek(); |
352 |
|
COLOR *scanbar[MAXDIV+1]; /* scanline arrays of pixel values */ |
353 |
|
float *zbar[MAXDIV+1]; /* z values */ |
354 |
+ |
char *sampdens; /* previous sample density */ |
355 |
|
int ypos; /* current scanline */ |
356 |
|
int ystep; /* current y step size */ |
357 |
+ |
int hstep; /* h step size */ |
358 |
|
int zfd; |
359 |
|
COLOR *colptr; |
360 |
|
float *zptr; |
361 |
|
register int i; |
127 |
– |
/* check sampling */ |
128 |
– |
if (psample < 1) |
129 |
– |
psample = 1; |
130 |
– |
else if (psample > MAXDIV) { |
131 |
– |
sprintf(errmsg, "pixel sampling reduced from %d to %d", |
132 |
– |
psample, MAXDIV); |
133 |
– |
error(WARNING, errmsg); |
134 |
– |
psample = MAXDIV; |
135 |
– |
} |
362 |
|
/* allocate scanlines */ |
363 |
|
for (i = 0; i <= psample; i++) { |
364 |
< |
scanbar[i] = (COLOR *)malloc(hresolu*sizeof(COLOR)); |
364 |
> |
scanbar[i] = (COLOR *)malloc(hres*sizeof(COLOR)); |
365 |
|
if (scanbar[i] == NULL) |
366 |
|
goto memerr; |
367 |
|
} |
368 |
< |
/* open z file */ |
368 |
> |
hstep = (psample*140+49)/99; /* quincunx sampling */ |
369 |
> |
ystep = (psample*99+70)/140; |
370 |
> |
if (hstep > 2) { |
371 |
> |
i = hres/hstep + 2; |
372 |
> |
if ((sampdens = malloc(i)) == NULL) |
373 |
> |
goto memerr; |
374 |
> |
while (i--) |
375 |
> |
sampdens[i] = hstep; |
376 |
> |
} else |
377 |
> |
sampdens = NULL; |
378 |
> |
/* open z-file */ |
379 |
|
if (zfile != NULL) { |
380 |
|
if ((zfd = open(zfile, O_WRONLY|O_CREAT, 0666)) == -1) { |
381 |
< |
sprintf(errmsg, "cannot open z file \"%s\"", zfile); |
381 |
> |
sprintf(errmsg, "cannot open z-file \"%s\"", zfile); |
382 |
|
error(SYSTEM, errmsg); |
383 |
|
} |
384 |
+ |
#ifdef MSDOS |
385 |
+ |
setmode(zfd, O_BINARY); |
386 |
+ |
#endif |
387 |
|
for (i = 0; i <= psample; i++) { |
388 |
< |
zbar[i] = (float *)malloc(hresolu*sizeof(float)); |
388 |
> |
zbar[i] = (float *)malloc(hres*sizeof(float)); |
389 |
|
if (zbar[i] == NULL) |
390 |
|
goto memerr; |
391 |
|
} |
395 |
|
zbar[i] = NULL; |
396 |
|
} |
397 |
|
/* write out boundaries */ |
398 |
< |
fputresolu(YMAJOR|YDECR, hresolu, vresolu, stdout); |
398 |
> |
fprtresolu(hres, vres, stdout); |
399 |
|
/* recover file and compute first */ |
400 |
|
i = salvage(oldfile); |
401 |
|
if (zfd != -1 && i > 0 && |
402 |
< |
lseek(zfd, (long)i*hresolu*sizeof(float), 0) == -1) |
403 |
< |
error(SYSTEM, "z file seek error in render"); |
404 |
< |
pctdone = 100.0*i/vresolu; |
402 |
> |
lseek(zfd, (long)i*hres*sizeof(float), 0) == -1) |
403 |
> |
error(SYSTEM, "z-file seek error in render"); |
404 |
> |
pctdone = 100.0*i/vres; |
405 |
|
if (ralrm > 0) /* report init stats */ |
406 |
|
report(); |
407 |
< |
ypos = vresolu-1 - i; |
408 |
< |
fillscanline(scanbar[0], zbar[0], hresolu, ypos, psample); |
409 |
< |
ystep = psample; |
407 |
> |
#ifndef BSD |
408 |
> |
else |
409 |
> |
#endif |
410 |
> |
signal(SIGCONT, report); |
411 |
> |
ypos = vres-1 - i; |
412 |
> |
fillscanline(scanbar[0], zbar[0], sampdens, hres, ypos, hstep); |
413 |
|
/* compute scanlines */ |
414 |
|
for (ypos -= ystep; ypos > -ystep; ypos -= ystep) { |
415 |
|
/* bottom adjust? */ |
424 |
|
zbar[ystep] = zbar[0]; |
425 |
|
zbar[0] = zptr; |
426 |
|
/* fill base line */ |
427 |
< |
fillscanline(scanbar[0], zbar[0], hresolu, ypos, psample); |
427 |
> |
fillscanline(scanbar[0], zbar[0], sampdens, |
428 |
> |
hres, ypos, hstep); |
429 |
|
/* fill bar */ |
430 |
< |
fillscanbar(scanbar, zbar, hresolu, ypos, ystep); |
430 |
> |
fillscanbar(scanbar, zbar, hres, ypos, ystep); |
431 |
|
/* write it out */ |
432 |
+ |
#ifndef BSD |
433 |
+ |
signal(SIGCONT, SIG_IGN); /* don't interrupt writes */ |
434 |
+ |
#endif |
435 |
|
for (i = ystep; i > 0; i--) { |
436 |
|
if (zfd != -1 && write(zfd, (char *)zbar[i], |
437 |
< |
hresolu*sizeof(float)) |
438 |
< |
< hresolu*sizeof(float)) |
437 |
> |
hres*sizeof(float)) |
438 |
> |
< hres*sizeof(float)) |
439 |
|
goto writerr; |
440 |
< |
if (fwritescan(scanbar[i], hresolu, stdout) < 0) |
440 |
> |
if (fwritescan(scanbar[i], hres, stdout) < 0) |
441 |
|
goto writerr; |
442 |
|
} |
443 |
|
if (fflush(stdout) == EOF) |
444 |
|
goto writerr; |
445 |
|
/* record progress */ |
446 |
< |
pctdone = 100.0*(vresolu-1-ypos)/vresolu; |
447 |
< |
if (ralrm > 0 && time((long *)0) >= tlastrept+ralrm) |
446 |
> |
pctdone = 100.0*(vres-1-ypos)/vres; |
447 |
> |
if (ralrm > 0 && time((time_t *)NULL) >= tlastrept+ralrm) |
448 |
|
report(); |
449 |
+ |
#ifndef BSD |
450 |
+ |
else |
451 |
+ |
signal(SIGCONT, report); |
452 |
+ |
#endif |
453 |
|
} |
454 |
|
/* clean up */ |
455 |
+ |
signal(SIGCONT, SIG_IGN); |
456 |
|
if (zfd != -1) { |
457 |
< |
if (write(zfd, (char *)zbar[0], hresolu*sizeof(float)) |
458 |
< |
< hresolu*sizeof(float)) |
457 |
> |
if (write(zfd, (char *)zbar[0], hres*sizeof(float)) |
458 |
> |
< hres*sizeof(float)) |
459 |
|
goto writerr; |
460 |
|
if (close(zfd) == -1) |
461 |
|
goto writerr; |
462 |
|
for (i = 0; i <= psample; i++) |
463 |
|
free((char *)zbar[i]); |
464 |
|
} |
465 |
< |
fwritescan(scanbar[0], hresolu, stdout); |
465 |
> |
fwritescan(scanbar[0], hres, stdout); |
466 |
|
if (fflush(stdout) == EOF) |
467 |
|
goto writerr; |
468 |
|
for (i = 0; i <= psample; i++) |
469 |
|
free((char *)scanbar[i]); |
470 |
+ |
if (sampdens != NULL) |
471 |
+ |
free(sampdens); |
472 |
|
pctdone = 100.0; |
473 |
+ |
if (ralrm > 0) |
474 |
+ |
report(); |
475 |
+ |
signal(SIGCONT, SIG_DFL); |
476 |
|
return; |
477 |
|
writerr: |
478 |
|
error(SYSTEM, "write error in render"); |
481 |
|
} |
482 |
|
|
483 |
|
|
484 |
< |
fillscanline(scanline, zline, xres, y, xstep) /* fill scan line at y */ |
485 |
< |
register COLOR *scanline; |
486 |
< |
register float *zline; |
484 |
> |
fillscanline(scanline, zline, sd, xres, y, xstep) /* fill scan at y */ |
485 |
> |
register COLOR *scanline; |
486 |
> |
register float *zline; |
487 |
> |
register char *sd; |
488 |
|
int xres, y, xstep; |
489 |
|
{ |
490 |
< |
int b = xstep; |
491 |
< |
double z; |
490 |
> |
static int nc = 0; /* number of calls */ |
491 |
> |
int bl = xstep, b = xstep; |
492 |
> |
double z; |
493 |
|
register int i; |
494 |
|
|
495 |
|
z = pixvalue(scanline[0], 0, y); |
496 |
|
if (zline) zline[0] = z; |
497 |
< |
|
498 |
< |
for (i = xstep; i < xres-1+xstep; i += xstep) { |
497 |
> |
/* zig-zag start for quincunx pattern */ |
498 |
> |
for (i = ++nc & 1 ? xstep : xstep/2; i < xres-1+xstep; i += xstep) { |
499 |
|
if (i >= xres) { |
500 |
|
xstep += xres-1-i; |
501 |
|
i = xres-1; |
502 |
|
} |
503 |
|
z = pixvalue(scanline[i], i, y); |
504 |
|
if (zline) zline[i] = z; |
505 |
< |
|
506 |
< |
b = fillsample(scanline+i-xstep, zline ? zline+i-xstep : NULL, |
507 |
< |
i-xstep, y, xstep, 0, b/2); |
505 |
> |
if (sd) b = sd[0] > sd[1] ? sd[0] : sd[1]; |
506 |
> |
if (i <= xstep) |
507 |
> |
b = fillsample(scanline, zline, 0, y, i, 0, b/2); |
508 |
> |
else |
509 |
> |
b = fillsample(scanline+i-xstep, |
510 |
> |
zline ? zline+i-xstep : (float *)NULL, |
511 |
> |
i-xstep, y, xstep, 0, b/2); |
512 |
> |
if (sd) *sd++ = nc & 1 ? bl : b; |
513 |
> |
bl = b; |
514 |
|
} |
515 |
+ |
if (sd && nc & 1) *sd = bl; |
516 |
|
} |
517 |
|
|
518 |
|
|
519 |
|
fillscanbar(scanbar, zbar, xres, y, ysize) /* fill interior */ |
520 |
< |
register COLOR *scanbar[]; |
521 |
< |
register float *zbar[]; |
520 |
> |
register COLOR *scanbar[]; |
521 |
> |
register float *zbar[]; |
522 |
|
int xres, y, ysize; |
523 |
|
{ |
524 |
|
COLOR vline[MAXDIV+1]; |
535 |
|
zline[ysize] = zbar[ysize][i]; |
536 |
|
} |
537 |
|
|
538 |
< |
b = fillsample(vline, zbar[0] ? zline : NULL, |
538 |
> |
b = fillsample(vline, zbar[0] ? zline : (float *)NULL, |
539 |
|
i, y, 0, ysize, b/2); |
540 |
|
|
541 |
|
for (j = 1; j < ysize; j++) |
548 |
|
|
549 |
|
|
550 |
|
int |
551 |
< |
fillsample(colline, zline, x, y, xlen, ylen, b) /* fill interior points */ |
552 |
< |
register COLOR *colline; |
553 |
< |
register float *zline; |
551 |
> |
fillsample(colline, zline, x, y, xlen, ylen, b) /* fill interior points */ |
552 |
> |
register COLOR *colline; |
553 |
> |
register float *zline; |
554 |
|
int x, y; |
555 |
|
int xlen, ylen; |
556 |
|
int b; |
557 |
|
{ |
558 |
< |
extern double fabs(); |
559 |
< |
double ratio; |
295 |
< |
double z; |
558 |
> |
double ratio; |
559 |
> |
double z; |
560 |
|
COLOR ctmp; |
561 |
|
int ncut; |
562 |
|
register int len; |
593 |
|
/* recurse */ |
594 |
|
ncut += fillsample(colline, zline, x, y, xlen>>1, ylen>>1, (b-1)/2); |
595 |
|
|
596 |
< |
ncut += fillsample(colline+(len>>1), zline ? zline+(len>>1) : NULL, |
596 |
> |
ncut += fillsample(colline+(len>>1), |
597 |
> |
zline ? zline+(len>>1) : (float *)NULL, |
598 |
|
x+(xlen>>1), y+(ylen>>1), |
599 |
|
xlen-(xlen>>1), ylen-(ylen>>1), b/2); |
600 |
|
|
609 |
|
{ |
610 |
|
static RAY thisray; |
611 |
|
|
612 |
< |
if (viewray(thisray.rorg, thisray.rdir, &ourview, |
613 |
< |
(x+pixjitter())/hresolu, (y+pixjitter())/vresolu) < 0) { |
612 |
> |
if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir, &ourview, |
613 |
> |
(x+pixjitter())/hres, (y+pixjitter())/vres)) < -FTINY) { |
614 |
|
setcolor(col, 0.0, 0.0, 0.0); |
615 |
|
return(0.0); |
616 |
|
} |
617 |
|
|
618 |
|
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
619 |
|
|
620 |
< |
samplendx = 3*y + x; /* set pixel index */ |
620 |
> |
samplendx = pixnumber(x,y,hres,vres); /* set pixel index */ |
621 |
|
|
622 |
|
rayvalue(&thisray); /* trace ray */ |
623 |
|
|
636 |
|
int x, y; |
637 |
|
|
638 |
|
if (oldfile == NULL) |
639 |
< |
return(0); |
640 |
< |
|
639 |
> |
goto gotzip; |
640 |
> |
|
641 |
|
if ((fp = fopen(oldfile, "r")) == NULL) { |
642 |
|
sprintf(errmsg, "cannot open recover file \"%s\"", oldfile); |
643 |
|
error(WARNING, errmsg); |
644 |
< |
return(0); |
644 |
> |
goto gotzip; |
645 |
|
} |
646 |
+ |
#ifdef MSDOS |
647 |
+ |
setmode(fileno(fp), O_BINARY); |
648 |
+ |
#endif |
649 |
|
/* discard header */ |
650 |
< |
getheader(fp, NULL); |
650 |
> |
getheader(fp, NULL, NULL); |
651 |
|
/* get picture size */ |
652 |
< |
if (fgetresolu(&x, &y, fp) != (YMAJOR|YDECR)) { |
653 |
< |
sprintf(errmsg, "bad recover file \"%s\"", oldfile); |
652 |
> |
if (!fscnresolu(&x, &y, fp)) { |
653 |
> |
sprintf(errmsg, "bad recover file \"%s\" - not removed", |
654 |
> |
oldfile); |
655 |
|
error(WARNING, errmsg); |
656 |
|
fclose(fp); |
657 |
< |
return(0); |
657 |
> |
goto gotzip; |
658 |
|
} |
659 |
|
|
660 |
< |
if (x != hresolu || y != vresolu) { |
660 |
> |
if (x != hres || y != vres) { |
661 |
|
sprintf(errmsg, "resolution mismatch in recover file \"%s\"", |
662 |
|
oldfile); |
663 |
|
error(USER, errmsg); |
664 |
|
} |
665 |
|
|
666 |
< |
scanline = (COLR *)malloc(hresolu*sizeof(COLR)); |
666 |
> |
scanline = (COLR *)malloc(hres*sizeof(COLR)); |
667 |
|
if (scanline == NULL) |
668 |
|
error(SYSTEM, "out of memory in salvage"); |
669 |
< |
for (y = 0; y < vresolu; y++) { |
670 |
< |
if (freadcolrs(scanline, hresolu, fp) < 0) |
669 |
> |
for (y = 0; y < vres; y++) { |
670 |
> |
if (freadcolrs(scanline, hres, fp) < 0) |
671 |
|
break; |
672 |
< |
if (fwritecolrs(scanline, hresolu, stdout) < 0) |
672 |
> |
if (fwritecolrs(scanline, hres, stdout) < 0) |
673 |
|
goto writerr; |
674 |
|
} |
675 |
|
if (fflush(stdout) == EOF) |
678 |
|
fclose(fp); |
679 |
|
unlink(oldfile); |
680 |
|
return(y); |
681 |
+ |
gotzip: |
682 |
+ |
if (fflush(stdout) == EOF) |
683 |
+ |
error(SYSTEM, "error writing picture header"); |
684 |
+ |
return(0); |
685 |
|
writerr: |
686 |
< |
error(SYSTEM, "write error in salvage"); |
686 |
> |
sprintf(errmsg, "write error during recovery of \"%s\"", oldfile); |
687 |
> |
error(SYSTEM, errmsg); |
688 |
> |
} |
689 |
> |
|
690 |
> |
|
691 |
> |
int |
692 |
> |
pixnumber(x, y, xres, yres) /* compute pixel index (brushed) */ |
693 |
> |
register int x, y; |
694 |
> |
int xres, yres; |
695 |
> |
{ |
696 |
> |
x -= y; |
697 |
> |
while (x < 0) |
698 |
> |
x += xres; |
699 |
> |
return((((x>>2)*yres + y) << 2) + (x & 3)); |
700 |
|
} |