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.10 by greg, Tue Oct 3 12:17:09 1989 UTC vs.
Revision 2.16 by greg, Tue Oct 6 12:30:07 1992 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 + int  dimlist[MAXDIM];                   /* sampling dimensions */
31 + int  ndims = 0;                         /* number of sampling dimensions */
32 + int  samplendx;                         /* sample index number */
33 +
34 + VIEW  ourview = STDVIEW;                /* view parameters */
35 + int  hresolu = 512;                     /* horizontal resolution */
36 + int  vresolu = 512;                     /* vertical resolution */
37 + double  pixaspect = 1.0;                /* pixel aspect ratio */
38 +
39   int  psample = 4;                       /* pixel sample size */
40 < double  maxdiff = .05;                  /* max. difference for interpolation */
41 < double  dstrpix = 0.67;                 /* square pixel distribution */
40 > double  maxdiff = .05;                  /* max. difference for interpolation */
41 > double  dstrpix = 0.67;                 /* square pixel distribution */
42  
43 < double  dstrsrc = 0.0;                  /* square source distribution */
44 < double  shadthresh = .05;               /* shadow threshold */
45 < double  shadcert = .5;                  /* shadow certainty */
43 > double  dstrsrc = 0.0;                  /* square source distribution */
44 > double  shadthresh = .05;               /* shadow threshold */
45 > double  shadcert = .5;                  /* shadow certainty */
46 > int  directrelay = 1;                   /* number of source relays */
47 > int  vspretest = 512;                   /* virtual source pretest density */
48 > int  directinvis = 0;                   /* sources invisible? */
49 > double  srcsizerat = .25;               /* maximum ratio source size/dist. */
50  
51 + double  specthresh = .15;               /* specular sampling threshold */
52 + double  specjitter = 1.;                /* specular sampling jitter */
53 +
54   int  maxdepth = 6;                      /* maximum recursion depth */
55 < double  minweight = 5e-3;               /* minimum ray weight */
55 > double  minweight = 5e-3;               /* minimum ray weight */
56  
57   COLOR  ambval = BLKCOLOR;               /* ambient value */
58 < double  ambacc = 0.2;                   /* ambient accuracy */
58 > double  ambacc = 0.2;                   /* ambient accuracy */
59   int  ambres = 32;                       /* ambient resolution */
60   int  ambdiv = 128;                      /* ambient divisions */
61   int  ambssamp = 0;                      /* ambient super-samples */
# Line 43 | Line 63 | int  ambounce = 0;                     /* ambient bounces */
63   char  *amblist[128];                    /* ambient include/exclude list */
64   int  ambincl = -1;                      /* include == 1, exclude == 0 */
65  
66 + #ifdef MSDOS
67 + int  ralrm = 60;                        /* seconds between reports */
68 + #else
69   int  ralrm = 0;                         /* seconds between reports */
70 + #endif
71  
72 < double  pctdone = 0.0;                  /* percentage done */
72 > double  pctdone = 0.0;                  /* percentage done */
73  
74 + long  tlastrept = 0L;                   /* time at last report */
75 +
76 + extern long  time();
77 + extern long  tstart;                    /* starting time */
78 +
79   extern long  nrays;                     /* number of rays traced */
80  
81 < #define  MAXDIV         32              /* maximum sample size */
81 > #define  MAXDIV         16              /* maximum sample size */
82  
83 < #define  pixjitter()    (.5+dstrpix*(.5-frandom()))
83 > #define  pixjitter()    (.5+dstrpix*(.5-frandom()))
84  
85 + #define  RFTEMPLATE     "rfXXXXXX"
86 + #define  HFTEMPLATE     TEMPLATE
87  
88 + static char  *hfname = NULL;            /* header file name */
89 + static FILE  *hfp = NULL;               /* header file pointer */
90 +
91 + static int  hres, vres;                 /* resolution for this frame */
92 +
93 + extern char  *mktemp();
94 +
95 + double  pixvalue();
96 +
97 +
98   quit(code)                      /* quit program */
99   int  code;
100   {
101 <        if (code || ralrm > 0)          /* report status */
101 >        if (code)                       /* report status */
102                  report();
103 <
103 >        if (hfname != NULL) {           /* delete header file */
104 >                if (hfp != NULL)
105 >                        fclose(hfp);
106 >                unlink(hfname);
107 >        }
108          exit(code);
109   }
110  
111  
112 + #ifdef BSD
113   report()                /* report progress */
114   {
69 #ifdef BSD
115          struct rusage  rubuf;
116 <        double  t;
116 >        double  t;
117  
118          getrusage(RUSAGE_SELF, &rubuf);
119          t = (rubuf.ru_utime.tv_usec + rubuf.ru_stime.tv_usec) / 1e6;
# Line 79 | Line 124 | report()               /* report progress */
124  
125          sprintf(errmsg, "%ld rays, %4.2f%% done after %5.4f CPU hours\n",
126                          nrays, pctdone, t/3600.0);
127 +        eputs(errmsg);
128 +        tlastrept = time((long *)0);
129 + }
130   #else
131 <        sprintf(errmsg, "%ld rays, %4.2f%% done\n", nrays, pctdone);
132 < #endif
131 > report()                /* report progress */
132 > {
133 >        tlastrept = time((long *)0);
134 >        sprintf(errmsg, "%ld rays, %4.2f%% done after %5.4f hours\n",
135 >                        nrays, pctdone, (tlastrept-tstart)/3600.0);
136          eputs(errmsg);
137 +        signal(SIGALRM, report);
138 + }
139 + #endif
140  
141 <        if (ralrm > 0)
142 <                alarm(ralrm);
141 >
142 > openheader()                    /* save standard output to header file */
143 > {
144 >        hfname = mktemp(HFTEMPLATE);
145 >        if (freopen(hfname, "w", stdout) == NULL) {
146 >                sprintf(errmsg, "cannot open header file \"%s\"", hfname);
147 >                error(SYSTEM, errmsg);
148 >        }
149   }
150  
151  
152 < render(oldfile)                         /* render the scene */
93 < char  *oldfile;
152 > closeheader()                   /* done with header output */
153   {
154 <        COLOR  *scanbar[MAXDIV+1];      /* scanline arrays of pixel values */
155 <        int  ypos;                      /* current scanline */
156 <        COLOR  *colptr;
157 <        register int  i;
154 >        if (hfname == NULL)
155 >                return;
156 >        if (fflush(stdout) == EOF || (hfp = fopen(hfname, "r")) == NULL)
157 >                error(SYSTEM, "error reopening header file");
158 > }
159 >
160 >
161 > dupheader()                     /* repeat header on standard output */
162 > {
163 >        register int  c;
164 >
165 >        if (fseek(hfp, 0L, 0) < 0)
166 >                error(SYSTEM, "seek error on header file");
167 >        while ((c = getc(hfp)) != EOF)
168 >                putchar(c);
169 > }
170 >
171 >
172 > rpict(seq, pout, zout, prvr)                    /* generate image(s) */
173 > int  seq;
174 > char  *pout, *zout, *prvr;
175 > /*
176 > * If seq is greater than zero, then we will render a sequence of
177 > * images based on view parameter strings read from the standard input.
178 > * If pout is NULL, then all images will be sent to the standard ouput.
179 > * If seq is greater than zero and prvr is an integer, then it is the
180 > * frame number at which rendering should begin.  Preceeding view parameter
181 > * strings will be skipped in the input.
182 > * If pout and prvr are the same, prvr is renamed to avoid overwriting.
183 > * Note that pout and zout should contain %d format specifications for
184 > * sequenced file naming.
185 > */
186 > {
187 >        extern char  *rindex(), *strncpy(), *strcat();
188 >        char  fbuf[128], fbuf2[128];
189 >        register char  *cp;
190 >        RESOLU  rs;
191 >        double  pa;
192 >                                        /* finished writing header */
193 >        closeheader();
194                                          /* check sampling */
195          if (psample < 1)
196                  psample = 1;
197 <        else if (psample > MAXDIV)
197 >        else if (psample > MAXDIV) {
198 >                sprintf(errmsg, "pixel sampling reduced from %d to %d",
199 >                                psample, MAXDIV);
200 >                error(WARNING, errmsg);
201                  psample = MAXDIV;
202 +        }
203 +                                        /* get starting frame */
204 +        if (seq <= 0)
205 +                seq = 0;
206 +        else if (prvr != NULL && isint(prvr)) {
207 +                register int  rn;               /* skip to specified view */
208 +                if ((rn = atoi(prvr)) < seq)
209 +                        error(USER, "recover frame less than start frame");
210 +                if (pout == NULL)
211 +                        error(USER, "missing output file specification");
212 +                for ( ; seq < rn; seq++)
213 +                        if (nextview(stdin) == EOF)
214 +                                error(USER, "unexpected EOF on view input");
215 +                prvr = fbuf;                    /* mark for renaming */
216 +        }
217 +        if (pout != NULL) {
218 +                sprintf(fbuf, pout, seq);
219 +                if (prvr != NULL && !strcmp(prvr, fbuf)) {      /* rename */
220 +                        fbuf2[0] = '\0';
221 +                        if ((cp = rindex(fbuf, '/')) != NULL)
222 +                                strncpy(fbuf2, fbuf, cp-fbuf+1);
223 +                        strcat(fbuf2, RFTEMPLATE);
224 +                        prvr = mktemp(fbuf2);
225 +                        if (rename(fbuf, prvr) < 0 && errno != ENOENT) {
226 +                                sprintf(errmsg,
227 +                                        "cannot rename \"%s\" to \"%s\"",
228 +                                                fbuf, prvr);
229 +                                error(SYSTEM, errmsg);
230 +                        }
231 +                }
232 +        }
233 +                                        /* render sequence */
234 +        do {
235 +                if (seq && nextview(stdin) == EOF)
236 +                        break;
237 +                if (pout != NULL) {
238 +                        sprintf(fbuf, pout, seq);
239 +                        if (freopen(fbuf, "w", stdout) == NULL) {
240 +                                sprintf(errmsg,
241 +                                        "cannot open output file \"%s\"", fbuf);
242 +                                error(SYSTEM, errmsg);
243 +                        }
244 +                        dupheader();
245 +                }
246 +                hres = hresolu; vres = vresolu; pa = pixaspect;
247 +                if (prvr != NULL)
248 +                        if (viewfile(prvr, &ourview, &rs) <= 0
249 +                                        || rs.or != PIXSTANDARD) {
250 +                                sprintf(errmsg,
251 +                        "cannot recover view parameters from \"%s\"", prvr);
252 +                                error(WARNING, errmsg);
253 +                        } else {
254 +                                pa = 0.0;
255 +                                hres = scanlen(&rs);
256 +                                vres = numscans(&rs);
257 +                        }
258 +                if ((cp = setview(&ourview)) != NULL)
259 +                        error(USER, cp);
260 +                normaspect(viewaspect(&ourview), &pa, &hres, &vres);
261 +                if (seq) {
262 +                        if (ralrm > 0) {
263 +                                fprintf(stderr, "FRAME %d:", seq);
264 +                                fprintview(&ourview, stderr);
265 +                                putc('\n', stderr);
266 +                                fflush(stderr);
267 +                        }
268 +                        printf("FRAME=%d\n", seq);
269 +                }
270 +                fputs(VIEWSTR, stdout);
271 +                fprintview(&ourview, stdout);
272 +                putchar('\n');
273 +                if (pa < .99 || pa > 1.01)
274 +                        fputaspect(pa, stdout);
275 +                fputformat(COLRFMT, stdout);
276 +                putchar('\n');
277 +                if (zout != NULL)
278 +                        sprintf(cp=fbuf, zout, seq);
279 +                else
280 +                        cp = NULL;
281 +                render(cp, prvr);
282 +                prvr = NULL;
283 +        } while (seq++);
284 + }
285 +
286 +
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                                          /* allocate scanlines */
314          for (i = 0; i <= psample; i++) {
315 <                scanbar[i] = (COLOR *)malloc(ourview.hresolu*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 +        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 +                for (i = 0; i <= psample; i++) {
336 +                        zbar[i] = (float *)malloc(hres*sizeof(float));
337 +                        if (zbar[i] == NULL)
338 +                                goto memerr;
339 +                }
340 +        } else {
341 +                zfd = -1;
342 +                for (i = 0; i <= psample; i++)
343 +                        zbar[i] = NULL;
344 +        }
345                                          /* write out boundaries */
346 <        fputresolu(YMAJOR|YDECR, ourview.hresolu, ourview.vresolu, stdout);
346 >        fprtresolu(hres, vres, stdout);
347                                          /* recover file and compute first */
348 <        ypos = ourview.vresolu-1 - salvage(oldfile);
349 <        fillscanline(scanbar[0], ourview.hresolu, ypos, psample);
348 >        i = salvage(oldfile);
349 >        if (zfd != -1 && i > 0 &&
350 >                        lseek(zfd, (long)i*hres*sizeof(float), 0) == -1)
351 >                error(SYSTEM, "z file seek error in render");
352 >        pctdone = 100.0*i/vres;
353 >        if (ralrm > 0)                  /* report init stats */
354 >                report();
355 > #ifndef  BSD
356 >        else
357 > #endif
358 >        signal(SIGALRM, report);
359 >        ypos = vres-1 - i;
360 >        fillscanline(scanbar[0], zbar[0], sampdens, hres, ypos, hstep);
361                                                  /* compute scanlines */
362 <        for (ypos -= psample; ypos >= 0; ypos -= psample) {
363 <        
364 <                pctdone = 100.0*(ourview.vresolu-ypos-psample)/ourview.vresolu;
365 <
366 <                colptr = scanbar[psample];              /* move base to top */
367 <                scanbar[psample] = scanbar[0];
362 >        for (ypos -= ystep; ypos > -ystep; ypos -= ystep) {
363 >                                                        /* bottom adjust? */
364 >                if (ypos < 0) {
365 >                        ystep += ypos;
366 >                        ypos = 0;
367 >                }
368 >                colptr = scanbar[ystep];                /* move base to top */
369 >                scanbar[ystep] = scanbar[0];
370                  scanbar[0] = colptr;
371 +                zptr = zbar[ystep];
372 +                zbar[ystep] = zbar[0];
373 +                zbar[0] = zptr;
374                                                          /* fill base line */
375 <                fillscanline(scanbar[0], ourview.hresolu, ypos, psample);
375 >                fillscanline(scanbar[0], zbar[0], sampdens,
376 >                                hres, ypos, hstep);
377                                                          /* fill bar */
378 <                fillscanbar(scanbar, ourview.hresolu, ypos, psample);
378 >                fillscanbar(scanbar, zbar, hres, ypos, ystep);
379                                                          /* write it out */
380 <                for (i = psample; i > 0; i--)
381 <                        if (fwritescan(scanbar[i], ourview.hresolu, stdout) < 0)
380 > #ifndef  BSD
381 >                signal(SIGALRM, SIG_IGN);       /* don't interrupt writes */
382 > #endif
383 >                for (i = ystep; i > 0; i--) {
384 >                        if (zfd != -1 && write(zfd, (char *)zbar[i],
385 >                                        hres*sizeof(float))
386 >                                        < hres*sizeof(float))
387                                  goto writerr;
388 +                        if (fwritescan(scanbar[i], hres, stdout) < 0)
389 +                                goto writerr;
390 +                }
391                  if (fflush(stdout) == EOF)
392                          goto writerr;
393 +                                                        /* record progress */
394 +                pctdone = 100.0*(vres-1-ypos)/vres;
395 +                if (ralrm > 0 && time((long *)0) >= tlastrept+ralrm)
396 +                        report();
397 + #ifndef  BSD
398 +                else
399 +                        signal(SIGALRM, report);
400 + #endif
401          }
402 <                                                /* compute residual */
403 <        colptr = scanbar[psample];
404 <        scanbar[psample] = scanbar[0];
405 <        scanbar[0] = colptr;
406 <        if (ypos > -psample) {
139 <                fillscanline(scanbar[-ypos], ourview.hresolu,
140 <                                0, psample);
141 <                fillscanbar(scanbar-ypos, ourview.hresolu,
142 <                                0, psample+ypos);
143 <        }
144 <        for (i = psample; i+ypos >= 0; i--)
145 <                if (fwritescan(scanbar[i], ourview.hresolu, stdout) < 0)
402 >                                                /* clean up */
403 >        signal(SIGALRM, SIG_IGN);
404 >        if (zfd != -1) {
405 >                if (write(zfd, (char *)zbar[0], hres*sizeof(float))
406 >                                < hres*sizeof(float))
407                          goto writerr;
408 +                if (close(zfd) == -1)
409 +                        goto writerr;
410 +                for (i = 0; i <= psample; i++)
411 +                        free((char *)zbar[i]);
412 +        }
413 +        fwritescan(scanbar[0], hres, stdout);
414          if (fflush(stdout) == EOF)
415                  goto writerr;
149        pctdone = 100.0;
150                                                /* free scanlines */
416          for (i = 0; i <= psample; i++)
417                  free((char *)scanbar[i]);
418 +        if (sampdens != NULL)
419 +                free(sampdens);
420 +        pctdone = 100.0;
421 +        if (ralrm > 0)
422 +                report();
423          return;
424   writerr:
425          error(SYSTEM, "write error in render");
426 + memerr:
427 +        error(SYSTEM, "out of memory in render");
428   }
429  
430  
431 < fillscanline(scanline, xres, y, xstep)          /* fill scan line at y */
432 < register COLOR  *scanline;
431 > fillscanline(scanline, zline, sd, xres, y, xstep)       /* fill scan at y */
432 > register COLOR  *scanline;
433 > register float  *zline;
434 > register char  *sd;
435   int  xres, y, xstep;
436   {
437 <        int  b = xstep;
437 >        static int  nc = 0;             /* number of calls */
438 >        int  bl = xstep, b = xstep;
439 >        double  z;
440          register int  i;
441          
442 <        pixvalue(scanline[0], 0, y);
443 <
444 <        for (i = xstep; i < xres; i += xstep) {
445 <        
446 <                pixvalue(scanline[i], i, y);
447 <                
448 <                b = fillsample(scanline+i-xstep, i-xstep, y, xstep, 0, b/2);
442 >        z = pixvalue(scanline[0], 0, y);
443 >        if (zline) zline[0] = z;
444 >                                /* zig-zag start for quincunx pattern */
445 >        for (i = ++nc & 1 ? xstep : xstep/2; i < xres-1+xstep; i += xstep) {
446 >                if (i >= xres) {
447 >                        xstep += xres-1-i;
448 >                        i = xres-1;
449 >                }
450 >                z = pixvalue(scanline[i], i, y);
451 >                if (zline) zline[i] = z;
452 >                if (sd) b = sd[0] > sd[1] ? sd[0] : sd[1];
453 >                if (i <= xstep)
454 >                        b = fillsample(scanline, zline, 0, y, i, 0, b/2);
455 >                else
456 >                        b = fillsample(scanline+i-xstep,
457 >                                        zline ? zline+i-xstep : NULL,
458 >                                        i-xstep, y, xstep, 0, b/2);
459 >                if (sd) *sd++ = nc & 1 ? bl : b;
460 >                bl = b;
461          }
462 <        if (i-xstep < xres-1) {
175 <                pixvalue(scanline[xres-1], xres-1, y);
176 <                fillsample(scanline+i-xstep, i-xstep, y,
177 <                                xres-1-(i-xstep), 0, b/2);
178 <        }
462 >        if (sd && nc & 1) *sd = bl;
463   }
464  
465  
466 < fillscanbar(scanbar, xres, y, ysize)            /* fill interior */
467 < register COLOR  *scanbar[];
466 > fillscanbar(scanbar, zbar, xres, y, ysize)      /* fill interior */
467 > register COLOR  *scanbar[];
468 > register float  *zbar[];
469   int  xres, y, ysize;
470   {
471          COLOR  vline[MAXDIV+1];
472 +        float  zline[MAXDIV+1];
473          int  b = ysize;
474          register int  i, j;
475          
# Line 191 | Line 477 | int  xres, y, ysize;
477                  
478                  copycolor(vline[0], scanbar[0][i]);
479                  copycolor(vline[ysize], scanbar[ysize][i]);
480 +                if (zbar[0]) {
481 +                        zline[0] = zbar[0][i];
482 +                        zline[ysize] = zbar[ysize][i];
483 +                }
484                  
485 <                b = fillsample(vline, i, y, 0, ysize, b/2);
485 >                b = fillsample(vline, zbar[0] ? zline : NULL,
486 >                                i, y, 0, ysize, b/2);
487                  
488                  for (j = 1; j < ysize; j++)
489                          copycolor(scanbar[j][i], vline[j]);
490 +                if (zbar[0])
491 +                        for (j = 1; j < ysize; j++)
492 +                                zbar[j][i] = zline[j];
493          }
494   }
495  
496  
497   int
498 < fillsample(colline, x, y, xlen, ylen, b)        /* fill interior points */
499 < register COLOR  *colline;
498 > fillsample(colline, zline, x, y, xlen, ylen, b) /* fill interior points */
499 > register COLOR  *colline;
500 > register float  *zline;
501   int  x, y;
502   int  xlen, ylen;
503   int  b;
504   {
505 <        double  ratio;
505 >        double  ratio;
506 >        double  z;
507          COLOR  ctmp;
508          int  ncut;
509          register int  len;
# Line 220 | Line 516 | int  b;
516          if (len <= 1)                   /* limit recursion */
517                  return(0);
518          
519 <        if (b > 0 || bigdiff(colline[0], colline[len], maxdiff)) {
519 >        if (b > 0
520 >        || (zline && 2.*fabs(zline[0]-zline[len]) > maxdiff*(zline[0]+zline[len]))
521 >                        || bigdiff(colline[0], colline[len], maxdiff)) {
522          
523 <                pixvalue(colline[len>>1], x + (xlen>>1), y + (ylen>>1));
523 >                z = pixvalue(colline[len>>1], x + (xlen>>1), y + (ylen>>1));
524 >                if (zline) zline[len>>1] = z;
525                  ncut = 1;
526                  
527          } else {                                        /* interpolate */
# Line 230 | Line 529 | int  b;
529                  copycolor(colline[len>>1], colline[len]);
530                  ratio = (double)(len>>1) / len;
531                  scalecolor(colline[len>>1], ratio);
532 <                copycolor(ctmp, colline[0]);
532 >                if (zline) zline[len>>1] = zline[len] * ratio;
533                  ratio = 1.0 - ratio;
534 +                copycolor(ctmp, colline[0]);
535                  scalecolor(ctmp, ratio);
536                  addcolor(colline[len>>1], ctmp);
537 +                if (zline) zline[len>>1] += zline[0] * ratio;
538                  ncut = 0;
539          }
540                                                          /* recurse */
541 <        ncut += fillsample(colline, x, y, xlen>>1, ylen>>1, (b-1)/2);
541 >        ncut += fillsample(colline, zline, x, y, xlen>>1, ylen>>1, (b-1)/2);
542          
543 <        ncut += fillsample(colline + (len>>1), x + (xlen>>1), y + (ylen>>1),
544 <                                xlen - (xlen>>1), ylen - (ylen>>1), b/2);
543 >        ncut += fillsample(colline+(len>>1), zline ? zline+(len>>1) : NULL,
544 >                        x+(xlen>>1), y+(ylen>>1),
545 >                        xlen-(xlen>>1), ylen-(ylen>>1), b/2);
546  
547          return(ncut);
548   }
549  
550  
551 + double
552   pixvalue(col, x, y)             /* compute pixel value */
553   COLOR  col;                     /* returned color */
554   int  x, y;                      /* pixel position */
555   {
556 <        static RAY  thisray;    /* our ray for this pixel */
556 >        static RAY  thisray;
557  
558 <        rayview(thisray.rorg, thisray.rdir, &ourview,
559 <                        x + pixjitter(), y + pixjitter());
558 >        if (viewray(thisray.rorg, thisray.rdir, &ourview,
559 >                        (x+pixjitter())/hres, (y+pixjitter())/vres) < 0) {
560 >                setcolor(col, 0.0, 0.0, 0.0);
561 >                return(0.0);
562 >        }
563  
564          rayorigin(&thisray, NULL, PRIMARY, 1.0);
565 <        
565 >
566 >        samplendx = pixnumber(x,y,hres,vres);   /* set pixel index */
567 >
568          rayvalue(&thisray);                     /* trace ray */
569  
570          copycolor(col, thisray.rcol);           /* return color */
571 +        
572 +        return(thisray.rt);                     /* return distance */
573   }
574  
575  
# Line 282 | Line 592 | char  *oldfile;
592                                  /* discard header */
593          getheader(fp, NULL);
594                                  /* get picture size */
595 <        if (fgetresolu(&x, &y, fp) != (YMAJOR|YDECR)) {
595 >        if (!fscnresolu(&x, &y, fp)) {
596                  sprintf(errmsg, "bad recover file \"%s\"", oldfile);
597                  error(WARNING, errmsg);
598                  fclose(fp);
599                  return(0);
600          }
601  
602 <        if (x != ourview.hresolu || y != ourview.vresolu) {
602 >        if (x != hres || y != vres) {
603                  sprintf(errmsg, "resolution mismatch in recover file \"%s\"",
604                                  oldfile);
605                  error(USER, errmsg);
606          }
607  
608 <        scanline = (COLR *)malloc(ourview.hresolu*sizeof(COLR));
608 >        scanline = (COLR *)malloc(hres*sizeof(COLR));
609          if (scanline == NULL)
610                  error(SYSTEM, "out of memory in salvage");
611 <        for (y = 0; y < ourview.vresolu; y++) {
612 <                if (freadcolrs(scanline, ourview.hresolu, fp) < 0)
611 >        for (y = 0; y < vres; y++) {
612 >                if (freadcolrs(scanline, hres, fp) < 0)
613                          break;
614 <                if (fwritecolrs(scanline, ourview.hresolu, stdout) < 0)
614 >                if (fwritecolrs(scanline, hres, stdout) < 0)
615                          goto writerr;
616          }
617          if (fflush(stdout) == EOF)
# Line 311 | Line 621 | char  *oldfile;
621          unlink(oldfile);
622          return(y);
623   writerr:
624 <        error(SYSTEM, "write error in salvage");
624 >        sprintf(errmsg, "write error during recovery of \"%s\"", oldfile);
625 >        error(SYSTEM, errmsg);
626 > }
627 >
628 >
629 > int
630 > pixnumber(x, y, xres, yres)             /* compute pixel index (brushed) */
631 > register int  x, y;
632 > int  xres, yres;
633 > {
634 >        x -= y;
635 >        while (x < 0)
636 >                x += xres;
637 >        return((((x>>2)*yres + y) << 2) + (x & 3));
638   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines