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"; |
15 |
|
#ifdef BSD |
16 |
|
#include <sys/time.h> |
17 |
|
#include <sys/resource.h> |
18 |
– |
#else |
19 |
– |
#include <signal.h> |
18 |
|
#endif |
19 |
|
|
20 |
+ |
#include <signal.h> |
21 |
+ |
#include <fcntl.h> |
22 |
+ |
|
23 |
|
#include "view.h" |
24 |
|
|
25 |
+ |
#include "resolu.h" |
26 |
+ |
|
27 |
|
#include "random.h" |
28 |
|
|
29 |
+ |
#include "paths.h" |
30 |
+ |
|
31 |
+ |
int dimlist[MAXDIM]; /* sampling dimensions */ |
32 |
+ |
int ndims = 0; /* number of sampling dimensions */ |
33 |
+ |
int samplendx; /* sample index number */ |
34 |
+ |
|
35 |
|
VIEW ourview = STDVIEW; /* view parameters */ |
36 |
|
int hresolu = 512; /* horizontal resolution */ |
37 |
|
int vresolu = 512; /* vertical resolution */ |
44 |
|
double dstrsrc = 0.0; /* square source distribution */ |
45 |
|
double shadthresh = .05; /* shadow threshold */ |
46 |
|
double shadcert = .5; /* shadow certainty */ |
47 |
+ |
int directrelay = 1; /* number of source relays */ |
48 |
+ |
int vspretest = 512; /* virtual source pretest density */ |
49 |
+ |
int directinvis = 0; /* sources invisible? */ |
50 |
+ |
double srcsizerat = .25; /* maximum ratio source size/dist. */ |
51 |
|
|
52 |
+ |
double specthresh = .15; /* specular sampling threshold */ |
53 |
+ |
double specjitter = 1.; /* specular sampling jitter */ |
54 |
+ |
|
55 |
|
int maxdepth = 6; /* maximum recursion depth */ |
56 |
|
double minweight = 5e-3; /* minimum ray weight */ |
57 |
|
|
68 |
|
|
69 |
|
double pctdone = 0.0; /* percentage done */ |
70 |
|
|
71 |
+ |
long tlastrept = 0L; /* time at last report */ |
72 |
+ |
|
73 |
+ |
extern long time(); |
74 |
+ |
extern long tstart; /* starting time */ |
75 |
+ |
|
76 |
|
extern long nrays; /* number of rays traced */ |
77 |
|
|
78 |
< |
#define MAXDIV 32 /* maximum sample size */ |
78 |
> |
#define MAXDIV 16 /* maximum sample size */ |
79 |
|
|
80 |
|
#define pixjitter() (.5+dstrpix*(.5-frandom())) |
81 |
|
|
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 |
+ |
|
88 |
+ |
static int hres, vres; /* resolution for this frame */ |
89 |
+ |
|
90 |
+ |
extern char *mktemp(); |
91 |
+ |
|
92 |
|
double pixvalue(); |
93 |
|
|
94 |
|
|
95 |
|
quit(code) /* quit program */ |
96 |
|
int code; |
97 |
|
{ |
98 |
< |
if (code || ralrm > 0) /* report status */ |
98 |
> |
if (code) /* report status */ |
99 |
|
report(); |
100 |
< |
|
100 |
> |
if (hfname != NULL) { /* delete header file */ |
101 |
> |
if (hfp != NULL) |
102 |
> |
fclose(hfp); |
103 |
> |
unlink(hfname); |
104 |
> |
} |
105 |
|
exit(code); |
106 |
|
} |
107 |
|
|
108 |
|
|
109 |
+ |
#ifdef BSD |
110 |
|
report() /* report progress */ |
111 |
|
{ |
76 |
– |
#ifdef BSD |
112 |
|
struct rusage rubuf; |
113 |
|
double t; |
114 |
|
|
121 |
|
|
122 |
|
sprintf(errmsg, "%ld rays, %4.2f%% done after %5.4f CPU hours\n", |
123 |
|
nrays, pctdone, t/3600.0); |
124 |
+ |
eputs(errmsg); |
125 |
+ |
tlastrept = time((long *)0); |
126 |
+ |
} |
127 |
|
#else |
128 |
+ |
report() /* report progress */ |
129 |
+ |
{ |
130 |
+ |
tlastrept = time((long *)0); |
131 |
+ |
sprintf(errmsg, "%ld rays, %4.2f%% done after %5.4f hours\n", |
132 |
+ |
nrays, pctdone, (tlastrept-tstart)/3600.0); |
133 |
+ |
eputs(errmsg); |
134 |
|
signal(SIGALRM, report); |
135 |
< |
sprintf(errmsg, "%ld rays, %4.2f%% done\n", nrays, pctdone); |
135 |
> |
} |
136 |
|
#endif |
93 |
– |
eputs(errmsg); |
137 |
|
|
138 |
< |
if (ralrm > 0) |
139 |
< |
alarm(ralrm); |
138 |
> |
|
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 |
+ |
|
169 |
+ |
rpict(seq, pout, zout, prvr) /* generate image(s) */ |
170 |
+ |
int seq; |
171 |
+ |
char *pout, *zout, *prvr; |
172 |
+ |
/* |
173 |
+ |
* If seq is greater than zero, then we will render a sequence of |
174 |
+ |
* images based on view parameter strings read from the standard input. |
175 |
+ |
* If pout is NULL, then all images will be sent to the standard ouput. |
176 |
+ |
* If seq is greater than zero and prvr is an integer, then it is the |
177 |
+ |
* frame number at which rendering should begin. Preceeding view parameter |
178 |
+ |
* strings will be skipped in the input. |
179 |
+ |
* If pout and prvr are the same, prvr is renamed to avoid overwriting. |
180 |
+ |
* Note that pout and zout should contain %d format specifications for |
181 |
+ |
* sequenced file naming. |
182 |
+ |
*/ |
183 |
+ |
{ |
184 |
+ |
extern char *rindex(), *strncpy(), *strcat(); |
185 |
+ |
char fbuf[128], fbuf2[128]; |
186 |
+ |
register char *cp; |
187 |
+ |
RESOLU rs; |
188 |
+ |
double pa; |
189 |
+ |
/* finished writing header */ |
190 |
+ |
closeheader(); |
191 |
+ |
/* check sampling */ |
192 |
+ |
if (psample < 1) |
193 |
+ |
psample = 1; |
194 |
+ |
else if (psample > MAXDIV) { |
195 |
+ |
sprintf(errmsg, "pixel sampling reduced from %d to %d", |
196 |
+ |
psample, MAXDIV); |
197 |
+ |
error(WARNING, errmsg); |
198 |
+ |
psample = MAXDIV; |
199 |
+ |
} |
200 |
+ |
/* get starting frame */ |
201 |
+ |
if (seq <= 0) |
202 |
+ |
seq = 0; |
203 |
+ |
else if (prvr != NULL && isint(prvr)) { |
204 |
+ |
register int rn; /* skip to specified view */ |
205 |
+ |
if ((rn = atoi(prvr)) < seq) |
206 |
+ |
error(USER, "recover frame less than start frame"); |
207 |
+ |
if (pout == NULL) |
208 |
+ |
error(USER, "missing output file specification"); |
209 |
+ |
for ( ; seq < rn; seq++) |
210 |
+ |
if (nextview(stdin) == EOF) |
211 |
+ |
error(USER, "unexpected EOF on view input"); |
212 |
+ |
prvr = fbuf; /* mark for renaming */ |
213 |
+ |
} |
214 |
+ |
if (pout != NULL) { |
215 |
+ |
sprintf(fbuf, pout, seq); |
216 |
+ |
if (prvr != NULL && !strcmp(prvr, fbuf)) { /* rename */ |
217 |
+ |
fbuf2[0] = '\0'; |
218 |
+ |
if ((cp = rindex(fbuf, '/')) != NULL) |
219 |
+ |
strncpy(fbuf2, fbuf, cp-fbuf+1); |
220 |
+ |
strcat(fbuf2, RFTEMPLATE); |
221 |
+ |
prvr = mktemp(fbuf2); |
222 |
+ |
if (rename(fbuf, prvr) < 0 && errno != ENOENT) { |
223 |
+ |
sprintf(errmsg, |
224 |
+ |
"cannot rename \"%s\" to \"%s\"", |
225 |
+ |
fbuf, prvr); |
226 |
+ |
error(SYSTEM, errmsg); |
227 |
+ |
} |
228 |
+ |
} |
229 |
+ |
} |
230 |
+ |
/* render sequence */ |
231 |
+ |
do { |
232 |
+ |
if (seq && nextview(stdin) == EOF) |
233 |
+ |
break; |
234 |
+ |
if (pout != NULL) { |
235 |
+ |
sprintf(fbuf, pout, seq); |
236 |
+ |
if (freopen(fbuf, "w", stdout) == NULL) { |
237 |
+ |
sprintf(errmsg, |
238 |
+ |
"cannot open output file \"%s\"", fbuf); |
239 |
+ |
error(SYSTEM, errmsg); |
240 |
+ |
} |
241 |
+ |
dupheader(); |
242 |
+ |
} |
243 |
+ |
hres = hresolu; vres = vresolu; pa = pixaspect; |
244 |
+ |
if (prvr != NULL) |
245 |
+ |
if (viewfile(prvr, &ourview, &rs) <= 0 |
246 |
+ |
|| rs.or != PIXSTANDARD) { |
247 |
+ |
sprintf(errmsg, |
248 |
+ |
"cannot recover view parameters from \"%s\"", prvr); |
249 |
+ |
error(WARNING, errmsg); |
250 |
+ |
} else { |
251 |
+ |
pa = 0.0; |
252 |
+ |
hres = scanlen(&rs); |
253 |
+ |
vres = numscans(&rs); |
254 |
+ |
} |
255 |
+ |
if ((cp = setview(&ourview)) != NULL) |
256 |
+ |
error(USER, cp); |
257 |
+ |
normaspect(viewaspect(&ourview), &pa, &hres, &vres); |
258 |
+ |
if (seq) { |
259 |
+ |
if (ralrm > 0) { |
260 |
+ |
fprintf(stderr, "FRAME %d:", seq); |
261 |
+ |
fprintview(&ourview, stderr); |
262 |
+ |
putc('\n', stderr); |
263 |
+ |
fflush(stderr); |
264 |
+ |
} |
265 |
+ |
printf("FRAME=%d\n", seq); |
266 |
+ |
} |
267 |
+ |
fputs(VIEWSTR, stdout); |
268 |
+ |
fprintview(&ourview, stdout); |
269 |
+ |
putchar('\n'); |
270 |
+ |
if (pa < .99 || pa > 1.01) |
271 |
+ |
fputaspect(pa, stdout); |
272 |
+ |
fputformat(COLRFMT, stdout); |
273 |
+ |
putchar('\n'); |
274 |
+ |
if (zout != NULL) |
275 |
+ |
sprintf(cp=fbuf, zout, seq); |
276 |
+ |
else |
277 |
+ |
cp = NULL; |
278 |
+ |
render(cp, prvr); |
279 |
+ |
prvr = NULL; |
280 |
+ |
} while (seq++); |
281 |
+ |
} |
282 |
+ |
|
283 |
+ |
|
284 |
+ |
nextview(fp) /* get next view from fp */ |
285 |
+ |
FILE *fp; |
286 |
+ |
{ |
287 |
+ |
char linebuf[256]; |
288 |
+ |
|
289 |
+ |
while (fgets(linebuf, sizeof(linebuf), fp) != NULL) |
290 |
+ |
if (isview(linebuf) && sscanview(&ourview, linebuf) > 0) |
291 |
+ |
return(0); |
292 |
+ |
return(EOF); |
293 |
+ |
} |
294 |
+ |
|
295 |
+ |
|
296 |
|
render(zfile, oldfile) /* render the scene */ |
297 |
|
char *zfile, *oldfile; |
298 |
|
{ |
299 |
+ |
extern long lseek(); |
300 |
|
COLOR *scanbar[MAXDIV+1]; /* scanline arrays of pixel values */ |
301 |
|
float *zbar[MAXDIV+1]; /* z values */ |
302 |
+ |
char *sampdens; /* previous sample density */ |
303 |
|
int ypos; /* current scanline */ |
304 |
|
int ystep; /* current y step size */ |
305 |
< |
FILE *zfp; |
305 |
> |
int hstep; /* h step size */ |
306 |
> |
int zfd; |
307 |
|
COLOR *colptr; |
308 |
|
float *zptr; |
309 |
|
register int i; |
111 |
– |
/* check sampling */ |
112 |
– |
if (psample < 1) |
113 |
– |
psample = 1; |
114 |
– |
else if (psample > MAXDIV) |
115 |
– |
psample = MAXDIV; |
310 |
|
/* allocate scanlines */ |
311 |
|
for (i = 0; i <= psample; i++) { |
312 |
< |
scanbar[i] = (COLOR *)malloc(hresolu*sizeof(COLOR)); |
312 |
> |
scanbar[i] = (COLOR *)malloc(hres*sizeof(COLOR)); |
313 |
|
if (scanbar[i] == NULL) |
314 |
|
goto memerr; |
315 |
|
} |
316 |
+ |
hstep = (psample*140+49)/99; /* quincunx sampling */ |
317 |
+ |
ystep = (psample*99+70)/140; |
318 |
+ |
if (hstep > 2) { |
319 |
+ |
i = hres/hstep + 2; |
320 |
+ |
if ((sampdens = malloc(i)) == NULL) |
321 |
+ |
goto memerr; |
322 |
+ |
while (i--) |
323 |
+ |
sampdens[i] = hstep; |
324 |
+ |
} else |
325 |
+ |
sampdens = NULL; |
326 |
|
/* open z file */ |
327 |
|
if (zfile != NULL) { |
328 |
< |
if ((zfp = fopen(zfile, "a+")) == NULL) { |
328 |
> |
if ((zfd = open(zfile, O_WRONLY|O_CREAT, 0666)) == -1) { |
329 |
|
sprintf(errmsg, "cannot open z file \"%s\"", zfile); |
330 |
|
error(SYSTEM, errmsg); |
331 |
|
} |
332 |
|
for (i = 0; i <= psample; i++) { |
333 |
< |
zbar[i] = (float *)malloc(hresolu*sizeof(float)); |
333 |
> |
zbar[i] = (float *)malloc(hres*sizeof(float)); |
334 |
|
if (zbar[i] == NULL) |
335 |
|
goto memerr; |
336 |
|
} |
337 |
|
} else { |
338 |
< |
zfp = NULL; |
338 |
> |
zfd = -1; |
339 |
|
for (i = 0; i <= psample; i++) |
340 |
|
zbar[i] = NULL; |
341 |
|
} |
342 |
|
/* write out boundaries */ |
343 |
< |
fputresolu(YMAJOR|YDECR, hresolu, vresolu, stdout); |
343 |
> |
fprtresolu(hres, vres, stdout); |
344 |
|
/* recover file and compute first */ |
345 |
|
i = salvage(oldfile); |
346 |
< |
if (zfp != NULL && fseek(zfp, (long)i*hresolu*sizeof(float), 0) == EOF) |
346 |
> |
if (zfd != -1 && i > 0 && |
347 |
> |
lseek(zfd, (long)i*hres*sizeof(float), 0) == -1) |
348 |
|
error(SYSTEM, "z file seek error in render"); |
349 |
< |
ypos = vresolu-1 - i; |
350 |
< |
fillscanline(scanbar[0], zbar[0], hresolu, ypos, psample); |
351 |
< |
ystep = psample; |
349 |
> |
pctdone = 100.0*i/vres; |
350 |
> |
if (ralrm > 0) /* report init stats */ |
351 |
> |
report(); |
352 |
> |
#ifndef BSD |
353 |
> |
else |
354 |
> |
#endif |
355 |
> |
signal(SIGALRM, report); |
356 |
> |
ypos = vres-1 - i; |
357 |
> |
fillscanline(scanbar[0], zbar[0], sampdens, hres, ypos, hstep); |
358 |
|
/* compute scanlines */ |
359 |
|
for (ypos -= ystep; ypos > -ystep; ypos -= ystep) { |
149 |
– |
/* record progress */ |
150 |
– |
pctdone = 100.0*(vresolu-ypos-ystep)/vresolu; |
360 |
|
/* bottom adjust? */ |
361 |
|
if (ypos < 0) { |
362 |
|
ystep += ypos; |
369 |
|
zbar[ystep] = zbar[0]; |
370 |
|
zbar[0] = zptr; |
371 |
|
/* fill base line */ |
372 |
< |
fillscanline(scanbar[0], zbar[0], hresolu, ypos, psample); |
372 |
> |
fillscanline(scanbar[0], zbar[0], sampdens, |
373 |
> |
hres, ypos, hstep); |
374 |
|
/* fill bar */ |
375 |
< |
fillscanbar(scanbar, zbar, hresolu, ypos, ystep); |
375 |
> |
fillscanbar(scanbar, zbar, hres, ypos, ystep); |
376 |
|
/* write it out */ |
377 |
+ |
#ifndef BSD |
378 |
+ |
signal(SIGALRM, SIG_IGN); /* don't interrupt writes */ |
379 |
+ |
#endif |
380 |
|
for (i = ystep; i > 0; i--) { |
381 |
< |
if (zfp != NULL && fwrite(zbar[i],sizeof(float),hresolu,zfp) != hresolu) |
381 |
> |
if (zfd != -1 && write(zfd, (char *)zbar[i], |
382 |
> |
hres*sizeof(float)) |
383 |
> |
< hres*sizeof(float)) |
384 |
|
goto writerr; |
385 |
< |
if (fwritescan(scanbar[i],hresolu,stdout) < 0) |
385 |
> |
if (fwritescan(scanbar[i], hres, stdout) < 0) |
386 |
|
goto writerr; |
387 |
|
} |
173 |
– |
if (zfp != NULL && fflush(zfp) == EOF) |
174 |
– |
goto writerr; |
388 |
|
if (fflush(stdout) == EOF) |
389 |
|
goto writerr; |
390 |
+ |
/* record progress */ |
391 |
+ |
pctdone = 100.0*(vres-1-ypos)/vres; |
392 |
+ |
if (ralrm > 0 && time((long *)0) >= tlastrept+ralrm) |
393 |
+ |
report(); |
394 |
+ |
#ifndef BSD |
395 |
+ |
else |
396 |
+ |
signal(SIGALRM, report); |
397 |
+ |
#endif |
398 |
|
} |
399 |
|
/* clean up */ |
400 |
< |
if (zfp != NULL) { |
401 |
< |
fwrite(zbar[0], sizeof(float), hresolu, zfp); |
402 |
< |
if (fclose(zfp) == EOF) |
400 |
> |
signal(SIGALRM, SIG_IGN); |
401 |
> |
if (zfd != -1) { |
402 |
> |
if (write(zfd, (char *)zbar[0], hres*sizeof(float)) |
403 |
> |
< hres*sizeof(float)) |
404 |
|
goto writerr; |
405 |
+ |
if (close(zfd) == -1) |
406 |
+ |
goto writerr; |
407 |
|
for (i = 0; i <= psample; i++) |
408 |
|
free((char *)zbar[i]); |
409 |
|
} |
410 |
< |
fwritescan(scanbar[0], hresolu, stdout); |
410 |
> |
fwritescan(scanbar[0], hres, stdout); |
411 |
|
if (fflush(stdout) == EOF) |
412 |
|
goto writerr; |
413 |
|
for (i = 0; i <= psample; i++) |
414 |
|
free((char *)scanbar[i]); |
415 |
+ |
if (sampdens != NULL) |
416 |
+ |
free(sampdens); |
417 |
|
pctdone = 100.0; |
418 |
|
return; |
419 |
|
writerr: |
423 |
|
} |
424 |
|
|
425 |
|
|
426 |
< |
fillscanline(scanline, zline, xres, y, xstep) /* fill scan line at y */ |
426 |
> |
fillscanline(scanline, zline, sd, xres, y, xstep) /* fill scan at y */ |
427 |
|
register COLOR *scanline; |
428 |
|
register float *zline; |
429 |
+ |
register char *sd; |
430 |
|
int xres, y, xstep; |
431 |
|
{ |
432 |
< |
int b = xstep; |
432 |
> |
static int nc = 0; /* number of calls */ |
433 |
> |
int bl = xstep, b = xstep; |
434 |
|
double z; |
435 |
|
register int i; |
436 |
|
|
437 |
|
z = pixvalue(scanline[0], 0, y); |
438 |
|
if (zline) zline[0] = z; |
439 |
< |
|
440 |
< |
for (i = xstep; i < xres-1+xstep; i += xstep) { |
439 |
> |
/* zig-zag start for quincunx pattern */ |
440 |
> |
for (i = ++nc & 1 ? xstep : xstep/2; i < xres-1+xstep; i += xstep) { |
441 |
|
if (i >= xres) { |
442 |
|
xstep += xres-1-i; |
443 |
|
i = xres-1; |
444 |
|
} |
445 |
|
z = pixvalue(scanline[i], i, y); |
446 |
|
if (zline) zline[i] = z; |
447 |
< |
|
448 |
< |
b = fillsample(scanline+i-xstep, zline ? zline+i-xstep : NULL, |
449 |
< |
i-xstep, y, xstep, 0, b/2); |
447 |
> |
if (sd) b = sd[0] > sd[1] ? sd[0] : sd[1]; |
448 |
> |
if (i <= xstep) |
449 |
> |
b = fillsample(scanline, zline, 0, y, i, 0, b/2); |
450 |
> |
else |
451 |
> |
b = fillsample(scanline+i-xstep, |
452 |
> |
zline ? zline+i-xstep : NULL, |
453 |
> |
i-xstep, y, xstep, 0, b/2); |
454 |
> |
if (sd) *sd++ = nc & 1 ? bl : b; |
455 |
> |
bl = b; |
456 |
|
} |
457 |
+ |
if (sd && nc & 1) *sd = bl; |
458 |
|
} |
459 |
|
|
460 |
|
|
466 |
|
COLOR vline[MAXDIV+1]; |
467 |
|
float zline[MAXDIV+1]; |
468 |
|
int b = ysize; |
234 |
– |
double z; |
469 |
|
register int i, j; |
470 |
|
|
471 |
|
for (i = 0; i < xres; i++) { |
549 |
|
COLOR col; /* returned color */ |
550 |
|
int x, y; /* pixel position */ |
551 |
|
{ |
552 |
< |
static RAY thisray; /* our ray for this pixel */ |
552 |
> |
static RAY thisray; |
553 |
|
|
554 |
< |
viewray(thisray.rorg, thisray.rdir, &ourview, |
555 |
< |
(x+pixjitter())/hresolu, (y+pixjitter())/vresolu); |
554 |
> |
if (viewray(thisray.rorg, thisray.rdir, &ourview, |
555 |
> |
(x+pixjitter())/hres, (y+pixjitter())/vres) < 0) { |
556 |
> |
setcolor(col, 0.0, 0.0, 0.0); |
557 |
> |
return(0.0); |
558 |
> |
} |
559 |
|
|
560 |
|
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
561 |
< |
|
561 |
> |
|
562 |
> |
samplendx = pixnumber(x,y,hres,vres); /* set pixel index */ |
563 |
> |
|
564 |
|
rayvalue(&thisray); /* trace ray */ |
565 |
|
|
566 |
|
copycolor(col, thisray.rcol); /* return color */ |
567 |
|
|
568 |
< |
return(thisray.rot); /* return distance */ |
568 |
> |
return(thisray.rt); /* return distance */ |
569 |
|
} |
570 |
|
|
571 |
|
|
588 |
|
/* discard header */ |
589 |
|
getheader(fp, NULL); |
590 |
|
/* get picture size */ |
591 |
< |
if (fgetresolu(&x, &y, fp) != (YMAJOR|YDECR)) { |
591 |
> |
if (!fscnresolu(&x, &y, fp)) { |
592 |
|
sprintf(errmsg, "bad recover file \"%s\"", oldfile); |
593 |
|
error(WARNING, errmsg); |
594 |
|
fclose(fp); |
595 |
|
return(0); |
596 |
|
} |
597 |
|
|
598 |
< |
if (x != hresolu || y != vresolu) { |
598 |
> |
if (x != hres || y != vres) { |
599 |
|
sprintf(errmsg, "resolution mismatch in recover file \"%s\"", |
600 |
|
oldfile); |
601 |
|
error(USER, errmsg); |
602 |
|
} |
603 |
|
|
604 |
< |
scanline = (COLR *)malloc(hresolu*sizeof(COLR)); |
604 |
> |
scanline = (COLR *)malloc(hres*sizeof(COLR)); |
605 |
|
if (scanline == NULL) |
606 |
|
error(SYSTEM, "out of memory in salvage"); |
607 |
< |
for (y = 0; y < vresolu; y++) { |
608 |
< |
if (freadcolrs(scanline, hresolu, fp) < 0) |
607 |
> |
for (y = 0; y < vres; y++) { |
608 |
> |
if (freadcolrs(scanline, hres, fp) < 0) |
609 |
|
break; |
610 |
< |
if (fwritecolrs(scanline, hresolu, stdout) < 0) |
610 |
> |
if (fwritecolrs(scanline, hres, stdout) < 0) |
611 |
|
goto writerr; |
612 |
|
} |
613 |
|
if (fflush(stdout) == EOF) |
617 |
|
unlink(oldfile); |
618 |
|
return(y); |
619 |
|
writerr: |
620 |
< |
error(SYSTEM, "write error in salvage"); |
620 |
> |
sprintf(errmsg, "write error during recovery of \"%s\"", oldfile); |
621 |
> |
error(SYSTEM, errmsg); |
622 |
> |
} |
623 |
> |
|
624 |
> |
|
625 |
> |
int |
626 |
> |
pixnumber(x, y, xres, yres) /* compute pixel index (brushed) */ |
627 |
> |
register int x, y; |
628 |
> |
int xres, yres; |
629 |
> |
{ |
630 |
> |
x -= y; |
631 |
> |
while (x < 0) |
632 |
> |
x += xres; |
633 |
> |
return((((x>>2)*yres + y) << 2) + (x & 3)); |
634 |
|
} |