ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/rpict.c
(Generate patch)

Comparing ray/src/rt/rpict.c (file contents):
Revision 1.2 by greg, Mon Apr 10 09:32:55 1989 UTC vs.
Revision 2.27 by greg, Mon Aug 2 21:48:37 1993 UTC

# Line 1 | Line 1
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";
# Line 17 | Line 17 | 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 < VIEW  ourview = STDVIEW(512);           /* view parameters */
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 */
48  
49 < double  maxdiff = .05;                  /* max. difference for interpolation */
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  dstrpix = 0.67;                 /* square pixel distribution */
58 < double  dstrsrc = 0.0;                  /* square source distribution */
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 */
65 < int  ambres = 128;                      /* ambient resolution */
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 */
68   int  ambounce = 0;                      /* ambient bounces */
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 + #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   {
68 #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;
# Line 76 | Line 134 | report()               /* report progress */
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 && errno != ENOENT) {
209 >                                sprintf(errmsg,
210 >                                        "cannot rename \"%s\" to \"%s\"",
211 >                                                fbuf, prvr);
212 >                                error(SYSTEM, errmsg);
213 >                        }
214 >                }
215 >        }
216 >        npicts = 0;                     /* render sequence */
217 >        do {
218 >                if (seq && nextview(stdin) == EOF)
219 >                        break;
220 >                pctdone = 0.0;
221 >                if (pout != NULL) {
222 >                        sprintf(fbuf, pout, seq);
223 >                        if (file_exists(fbuf)) {
224 >                                if (prvr != NULL || !strcmp(fbuf, pout)) {
225 >                                        sprintf(errmsg,
226 >                                                "output file \"%s\" exists",
227 >                                                fbuf);
228 >                                        error(USER, errmsg);
229 >                                }
230 >                                continue;               /* don't clobber */
231 >                        }
232 >                        if (freopen(fbuf, "w", stdout) == NULL) {
233 >                                sprintf(errmsg,
234 >                                        "cannot open output file \"%s\"", fbuf);
235 >                                error(SYSTEM, errmsg);
236 >                        }
237 > #ifdef MSDOS
238 >                        setmode(fileno(stdout), O_BINARY);
239 > #endif
240 >                        dupheader();
241 >                }
242 >                hres = hresolu; vres = vresolu; pa = pixaspect;
243 >                if (prvr != NULL)
244 >                        if (viewfile(prvr, &ourview, &rs) <= 0
245 >                                        || rs.or != PIXSTANDARD) {
246 >                                sprintf(errmsg,
247 >                        "cannot recover view parameters from \"%s\"", prvr);
248 >                                error(WARNING, errmsg);
249 >                        } else {
250 >                                pa = 0.0;
251 >                                hres = scanlen(&rs);
252 >                                vres = numscans(&rs);
253 >                        }
254 >                if ((cp = setview(&ourview)) != NULL)
255 >                        error(USER, cp);
256 >                normaspect(viewaspect(&ourview), &pa, &hres, &vres);
257 >                if (seq) {
258 >                        if (ralrm > 0) {
259 >                                fprintf(stderr, "FRAME %d:", seq);
260 >                                fprintview(&ourview, stderr);
261 >                                putc('\n', stderr);
262 >                                fflush(stderr);
263 >                        }
264 >                        printf("FRAME=%d\n", seq);
265 >                }
266 >                fputs(VIEWSTR, stdout);
267 >                fprintview(&ourview, stdout);
268 >                putchar('\n');
269 >                if (pa < .99 || pa > 1.01)
270 >                        fputaspect(pa, stdout);
271 >                fputformat(COLRFMT, stdout);
272 >                putchar('\n');
273 >                if (zout != NULL)
274 >                        sprintf(cp=fbuf, zout, seq);
275 >                else
276 >                        cp = NULL;
277 >                render(cp, prvr);
278 >                prvr = NULL;
279 >                npicts++;
280 >        } while (seq++);
281 >                                        /* check that we did something */
282 >        if (npicts == 0)
283 >                error(WARNING, "no output produced");
284   }
285  
286  
287 < render(oldfile)                         /* render the scene */
288 < char  *oldfile;
287 > nextview(fp)                            /* get next view from fp */
288 > FILE  *fp;
289   {
290 +        char  linebuf[256];
291 +
292 +        while (fgets(linebuf, sizeof(linebuf), fp) != NULL)
293 +                if (isview(linebuf) && sscanview(&ourview, linebuf) > 0)
294 +                        return(0);
295 +        return(EOF);
296 + }      
297 +
298 +
299 + render(zfile, oldfile)                          /* render the scene */
300 + char  *zfile, *oldfile;
301 + {
302 +        extern long  lseek();
303          COLOR  *scanbar[MAXDIV+1];      /* scanline arrays of pixel values */
304 +        float  *zbar[MAXDIV+1];         /* z values */
305 +        char  *sampdens;                /* previous sample density */
306          int  ypos;                      /* current scanline */
307 +        int  ystep;                     /* current y step size */
308 +        int  hstep;                     /* h step size */
309 +        int  zfd;
310          COLOR  *colptr;
311 +        float  *zptr;
312          register int  i;
313 <
99 <        if (psample < 1)
100 <                psample = 1;
101 <        else if (psample > MAXDIV)
102 <                psample = MAXDIV;
103 <
104 <        ourview.hresolu -= ourview.hresolu % psample;
105 <        ourview.vresolu -= ourview.vresolu % psample;
106 <                
313 >                                        /* allocate scanlines */
314          for (i = 0; i <= psample; i++) {
315 <                scanbar[i] = (COLOR *)malloc((ourview.hresolu+1)*sizeof(COLOR));
315 >                scanbar[i] = (COLOR *)malloc(hres*sizeof(COLOR));
316                  if (scanbar[i] == NULL)
317 <                        error(SYSTEM, "out of memory in render");
317 >                        goto memerr;
318          }
319 <        
319 >        hstep = (psample*140+49)/99;            /* quincunx sampling */
320 >        ystep = (psample*99+70)/140;
321 >        if (hstep > 2) {
322 >                i = hres/hstep + 2;
323 >                if ((sampdens = malloc(i)) == NULL)
324 >                        goto memerr;
325 >                while (i--)
326 >                        sampdens[i] = hstep;
327 >        } else
328 >                sampdens = NULL;
329 >                                        /* open z-file */
330 >        if (zfile != NULL) {
331 >                if ((zfd = open(zfile, O_WRONLY|O_CREAT, 0666)) == -1) {
332 >                        sprintf(errmsg, "cannot open z-file \"%s\"", zfile);
333 >                        error(SYSTEM, errmsg);
334 >                }
335 > #ifdef MSDOS
336 >                setmode(zfd, O_BINARY);
337 > #endif
338 >                for (i = 0; i <= psample; i++) {
339 >                        zbar[i] = (float *)malloc(hres*sizeof(float));
340 >                        if (zbar[i] == NULL)
341 >                                goto memerr;
342 >                }
343 >        } else {
344 >                zfd = -1;
345 >                for (i = 0; i <= psample; i++)
346 >                        zbar[i] = NULL;
347 >        }
348                                          /* write out boundaries */
349 <        printf("-Y %d +X %d\n", ourview.vresolu, ourview.hresolu);
350 <
351 <        ypos = ourview.vresolu - salvage(oldfile);      /* find top line */
352 <        fillscanline(scanbar[0], ypos, psample);        /* top scan */
353 <
354 <        for (ypos -= psample; ypos > -psample; ypos -= psample) {
355 <        
356 <                colptr = scanbar[psample];              /* get last scanline */
357 <                scanbar[psample] = scanbar[0];
349 >        fprtresolu(hres, vres, stdout);
350 >                                        /* recover file and compute first */
351 >        i = salvage(oldfile);
352 >        if (zfd != -1 && i > 0 &&
353 >                        lseek(zfd, (long)i*hres*sizeof(float), 0) == -1)
354 >                error(SYSTEM, "z-file seek error in render");
355 >        pctdone = 100.0*i/vres;
356 >        if (ralrm > 0)                  /* report init stats */
357 >                report();
358 > #ifndef  BSD
359 >        else
360 > #endif
361 >        signal(SIGCONT, report);
362 >        ypos = vres-1 - i;
363 >        fillscanline(scanbar[0], zbar[0], sampdens, hres, ypos, hstep);
364 >                                                /* compute scanlines */
365 >        for (ypos -= ystep; ypos > -ystep; ypos -= ystep) {
366 >                                                        /* bottom adjust? */
367 >                if (ypos < 0) {
368 >                        ystep += ypos;
369 >                        ypos = 0;
370 >                }
371 >                colptr = scanbar[ystep];                /* move base to top */
372 >                scanbar[ystep] = scanbar[0];
373                  scanbar[0] = colptr;
374 <
375 <                fillscanline(scanbar[0], ypos, psample);        /* base scan */
376 <        
377 <                fillscanbar(scanbar, ypos, psample);
378 <                
379 <                for (i = psample-1; i >= 0; i--)
380 <                        if (fwritescan(scanbar[i], ourview.hresolu, stdout) < 0)
374 >                zptr = zbar[ystep];
375 >                zbar[ystep] = zbar[0];
376 >                zbar[0] = zptr;
377 >                                                        /* fill base line */
378 >                fillscanline(scanbar[0], zbar[0], sampdens,
379 >                                hres, ypos, hstep);
380 >                                                        /* fill bar */
381 >                fillscanbar(scanbar, zbar, hres, ypos, ystep);
382 >                                                        /* write it out */
383 > #ifndef  BSD
384 >                signal(SIGCONT, SIG_IGN);       /* don't interrupt writes */
385 > #endif
386 >                for (i = ystep; i > 0; i--) {
387 >                        if (zfd != -1 && write(zfd, (char *)zbar[i],
388 >                                        hres*sizeof(float))
389 >                                        < hres*sizeof(float))
390                                  goto writerr;
391 +                        if (fwritescan(scanbar[i], hres, stdout) < 0)
392 +                                goto writerr;
393 +                }
394                  if (fflush(stdout) == EOF)
395                          goto writerr;
396 <                pctdone = 100.0*(ourview.vresolu-ypos)/ourview.vresolu;
396 >                                                        /* record progress */
397 >                pctdone = 100.0*(vres-1-ypos)/vres;
398 >                if (ralrm > 0 && time((long *)0) >= tlastrept+ralrm)
399 >                        report();
400 > #ifndef  BSD
401 >                else
402 >                        signal(SIGCONT, report);
403 > #endif
404          }
405 <                
405 >                                                /* clean up */
406 >        signal(SIGCONT, SIG_IGN);
407 >        if (zfd != -1) {
408 >                if (write(zfd, (char *)zbar[0], hres*sizeof(float))
409 >                                < hres*sizeof(float))
410 >                        goto writerr;
411 >                if (close(zfd) == -1)
412 >                        goto writerr;
413 >                for (i = 0; i <= psample; i++)
414 >                        free((char *)zbar[i]);
415 >        }
416 >        fwritescan(scanbar[0], hres, stdout);
417 >        if (fflush(stdout) == EOF)
418 >                goto writerr;
419          for (i = 0; i <= psample; i++)
420                  free((char *)scanbar[i]);
421 +        if (sampdens != NULL)
422 +                free(sampdens);
423 +        pctdone = 100.0;
424 +        if (ralrm > 0)
425 +                report();
426 +        signal(SIGCONT, SIG_DFL);
427          return;
428   writerr:
429          error(SYSTEM, "write error in render");
430 + memerr:
431 +        error(SYSTEM, "out of memory in render");
432   }
433  
434  
435 < fillscanline(scanline, y, xstep)                /* fill scan line at y */
436 < register COLOR  *scanline;
437 < int  y, xstep;
435 > fillscanline(scanline, zline, sd, xres, y, xstep)       /* fill scan at y */
436 > register COLOR  *scanline;
437 > register float  *zline;
438 > register char  *sd;
439 > int  xres, y, xstep;
440   {
441 <        int  b = xstep;
441 >        static int  nc = 0;             /* number of calls */
442 >        int  bl = xstep, b = xstep;
443 >        double  z;
444          register int  i;
445          
446 <        pixvalue(scanline[0], 0, y);
447 <
448 <        for (i = xstep; i <= ourview.hresolu; i += xstep) {
449 <        
450 <                pixvalue(scanline[i], i, y);
451 <                
452 <                b = fillsample(scanline+i-xstep, i-xstep, y, xstep, 0, b/2);
446 >        z = pixvalue(scanline[0], 0, y);
447 >        if (zline) zline[0] = z;
448 >                                /* zig-zag start for quincunx pattern */
449 >        for (i = ++nc & 1 ? xstep : xstep/2; i < xres-1+xstep; i += xstep) {
450 >                if (i >= xres) {
451 >                        xstep += xres-1-i;
452 >                        i = xres-1;
453 >                }
454 >                z = pixvalue(scanline[i], i, y);
455 >                if (zline) zline[i] = z;
456 >                if (sd) b = sd[0] > sd[1] ? sd[0] : sd[1];
457 >                if (i <= xstep)
458 >                        b = fillsample(scanline, zline, 0, y, i, 0, b/2);
459 >                else
460 >                        b = fillsample(scanline+i-xstep,
461 >                                        zline ? zline+i-xstep : NULL,
462 >                                        i-xstep, y, xstep, 0, b/2);
463 >                if (sd) *sd++ = nc & 1 ? bl : b;
464 >                bl = b;
465          }
466 +        if (sd && nc & 1) *sd = bl;
467   }
468  
469  
470 < fillscanbar(scanbar, y, ysize)          /* fill interior */
471 < register COLOR  *scanbar[];
472 < int  y, ysize;
470 > fillscanbar(scanbar, zbar, xres, y, ysize)      /* fill interior */
471 > register COLOR  *scanbar[];
472 > register float  *zbar[];
473 > int  xres, y, ysize;
474   {
475          COLOR  vline[MAXDIV+1];
476 +        float  zline[MAXDIV+1];
477          int  b = ysize;
478          register int  i, j;
479          
480 <        for (i = 0; i < ourview.hresolu; i++) {
480 >        for (i = 0; i < xres; i++) {
481                  
482                  copycolor(vline[0], scanbar[0][i]);
483                  copycolor(vline[ysize], scanbar[ysize][i]);
484 +                if (zbar[0]) {
485 +                        zline[0] = zbar[0][i];
486 +                        zline[ysize] = zbar[ysize][i];
487 +                }
488                  
489 <                b = fillsample(vline, i, y, 0, ysize, b/2);
489 >                b = fillsample(vline, zbar[0] ? zline : NULL,
490 >                                i, y, 0, ysize, b/2);
491                  
492                  for (j = 1; j < ysize; j++)
493                          copycolor(scanbar[j][i], vline[j]);
494 +                if (zbar[0])
495 +                        for (j = 1; j < ysize; j++)
496 +                                zbar[j][i] = zline[j];
497          }
498   }
499  
500  
501   int
502 < fillsample(colline, x, y, xlen, ylen, b)        /* fill interior points */
503 < register COLOR  *colline;
502 > fillsample(colline, zline, x, y, xlen, ylen, b) /* fill interior points */
503 > register COLOR  *colline;
504 > register float  *zline;
505   int  x, y;
506   int  xlen, ylen;
507   int  b;
508   {
509 <        double  ratio;
509 >        double  ratio;
510 >        double  z;
511          COLOR  ctmp;
512          int  ncut;
513          register int  len;
# Line 201 | Line 520 | int  b;
520          if (len <= 1)                   /* limit recursion */
521                  return(0);
522          
523 <        if (b > 0 || bigdiff(colline[0], colline[len], maxdiff)) {
523 >        if (b > 0
524 >        || (zline && 2.*fabs(zline[0]-zline[len]) > maxdiff*(zline[0]+zline[len]))
525 >                        || bigdiff(colline[0], colline[len], maxdiff)) {
526          
527 <                pixvalue(colline[len>>1], x + (xlen>>1), y + (ylen>>1));
527 >                z = pixvalue(colline[len>>1], x + (xlen>>1), y + (ylen>>1));
528 >                if (zline) zline[len>>1] = z;
529                  ncut = 1;
530                  
531          } else {                                        /* interpolate */
# Line 211 | Line 533 | int  b;
533                  copycolor(colline[len>>1], colline[len]);
534                  ratio = (double)(len>>1) / len;
535                  scalecolor(colline[len>>1], ratio);
536 <                copycolor(ctmp, colline[0]);
536 >                if (zline) zline[len>>1] = zline[len] * ratio;
537                  ratio = 1.0 - ratio;
538 +                copycolor(ctmp, colline[0]);
539                  scalecolor(ctmp, ratio);
540                  addcolor(colline[len>>1], ctmp);
541 +                if (zline) zline[len>>1] += zline[0] * ratio;
542                  ncut = 0;
543          }
544                                                          /* recurse */
545 <        ncut += fillsample(colline, x, y, xlen>>1, ylen>>1, (b-1)/2);
545 >        ncut += fillsample(colline, zline, x, y, xlen>>1, ylen>>1, (b-1)/2);
546          
547 <        ncut += fillsample(colline + (len>>1), x + (xlen>>1), y + (ylen>>1),
548 <                                xlen - (xlen>>1), ylen - (ylen>>1), b/2);
547 >        ncut += fillsample(colline+(len>>1), zline ? zline+(len>>1) : NULL,
548 >                        x+(xlen>>1), y+(ylen>>1),
549 >                        xlen-(xlen>>1), ylen-(ylen>>1), b/2);
550  
551          return(ncut);
552   }
553  
554  
555 + double
556   pixvalue(col, x, y)             /* compute pixel value */
557   COLOR  col;                     /* returned color */
558   int  x, y;                      /* pixel position */
559   {
560 <        static RAY  thisray;    /* our ray for this pixel */
560 >        static RAY  thisray;
561  
562 <        rayview(thisray.rorg, thisray.rdir, &ourview,
563 <                        x + pixjitter(), y + pixjitter());
562 >        if (viewray(thisray.rorg, thisray.rdir, &ourview,
563 >                        (x+pixjitter())/hres, (y+pixjitter())/vres) < 0) {
564 >                setcolor(col, 0.0, 0.0, 0.0);
565 >                return(0.0);
566 >        }
567  
568          rayorigin(&thisray, NULL, PRIMARY, 1.0);
569 <        
569 >
570 >        samplendx = pixnumber(x,y,hres,vres);   /* set pixel index */
571 >
572          rayvalue(&thisray);                     /* trace ray */
573  
574          copycolor(col, thisray.rcol);           /* return color */
575 +        
576 +        return(thisray.rt);                     /* return distance */
577   }
578  
579  
# Line 254 | Line 587 | char  *oldfile;
587  
588          if (oldfile == NULL)
589                  return(0);
590 <        else if ((fp = fopen(oldfile, "r")) == NULL) {
590 >        
591 >        if ((fp = fopen(oldfile, "r")) == NULL) {
592                  sprintf(errmsg, "cannot open recover file \"%s\"", oldfile);
593                  error(WARNING, errmsg);
594                  return(0);
595          }
596 + #ifdef MSDOS
597 +        setmode(fileno(fp), O_BINARY);
598 + #endif
599                                  /* discard header */
600 <        getheader(fp, NULL);
600 >        getheader(fp, NULL, NULL);
601                                  /* get picture size */
602 <        if (fscanf(fp, "-Y %d +X %d\n", &y, &x) != 2) {
602 >        if (!fscnresolu(&x, &y, fp)) {
603                  sprintf(errmsg, "bad recover file \"%s\"", oldfile);
604                  error(WARNING, errmsg);
605                  fclose(fp);
606                  return(0);
607          }
608  
609 <        if (x != ourview.hresolu || y != ourview.vresolu) {
609 >        if (x != hres || y != vres) {
610                  sprintf(errmsg, "resolution mismatch in recover file \"%s\"",
611                                  oldfile);
612                  error(USER, errmsg);
276                return(0);
613          }
614  
615 <        scanline = (COLR *)malloc(ourview.hresolu*sizeof(COLR));
615 >        scanline = (COLR *)malloc(hres*sizeof(COLR));
616          if (scanline == NULL)
617                  error(SYSTEM, "out of memory in salvage");
618 <        for (y = 0; y < ourview.vresolu; y++) {
619 <                if (freadcolrs(scanline, ourview.hresolu, fp) < 0)
618 >        for (y = 0; y < vres; y++) {
619 >                if (freadcolrs(scanline, hres, fp) < 0)
620                          break;
621 <                if (fwritecolrs(scanline, ourview.hresolu, stdout) < 0)
621 >                if (fwritecolrs(scanline, hres, stdout) < 0)
622                          goto writerr;
623          }
624          if (fflush(stdout) == EOF)
# Line 292 | Line 628 | char  *oldfile;
628          unlink(oldfile);
629          return(y);
630   writerr:
631 <        error(SYSTEM, "write error in salvage");
631 >        sprintf(errmsg, "write error during recovery of \"%s\"", oldfile);
632 >        error(SYSTEM, errmsg);
633 > }
634 >
635 >
636 > int
637 > pixnumber(x, y, xres, yres)             /* compute pixel index (brushed) */
638 > register int  x, y;
639 > int  xres, yres;
640 > {
641 >        x -= y;
642 >        while (x < 0)
643 >                x += xres;
644 >        return((((x>>2)*yres + y) << 2) + (x & 3));
645   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines