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 2.12 by greg, Tue Sep 8 15:35:16 1992 UTC vs.
Revision 2.46 by greg, Wed Apr 17 14:02:05 1996 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1992 Regents of the University of California */
1 > /* Copyright (c) 1995 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 6 | Line 6 | static char SCCSid[] = "$SunId$ LBL";
6  
7   /*
8   *  rpict.c - routines and variables for picture generation.
9 *
10 *     8/14/85
9   */
10  
11   #include  "ray.h"
12  
13 + #include  <sys/types.h>
14 +
15 + #ifndef NIX
16   #ifdef BSD
17   #include  <sys/time.h>
18   #include  <sys/resource.h>
19 + #else
20 + #include  <sys/times.h>
21 + #include  <unistd.h>
22   #endif
23 + #endif
24  
25 + extern time_t   time();
26 +
27   #include  <signal.h>
21 #include  <fcntl.h>
28  
29   #include  "view.h"
30  
# Line 28 | Line 34 | static char SCCSid[] = "$SunId$ LBL";
34  
35   #include  "paths.h"
36  
37 + #define  RFTEMPLATE     "rfXXXXXX"
38 +
39 + #ifndef SIGCONT
40 + #define SIGCONT         SIGIO
41 + #endif
42 +
43   int  dimlist[MAXDIM];                   /* sampling dimensions */
44   int  ndims = 0;                         /* number of sampling dimensions */
45   int  samplendx;                         /* sample index number */
# Line 35 | Line 47 | int  samplendx;                                /* sample index number */
47   VIEW  ourview = STDVIEW;                /* view parameters */
48   int  hresolu = 512;                     /* horizontal resolution */
49   int  vresolu = 512;                     /* vertical resolution */
50 < double  pixaspect = 1.0;                /* pixel aspect ratio */
50 > double  pixaspect = 1.0;                /* pixel aspect ratio */
51  
52   int  psample = 4;                       /* pixel sample size */
53 < double  maxdiff = .05;                  /* max. difference for interpolation */
54 < double  dstrpix = 0.67;                 /* square pixel distribution */
53 > double  maxdiff = .05;                  /* max. difference for interpolation */
54 > double  dstrpix = 0.67;                 /* square pixel distribution */
55  
56 < double  dstrsrc = 0.0;                  /* square source distribution */
57 < double  shadthresh = .05;               /* shadow threshold */
58 < double  shadcert = .5;                  /* shadow certainty */
56 > double  dstrsrc = 0.0;                  /* square source distribution */
57 > double  shadthresh = .05;               /* shadow threshold */
58 > double  shadcert = .5;                  /* shadow certainty */
59   int  directrelay = 1;                   /* number of source relays */
60   int  vspretest = 512;                   /* virtual source pretest density */
61 < int  directinvis = 0;                   /* sources invisible? */
62 < double  srcsizerat = .25;               /* maximum ratio source size/dist. */
61 > int  directvis = 1;                     /* sources visible? */
62 > double  srcsizerat = .25;               /* maximum ratio source size/dist. */
63  
64 < double  specthresh = .15;               /* specular sampling threshold */
65 < double  specjitter = 1.;                /* specular sampling jitter */
64 > COLOR  cextinction = BLKCOLOR;          /* global extinction coefficient */
65 > COLOR  salbedo = BLKCOLOR;              /* global scattering albedo */
66 > double  seccg = 0.;                     /* global scattering eccentricity */
67 > double  ssampdist = 0.;                 /* scatter sampling distance */
68  
69 + double  specthresh = .15;               /* specular sampling threshold */
70 + double  specjitter = 1.;                /* specular sampling jitter */
71 +
72 + int  backvis = 1;                       /* back face visibility */
73 +
74   int  maxdepth = 6;                      /* maximum recursion depth */
75 < double  minweight = 5e-3;               /* minimum ray weight */
75 > double  minweight = 5e-3;               /* minimum ray weight */
76  
77   COLOR  ambval = BLKCOLOR;               /* ambient value */
78 < double  ambacc = 0.2;                   /* ambient accuracy */
78 > int  ambvwt = 0;                        /* initial weight for ambient value */
79 > double  ambacc = 0.2;                   /* ambient accuracy */
80   int  ambres = 32;                       /* ambient resolution */
81   int  ambdiv = 128;                      /* ambient divisions */
82   int  ambssamp = 0;                      /* ambient super-samples */
# Line 64 | Line 84 | int  ambounce = 0;                     /* ambient bounces */
84   char  *amblist[128];                    /* ambient include/exclude list */
85   int  ambincl = -1;                      /* include == 1, exclude == 0 */
86  
87 + #ifdef MSDOS
88 + int  ralrm = 60;                        /* seconds between reports */
89 + #else
90   int  ralrm = 0;                         /* seconds between reports */
91 + #endif
92  
93 < double  pctdone = 0.0;                  /* percentage done */
93 > double  pctdone = 0.0;                  /* percentage done */
94  
95 < long  tlastrept = 0L;                   /* time at last report */
95 > time_t  tlastrept = 0L;                 /* time at last report */
96  
97 < extern long  time();
74 < extern long  tstart;                    /* starting time */
97 > extern time_t  tstart;                  /* starting time */
98  
99 < extern long  nrays;                     /* number of rays traced */
99 > extern unsigned long  nrays;            /* number of rays traced */
100  
101 < #define  MAXDIV         16              /* maximum sample size */
101 > #define  MAXDIV         16              /* maximum sample size */
102  
103 < #define  pixjitter()    (.5+dstrpix*(.5-frandom()))
103 > #define  pixjitter()    (.5+dstrpix*(.5-frandom()))
104  
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
105   static int  hres, vres;                 /* resolution for this frame */
106  
107   extern char  *mktemp();
108  
109 < double  pixvalue();
109 > double  pixvalue();
110  
111 + #ifdef NIX
112 + #define  file_exists(f) (access(f,F_OK)==0)
113 + #else
114 + #include  <sys/types.h>
115 + #include  <sys/stat.h>
116 + int
117 + file_exists(fname)                              /* ordinary file exists? */
118 + char  *fname;
119 + {
120 +        struct stat  sbuf;
121 +        if (stat(fname, &sbuf) < 0) return(0);
122 +        return((sbuf.st_mode & S_IFREG) != 0);
123 + }
124 + #endif
125  
126 +
127   quit(code)                      /* quit program */
128   int  code;
129   {
130          if (code)                       /* report status */
131                  report();
132 <        if (hfname != NULL) {           /* delete header file */
133 <                if (hfp != NULL)
102 <                        fclose(hfp);
103 <                unlink(hfname);
104 <        }
132 >        headclean();                    /* delete header file */
133 >        pfclean();                      /* clean up persist files */
134          exit(code);
135   }
136  
137  
138 < #ifdef BSD
138 > #ifndef NIX
139   report()                /* report progress */
140   {
141 +        extern char  *myhostname();
142 +        double  u, s;
143 + #ifdef BSD
144          struct rusage  rubuf;
145 <        double  t;
145 > #else
146 >        struct tms  tbuf;
147 >        double  period;
148 > #endif
149  
150 +        tlastrept = time((time_t *)NULL);
151 + #ifdef BSD
152          getrusage(RUSAGE_SELF, &rubuf);
153 <        t = (rubuf.ru_utime.tv_usec + rubuf.ru_stime.tv_usec) / 1e6;
154 <        t += rubuf.ru_utime.tv_sec + rubuf.ru_stime.tv_sec;
153 >        u = rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec/1e6;
154 >        s = rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec/1e6;
155          getrusage(RUSAGE_CHILDREN, &rubuf);
156 <        t += (rubuf.ru_utime.tv_usec + rubuf.ru_stime.tv_usec) / 1e6;
157 <        t += rubuf.ru_utime.tv_sec + rubuf.ru_stime.tv_sec;
156 >        u += rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec/1e6;
157 >        s += rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec/1e6;
158 > #else
159 >        times(&tbuf);
160 > #ifdef _SC_CLK_TCK
161 >        period = 1.0 / sysconf(_SC_CLK_TCK);
162 > #else
163 >        period = 1.0 / 60.0;
164 > #endif
165 >        u = ( tbuf.tms_utime + tbuf.tms_cutime ) * period;
166 >        s = ( tbuf.tms_stime + tbuf.tms_cstime ) * period;
167 > #endif
168  
169 <        sprintf(errmsg, "%ld rays, %4.2f%% done after %5.4f CPU hours\n",
170 <                        nrays, pctdone, t/3600.0);
169 >        sprintf(errmsg,
170 >                "%lu rays, %4.2f%% after %.3fu %.3fs %.3fr hours on %s\n",
171 >                        nrays, pctdone, u/3600., s/3600.,
172 >                        (tlastrept-tstart)/3600., myhostname());
173          eputs(errmsg);
174 <        tlastrept = time((long *)0);
174 > #ifndef BSD
175 >        signal(SIGCONT, report);
176 > #endif
177   }
178   #else
179   report()                /* report progress */
180   {
181 <        tlastrept = time((long *)0);
182 <        sprintf(errmsg, "%ld rays, %4.2f%% done after %5.4f hours\n",
181 >        tlastrept = time((time_t *)NULL);
182 >        sprintf(errmsg, "%lu rays, %4.2f%% after %5.4f hours\n",
183                          nrays, pctdone, (tlastrept-tstart)/3600.0);
184          eputs(errmsg);
134        signal(SIGALRM, report);
185   }
186   #endif
187  
188  
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
189   rpict(seq, pout, zout, prvr)                    /* generate image(s) */
190   int  seq;
191   char  *pout, *zout, *prvr;
# Line 181 | Line 201 | char  *pout, *zout, *prvr;
201   * sequenced file naming.
202   */
203   {
204 <        extern char  *rindex(), *strncpy(), *strcat();
204 >        extern char  *rindex(), *strncpy(), *strcat(), *strcpy();
205          char  fbuf[128], fbuf2[128];
206 +        int  npicts;
207          register char  *cp;
208 <        RESOLU  rs;
209 <        double  pa;
189 <                                        /* finished writing header */
190 <        closeheader();
208 >        RESOLU  rs;
209 >        double  pa;
210                                          /* check sampling */
211          if (psample < 1)
212                  psample = 1;
# Line 211 | Line 230 | char  *pout, *zout, *prvr;
230                                  error(USER, "unexpected EOF on view input");
231                  prvr = fbuf;                    /* mark for renaming */
232          }
233 <        if (pout != NULL) {
233 >        if (pout != NULL & prvr != NULL) {
234                  sprintf(fbuf, pout, seq);
235 <                if (prvr != NULL && !strcmp(prvr, fbuf)) {      /* rename */
236 <                        fbuf2[0] = '\0';
237 <                        if ((cp = rindex(fbuf, '/')) != NULL)
238 <                                strncpy(fbuf2, fbuf, cp-fbuf+1);
239 <                        strcat(fbuf2, RFTEMPLATE);
235 >                if (!strcmp(prvr, fbuf)) {      /* rename */
236 >                        strcpy(fbuf2, fbuf);
237 >                        for (cp = fbuf2; *cp; cp++)
238 >                                ;
239 >                        while (cp > fbuf2 && !ISDIRSEP(cp[-1]))
240 >                                cp--;
241 >                        strcpy(cp, RFTEMPLATE);
242                          prvr = mktemp(fbuf2);
243 <                        if (rename(fbuf, prvr) < 0 && errno != ENOENT) {
244 <                                sprintf(errmsg,
243 >                        if (rename(fbuf, prvr) < 0)
244 >                                if (errno == ENOENT) {  /* ghost file */
245 >                                        sprintf(errmsg,
246 >                                                "new output file \"%s\"",
247 >                                                fbuf);
248 >                                        error(WARNING, errmsg);
249 >                                        prvr = NULL;
250 >                                } else {                /* serious error */
251 >                                        sprintf(errmsg,
252                                          "cannot rename \"%s\" to \"%s\"",
253                                                  fbuf, prvr);
254 <                                error(SYSTEM, errmsg);
255 <                        }
254 >                                        error(SYSTEM, errmsg);
255 >                                }
256                  }
257          }
258 <                                        /* render sequence */
258 >        npicts = 0;                     /* render sequence */
259          do {
260                  if (seq && nextview(stdin) == EOF)
261                          break;
262 +                pctdone = 0.0;
263                  if (pout != NULL) {
264                          sprintf(fbuf, pout, seq);
265 +                        if (file_exists(fbuf)) {
266 +                                if (prvr != NULL || !strcmp(fbuf, pout)) {
267 +                                        sprintf(errmsg,
268 +                                                "output file \"%s\" exists",
269 +                                                fbuf);
270 +                                        error(USER, errmsg);
271 +                                }
272 +                                continue;               /* don't clobber */
273 +                        }
274                          if (freopen(fbuf, "w", stdout) == NULL) {
275                                  sprintf(errmsg,
276                                          "cannot open output file \"%s\"", fbuf);
277                                  error(SYSTEM, errmsg);
278                          }
279 + #ifdef MSDOS
280 +                        setmode(fileno(stdout), O_BINARY);
281 + #endif
282                          dupheader();
283                  }
284                  hres = hresolu; vres = vresolu; pa = pixaspect;
# Line 277 | Line 318 | char  *pout, *zout, *prvr;
318                          cp = NULL;
319                  render(cp, prvr);
320                  prvr = NULL;
321 +                npicts++;
322          } while (seq++);
323 +                                        /* check that we did something */
324 +        if (npicts == 0)
325 +                error(WARNING, "no output produced");
326   }
327  
328  
# Line 323 | Line 368 | char  *zfile, *oldfile;
368                          sampdens[i] = hstep;
369          } else
370                  sampdens = NULL;
371 <                                        /* open z file */
371 >                                        /* open z-file */
372          if (zfile != NULL) {
373                  if ((zfd = open(zfile, O_WRONLY|O_CREAT, 0666)) == -1) {
374 <                        sprintf(errmsg, "cannot open z file \"%s\"", zfile);
374 >                        sprintf(errmsg, "cannot open z-file \"%s\"", zfile);
375                          error(SYSTEM, errmsg);
376                  }
377 + #ifdef MSDOS
378 +                setmode(zfd, O_BINARY);
379 + #endif
380                  for (i = 0; i <= psample; i++) {
381                          zbar[i] = (float *)malloc(hres*sizeof(float));
382                          if (zbar[i] == NULL)
# Line 343 | Line 391 | char  *zfile, *oldfile;
391          fprtresolu(hres, vres, stdout);
392                                          /* recover file and compute first */
393          i = salvage(oldfile);
394 +        if (i >= vres)
395 +                goto alldone;
396          if (zfd != -1 && i > 0 &&
397                          lseek(zfd, (long)i*hres*sizeof(float), 0) == -1)
398 <                error(SYSTEM, "z file seek error in render");
398 >                error(SYSTEM, "z-file seek error in render");
399          pctdone = 100.0*i/vres;
400          if (ralrm > 0)                  /* report init stats */
401                  report();
402 < #ifndef  BSD
402 > #ifndef  BSD
403          else
404   #endif
405 <        signal(SIGALRM, report);
405 >        signal(SIGCONT, report);
406          ypos = vres-1 - i;
407          fillscanline(scanbar[0], zbar[0], sampdens, hres, ypos, hstep);
408                                                  /* compute scanlines */
# Line 373 | Line 423 | char  *zfile, *oldfile;
423                                  hres, ypos, hstep);
424                                                          /* fill bar */
425                  fillscanbar(scanbar, zbar, hres, ypos, ystep);
426 +                                                        /* add bitty sources */
427 +                drawsources(&ourview, hres, vres, scanbar, zbar,
428 +                                0, hres, ypos, ystep, psample);
429                                                          /* write it out */
430 < #ifndef  BSD
431 <                signal(SIGALRM, SIG_IGN);       /* don't interrupt writes */
430 > #ifndef  BSD
431 >                signal(SIGCONT, SIG_IGN);       /* don't interrupt writes */
432   #endif
433                  for (i = ystep; i > 0; i--) {
434                          if (zfd != -1 && write(zfd, (char *)zbar[i],
# Line 389 | Line 442 | char  *zfile, *oldfile;
442                          goto writerr;
443                                                          /* record progress */
444                  pctdone = 100.0*(vres-1-ypos)/vres;
445 <                if (ralrm > 0 && time((long *)0) >= tlastrept+ralrm)
445 >                if (ralrm > 0 && time((time_t *)NULL) >= tlastrept+ralrm)
446                          report();
447 < #ifndef  BSD
447 > #ifndef  BSD
448                  else
449 <                        signal(SIGALRM, report);
449 >                        signal(SIGCONT, report);
450   #endif
451          }
452                                                  /* clean up */
453 <        signal(SIGALRM, SIG_IGN);
454 <        if (zfd != -1) {
402 <                if (write(zfd, (char *)zbar[0], hres*sizeof(float))
453 >        signal(SIGCONT, SIG_IGN);
454 >        if (zfd != -1 && write(zfd, (char *)zbar[0], hres*sizeof(float))
455                                  < hres*sizeof(float))
456 <                        goto writerr;
456 >                goto writerr;
457 >        fwritescan(scanbar[0], hres, stdout);
458 >        if (fflush(stdout) == EOF)
459 >                goto writerr;
460 > alldone:
461 >        if (zfd != -1) {
462                  if (close(zfd) == -1)
463                          goto writerr;
464                  for (i = 0; i <= psample; i++)
465                          free((char *)zbar[i]);
466          }
410        fwritescan(scanbar[0], hres, stdout);
411        if (fflush(stdout) == EOF)
412                goto writerr;
467          for (i = 0; i <= psample; i++)
468                  free((char *)scanbar[i]);
469          if (sampdens != NULL)
470                  free(sampdens);
471          pctdone = 100.0;
472 +        if (ralrm > 0)
473 +                report();
474 +        signal(SIGCONT, SIG_DFL);
475          return;
476   writerr:
477          error(SYSTEM, "write error in render");
# Line 424 | Line 481 | memerr:
481  
482  
483   fillscanline(scanline, zline, sd, xres, y, xstep)       /* fill scan at y */
484 < register COLOR  *scanline;
485 < register float  *zline;
484 > register COLOR  *scanline;
485 > register float  *zline;
486   register char  *sd;
487   int  xres, y, xstep;
488   {
489          static int  nc = 0;             /* number of calls */
490          int  bl = xstep, b = xstep;
491 <        double  z;
491 >        double  z;
492          register int  i;
493 <        
493 >
494          z = pixvalue(scanline[0], 0, y);
495          if (zline) zline[0] = z;
496                                  /* zig-zag start for quincunx pattern */
# Line 449 | Line 506 | int  xres, y, xstep;
506                          b = fillsample(scanline, zline, 0, y, i, 0, b/2);
507                  else
508                          b = fillsample(scanline+i-xstep,
509 <                                        zline ? zline+i-xstep : NULL,
509 >                                        zline ? zline+i-xstep : (float *)NULL,
510                                          i-xstep, y, xstep, 0, b/2);
511                  if (sd) *sd++ = nc & 1 ? bl : b;
512                  bl = b;
# Line 459 | Line 516 | int  xres, y, xstep;
516  
517  
518   fillscanbar(scanbar, zbar, xres, y, ysize)      /* fill interior */
519 < register COLOR  *scanbar[];
520 < register float  *zbar[];
519 > register COLOR  *scanbar[];
520 > register float  *zbar[];
521   int  xres, y, ysize;
522   {
523          COLOR  vline[MAXDIV+1];
524          float  zline[MAXDIV+1];
525          int  b = ysize;
526          register int  i, j;
527 <        
527 >
528          for (i = 0; i < xres; i++) {
472                
529                  copycolor(vline[0], scanbar[0][i]);
530                  copycolor(vline[ysize], scanbar[ysize][i]);
531                  if (zbar[0]) {
532                          zline[0] = zbar[0][i];
533                          zline[ysize] = zbar[ysize][i];
534                  }
535 <                
480 <                b = fillsample(vline, zbar[0] ? zline : NULL,
535 >                b = fillsample(vline, zbar[0] ? zline : (float *)NULL,
536                                  i, y, 0, ysize, b/2);
537 <                
537 >
538                  for (j = 1; j < ysize; j++)
539                          copycolor(scanbar[j][i], vline[j]);
540                  if (zbar[0])
# Line 490 | Line 545 | int  xres, y, ysize;
545  
546  
547   int
548 < fillsample(colline, zline, x, y, xlen, ylen, b) /* fill interior points */
549 < register COLOR  *colline;
550 < register float  *zline;
548 > fillsample(colline, zline, x, y, xlen, ylen, b) /* fill interior points */
549 > register COLOR  *colline;
550 > register float  *zline;
551   int  x, y;
552   int  xlen, ylen;
553   int  b;
554   {
555 <        extern double  fabs();
556 <        double  ratio;
502 <        double  z;
555 >        double  ratio;
556 >        double  z;
557          COLOR  ctmp;
558          int  ncut;
559          register int  len;
560 <        
560 >
561          if (xlen > 0)                   /* x or y length is zero */
562                  len = xlen;
563          else
564                  len = ylen;
565 <                
565 >
566          if (len <= 1)                   /* limit recursion */
567                  return(0);
568 <        
569 <        if (b > 0
570 <        || (zline && 2.*fabs(zline[0]-zline[len]) > maxdiff*(zline[0]+zline[len]))
568 >
569 >        if (b > 0 ||
570 >        (zline && 2.*fabs(zline[0]-zline[len]) > maxdiff*(zline[0]+zline[len]))
571                          || bigdiff(colline[0], colline[len], maxdiff)) {
572 <        
572 >
573                  z = pixvalue(colline[len>>1], x + (xlen>>1), y + (ylen>>1));
574                  if (zline) zline[len>>1] = z;
575                  ncut = 1;
522                
576          } else {                                        /* interpolate */
524        
577                  copycolor(colline[len>>1], colline[len]);
578                  ratio = (double)(len>>1) / len;
579                  scalecolor(colline[len>>1], ratio);
# Line 535 | Line 587 | int  b;
587          }
588                                                          /* recurse */
589          ncut += fillsample(colline, zline, x, y, xlen>>1, ylen>>1, (b-1)/2);
590 <        
591 <        ncut += fillsample(colline+(len>>1), zline ? zline+(len>>1) : NULL,
590 >
591 >        ncut += fillsample(colline+(len>>1),
592 >                        zline ? zline+(len>>1) : (float *)NULL,
593                          x+(xlen>>1), y+(ylen>>1),
594                          xlen-(xlen>>1), ylen-(ylen>>1), b/2);
595  
# Line 551 | Line 604 | int  x, y;                     /* pixel position */
604   {
605          static RAY  thisray;
606  
607 <        if (viewray(thisray.rorg, thisray.rdir, &ourview,
608 <                        (x+pixjitter())/hres, (y+pixjitter())/vres) < 0) {
607 >        if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir, &ourview,
608 >                        (x+pixjitter())/hres, (y+pixjitter())/vres)) < -FTINY) {
609                  setcolor(col, 0.0, 0.0, 0.0);
610                  return(0.0);
611          }
# Line 564 | Line 617 | int  x, y;                     /* pixel position */
617          rayvalue(&thisray);                     /* trace ray */
618  
619          copycolor(col, thisray.rcol);           /* return color */
620 <        
620 >
621          return(thisray.rt);                     /* return distance */
622   }
623  
# Line 578 | Line 631 | char  *oldfile;
631          int  x, y;
632  
633          if (oldfile == NULL)
634 <                return(0);
635 <        
634 >                goto gotzip;
635 >
636          if ((fp = fopen(oldfile, "r")) == NULL) {
637                  sprintf(errmsg, "cannot open recover file \"%s\"", oldfile);
638                  error(WARNING, errmsg);
639 <                return(0);
639 >                goto gotzip;
640          }
641 + #ifdef MSDOS
642 +        setmode(fileno(fp), O_BINARY);
643 + #endif
644                                  /* discard header */
645 <        getheader(fp, NULL);
645 >        getheader(fp, NULL, NULL);
646                                  /* get picture size */
647          if (!fscnresolu(&x, &y, fp)) {
648 <                sprintf(errmsg, "bad recover file \"%s\"", oldfile);
648 >                sprintf(errmsg, "bad recover file \"%s\" - not removed",
649 >                                oldfile);
650                  error(WARNING, errmsg);
651                  fclose(fp);
652 <                return(0);
652 >                goto gotzip;
653          }
654  
655          if (x != hres || y != vres) {
# Line 616 | Line 673 | char  *oldfile;
673          fclose(fp);
674          unlink(oldfile);
675          return(y);
676 + gotzip:
677 +        if (fflush(stdout) == EOF)
678 +                error(SYSTEM, "error writing picture header");
679 +        return(0);
680   writerr:
681          sprintf(errmsg, "write error during recovery of \"%s\"", oldfile);
682          error(SYSTEM, errmsg);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines