1 |
< |
/* Copyright (c) 1986 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1992 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
17 |
|
#include <sys/resource.h> |
18 |
|
#endif |
19 |
|
|
20 |
+ |
#include <signal.h> |
21 |
+ |
|
22 |
|
#include "view.h" |
23 |
|
|
24 |
+ |
#include "resolu.h" |
25 |
+ |
|
26 |
|
#include "random.h" |
27 |
|
|
28 |
+ |
#include "paths.h" |
29 |
+ |
|
30 |
+ |
#define RFTEMPLATE "rfXXXXXX" |
31 |
+ |
|
32 |
+ |
#ifndef SIGCONT |
33 |
+ |
#define SIGCONT SIGIO |
34 |
+ |
#endif |
35 |
+ |
|
36 |
+ |
int dimlist[MAXDIM]; /* sampling dimensions */ |
37 |
+ |
int ndims = 0; /* number of sampling dimensions */ |
38 |
+ |
int samplendx; /* sample index number */ |
39 |
+ |
|
40 |
|
VIEW ourview = STDVIEW; /* view parameters */ |
41 |
|
int hresolu = 512; /* horizontal resolution */ |
42 |
|
int vresolu = 512; /* vertical resolution */ |
43 |
+ |
double pixaspect = 1.0; /* pixel aspect ratio */ |
44 |
|
|
45 |
|
int psample = 4; /* pixel sample size */ |
46 |
< |
double maxdiff = .05; /* max. difference for interpolation */ |
47 |
< |
double dstrpix = 0.67; /* square pixel distribution */ |
46 |
> |
double maxdiff = .05; /* max. difference for interpolation */ |
47 |
> |
double dstrpix = 0.67; /* square pixel distribution */ |
48 |
|
|
49 |
< |
double dstrsrc = 0.0; /* square source distribution */ |
50 |
< |
double shadthresh = .05; /* shadow threshold */ |
51 |
< |
double shadcert = .5; /* shadow certainty */ |
49 |
> |
double dstrsrc = 0.0; /* square source distribution */ |
50 |
> |
double shadthresh = .05; /* shadow threshold */ |
51 |
> |
double shadcert = .5; /* shadow certainty */ |
52 |
> |
int directrelay = 1; /* number of source relays */ |
53 |
> |
int vspretest = 512; /* virtual source pretest density */ |
54 |
> |
int directvis = 1; /* sources visible? */ |
55 |
> |
double srcsizerat = .25; /* maximum ratio source size/dist. */ |
56 |
|
|
57 |
+ |
double specthresh = .15; /* specular sampling threshold */ |
58 |
+ |
double specjitter = 1.; /* specular sampling jitter */ |
59 |
+ |
|
60 |
|
int maxdepth = 6; /* maximum recursion depth */ |
61 |
< |
double minweight = 5e-3; /* minimum ray weight */ |
61 |
> |
double minweight = 5e-3; /* minimum ray weight */ |
62 |
|
|
63 |
|
COLOR ambval = BLKCOLOR; /* ambient value */ |
64 |
< |
double ambacc = 0.2; /* ambient accuracy */ |
64 |
> |
double ambacc = 0.2; /* ambient accuracy */ |
65 |
|
int ambres = 32; /* ambient resolution */ |
66 |
|
int ambdiv = 128; /* ambient divisions */ |
67 |
|
int ambssamp = 0; /* ambient super-samples */ |
69 |
|
char *amblist[128]; /* ambient include/exclude list */ |
70 |
|
int ambincl = -1; /* include == 1, exclude == 0 */ |
71 |
|
|
72 |
+ |
#ifdef MSDOS |
73 |
+ |
int ralrm = 60; /* seconds between reports */ |
74 |
+ |
#else |
75 |
|
int ralrm = 0; /* seconds between reports */ |
76 |
+ |
#endif |
77 |
|
|
78 |
< |
double pctdone = 0.0; /* percentage done */ |
78 |
> |
double pctdone = 0.0; /* percentage done */ |
79 |
|
|
80 |
< |
extern long nrays; /* number of rays traced */ |
80 |
> |
long tlastrept = 0L; /* time at last report */ |
81 |
|
|
82 |
< |
#define MAXDIV 32 /* maximum sample size */ |
82 |
> |
extern long time(); |
83 |
> |
extern long tstart; /* starting time */ |
84 |
|
|
85 |
< |
#define pixjitter() (.5+dstrpix*(.5-frandom())) |
85 |
> |
extern unsigned long nrays; /* number of rays traced */ |
86 |
|
|
87 |
< |
double pixvalue(); |
87 |
> |
#define MAXDIV 16 /* maximum sample size */ |
88 |
|
|
89 |
+ |
#define pixjitter() (.5+dstrpix*(.5-frandom())) |
90 |
|
|
91 |
+ |
static int hres, vres; /* resolution for this frame */ |
92 |
+ |
|
93 |
+ |
extern char *mktemp(); |
94 |
+ |
|
95 |
+ |
double pixvalue(); |
96 |
+ |
|
97 |
+ |
#ifdef NIX |
98 |
+ |
#define file_exists(f) (access(f,F_OK)==0) |
99 |
+ |
#else |
100 |
+ |
#include <sys/types.h> |
101 |
+ |
#include <sys/stat.h> |
102 |
+ |
int |
103 |
+ |
file_exists(fname) /* ordinary file exists? */ |
104 |
+ |
char *fname; |
105 |
+ |
{ |
106 |
+ |
struct stat sbuf; |
107 |
+ |
if (stat(fname, &sbuf) < 0) return(0); |
108 |
+ |
return((sbuf.st_mode & S_IFREG) != 0); |
109 |
+ |
} |
110 |
+ |
#endif |
111 |
+ |
|
112 |
+ |
|
113 |
|
quit(code) /* quit program */ |
114 |
|
int code; |
115 |
|
{ |
116 |
< |
if (code || ralrm > 0) /* report status */ |
116 |
> |
if (code) /* report status */ |
117 |
|
report(); |
118 |
< |
|
118 |
> |
headclean(); /* delete header file */ |
119 |
> |
pfclean(); /* clean up persist files */ |
120 |
|
exit(code); |
121 |
|
} |
122 |
|
|
123 |
|
|
124 |
+ |
#ifdef BSD |
125 |
|
report() /* report progress */ |
126 |
|
{ |
73 |
– |
#ifdef BSD |
127 |
|
struct rusage rubuf; |
128 |
< |
double t; |
128 |
> |
double t; |
129 |
|
|
130 |
|
getrusage(RUSAGE_SELF, &rubuf); |
131 |
|
t = (rubuf.ru_utime.tv_usec + rubuf.ru_stime.tv_usec) / 1e6; |
134 |
|
t += (rubuf.ru_utime.tv_usec + rubuf.ru_stime.tv_usec) / 1e6; |
135 |
|
t += rubuf.ru_utime.tv_sec + rubuf.ru_stime.tv_sec; |
136 |
|
|
137 |
< |
sprintf(errmsg, "%ld rays, %4.2f%% done after %5.4f CPU hours\n", |
137 |
> |
sprintf(errmsg, "%lu rays, %4.2f%% done after %5.4f CPU hours\n", |
138 |
|
nrays, pctdone, t/3600.0); |
139 |
+ |
eputs(errmsg); |
140 |
+ |
tlastrept = time((long *)0); |
141 |
+ |
} |
142 |
|
#else |
143 |
< |
sprintf(errmsg, "%ld rays, %4.2f%% done\n", nrays, pctdone); |
144 |
< |
#endif |
143 |
> |
report() /* report progress */ |
144 |
> |
{ |
145 |
> |
tlastrept = time((long *)0); |
146 |
> |
sprintf(errmsg, "%lu rays, %4.2f%% done after %5.4f hours\n", |
147 |
> |
nrays, pctdone, (tlastrept-tstart)/3600.0); |
148 |
|
eputs(errmsg); |
149 |
+ |
signal(SIGCONT, report); |
150 |
+ |
} |
151 |
+ |
#endif |
152 |
|
|
153 |
< |
if (ralrm > 0) |
154 |
< |
alarm(ralrm); |
153 |
> |
|
154 |
> |
rpict(seq, pout, zout, prvr) /* generate image(s) */ |
155 |
> |
int seq; |
156 |
> |
char *pout, *zout, *prvr; |
157 |
> |
/* |
158 |
> |
* If seq is greater than zero, then we will render a sequence of |
159 |
> |
* images based on view parameter strings read from the standard input. |
160 |
> |
* If pout is NULL, then all images will be sent to the standard ouput. |
161 |
> |
* If seq is greater than zero and prvr is an integer, then it is the |
162 |
> |
* frame number at which rendering should begin. Preceeding view parameter |
163 |
> |
* strings will be skipped in the input. |
164 |
> |
* If pout and prvr are the same, prvr is renamed to avoid overwriting. |
165 |
> |
* Note that pout and zout should contain %d format specifications for |
166 |
> |
* sequenced file naming. |
167 |
> |
*/ |
168 |
> |
{ |
169 |
> |
extern char *rindex(), *strncpy(), *strcat(), *strcpy(); |
170 |
> |
char fbuf[128], fbuf2[128]; |
171 |
> |
int npicts; |
172 |
> |
register char *cp; |
173 |
> |
RESOLU rs; |
174 |
> |
double pa; |
175 |
> |
/* check sampling */ |
176 |
> |
if (psample < 1) |
177 |
> |
psample = 1; |
178 |
> |
else if (psample > MAXDIV) { |
179 |
> |
sprintf(errmsg, "pixel sampling reduced from %d to %d", |
180 |
> |
psample, MAXDIV); |
181 |
> |
error(WARNING, errmsg); |
182 |
> |
psample = MAXDIV; |
183 |
> |
} |
184 |
> |
/* get starting frame */ |
185 |
> |
if (seq <= 0) |
186 |
> |
seq = 0; |
187 |
> |
else if (prvr != NULL && isint(prvr)) { |
188 |
> |
register int rn; /* skip to specified view */ |
189 |
> |
if ((rn = atoi(prvr)) < seq) |
190 |
> |
error(USER, "recover frame less than start frame"); |
191 |
> |
if (pout == NULL) |
192 |
> |
error(USER, "missing output file specification"); |
193 |
> |
for ( ; seq < rn; seq++) |
194 |
> |
if (nextview(stdin) == EOF) |
195 |
> |
error(USER, "unexpected EOF on view input"); |
196 |
> |
prvr = fbuf; /* mark for renaming */ |
197 |
> |
} |
198 |
> |
if (pout != NULL & prvr != NULL) { |
199 |
> |
sprintf(fbuf, pout, seq); |
200 |
> |
if (!strcmp(prvr, fbuf)) { /* rename */ |
201 |
> |
strcpy(fbuf2, fbuf); |
202 |
> |
for (cp = fbuf2; *cp; cp++) |
203 |
> |
; |
204 |
> |
while (cp > fbuf2 && !ISDIRSEP(cp[-1])) |
205 |
> |
cp--; |
206 |
> |
strcpy(cp, RFTEMPLATE); |
207 |
> |
prvr = mktemp(fbuf2); |
208 |
> |
if (rename(fbuf, prvr) < 0) |
209 |
> |
if (errno == ENOENT) { /* ghost file */ |
210 |
> |
sprintf(errmsg, |
211 |
> |
"new output file \"%s\"", |
212 |
> |
fbuf); |
213 |
> |
error(WARNING, errmsg); |
214 |
> |
prvr = NULL; |
215 |
> |
} else { /* serious error */ |
216 |
> |
sprintf(errmsg, |
217 |
> |
"cannot rename \"%s\" to \"%s\"", |
218 |
> |
fbuf, prvr); |
219 |
> |
error(SYSTEM, errmsg); |
220 |
> |
} |
221 |
> |
} |
222 |
> |
} |
223 |
> |
npicts = 0; /* render sequence */ |
224 |
> |
do { |
225 |
> |
if (seq && nextview(stdin) == EOF) |
226 |
> |
break; |
227 |
> |
pctdone = 0.0; |
228 |
> |
if (pout != NULL) { |
229 |
> |
sprintf(fbuf, pout, seq); |
230 |
> |
if (file_exists(fbuf)) { |
231 |
> |
if (prvr != NULL || !strcmp(fbuf, pout)) { |
232 |
> |
sprintf(errmsg, |
233 |
> |
"output file \"%s\" exists", |
234 |
> |
fbuf); |
235 |
> |
error(USER, errmsg); |
236 |
> |
} |
237 |
> |
continue; /* don't clobber */ |
238 |
> |
} |
239 |
> |
if (freopen(fbuf, "w", stdout) == NULL) { |
240 |
> |
sprintf(errmsg, |
241 |
> |
"cannot open output file \"%s\"", fbuf); |
242 |
> |
error(SYSTEM, errmsg); |
243 |
> |
} |
244 |
> |
#ifdef MSDOS |
245 |
> |
setmode(fileno(stdout), O_BINARY); |
246 |
> |
#endif |
247 |
> |
dupheader(); |
248 |
> |
} |
249 |
> |
hres = hresolu; vres = vresolu; pa = pixaspect; |
250 |
> |
if (prvr != NULL) |
251 |
> |
if (viewfile(prvr, &ourview, &rs) <= 0 |
252 |
> |
|| rs.or != PIXSTANDARD) { |
253 |
> |
sprintf(errmsg, |
254 |
> |
"cannot recover view parameters from \"%s\"", prvr); |
255 |
> |
error(WARNING, errmsg); |
256 |
> |
} else { |
257 |
> |
pa = 0.0; |
258 |
> |
hres = scanlen(&rs); |
259 |
> |
vres = numscans(&rs); |
260 |
> |
} |
261 |
> |
if ((cp = setview(&ourview)) != NULL) |
262 |
> |
error(USER, cp); |
263 |
> |
normaspect(viewaspect(&ourview), &pa, &hres, &vres); |
264 |
> |
if (seq) { |
265 |
> |
if (ralrm > 0) { |
266 |
> |
fprintf(stderr, "FRAME %d:", seq); |
267 |
> |
fprintview(&ourview, stderr); |
268 |
> |
putc('\n', stderr); |
269 |
> |
fflush(stderr); |
270 |
> |
} |
271 |
> |
printf("FRAME=%d\n", seq); |
272 |
> |
} |
273 |
> |
fputs(VIEWSTR, stdout); |
274 |
> |
fprintview(&ourview, stdout); |
275 |
> |
putchar('\n'); |
276 |
> |
if (pa < .99 || pa > 1.01) |
277 |
> |
fputaspect(pa, stdout); |
278 |
> |
fputformat(COLRFMT, stdout); |
279 |
> |
putchar('\n'); |
280 |
> |
if (zout != NULL) |
281 |
> |
sprintf(cp=fbuf, zout, seq); |
282 |
> |
else |
283 |
> |
cp = NULL; |
284 |
> |
render(cp, prvr); |
285 |
> |
prvr = NULL; |
286 |
> |
npicts++; |
287 |
> |
} while (seq++); |
288 |
> |
/* check that we did something */ |
289 |
> |
if (npicts == 0) |
290 |
> |
error(WARNING, "no output produced"); |
291 |
|
} |
292 |
|
|
293 |
|
|
294 |
+ |
nextview(fp) /* get next view from fp */ |
295 |
+ |
FILE *fp; |
296 |
+ |
{ |
297 |
+ |
char linebuf[256]; |
298 |
+ |
|
299 |
+ |
while (fgets(linebuf, sizeof(linebuf), fp) != NULL) |
300 |
+ |
if (isview(linebuf) && sscanview(&ourview, linebuf) > 0) |
301 |
+ |
return(0); |
302 |
+ |
return(EOF); |
303 |
+ |
} |
304 |
+ |
|
305 |
+ |
|
306 |
|
render(zfile, oldfile) /* render the scene */ |
307 |
|
char *zfile, *oldfile; |
308 |
|
{ |
309 |
+ |
extern long lseek(); |
310 |
|
COLOR *scanbar[MAXDIV+1]; /* scanline arrays of pixel values */ |
311 |
|
float *zbar[MAXDIV+1]; /* z values */ |
312 |
+ |
char *sampdens; /* previous sample density */ |
313 |
|
int ypos; /* current scanline */ |
314 |
< |
FILE *zfp; |
314 |
> |
int ystep; /* current y step size */ |
315 |
> |
int hstep; /* h step size */ |
316 |
> |
int zfd; |
317 |
|
COLOR *colptr; |
318 |
|
float *zptr; |
319 |
|
register int i; |
106 |
– |
/* check sampling */ |
107 |
– |
if (psample < 1) |
108 |
– |
psample = 1; |
109 |
– |
else if (psample > MAXDIV) |
110 |
– |
psample = MAXDIV; |
320 |
|
/* allocate scanlines */ |
321 |
|
for (i = 0; i <= psample; i++) { |
322 |
< |
scanbar[i] = (COLOR *)malloc(hresolu*sizeof(COLOR)); |
322 |
> |
scanbar[i] = (COLOR *)malloc(hres*sizeof(COLOR)); |
323 |
|
if (scanbar[i] == NULL) |
324 |
|
goto memerr; |
325 |
|
} |
326 |
< |
/* open z file */ |
326 |
> |
hstep = (psample*140+49)/99; /* quincunx sampling */ |
327 |
> |
ystep = (psample*99+70)/140; |
328 |
> |
if (hstep > 2) { |
329 |
> |
i = hres/hstep + 2; |
330 |
> |
if ((sampdens = malloc(i)) == NULL) |
331 |
> |
goto memerr; |
332 |
> |
while (i--) |
333 |
> |
sampdens[i] = hstep; |
334 |
> |
} else |
335 |
> |
sampdens = NULL; |
336 |
> |
/* open z-file */ |
337 |
|
if (zfile != NULL) { |
338 |
< |
if ((zfp = fopen(zfile, "a+")) == NULL) { |
339 |
< |
sprintf(errmsg, "cannot open z file \"%s\"", zfile); |
338 |
> |
if ((zfd = open(zfile, O_WRONLY|O_CREAT, 0666)) == -1) { |
339 |
> |
sprintf(errmsg, "cannot open z-file \"%s\"", zfile); |
340 |
|
error(SYSTEM, errmsg); |
341 |
|
} |
342 |
+ |
#ifdef MSDOS |
343 |
+ |
setmode(zfd, O_BINARY); |
344 |
+ |
#endif |
345 |
|
for (i = 0; i <= psample; i++) { |
346 |
< |
zbar[i] = (float *)malloc(hresolu*sizeof(float)); |
346 |
> |
zbar[i] = (float *)malloc(hres*sizeof(float)); |
347 |
|
if (zbar[i] == NULL) |
348 |
|
goto memerr; |
349 |
|
} |
350 |
|
} else { |
351 |
< |
zfp = NULL; |
351 |
> |
zfd = -1; |
352 |
|
for (i = 0; i <= psample; i++) |
353 |
|
zbar[i] = NULL; |
354 |
|
} |
355 |
|
/* write out boundaries */ |
356 |
< |
fputresolu(YMAJOR|YDECR, hresolu, vresolu, stdout); |
356 |
> |
fprtresolu(hres, vres, stdout); |
357 |
|
/* recover file and compute first */ |
358 |
|
i = salvage(oldfile); |
359 |
< |
if (zfp != NULL && fseek(zfp, (long)i*hresolu*sizeof(float), 0) == EOF) |
360 |
< |
error(SYSTEM, "z file seek error in render"); |
361 |
< |
ypos = vresolu-1 - i; |
362 |
< |
fillscanline(scanbar[0], zbar[0], hresolu, ypos, psample); |
359 |
> |
if (zfd != -1 && i > 0 && |
360 |
> |
lseek(zfd, (long)i*hres*sizeof(float), 0) == -1) |
361 |
> |
error(SYSTEM, "z-file seek error in render"); |
362 |
> |
pctdone = 100.0*i/vres; |
363 |
> |
if (ralrm > 0) /* report init stats */ |
364 |
> |
report(); |
365 |
> |
#ifndef BSD |
366 |
> |
else |
367 |
> |
#endif |
368 |
> |
signal(SIGCONT, report); |
369 |
> |
ypos = vres-1 - i; |
370 |
> |
fillscanline(scanbar[0], zbar[0], sampdens, hres, ypos, hstep); |
371 |
|
/* compute scanlines */ |
372 |
< |
for (ypos -= psample; ypos >= 0; ypos -= psample) { |
373 |
< |
|
374 |
< |
pctdone = 100.0*(vresolu-ypos-psample)/vresolu; |
375 |
< |
|
376 |
< |
colptr = scanbar[psample]; /* move base to top */ |
377 |
< |
scanbar[psample] = scanbar[0]; |
372 |
> |
for (ypos -= ystep; ypos > -ystep; ypos -= ystep) { |
373 |
> |
/* bottom adjust? */ |
374 |
> |
if (ypos < 0) { |
375 |
> |
ystep += ypos; |
376 |
> |
ypos = 0; |
377 |
> |
} |
378 |
> |
colptr = scanbar[ystep]; /* move base to top */ |
379 |
> |
scanbar[ystep] = scanbar[0]; |
380 |
|
scanbar[0] = colptr; |
381 |
< |
zptr = zbar[psample]; |
382 |
< |
zbar[psample] = zbar[0]; |
381 |
> |
zptr = zbar[ystep]; |
382 |
> |
zbar[ystep] = zbar[0]; |
383 |
|
zbar[0] = zptr; |
384 |
|
/* fill base line */ |
385 |
< |
fillscanline(scanbar[0], zbar[0], hresolu, ypos, psample); |
385 |
> |
fillscanline(scanbar[0], zbar[0], sampdens, |
386 |
> |
hres, ypos, hstep); |
387 |
|
/* fill bar */ |
388 |
< |
fillscanbar(scanbar, zbar, hresolu, ypos, psample); |
388 |
> |
fillscanbar(scanbar, zbar, hres, ypos, ystep); |
389 |
|
/* write it out */ |
390 |
< |
for (i = psample; i > 0; i--) { |
391 |
< |
if (zfp != NULL && fwrite(zbar[i],sizeof(float),hresolu,zfp) != hresolu) |
390 |
> |
#ifndef BSD |
391 |
> |
signal(SIGCONT, SIG_IGN); /* don't interrupt writes */ |
392 |
> |
#endif |
393 |
> |
for (i = ystep; i > 0; i--) { |
394 |
> |
if (zfd != -1 && write(zfd, (char *)zbar[i], |
395 |
> |
hres*sizeof(float)) |
396 |
> |
< hres*sizeof(float)) |
397 |
|
goto writerr; |
398 |
< |
if (fwritescan(scanbar[i],hresolu,stdout) < 0) |
398 |
> |
if (fwritescan(scanbar[i], hres, stdout) < 0) |
399 |
|
goto writerr; |
400 |
|
} |
163 |
– |
if (zfp != NULL && fflush(zfp) == EOF) |
164 |
– |
goto writerr; |
401 |
|
if (fflush(stdout) == EOF) |
402 |
|
goto writerr; |
403 |
+ |
/* record progress */ |
404 |
+ |
pctdone = 100.0*(vres-1-ypos)/vres; |
405 |
+ |
if (ralrm > 0 && time((long *)0) >= tlastrept+ralrm) |
406 |
+ |
report(); |
407 |
+ |
#ifndef BSD |
408 |
+ |
else |
409 |
+ |
signal(SIGCONT, report); |
410 |
+ |
#endif |
411 |
|
} |
168 |
– |
/* compute residual */ |
169 |
– |
colptr = scanbar[psample]; |
170 |
– |
scanbar[psample] = scanbar[0]; |
171 |
– |
scanbar[0] = colptr; |
172 |
– |
zptr = zbar[psample]; |
173 |
– |
zbar[psample] = zbar[0]; |
174 |
– |
zbar[0] = zptr; |
175 |
– |
if (ypos > -psample) { |
176 |
– |
fillscanline(scanbar[-ypos], zbar[-ypos], hresolu, 0, psample); |
177 |
– |
fillscanbar(scanbar-ypos, zbar-ypos, hresolu, 0, psample+ypos); |
178 |
– |
} |
179 |
– |
for (i = psample; i+ypos >= 0; i--) { |
180 |
– |
if (zfp != NULL && fwrite(zbar[i],sizeof(float),hresolu,zfp) != hresolu) |
181 |
– |
goto writerr; |
182 |
– |
if (fwritescan(scanbar[i], hresolu, stdout) < 0) |
183 |
– |
goto writerr; |
184 |
– |
} |
412 |
|
/* clean up */ |
413 |
< |
if (zfp != NULL) { |
414 |
< |
if (fclose(zfp) == EOF) |
413 |
> |
signal(SIGCONT, SIG_IGN); |
414 |
> |
if (zfd != -1) { |
415 |
> |
if (write(zfd, (char *)zbar[0], hres*sizeof(float)) |
416 |
> |
< hres*sizeof(float)) |
417 |
|
goto writerr; |
418 |
+ |
if (close(zfd) == -1) |
419 |
+ |
goto writerr; |
420 |
|
for (i = 0; i <= psample; i++) |
421 |
|
free((char *)zbar[i]); |
422 |
|
} |
423 |
+ |
fwritescan(scanbar[0], hres, stdout); |
424 |
|
if (fflush(stdout) == EOF) |
425 |
|
goto writerr; |
426 |
|
for (i = 0; i <= psample; i++) |
427 |
|
free((char *)scanbar[i]); |
428 |
+ |
if (sampdens != NULL) |
429 |
+ |
free(sampdens); |
430 |
|
pctdone = 100.0; |
431 |
+ |
if (ralrm > 0) |
432 |
+ |
report(); |
433 |
+ |
signal(SIGCONT, SIG_DFL); |
434 |
|
return; |
435 |
|
writerr: |
436 |
|
error(SYSTEM, "write error in render"); |
439 |
|
} |
440 |
|
|
441 |
|
|
442 |
< |
fillscanline(scanline, zline, xres, y, xstep) /* fill scan line at y */ |
443 |
< |
register COLOR *scanline; |
444 |
< |
register float *zline; |
442 |
> |
fillscanline(scanline, zline, sd, xres, y, xstep) /* fill scan at y */ |
443 |
> |
register COLOR *scanline; |
444 |
> |
register float *zline; |
445 |
> |
register char *sd; |
446 |
|
int xres, y, xstep; |
447 |
|
{ |
448 |
< |
int b = xstep; |
449 |
< |
double z; |
448 |
> |
static int nc = 0; /* number of calls */ |
449 |
> |
int bl = xstep, b = xstep; |
450 |
> |
double z; |
451 |
|
register int i; |
452 |
|
|
453 |
|
z = pixvalue(scanline[0], 0, y); |
454 |
|
if (zline) zline[0] = z; |
455 |
< |
|
456 |
< |
for (i = xstep; i < xres; i += xstep) { |
457 |
< |
|
455 |
> |
/* zig-zag start for quincunx pattern */ |
456 |
> |
for (i = ++nc & 1 ? xstep : xstep/2; i < xres-1+xstep; i += xstep) { |
457 |
> |
if (i >= xres) { |
458 |
> |
xstep += xres-1-i; |
459 |
> |
i = xres-1; |
460 |
> |
} |
461 |
|
z = pixvalue(scanline[i], i, y); |
462 |
|
if (zline) zline[i] = z; |
463 |
< |
|
464 |
< |
b = fillsample(scanline+i-xstep, zline ? zline+i-xstep : NULL, |
465 |
< |
i-xstep, y, xstep, 0, b/2); |
463 |
> |
if (sd) b = sd[0] > sd[1] ? sd[0] : sd[1]; |
464 |
> |
if (i <= xstep) |
465 |
> |
b = fillsample(scanline, zline, 0, y, i, 0, b/2); |
466 |
> |
else |
467 |
> |
b = fillsample(scanline+i-xstep, |
468 |
> |
zline ? zline+i-xstep : NULL, |
469 |
> |
i-xstep, y, xstep, 0, b/2); |
470 |
> |
if (sd) *sd++ = nc & 1 ? bl : b; |
471 |
> |
bl = b; |
472 |
|
} |
473 |
< |
if (i-xstep < xres-1) { |
226 |
< |
z = pixvalue(scanline[xres-1], xres-1, y); |
227 |
< |
if (zline) zline[xres-1] = z; |
228 |
< |
fillsample(scanline+i-xstep, zline ? zline+i-xstep : NULL, |
229 |
< |
i-xstep, y, xres-1-(i-xstep), 0, b/2); |
230 |
< |
} |
473 |
> |
if (sd && nc & 1) *sd = bl; |
474 |
|
} |
475 |
|
|
476 |
|
|
477 |
|
fillscanbar(scanbar, zbar, xres, y, ysize) /* fill interior */ |
478 |
< |
register COLOR *scanbar[]; |
479 |
< |
register float *zbar[]; |
478 |
> |
register COLOR *scanbar[]; |
479 |
> |
register float *zbar[]; |
480 |
|
int xres, y, ysize; |
481 |
|
{ |
482 |
|
COLOR vline[MAXDIV+1]; |
483 |
|
float zline[MAXDIV+1]; |
484 |
|
int b = ysize; |
242 |
– |
double z; |
485 |
|
register int i, j; |
486 |
|
|
487 |
|
for (i = 0; i < xres; i++) { |
506 |
|
|
507 |
|
|
508 |
|
int |
509 |
< |
fillsample(colline, zline, x, y, xlen, ylen, b) /* fill interior points */ |
510 |
< |
register COLOR *colline; |
511 |
< |
register float *zline; |
509 |
> |
fillsample(colline, zline, x, y, xlen, ylen, b) /* fill interior points */ |
510 |
> |
register COLOR *colline; |
511 |
> |
register float *zline; |
512 |
|
int x, y; |
513 |
|
int xlen, ylen; |
514 |
|
int b; |
515 |
|
{ |
516 |
< |
extern double fabs(); |
517 |
< |
double ratio; |
276 |
< |
double z; |
516 |
> |
double ratio; |
517 |
> |
double z; |
518 |
|
COLOR ctmp; |
519 |
|
int ncut; |
520 |
|
register int len; |
564 |
|
COLOR col; /* returned color */ |
565 |
|
int x, y; /* pixel position */ |
566 |
|
{ |
567 |
< |
static RAY thisray; /* our ray for this pixel */ |
567 |
> |
static RAY thisray; |
568 |
|
|
569 |
< |
viewray(thisray.rorg, thisray.rdir, &ourview, |
570 |
< |
(x+pixjitter())/hresolu, (y+pixjitter())/vresolu); |
569 |
> |
if (viewray(thisray.rorg, thisray.rdir, &ourview, |
570 |
> |
(x+pixjitter())/hres, (y+pixjitter())/vres) < 0) { |
571 |
> |
setcolor(col, 0.0, 0.0, 0.0); |
572 |
> |
return(0.0); |
573 |
> |
} |
574 |
|
|
575 |
|
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
576 |
< |
|
576 |
> |
|
577 |
> |
samplendx = pixnumber(x,y,hres,vres); /* set pixel index */ |
578 |
> |
|
579 |
|
rayvalue(&thisray); /* trace ray */ |
580 |
|
|
581 |
|
copycolor(col, thisray.rcol); /* return color */ |
582 |
|
|
583 |
< |
return(thisray.rot); /* return distance */ |
583 |
> |
return(thisray.rt); /* return distance */ |
584 |
|
} |
585 |
|
|
586 |
|
|
600 |
|
error(WARNING, errmsg); |
601 |
|
return(0); |
602 |
|
} |
603 |
+ |
#ifdef MSDOS |
604 |
+ |
setmode(fileno(fp), O_BINARY); |
605 |
+ |
#endif |
606 |
|
/* discard header */ |
607 |
< |
getheader(fp, NULL); |
607 |
> |
getheader(fp, NULL, NULL); |
608 |
|
/* get picture size */ |
609 |
< |
if (fgetresolu(&x, &y, fp) != (YMAJOR|YDECR)) { |
609 |
> |
if (!fscnresolu(&x, &y, fp)) { |
610 |
|
sprintf(errmsg, "bad recover file \"%s\"", oldfile); |
611 |
|
error(WARNING, errmsg); |
612 |
|
fclose(fp); |
613 |
|
return(0); |
614 |
|
} |
615 |
|
|
616 |
< |
if (x != hresolu || y != vresolu) { |
616 |
> |
if (x != hres || y != vres) { |
617 |
|
sprintf(errmsg, "resolution mismatch in recover file \"%s\"", |
618 |
|
oldfile); |
619 |
|
error(USER, errmsg); |
620 |
|
} |
621 |
|
|
622 |
< |
scanline = (COLR *)malloc(hresolu*sizeof(COLR)); |
622 |
> |
scanline = (COLR *)malloc(hres*sizeof(COLR)); |
623 |
|
if (scanline == NULL) |
624 |
|
error(SYSTEM, "out of memory in salvage"); |
625 |
< |
for (y = 0; y < vresolu; y++) { |
626 |
< |
if (freadcolrs(scanline, hresolu, fp) < 0) |
625 |
> |
for (y = 0; y < vres; y++) { |
626 |
> |
if (freadcolrs(scanline, hres, fp) < 0) |
627 |
|
break; |
628 |
< |
if (fwritecolrs(scanline, hresolu, stdout) < 0) |
628 |
> |
if (fwritecolrs(scanline, hres, stdout) < 0) |
629 |
|
goto writerr; |
630 |
|
} |
631 |
|
if (fflush(stdout) == EOF) |
635 |
|
unlink(oldfile); |
636 |
|
return(y); |
637 |
|
writerr: |
638 |
< |
error(SYSTEM, "write error in salvage"); |
638 |
> |
sprintf(errmsg, "write error during recovery of \"%s\"", oldfile); |
639 |
> |
error(SYSTEM, errmsg); |
640 |
> |
} |
641 |
> |
|
642 |
> |
|
643 |
> |
int |
644 |
> |
pixnumber(x, y, xres, yres) /* compute pixel index (brushed) */ |
645 |
> |
register int x, y; |
646 |
> |
int xres, yres; |
647 |
> |
{ |
648 |
> |
x -= y; |
649 |
> |
while (x < 0) |
650 |
> |
x += xres; |
651 |
> |
return((((x>>2)*yres + y) << 2) + (x & 3)); |
652 |
|
} |