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.14 by greg, Thu Jan 11 08:30:42 1990 UTC vs.
Revision 2.17 by greg, Thu Oct 15 21:13:17 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 15 | Line 15 | 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 +
22   #include  "view.h"
23  
24 + #include  "resolu.h"
25 +
26   #include  "random.h"
27  
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 */
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 48 | 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 < double  pixvalue();
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   {
76 #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 86 | 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 + 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 <        sprintf(errmsg, "%ld rays, %4.2f%% done\n", nrays, pctdone);
138 > }
139   #endif
93        eputs(errmsg);
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 + closeheader()                   /* done with header output */
153 + {
154 +        if (hfname == NULL)
155 +                return;
156 +        if (fflush(stdout) == EOF || (hfp = fopen(hfname, "r")) == NULL)
157 +                error(SYSTEM, "error reopening header file");
158 + #ifdef MSDOS
159 +        setmode(fileno(hfp), O_BINARY);
160 + #endif
161 + }
162 +
163 +
164 + dupheader()                     /* repeat header on standard output */
165 + {
166 +        register int  c;
167 +
168 +        if (fseek(hfp, 0L, 0) < 0)
169 +                error(SYSTEM, "seek error on header file");
170 +        while ((c = getc(hfp)) != EOF)
171 +                putchar(c);
172 + }
173 +
174 +
175 + rpict(seq, pout, zout, prvr)                    /* generate image(s) */
176 + int  seq;
177 + char  *pout, *zout, *prvr;
178 + /*
179 + * If seq is greater than zero, then we will render a sequence of
180 + * images based on view parameter strings read from the standard input.
181 + * If pout is NULL, then all images will be sent to the standard ouput.
182 + * If seq is greater than zero and prvr is an integer, then it is the
183 + * frame number at which rendering should begin.  Preceeding view parameter
184 + * strings will be skipped in the input.
185 + * If pout and prvr are the same, prvr is renamed to avoid overwriting.
186 + * Note that pout and zout should contain %d format specifications for
187 + * sequenced file naming.
188 + */
189 + {
190 +        extern char  *rindex(), *strncpy(), *strcat();
191 +        char  fbuf[128], fbuf2[128];
192 +        register char  *cp;
193 +        RESOLU  rs;
194 +        double  pa;
195 +                                        /* finished writing header */
196 +        closeheader();
197 +                                        /* check sampling */
198 +        if (psample < 1)
199 +                psample = 1;
200 +        else if (psample > MAXDIV) {
201 +                sprintf(errmsg, "pixel sampling reduced from %d to %d",
202 +                                psample, MAXDIV);
203 +                error(WARNING, errmsg);
204 +                psample = MAXDIV;
205 +        }
206 +                                        /* get starting frame */
207 +        if (seq <= 0)
208 +                seq = 0;
209 +        else if (prvr != NULL && isint(prvr)) {
210 +                register int  rn;               /* skip to specified view */
211 +                if ((rn = atoi(prvr)) < seq)
212 +                        error(USER, "recover frame less than start frame");
213 +                if (pout == NULL)
214 +                        error(USER, "missing output file specification");
215 +                for ( ; seq < rn; seq++)
216 +                        if (nextview(stdin) == EOF)
217 +                                error(USER, "unexpected EOF on view input");
218 +                prvr = fbuf;                    /* mark for renaming */
219 +        }
220 +        if (pout != NULL) {
221 +                sprintf(fbuf, pout, seq);
222 +                if (prvr != NULL && !strcmp(prvr, fbuf)) {      /* rename */
223 +                        fbuf2[0] = '\0';
224 +                        if ((cp = rindex(fbuf, '/')) != NULL)
225 +                                strncpy(fbuf2, fbuf, cp-fbuf+1);
226 +                        strcat(fbuf2, RFTEMPLATE);
227 +                        prvr = mktemp(fbuf2);
228 +                        if (rename(fbuf, prvr) < 0 && errno != ENOENT) {
229 +                                sprintf(errmsg,
230 +                                        "cannot rename \"%s\" to \"%s\"",
231 +                                                fbuf, prvr);
232 +                                error(SYSTEM, errmsg);
233 +                        }
234 +                }
235 +        }
236 +                                        /* render sequence */
237 +        do {
238 +                if (seq && nextview(stdin) == EOF)
239 +                        break;
240 +                if (pout != NULL) {
241 +                        sprintf(fbuf, pout, seq);
242 +                        if (freopen(fbuf, "w", stdout) == NULL) {
243 +                                sprintf(errmsg,
244 +                                        "cannot open output file \"%s\"", fbuf);
245 +                                error(SYSTEM, errmsg);
246 +                        }
247 + #ifdef MSDOS
248 +                        setmode(fileno(stdout), O_BINARY);
249 + #endif
250 +                        dupheader();
251 +                }
252 +                hres = hresolu; vres = vresolu; pa = pixaspect;
253 +                if (prvr != NULL)
254 +                        if (viewfile(prvr, &ourview, &rs) <= 0
255 +                                        || rs.or != PIXSTANDARD) {
256 +                                sprintf(errmsg,
257 +                        "cannot recover view parameters from \"%s\"", prvr);
258 +                                error(WARNING, errmsg);
259 +                        } else {
260 +                                pa = 0.0;
261 +                                hres = scanlen(&rs);
262 +                                vres = numscans(&rs);
263 +                        }
264 +                if ((cp = setview(&ourview)) != NULL)
265 +                        error(USER, cp);
266 +                normaspect(viewaspect(&ourview), &pa, &hres, &vres);
267 +                if (seq) {
268 +                        if (ralrm > 0) {
269 +                                fprintf(stderr, "FRAME %d:", seq);
270 +                                fprintview(&ourview, stderr);
271 +                                putc('\n', stderr);
272 +                                fflush(stderr);
273 +                        }
274 +                        printf("FRAME=%d\n", seq);
275 +                }
276 +                fputs(VIEWSTR, stdout);
277 +                fprintview(&ourview, stdout);
278 +                putchar('\n');
279 +                if (pa < .99 || pa > 1.01)
280 +                        fputaspect(pa, stdout);
281 +                fputformat(COLRFMT, stdout);
282 +                putchar('\n');
283 +                if (zout != NULL)
284 +                        sprintf(cp=fbuf, zout, seq);
285 +                else
286 +                        cp = NULL;
287 +                render(cp, prvr);
288 +                prvr = NULL;
289 +        } while (seq++);
290 + }
291 +
292 +
293 + nextview(fp)                            /* get next view from fp */
294 + FILE  *fp;
295 + {
296 +        char  linebuf[256];
297 +
298 +        while (fgets(linebuf, sizeof(linebuf), fp) != NULL)
299 +                if (isview(linebuf) && sscanview(&ourview, linebuf) > 0)
300 +                        return(0);
301 +        return(EOF);
302 + }      
303 +
304 +
305   render(zfile, oldfile)                          /* render the scene */
306   char  *zfile, *oldfile;
307   {
308 +        extern long  lseek();
309          COLOR  *scanbar[MAXDIV+1];      /* scanline arrays of pixel values */
310          float  *zbar[MAXDIV+1];         /* z values */
311 +        char  *sampdens;                /* previous sample density */
312          int  ypos;                      /* current scanline */
313 <        FILE  *zfp;
313 >        int  ystep;                     /* current y step size */
314 >        int  hstep;                     /* h step size */
315 >        int  zfd;
316          COLOR  *colptr;
317          float  *zptr;
318          register int  i;
110                                        /* check sampling */
111        if (psample < 1)
112                psample = 1;
113        else if (psample > MAXDIV)
114                psample = MAXDIV;
319                                          /* allocate scanlines */
320          for (i = 0; i <= psample; i++) {
321 <                scanbar[i] = (COLOR *)malloc(hresolu*sizeof(COLOR));
321 >                scanbar[i] = (COLOR *)malloc(hres*sizeof(COLOR));
322                  if (scanbar[i] == NULL)
323                          goto memerr;
324          }
325 +        hstep = (psample*140+49)/99;            /* quincunx sampling */
326 +        ystep = (psample*99+70)/140;
327 +        if (hstep > 2) {
328 +                i = hres/hstep + 2;
329 +                if ((sampdens = malloc(i)) == NULL)
330 +                        goto memerr;
331 +                while (i--)
332 +                        sampdens[i] = hstep;
333 +        } else
334 +                sampdens = NULL;
335                                          /* open z file */
336          if (zfile != NULL) {
337 <                if ((zfp = fopen(zfile, "a+")) == NULL) {
337 >                if ((zfd = open(zfile, O_WRONLY|O_CREAT, 0666)) == -1) {
338                          sprintf(errmsg, "cannot open z file \"%s\"", zfile);
339                          error(SYSTEM, errmsg);
340                  }
341 + #ifdef MSDOS
342 +                setmode(zfd, O_BINARY);
343 + #endif
344                  for (i = 0; i <= psample; i++) {
345 <                        zbar[i] = (float *)malloc(hresolu*sizeof(float));
345 >                        zbar[i] = (float *)malloc(hres*sizeof(float));
346                          if (zbar[i] == NULL)
347                                  goto memerr;
348                  }
349          } else {
350 <                zfp = NULL;
350 >                zfd = -1;
351                  for (i = 0; i <= psample; i++)
352                          zbar[i] = NULL;
353          }
354                                          /* write out boundaries */
355 <        fputresolu(YMAJOR|YDECR, hresolu, vresolu, stdout);
355 >        fprtresolu(hres, vres, stdout);
356                                          /* recover file and compute first */
357          i = salvage(oldfile);
358 <        if (zfp != NULL && fseek(zfp, (long)i*hresolu*sizeof(float), 0) == EOF)
358 >        if (zfd != -1 && i > 0 &&
359 >                        lseek(zfd, (long)i*hres*sizeof(float), 0) == -1)
360                  error(SYSTEM, "z file seek error in render");
361 <        ypos = vresolu-1 - i;
362 <        fillscanline(scanbar[0], zbar[0], hresolu, ypos, psample);
361 >        pctdone = 100.0*i/vres;
362 >        if (ralrm > 0)                  /* report init stats */
363 >                report();
364 > #ifndef  BSD
365 >        else
366 > #endif
367 >        signal(SIGALRM, report);
368 >        ypos = vres-1 - i;
369 >        fillscanline(scanbar[0], zbar[0], sampdens, hres, ypos, hstep);
370                                                  /* compute scanlines */
371 <        for (ypos -= psample; ypos >= 0; ypos -= psample) {
372 <        
373 <                pctdone = 100.0*(vresolu-ypos-psample)/vresolu;
374 <
375 <                colptr = scanbar[psample];              /* move base to top */
376 <                scanbar[psample] = scanbar[0];
371 >        for (ypos -= ystep; ypos > -ystep; ypos -= ystep) {
372 >                                                        /* bottom adjust? */
373 >                if (ypos < 0) {
374 >                        ystep += ypos;
375 >                        ypos = 0;
376 >                }
377 >                colptr = scanbar[ystep];                /* move base to top */
378 >                scanbar[ystep] = scanbar[0];
379                  scanbar[0] = colptr;
380 <                zptr = zbar[psample];
381 <                zbar[psample] = zbar[0];
380 >                zptr = zbar[ystep];
381 >                zbar[ystep] = zbar[0];
382                  zbar[0] = zptr;
383                                                          /* fill base line */
384 <                fillscanline(scanbar[0], zbar[0], hresolu, ypos, psample);
384 >                fillscanline(scanbar[0], zbar[0], sampdens,
385 >                                hres, ypos, hstep);
386                                                          /* fill bar */
387 <                fillscanbar(scanbar, zbar, hresolu, ypos, psample);
387 >                fillscanbar(scanbar, zbar, hres, ypos, ystep);
388                                                          /* write it out */
389 <                for (i = psample; i > 0; i--) {
390 <                        if (zfp != NULL && fwrite(zbar[i],sizeof(float),hresolu,zfp) != hresolu)
389 > #ifndef  BSD
390 >                signal(SIGALRM, SIG_IGN);       /* don't interrupt writes */
391 > #endif
392 >                for (i = ystep; i > 0; i--) {
393 >                        if (zfd != -1 && write(zfd, (char *)zbar[i],
394 >                                        hres*sizeof(float))
395 >                                        < hres*sizeof(float))
396                                  goto writerr;
397 <                        if (fwritescan(scanbar[i],hresolu,stdout) < 0)
397 >                        if (fwritescan(scanbar[i], hres, stdout) < 0)
398                                  goto writerr;
399                  }
167                if (zfp != NULL && fflush(zfp) == EOF)
168                        goto writerr;
400                  if (fflush(stdout) == EOF)
401                          goto writerr;
402 +                                                        /* record progress */
403 +                pctdone = 100.0*(vres-1-ypos)/vres;
404 +                if (ralrm > 0 && time((long *)0) >= tlastrept+ralrm)
405 +                        report();
406 + #ifndef  BSD
407 +                else
408 +                        signal(SIGALRM, report);
409 + #endif
410          }
172                                                /* compute residual */
173        colptr = scanbar[psample];
174        scanbar[psample] = scanbar[0];
175        scanbar[0] = colptr;
176        zptr = zbar[psample];
177        zbar[psample] = zbar[0];
178        zbar[0] = zptr;
179        if (ypos > -psample) {
180                fillscanline(scanbar[-ypos], zbar[-ypos], hresolu, 0, psample);
181                fillscanbar(scanbar-ypos, zbar-ypos, hresolu, 0, psample+ypos);
182        }
183        for (i = psample; i+ypos >= 0; i--) {
184                if (zfp != NULL && fwrite(zbar[i],sizeof(float),hresolu,zfp) != hresolu)
185                        goto writerr;
186                if (fwritescan(scanbar[i], hresolu, stdout) < 0)
187                        goto writerr;
188        }
411                                                  /* clean up */
412 <        if (zfp != NULL) {
413 <                if (fclose(zfp) == EOF)
412 >        signal(SIGALRM, SIG_IGN);
413 >        if (zfd != -1) {
414 >                if (write(zfd, (char *)zbar[0], hres*sizeof(float))
415 >                                < hres*sizeof(float))
416                          goto writerr;
417 +                if (close(zfd) == -1)
418 +                        goto writerr;
419                  for (i = 0; i <= psample; i++)
420                          free((char *)zbar[i]);
421          }
422 +        fwritescan(scanbar[0], hres, stdout);
423          if (fflush(stdout) == EOF)
424                  goto writerr;
425          for (i = 0; i <= psample; i++)
426                  free((char *)scanbar[i]);
427 +        if (sampdens != NULL)
428 +                free(sampdens);
429          pctdone = 100.0;
430 +        if (ralrm > 0)
431 +                report();
432          return;
433   writerr:
434          error(SYSTEM, "write error in render");
# Line 206 | Line 437 | memerr:
437   }
438  
439  
440 < fillscanline(scanline, zline, xres, y, xstep)   /* fill scan line at y */
441 < register COLOR  *scanline;
442 < register float  *zline;
440 > fillscanline(scanline, zline, sd, xres, y, xstep)       /* fill scan at y */
441 > register COLOR  *scanline;
442 > register float  *zline;
443 > register char  *sd;
444   int  xres, y, xstep;
445   {
446 <        int  b = xstep;
447 <        double  z;
446 >        static int  nc = 0;             /* number of calls */
447 >        int  bl = xstep, b = xstep;
448 >        double  z;
449          register int  i;
450          
451          z = pixvalue(scanline[0], 0, y);
452          if (zline) zline[0] = z;
453 <
454 <        for (i = xstep; i < xres; i += xstep) {
455 <        
453 >                                /* zig-zag start for quincunx pattern */
454 >        for (i = ++nc & 1 ? xstep : xstep/2; i < xres-1+xstep; i += xstep) {
455 >                if (i >= xres) {
456 >                        xstep += xres-1-i;
457 >                        i = xres-1;
458 >                }
459                  z = pixvalue(scanline[i], i, y);
460                  if (zline) zline[i] = z;
461 <                
462 <                b = fillsample(scanline+i-xstep, zline ? zline+i-xstep : NULL,
463 <                                i-xstep, y, xstep, 0, b/2);
461 >                if (sd) b = sd[0] > sd[1] ? sd[0] : sd[1];
462 >                if (i <= xstep)
463 >                        b = fillsample(scanline, zline, 0, y, i, 0, b/2);
464 >                else
465 >                        b = fillsample(scanline+i-xstep,
466 >                                        zline ? zline+i-xstep : NULL,
467 >                                        i-xstep, y, xstep, 0, b/2);
468 >                if (sd) *sd++ = nc & 1 ? bl : b;
469 >                bl = b;
470          }
471 <        if (i-xstep < xres-1) {
230 <                z = pixvalue(scanline[xres-1], xres-1, y);
231 <                if (zline) zline[xres-1] = z;
232 <                fillsample(scanline+i-xstep, zline ? zline+i-xstep : NULL,
233 <                                i-xstep, y, xres-1-(i-xstep), 0, b/2);
234 <        }
471 >        if (sd && nc & 1) *sd = bl;
472   }
473  
474  
475   fillscanbar(scanbar, zbar, xres, y, ysize)      /* fill interior */
476 < register COLOR  *scanbar[];
477 < register float  *zbar[];
476 > register COLOR  *scanbar[];
477 > register float  *zbar[];
478   int  xres, y, ysize;
479   {
480          COLOR  vline[MAXDIV+1];
481          float  zline[MAXDIV+1];
482          int  b = ysize;
246        double  z;
483          register int  i, j;
484          
485          for (i = 0; i < xres; i++) {
# Line 268 | Line 504 | int  xres, y, ysize;
504  
505  
506   int
507 < fillsample(colline, zline, x, y, xlen, ylen, b) /* fill interior points */
508 < register COLOR  *colline;
509 < register float  *zline;
507 > fillsample(colline, zline, x, y, xlen, ylen, b) /* fill interior points */
508 > register COLOR  *colline;
509 > register float  *zline;
510   int  x, y;
511   int  xlen, ylen;
512   int  b;
513   {
514 <        extern double  fabs();
515 <        double  ratio;
280 <        double  z;
514 >        double  ratio;
515 >        double  z;
516          COLOR  ctmp;
517          int  ncut;
518          register int  len;
# Line 327 | Line 562 | pixvalue(col, x, y)            /* compute pixel value */
562   COLOR  col;                     /* returned color */
563   int  x, y;                      /* pixel position */
564   {
565 <        static RAY  thisray;    /* our ray for this pixel */
565 >        static RAY  thisray;
566  
567 <        viewray(thisray.rorg, thisray.rdir, &ourview,
568 <                        (x+pixjitter())/hresolu, (y+pixjitter())/vresolu);
567 >        if (viewray(thisray.rorg, thisray.rdir, &ourview,
568 >                        (x+pixjitter())/hres, (y+pixjitter())/vres) < 0) {
569 >                setcolor(col, 0.0, 0.0, 0.0);
570 >                return(0.0);
571 >        }
572  
573          rayorigin(&thisray, NULL, PRIMARY, 1.0);
574 <        
574 >
575 >        samplendx = pixnumber(x,y,hres,vres);   /* set pixel index */
576 >
577          rayvalue(&thisray);                     /* trace ray */
578  
579          copycolor(col, thisray.rcol);           /* return color */
580          
581 <        return(thisray.rot);                    /* return distance */
581 >        return(thisray.rt);                     /* return distance */
582   }
583  
584  
# Line 358 | Line 598 | char  *oldfile;
598                  error(WARNING, errmsg);
599                  return(0);
600          }
601 + #ifdef MSDOS
602 +        setmode(fileno(fp), O_BINARY);
603 + #endif
604                                  /* discard header */
605          getheader(fp, NULL);
606                                  /* get picture size */
607 <        if (fgetresolu(&x, &y, fp) != (YMAJOR|YDECR)) {
607 >        if (!fscnresolu(&x, &y, fp)) {
608                  sprintf(errmsg, "bad recover file \"%s\"", oldfile);
609                  error(WARNING, errmsg);
610                  fclose(fp);
611                  return(0);
612          }
613  
614 <        if (x != hresolu || y != vresolu) {
614 >        if (x != hres || y != vres) {
615                  sprintf(errmsg, "resolution mismatch in recover file \"%s\"",
616                                  oldfile);
617                  error(USER, errmsg);
618          }
619  
620 <        scanline = (COLR *)malloc(hresolu*sizeof(COLR));
620 >        scanline = (COLR *)malloc(hres*sizeof(COLR));
621          if (scanline == NULL)
622                  error(SYSTEM, "out of memory in salvage");
623 <        for (y = 0; y < vresolu; y++) {
624 <                if (freadcolrs(scanline, hresolu, fp) < 0)
623 >        for (y = 0; y < vres; y++) {
624 >                if (freadcolrs(scanline, hres, fp) < 0)
625                          break;
626 <                if (fwritecolrs(scanline, hresolu, stdout) < 0)
626 >                if (fwritecolrs(scanline, hres, stdout) < 0)
627                          goto writerr;
628          }
629          if (fflush(stdout) == EOF)
# Line 390 | Line 633 | char  *oldfile;
633          unlink(oldfile);
634          return(y);
635   writerr:
636 <        error(SYSTEM, "write error in salvage");
636 >        sprintf(errmsg, "write error during recovery of \"%s\"", oldfile);
637 >        error(SYSTEM, errmsg);
638 > }
639 >
640 >
641 > int
642 > pixnumber(x, y, xres, yres)             /* compute pixel index (brushed) */
643 > register int  x, y;
644 > int  xres, yres;
645 > {
646 >        x -= y;
647 >        while (x < 0)
648 >                x += xres;
649 >        return((((x>>2)*yres + y) << 2) + (x & 3));
650   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines