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.1 by greg, Tue Nov 12 17:08:26 1991 UTC vs.
Revision 2.33 by greg, Tue Nov 23 09:56:31 1993 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1991 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 12 | Line 12 | static char SCCSid[] = "$SunId$ LBL";
12  
13   #include  "ray.h"
14  
15 + #include  <sys/types.h>
16 +
17 + #ifndef NIX
18   #ifdef BSD
19   #include  <sys/time.h>
20   #include  <sys/resource.h>
21 + #else
22 + #include  <sys/times.h>
23 + #include  <sys/utsname.h>
24 + #include  <unistd.h>
25   #endif
26 + #endif
27  
28 + extern time_t   time();
29 +
30   #include  <signal.h>
21 #include  <fcntl.h>
31  
32   #include  "view.h"
33  
# Line 26 | Line 35 | static char SCCSid[] = "$SunId$ LBL";
35  
36   #include  "random.h"
37  
38 + #include  "paths.h"
39 +
40 + #define  RFTEMPLATE     "rfXXXXXX"
41 +
42 + #ifndef SIGCONT
43 + #define SIGCONT         SIGIO
44 + #endif
45 +
46   int  dimlist[MAXDIM];                   /* sampling dimensions */
47   int  ndims = 0;                         /* number of sampling dimensions */
48   int  samplendx;                         /* sample index number */
# Line 33 | Line 50 | int  samplendx;                                /* sample index number */
50   VIEW  ourview = STDVIEW;                /* view parameters */
51   int  hresolu = 512;                     /* horizontal resolution */
52   int  vresolu = 512;                     /* vertical resolution */
53 < double  pixaspect = 1.0;                /* pixel aspect ratio */
53 > double  pixaspect = 1.0;                /* pixel aspect ratio */
54  
55   int  psample = 4;                       /* pixel sample size */
56 < double  maxdiff = .05;                  /* max. difference for interpolation */
57 < double  dstrpix = 0.67;                 /* square pixel distribution */
56 > double  maxdiff = .05;                  /* max. difference for interpolation */
57 > double  dstrpix = 0.67;                 /* square pixel distribution */
58  
59 < double  dstrsrc = 0.0;                  /* square source distribution */
60 < double  shadthresh = .05;               /* shadow threshold */
61 < double  shadcert = .5;                  /* shadow certainty */
59 > double  dstrsrc = 0.0;                  /* square source distribution */
60 > double  shadthresh = .05;               /* shadow threshold */
61 > double  shadcert = .5;                  /* shadow certainty */
62   int  directrelay = 1;                   /* number of source relays */
63   int  vspretest = 512;                   /* virtual source pretest density */
64 < int  directinvis = 0;                   /* sources invisible? */
65 < double  srcsizerat = .25;               /* maximum ratio source size/dist. */
64 > int  directvis = 1;                     /* sources visible? */
65 > double  srcsizerat = .25;               /* maximum ratio source size/dist. */
66  
67 + double  specthresh = .15;               /* specular sampling threshold */
68 + double  specjitter = 1.;                /* specular sampling jitter */
69 +
70   int  maxdepth = 6;                      /* maximum recursion depth */
71 < double  minweight = 5e-3;               /* minimum ray weight */
71 > double  minweight = 5e-3;               /* minimum ray weight */
72  
73   COLOR  ambval = BLKCOLOR;               /* ambient value */
74 < double  ambacc = 0.2;                   /* ambient accuracy */
74 > double  ambacc = 0.2;                   /* ambient accuracy */
75   int  ambres = 32;                       /* ambient resolution */
76   int  ambdiv = 128;                      /* ambient divisions */
77   int  ambssamp = 0;                      /* ambient super-samples */
# Line 59 | Line 79 | int  ambounce = 0;                     /* ambient bounces */
79   char  *amblist[128];                    /* ambient include/exclude list */
80   int  ambincl = -1;                      /* include == 1, exclude == 0 */
81  
82 + #ifdef MSDOS
83 + int  ralrm = 60;                        /* seconds between reports */
84 + #else
85   int  ralrm = 0;                         /* seconds between reports */
86 + #endif
87  
88 < double  pctdone = 0.0;                  /* percentage done */
88 > double  pctdone = 0.0;                  /* percentage done */
89  
90 < long  tlastrept = 0L;                   /* time at last report */
90 > time_t  tlastrept = 0L;                 /* time at last report */
91  
92 < extern long  time();
69 < extern long  tstart;                    /* starting time */
92 > extern time_t  tstart;                  /* starting time */
93  
94 < extern long  nrays;                     /* number of rays traced */
94 > extern unsigned long  nrays;            /* number of rays traced */
95  
96 < #define  MAXDIV         15              /* maximum sample size */
96 > #define  MAXDIV         16              /* maximum sample size */
97  
98 < #define  pixjitter()    (.5+dstrpix*(.5-frandom()))
98 > #define  pixjitter()    (.5+dstrpix*(.5-frandom()))
99  
100 < double  pixvalue();
100 > static int  hres, vres;                 /* resolution for this frame */
101  
102 + extern char  *mktemp();
103  
104 + double  pixvalue();
105 +
106 + #ifdef NIX
107 + #define  file_exists(f) (access(f,F_OK)==0)
108 + #else
109 + #include  <sys/types.h>
110 + #include  <sys/stat.h>
111 + int
112 + file_exists(fname)                              /* ordinary file exists? */
113 + char  *fname;
114 + {
115 +        struct stat  sbuf;
116 +        if (stat(fname, &sbuf) < 0) return(0);
117 +        return((sbuf.st_mode & S_IFREG) != 0);
118 + }
119 + #endif
120 +
121 +
122   quit(code)                      /* quit program */
123   int  code;
124   {
125 <        if (code || ralrm > 0)          /* report status */
125 >        if (code)                       /* report status */
126                  report();
127 <
127 >        headclean();                    /* delete header file */
128 >        pfclean();                      /* clean up persist files */
129          exit(code);
130   }
131  
132  
133 < #ifdef BSD
133 > #ifndef NIX
134   report()                /* report progress */
135   {
136 +        double  u, s;
137 + #ifdef BSD
138 +        char  hostname[257];
139          struct rusage  rubuf;
140 <        double  t;
140 > #else
141 >        struct tms  tbuf;
142 >        struct utsname  nambuf;
143 >        double  period;
144 > #define hostname  nambuf.sysname
145 > #endif
146  
147 +        tlastrept = time((time_t *)NULL);
148 + #ifdef BSD
149          getrusage(RUSAGE_SELF, &rubuf);
150 <        t = (rubuf.ru_utime.tv_usec + rubuf.ru_stime.tv_usec) / 1e6;
151 <        t += rubuf.ru_utime.tv_sec + rubuf.ru_stime.tv_sec;
150 >        u = rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec/1e6;
151 >        s = rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec/1e6;
152          getrusage(RUSAGE_CHILDREN, &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 >        gethostname(hostname, sizeof(hostname));
156 > #else
157 >        times(&tbuf);
158 >        period = 1.0 / sysconf(_SC_CLK_TCK);
159 >        u = ( tbuf.tms_utime + tbuf.tms_cutime ) * period;
160 >        s = ( tbuf.tms_stime + tbuf.tms_cstime ) * period;
161 >        uname(&nambuf);
162 > #endif
163  
164 <        sprintf(errmsg, "%ld rays, %4.2f%% done after %5.4f CPU hours\n",
165 <                        nrays, pctdone, t/3600.0);
164 >        sprintf(errmsg,
165 >                "%lu rays, %4.2f%% after %.3fu %.3fs %.3fr hours on %s\n",
166 >                        nrays, pctdone, u/3600., s/3600.,
167 >                        (tlastrept-tstart)/3600., hostname);
168          eputs(errmsg);
169 <        tlastrept = time((long *)0);
169 > #undef hostname
170   }
171   #else
172   report()                /* report progress */
173   {
174 <        signal(SIGALRM, report);
175 <        tlastrept = time((long *)0);
113 <        sprintf(errmsg, "%ld rays, %4.2f%% done after %5.4f hours\n",
174 >        tlastrept = time((time_t *)NULL);
175 >        sprintf(errmsg, "%lu rays, %4.2f%% after %5.4f hours\n",
176                          nrays, pctdone, (tlastrept-tstart)/3600.0);
177          eputs(errmsg);
178 +        signal(SIGCONT, report);
179   }
180   #endif
181  
182  
183 + rpict(seq, pout, zout, prvr)                    /* generate image(s) */
184 + int  seq;
185 + char  *pout, *zout, *prvr;
186 + /*
187 + * If seq is greater than zero, then we will render a sequence of
188 + * images based on view parameter strings read from the standard input.
189 + * If pout is NULL, then all images will be sent to the standard ouput.
190 + * If seq is greater than zero and prvr is an integer, then it is the
191 + * frame number at which rendering should begin.  Preceeding view parameter
192 + * strings will be skipped in the input.
193 + * If pout and prvr are the same, prvr is renamed to avoid overwriting.
194 + * Note that pout and zout should contain %d format specifications for
195 + * sequenced file naming.
196 + */
197 + {
198 +        extern char  *rindex(), *strncpy(), *strcat(), *strcpy();
199 +        char  fbuf[128], fbuf2[128];
200 +        int  npicts;
201 +        register char  *cp;
202 +        RESOLU  rs;
203 +        double  pa;
204 +                                        /* check sampling */
205 +        if (psample < 1)
206 +                psample = 1;
207 +        else if (psample > MAXDIV) {
208 +                sprintf(errmsg, "pixel sampling reduced from %d to %d",
209 +                                psample, MAXDIV);
210 +                error(WARNING, errmsg);
211 +                psample = MAXDIV;
212 +        }
213 +                                        /* get starting frame */
214 +        if (seq <= 0)
215 +                seq = 0;
216 +        else if (prvr != NULL && isint(prvr)) {
217 +                register int  rn;               /* skip to specified view */
218 +                if ((rn = atoi(prvr)) < seq)
219 +                        error(USER, "recover frame less than start frame");
220 +                if (pout == NULL)
221 +                        error(USER, "missing output file specification");
222 +                for ( ; seq < rn; seq++)
223 +                        if (nextview(stdin) == EOF)
224 +                                error(USER, "unexpected EOF on view input");
225 +                prvr = fbuf;                    /* mark for renaming */
226 +        }
227 +        if (pout != NULL & prvr != NULL) {
228 +                sprintf(fbuf, pout, seq);
229 +                if (!strcmp(prvr, fbuf)) {      /* rename */
230 +                        strcpy(fbuf2, fbuf);
231 +                        for (cp = fbuf2; *cp; cp++)
232 +                                ;
233 +                        while (cp > fbuf2 && !ISDIRSEP(cp[-1]))
234 +                                cp--;
235 +                        strcpy(cp, RFTEMPLATE);
236 +                        prvr = mktemp(fbuf2);
237 +                        if (rename(fbuf, prvr) < 0)
238 +                                if (errno == ENOENT) {  /* ghost file */
239 +                                        sprintf(errmsg,
240 +                                                "new output file \"%s\"",
241 +                                                fbuf);
242 +                                        error(WARNING, errmsg);
243 +                                        prvr = NULL;
244 +                                } else {                /* serious error */
245 +                                        sprintf(errmsg,
246 +                                        "cannot rename \"%s\" to \"%s\"",
247 +                                                fbuf, prvr);
248 +                                        error(SYSTEM, errmsg);
249 +                                }
250 +                }
251 +        }
252 +        npicts = 0;                     /* render sequence */
253 +        do {
254 +                if (seq && nextview(stdin) == EOF)
255 +                        break;
256 +                pctdone = 0.0;
257 +                if (pout != NULL) {
258 +                        sprintf(fbuf, pout, seq);
259 +                        if (file_exists(fbuf)) {
260 +                                if (prvr != NULL || !strcmp(fbuf, pout)) {
261 +                                        sprintf(errmsg,
262 +                                                "output file \"%s\" exists",
263 +                                                fbuf);
264 +                                        error(USER, errmsg);
265 +                                }
266 +                                continue;               /* don't clobber */
267 +                        }
268 +                        if (freopen(fbuf, "w", stdout) == NULL) {
269 +                                sprintf(errmsg,
270 +                                        "cannot open output file \"%s\"", fbuf);
271 +                                error(SYSTEM, errmsg);
272 +                        }
273 + #ifdef MSDOS
274 +                        setmode(fileno(stdout), O_BINARY);
275 + #endif
276 +                        dupheader();
277 +                }
278 +                hres = hresolu; vres = vresolu; pa = pixaspect;
279 +                if (prvr != NULL)
280 +                        if (viewfile(prvr, &ourview, &rs) <= 0
281 +                                        || rs.or != PIXSTANDARD) {
282 +                                sprintf(errmsg,
283 +                        "cannot recover view parameters from \"%s\"", prvr);
284 +                                error(WARNING, errmsg);
285 +                        } else {
286 +                                pa = 0.0;
287 +                                hres = scanlen(&rs);
288 +                                vres = numscans(&rs);
289 +                        }
290 +                if ((cp = setview(&ourview)) != NULL)
291 +                        error(USER, cp);
292 +                normaspect(viewaspect(&ourview), &pa, &hres, &vres);
293 +                if (seq) {
294 +                        if (ralrm > 0) {
295 +                                fprintf(stderr, "FRAME %d:", seq);
296 +                                fprintview(&ourview, stderr);
297 +                                putc('\n', stderr);
298 +                                fflush(stderr);
299 +                        }
300 +                        printf("FRAME=%d\n", seq);
301 +                }
302 +                fputs(VIEWSTR, stdout);
303 +                fprintview(&ourview, stdout);
304 +                putchar('\n');
305 +                if (pa < .99 || pa > 1.01)
306 +                        fputaspect(pa, stdout);
307 +                fputformat(COLRFMT, stdout);
308 +                putchar('\n');
309 +                if (zout != NULL)
310 +                        sprintf(cp=fbuf, zout, seq);
311 +                else
312 +                        cp = NULL;
313 +                render(cp, prvr);
314 +                prvr = NULL;
315 +                npicts++;
316 +        } while (seq++);
317 +                                        /* check that we did something */
318 +        if (npicts == 0)
319 +                error(WARNING, "no output produced");
320 + }
321 +
322 +
323 + nextview(fp)                            /* get next view from fp */
324 + FILE  *fp;
325 + {
326 +        char  linebuf[256];
327 +
328 +        while (fgets(linebuf, sizeof(linebuf), fp) != NULL)
329 +                if (isview(linebuf) && sscanview(&ourview, linebuf) > 0)
330 +                        return(0);
331 +        return(EOF);
332 + }      
333 +
334 +
335   render(zfile, oldfile)                          /* render the scene */
336   char  *zfile, *oldfile;
337   {
338          extern long  lseek();
339          COLOR  *scanbar[MAXDIV+1];      /* scanline arrays of pixel values */
340          float  *zbar[MAXDIV+1];         /* z values */
341 +        char  *sampdens;                /* previous sample density */
342          int  ypos;                      /* current scanline */
343          int  ystep;                     /* current y step size */
344          int  hstep;                     /* h step size */
# Line 130 | Line 346 | char  *zfile, *oldfile;
346          COLOR  *colptr;
347          float  *zptr;
348          register int  i;
133                                        /* check sampling */
134        if (psample < 1)
135                psample = 1;
136        else if (psample > MAXDIV) {
137                sprintf(errmsg, "pixel sampling reduced from %d to %d",
138                                psample, MAXDIV);
139                error(WARNING, errmsg);
140                psample = MAXDIV;
141        }
349                                          /* allocate scanlines */
350          for (i = 0; i <= psample; i++) {
351 <                scanbar[i] = (COLOR *)malloc(hresolu*sizeof(COLOR));
351 >                scanbar[i] = (COLOR *)malloc(hres*sizeof(COLOR));
352                  if (scanbar[i] == NULL)
353                          goto memerr;
354          }
355 <                                        /* open z file */
355 >        hstep = (psample*140+49)/99;            /* quincunx sampling */
356 >        ystep = (psample*99+70)/140;
357 >        if (hstep > 2) {
358 >                i = hres/hstep + 2;
359 >                if ((sampdens = malloc(i)) == NULL)
360 >                        goto memerr;
361 >                while (i--)
362 >                        sampdens[i] = hstep;
363 >        } else
364 >                sampdens = NULL;
365 >                                        /* open z-file */
366          if (zfile != NULL) {
367                  if ((zfd = open(zfile, O_WRONLY|O_CREAT, 0666)) == -1) {
368 <                        sprintf(errmsg, "cannot open z file \"%s\"", zfile);
368 >                        sprintf(errmsg, "cannot open z-file \"%s\"", zfile);
369                          error(SYSTEM, errmsg);
370                  }
371 + #ifdef MSDOS
372 +                setmode(zfd, O_BINARY);
373 + #endif
374                  for (i = 0; i <= psample; i++) {
375 <                        zbar[i] = (float *)malloc(hresolu*sizeof(float));
375 >                        zbar[i] = (float *)malloc(hres*sizeof(float));
376                          if (zbar[i] == NULL)
377                                  goto memerr;
378                  }
# Line 162 | Line 382 | char  *zfile, *oldfile;
382                          zbar[i] = NULL;
383          }
384                                          /* write out boundaries */
385 <        fprtresolu(hresolu, vresolu, stdout);
385 >        fprtresolu(hres, vres, stdout);
386                                          /* recover file and compute first */
387          i = salvage(oldfile);
388          if (zfd != -1 && i > 0 &&
389 <                        lseek(zfd, (long)i*hresolu*sizeof(float), 0) == -1)
390 <                error(SYSTEM, "z file seek error in render");
391 <        pctdone = 100.0*i/vresolu;
389 >                        lseek(zfd, (long)i*hres*sizeof(float), 0) == -1)
390 >                error(SYSTEM, "z-file seek error in render");
391 >        pctdone = 100.0*i/vres;
392          if (ralrm > 0)                  /* report init stats */
393                  report();
394 < #ifndef  BSD
394 > #ifndef  BSD
395          else
396   #endif
397 <        signal(SIGALRM, report);
398 <        ypos = vresolu-1 - i;
399 <        hstep = (psample*140+49)/99;            /* quincunx sampling */
180 <        ystep = (psample*99+70)/140;
181 <        fillscanline(scanbar[0], zbar[0], hresolu, ypos, hstep);
397 >        signal(SIGCONT, report);
398 >        ypos = vres-1 - i;
399 >        fillscanline(scanbar[0], zbar[0], sampdens, hres, ypos, hstep);
400                                                  /* compute scanlines */
401          for (ypos -= ystep; ypos > -ystep; ypos -= ystep) {
402                                                          /* bottom adjust? */
# Line 193 | Line 411 | char  *zfile, *oldfile;
411                  zbar[ystep] = zbar[0];
412                  zbar[0] = zptr;
413                                                          /* fill base line */
414 <                fillscanline(scanbar[0], zbar[0], hresolu, ypos, hstep);
414 >                fillscanline(scanbar[0], zbar[0], sampdens,
415 >                                hres, ypos, hstep);
416                                                          /* fill bar */
417 <                fillscanbar(scanbar, zbar, hresolu, ypos, ystep);
417 >                fillscanbar(scanbar, zbar, hres, ypos, ystep);
418                                                          /* write it out */
419 < #ifndef  BSD
420 <                signal(SIGALRM, SIG_IGN);       /* don't interrupt writes */
419 > #ifndef  BSD
420 >                signal(SIGCONT, SIG_IGN);       /* don't interrupt writes */
421   #endif
422                  for (i = ystep; i > 0; i--) {
423                          if (zfd != -1 && write(zfd, (char *)zbar[i],
424 <                                        hresolu*sizeof(float))
425 <                                        < hresolu*sizeof(float))
424 >                                        hres*sizeof(float))
425 >                                        < hres*sizeof(float))
426                                  goto writerr;
427 <                        if (fwritescan(scanbar[i], hresolu, stdout) < 0)
427 >                        if (fwritescan(scanbar[i], hres, stdout) < 0)
428                                  goto writerr;
429                  }
430                  if (fflush(stdout) == EOF)
431                          goto writerr;
432                                                          /* record progress */
433 <                pctdone = 100.0*(vresolu-1-ypos)/vresolu;
434 <                if (ralrm > 0 && time((long *)0) >= tlastrept+ralrm)
433 >                pctdone = 100.0*(vres-1-ypos)/vres;
434 >                if (ralrm > 0 && time((time_t *)NULL) >= tlastrept+ralrm)
435                          report();
436 < #ifndef  BSD
436 > #ifndef  BSD
437                  else
438 <                        signal(SIGALRM, report);
438 >                        signal(SIGCONT, report);
439   #endif
440          }
441                                                  /* clean up */
442 +        signal(SIGCONT, SIG_IGN);
443          if (zfd != -1) {
444 <                if (write(zfd, (char *)zbar[0], hresolu*sizeof(float))
445 <                                < hresolu*sizeof(float))
444 >                if (write(zfd, (char *)zbar[0], hres*sizeof(float))
445 >                                < hres*sizeof(float))
446                          goto writerr;
447                  if (close(zfd) == -1)
448                          goto writerr;
449                  for (i = 0; i <= psample; i++)
450                          free((char *)zbar[i]);
451          }
452 <        fwritescan(scanbar[0], hresolu, stdout);
452 >        fwritescan(scanbar[0], hres, stdout);
453          if (fflush(stdout) == EOF)
454                  goto writerr;
455          for (i = 0; i <= psample; i++)
456                  free((char *)scanbar[i]);
457 +        if (sampdens != NULL)
458 +                free(sampdens);
459          pctdone = 100.0;
460 +        if (ralrm > 0)
461 +                report();
462 +        signal(SIGCONT, SIG_DFL);
463          return;
464   writerr:
465          error(SYSTEM, "write error in render");
# Line 243 | Line 468 | memerr:
468   }
469  
470  
471 < fillscanline(scanline, zline, xres, y, xstep)   /* fill scan line at y */
472 < register COLOR  *scanline;
473 < register float  *zline;
471 > fillscanline(scanline, zline, sd, xres, y, xstep)       /* fill scan at y */
472 > register COLOR  *scanline;
473 > register float  *zline;
474 > register char  *sd;
475   int  xres, y, xstep;
476   {
477          static int  nc = 0;             /* number of calls */
478 <        int  b = xstep;
479 <        double  z;
478 >        int  bl = xstep, b = xstep;
479 >        double  z;
480          register int  i;
481          
482          z = pixvalue(scanline[0], 0, y);
483          if (zline) zline[0] = z;
484                                  /* zig-zag start for quincunx pattern */
485 <        for (i = nc++ & 1 ? xstep/2 : xstep; i < xres-1+xstep; i += xstep) {
485 >        for (i = ++nc & 1 ? xstep : xstep/2; i < xres-1+xstep; i += xstep) {
486                  if (i >= xres) {
487                          xstep += xres-1-i;
488                          i = xres-1;
489                  }
490                  z = pixvalue(scanline[i], i, y);
491                  if (zline) zline[i] = z;
492 <                
493 <                b = fillsample(scanline+i-xstep, zline ? zline+i-xstep : NULL,
494 <                                i-xstep, y, xstep, 0, b/2);
492 >                if (sd) b = sd[0] > sd[1] ? sd[0] : sd[1];
493 >                if (i <= xstep)
494 >                        b = fillsample(scanline, zline, 0, y, i, 0, b/2);
495 >                else
496 >                        b = fillsample(scanline+i-xstep,
497 >                                        zline ? zline+i-xstep : NULL,
498 >                                        i-xstep, y, xstep, 0, b/2);
499 >                if (sd) *sd++ = nc & 1 ? bl : b;
500 >                bl = b;
501          }
502 +        if (sd && nc & 1) *sd = bl;
503   }
504  
505  
506   fillscanbar(scanbar, zbar, xres, y, ysize)      /* fill interior */
507 < register COLOR  *scanbar[];
508 < register float  *zbar[];
507 > register COLOR  *scanbar[];
508 > register float  *zbar[];
509   int  xres, y, ysize;
510   {
511          COLOR  vline[MAXDIV+1];
# Line 302 | Line 535 | int  xres, y, ysize;
535  
536  
537   int
538 < fillsample(colline, zline, x, y, xlen, ylen, b) /* fill interior points */
539 < register COLOR  *colline;
540 < register float  *zline;
538 > fillsample(colline, zline, x, y, xlen, ylen, b) /* fill interior points */
539 > register COLOR  *colline;
540 > register float  *zline;
541   int  x, y;
542   int  xlen, ylen;
543   int  b;
544   {
545 <        extern double  fabs();
546 <        double  ratio;
314 <        double  z;
545 >        double  ratio;
546 >        double  z;
547          COLOR  ctmp;
548          int  ncut;
549          register int  len;
# Line 364 | Line 596 | int  x, y;                     /* pixel position */
596          static RAY  thisray;
597  
598          if (viewray(thisray.rorg, thisray.rdir, &ourview,
599 <                        (x+pixjitter())/hresolu, (y+pixjitter())/vresolu) < 0) {
599 >                        (x+pixjitter())/hres, (y+pixjitter())/vres) < 0) {
600                  setcolor(col, 0.0, 0.0, 0.0);
601                  return(0.0);
602          }
603  
604          rayorigin(&thisray, NULL, PRIMARY, 1.0);
605  
606 <        samplendx = pixnumber(x,y,hresolu,vresolu);     /* set pixel index */
606 >        samplendx = pixnumber(x,y,hres,vres);   /* set pixel index */
607  
608          rayvalue(&thisray);                     /* trace ray */
609  
# Line 397 | Line 629 | char  *oldfile;
629                  error(WARNING, errmsg);
630                  return(0);
631          }
632 + #ifdef MSDOS
633 +        setmode(fileno(fp), O_BINARY);
634 + #endif
635                                  /* discard header */
636 <        getheader(fp, NULL);
636 >        getheader(fp, NULL, NULL);
637                                  /* get picture size */
638          if (!fscnresolu(&x, &y, fp)) {
639 <                sprintf(errmsg, "bad recover file \"%s\"", oldfile);
639 >                sprintf(errmsg, "bad recover file \"%s\" - not removed",
640 >                                oldfile);
641                  error(WARNING, errmsg);
642                  fclose(fp);
643                  return(0);
644          }
645  
646 <        if (x != hresolu || y != vresolu) {
646 >        if (x != hres || y != vres) {
647                  sprintf(errmsg, "resolution mismatch in recover file \"%s\"",
648                                  oldfile);
649                  error(USER, errmsg);
650          }
651  
652 <        scanline = (COLR *)malloc(hresolu*sizeof(COLR));
652 >        scanline = (COLR *)malloc(hres*sizeof(COLR));
653          if (scanline == NULL)
654                  error(SYSTEM, "out of memory in salvage");
655 <        for (y = 0; y < vresolu; y++) {
656 <                if (freadcolrs(scanline, hresolu, fp) < 0)
655 >        for (y = 0; y < vres; y++) {
656 >                if (freadcolrs(scanline, hres, fp) < 0)
657                          break;
658 <                if (fwritecolrs(scanline, hresolu, stdout) < 0)
658 >                if (fwritecolrs(scanline, hres, stdout) < 0)
659                          goto writerr;
660          }
661          if (fflush(stdout) == EOF)
# Line 429 | Line 665 | char  *oldfile;
665          unlink(oldfile);
666          return(y);
667   writerr:
668 <        error(SYSTEM, "write error in salvage");
668 >        sprintf(errmsg, "write error during recovery of \"%s\"", oldfile);
669 >        error(SYSTEM, errmsg);
670   }
671  
672  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines