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.18 by greg, Wed Feb 21 12:39:37 1990 UTC vs.
Revision 2.26 by greg, Fri Jul 30 10:31:09 1993 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1986 Regents of the University of California */
1 > /* Copyright (c) 1992 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 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
21 #include  <fcntl.h>
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 + #define  RFTEMPLATE     "rfXXXXXX"
31 +
32 + #ifndef SIGCONT
33 + #define SIGCONT         SIGIO
34 + #endif
35 +
36 + int  dimlist[MAXDIM];                   /* sampling dimensions */
37 + int  ndims = 0;                         /* number of sampling dimensions */
38 + int  samplendx;                         /* sample index number */
39 +
40   VIEW  ourview = STDVIEW;                /* view parameters */
41   int  hresolu = 512;                     /* horizontal resolution */
42   int  vresolu = 512;                     /* vertical resolution */
43 < double  pixaspect = 1.0;                /* pixel aspect ratio */
43 > double  pixaspect = 1.0;                /* pixel aspect ratio */
44  
45   int  psample = 4;                       /* pixel sample size */
46 < double  maxdiff = .05;                  /* max. difference for interpolation */
47 < double  dstrpix = 0.67;                 /* square pixel distribution */
46 > double  maxdiff = .05;                  /* max. difference for interpolation */
47 > double  dstrpix = 0.67;                 /* square pixel distribution */
48  
49 < double  dstrsrc = 0.0;                  /* square source distribution */
50 < double  shadthresh = .05;               /* shadow threshold */
51 < double  shadcert = .5;                  /* shadow certainty */
49 > double  dstrsrc = 0.0;                  /* square source distribution */
50 > double  shadthresh = .05;               /* shadow threshold */
51 > double  shadcert = .5;                  /* shadow certainty */
52 > int  directrelay = 1;                   /* number of source relays */
53 > int  vspretest = 512;                   /* virtual source pretest density */
54 > int  directvis = 1;                     /* sources visible? */
55 > double  srcsizerat = .25;               /* maximum ratio source size/dist. */
56  
57 + double  specthresh = .15;               /* specular sampling threshold */
58 + double  specjitter = 1.;                /* specular sampling jitter */
59 +
60   int  maxdepth = 6;                      /* maximum recursion depth */
61 < double  minweight = 5e-3;               /* minimum ray weight */
61 > double  minweight = 5e-3;               /* minimum ray weight */
62  
63   COLOR  ambval = BLKCOLOR;               /* ambient value */
64 < double  ambacc = 0.2;                   /* ambient accuracy */
64 > double  ambacc = 0.2;                   /* ambient accuracy */
65   int  ambres = 32;                       /* ambient resolution */
66   int  ambdiv = 128;                      /* ambient divisions */
67   int  ambssamp = 0;                      /* ambient super-samples */
# Line 49 | Line 69 | int  ambounce = 0;                     /* ambient bounces */
69   char  *amblist[128];                    /* ambient include/exclude list */
70   int  ambincl = -1;                      /* include == 1, exclude == 0 */
71  
72 + #ifdef MSDOS
73 + int  ralrm = 60;                        /* seconds between reports */
74 + #else
75   int  ralrm = 0;                         /* seconds between reports */
76 + #endif
77  
78 < double  pctdone = 0.0;                  /* percentage done */
78 > double  pctdone = 0.0;                  /* percentage done */
79  
80 < extern long  nrays;                     /* number of rays traced */
80 > long  tlastrept = 0L;                   /* time at last report */
81  
82 < #define  MAXDIV         32              /* maximum sample size */
82 > extern long  time();
83 > extern long  tstart;                    /* starting time */
84  
85 < #define  pixjitter()    (.5+dstrpix*(.5-frandom()))
85 > extern unsigned long  nrays;            /* number of rays traced */
86  
87 < double  pixvalue();
87 > #define  MAXDIV         16              /* maximum sample size */
88  
89 + #define  pixjitter()    (.5+dstrpix*(.5-frandom()))
90  
91 + static int  hres, vres;                 /* resolution for this frame */
92 +
93 + extern char  *mktemp();
94 +
95 + double  pixvalue();
96 +
97 +
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 >        headclean();                    /* delete header file */
104 >        pfclean();                      /* clean up persist files */
105          exit(code);
106   }
107  
108  
109 + #ifdef BSD
110   report()                /* report progress */
111   {
77 #ifdef BSD
112          struct rusage  rubuf;
113 <        double  t;
113 >        double  t;
114  
115          getrusage(RUSAGE_SELF, &rubuf);
116          t = (rubuf.ru_utime.tv_usec + rubuf.ru_stime.tv_usec) / 1e6;
# Line 85 | Line 119 | report()               /* report progress */
119          t += (rubuf.ru_utime.tv_usec + rubuf.ru_stime.tv_usec) / 1e6;
120          t += rubuf.ru_utime.tv_sec + rubuf.ru_stime.tv_sec;
121  
122 <        sprintf(errmsg, "%ld rays, %4.2f%% done after %5.4f CPU hours\n",
122 >        sprintf(errmsg, "%lu rays, %4.2f%% done after %5.4f CPU hours\n",
123                          nrays, pctdone, t/3600.0);
124 +        eputs(errmsg);
125 +        tlastrept = time((long *)0);
126 + }
127   #else
128 <        signal(SIGALRM, report);
129 <        sprintf(errmsg, "%ld rays, %4.2f%% done\n", nrays, pctdone);
130 < #endif
128 > report()                /* report progress */
129 > {
130 >        tlastrept = time((long *)0);
131 >        sprintf(errmsg, "%lu rays, %4.2f%% done after %5.4f hours\n",
132 >                        nrays, pctdone, (tlastrept-tstart)/3600.0);
133          eputs(errmsg);
134 +        signal(SIGCONT, report);
135 + }
136 + #endif
137  
138 <        if (ralrm > 0)
139 <                alarm(ralrm);
138 >
139 > rpict(seq, pout, zout, prvr)                    /* generate image(s) */
140 > int  seq;
141 > char  *pout, *zout, *prvr;
142 > /*
143 > * If seq is greater than zero, then we will render a sequence of
144 > * images based on view parameter strings read from the standard input.
145 > * If pout is NULL, then all images will be sent to the standard ouput.
146 > * If seq is greater than zero and prvr is an integer, then it is the
147 > * frame number at which rendering should begin.  Preceeding view parameter
148 > * strings will be skipped in the input.
149 > * If pout and prvr are the same, prvr is renamed to avoid overwriting.
150 > * Note that pout and zout should contain %d format specifications for
151 > * sequenced file naming.
152 > */
153 > {
154 >        extern char  *rindex(), *strncpy(), *strcat(), *strcpy();
155 >        char  fbuf[128], fbuf2[128];
156 >        int  npicts;
157 >        register char  *cp;
158 >        RESOLU  rs;
159 >        double  pa;
160 >                                        /* check sampling */
161 >        if (psample < 1)
162 >                psample = 1;
163 >        else if (psample > MAXDIV) {
164 >                sprintf(errmsg, "pixel sampling reduced from %d to %d",
165 >                                psample, MAXDIV);
166 >                error(WARNING, errmsg);
167 >                psample = MAXDIV;
168 >        }
169 >                                        /* get starting frame */
170 >        if (seq <= 0)
171 >                seq = 0;
172 >        else if (prvr != NULL && isint(prvr)) {
173 >                register int  rn;               /* skip to specified view */
174 >                if ((rn = atoi(prvr)) < seq)
175 >                        error(USER, "recover frame less than start frame");
176 >                if (pout == NULL)
177 >                        error(USER, "missing output file specification");
178 >                for ( ; seq < rn; seq++)
179 >                        if (nextview(stdin) == EOF)
180 >                                error(USER, "unexpected EOF on view input");
181 >                prvr = fbuf;                    /* mark for renaming */
182 >        }
183 >        if (pout != NULL & prvr != NULL) {
184 >                sprintf(fbuf, pout, seq);
185 >                if (!strcmp(prvr, fbuf)) {      /* rename */
186 >                        strcpy(fbuf2, fbuf);
187 >                        for (cp = fbuf2; *cp; cp++)
188 >                                ;
189 >                        while (cp > fbuf2 && !ISDIRSEP(cp[-1]))
190 >                                cp--;
191 >                        strcpy(cp, RFTEMPLATE);
192 >                        prvr = mktemp(fbuf2);
193 >                        if (rename(fbuf, prvr) < 0 && errno != ENOENT) {
194 >                                sprintf(errmsg,
195 >                                        "cannot rename \"%s\" to \"%s\"",
196 >                                                fbuf, prvr);
197 >                                error(SYSTEM, errmsg);
198 >                        }
199 >                }
200 >        }
201 >        npicts = 0;                     /* render sequence */
202 >        do {
203 >                if (seq && nextview(stdin) == EOF)
204 >                        break;
205 >                pctdone = 0.0;
206 >                if (pout != NULL) {
207 >                        sprintf(fbuf, pout, seq);
208 >                        if (prvr == NULL && access(fbuf, F_OK) == 0)
209 >                                continue;               /* don't clobber */
210 >                        if (freopen(fbuf, "w", stdout) == NULL) {
211 >                                sprintf(errmsg,
212 >                                        "cannot open output file \"%s\"", fbuf);
213 >                                error(SYSTEM, errmsg);
214 >                        }
215 > #ifdef MSDOS
216 >                        setmode(fileno(stdout), O_BINARY);
217 > #endif
218 >                        dupheader();
219 >                }
220 >                hres = hresolu; vres = vresolu; pa = pixaspect;
221 >                if (prvr != NULL)
222 >                        if (viewfile(prvr, &ourview, &rs) <= 0
223 >                                        || rs.or != PIXSTANDARD) {
224 >                                sprintf(errmsg,
225 >                        "cannot recover view parameters from \"%s\"", prvr);
226 >                                error(WARNING, errmsg);
227 >                        } else {
228 >                                pa = 0.0;
229 >                                hres = scanlen(&rs);
230 >                                vres = numscans(&rs);
231 >                        }
232 >                if ((cp = setview(&ourview)) != NULL)
233 >                        error(USER, cp);
234 >                normaspect(viewaspect(&ourview), &pa, &hres, &vres);
235 >                if (seq) {
236 >                        if (ralrm > 0) {
237 >                                fprintf(stderr, "FRAME %d:", seq);
238 >                                fprintview(&ourview, stderr);
239 >                                putc('\n', stderr);
240 >                                fflush(stderr);
241 >                        }
242 >                        printf("FRAME=%d\n", seq);
243 >                }
244 >                fputs(VIEWSTR, stdout);
245 >                fprintview(&ourview, stdout);
246 >                putchar('\n');
247 >                if (pa < .99 || pa > 1.01)
248 >                        fputaspect(pa, stdout);
249 >                fputformat(COLRFMT, stdout);
250 >                putchar('\n');
251 >                if (zout != NULL)
252 >                        sprintf(cp=fbuf, zout, seq);
253 >                else
254 >                        cp = NULL;
255 >                render(cp, prvr);
256 >                prvr = NULL;
257 >                npicts++;
258 >        } while (seq++);
259 >                                        /* check that we did something */
260 >        if (npicts == 0)
261 >                error(WARNING, "no output produced");
262   }
263  
264  
265 + nextview(fp)                            /* get next view from fp */
266 + FILE  *fp;
267 + {
268 +        char  linebuf[256];
269 +
270 +        while (fgets(linebuf, sizeof(linebuf), fp) != NULL)
271 +                if (isview(linebuf) && sscanview(&ourview, linebuf) > 0)
272 +                        return(0);
273 +        return(EOF);
274 + }      
275 +
276 +
277   render(zfile, oldfile)                          /* render the scene */
278   char  *zfile, *oldfile;
279   {
280          extern long  lseek();
281          COLOR  *scanbar[MAXDIV+1];      /* scanline arrays of pixel values */
282          float  *zbar[MAXDIV+1];         /* z values */
283 +        char  *sampdens;                /* previous sample density */
284          int  ypos;                      /* current scanline */
285          int  ystep;                     /* current y step size */
286 +        int  hstep;                     /* h step size */
287          int  zfd;
288          COLOR  *colptr;
289          float  *zptr;
290          register int  i;
113                                        /* check sampling */
114        if (psample < 1)
115                psample = 1;
116        else if (psample > MAXDIV)
117                psample = MAXDIV;
291                                          /* allocate scanlines */
292          for (i = 0; i <= psample; i++) {
293 <                scanbar[i] = (COLOR *)malloc(hresolu*sizeof(COLOR));
293 >                scanbar[i] = (COLOR *)malloc(hres*sizeof(COLOR));
294                  if (scanbar[i] == NULL)
295                          goto memerr;
296          }
297 <                                        /* open z file */
297 >        hstep = (psample*140+49)/99;            /* quincunx sampling */
298 >        ystep = (psample*99+70)/140;
299 >        if (hstep > 2) {
300 >                i = hres/hstep + 2;
301 >                if ((sampdens = malloc(i)) == NULL)
302 >                        goto memerr;
303 >                while (i--)
304 >                        sampdens[i] = hstep;
305 >        } else
306 >                sampdens = NULL;
307 >                                        /* open z-file */
308          if (zfile != NULL) {
309                  if ((zfd = open(zfile, O_WRONLY|O_CREAT, 0666)) == -1) {
310 <                        sprintf(errmsg, "cannot open z file \"%s\"", zfile);
310 >                        sprintf(errmsg, "cannot open z-file \"%s\"", zfile);
311                          error(SYSTEM, errmsg);
312                  }
313 + #ifdef MSDOS
314 +                setmode(zfd, O_BINARY);
315 + #endif
316                  for (i = 0; i <= psample; i++) {
317 <                        zbar[i] = (float *)malloc(hresolu*sizeof(float));
317 >                        zbar[i] = (float *)malloc(hres*sizeof(float));
318                          if (zbar[i] == NULL)
319                                  goto memerr;
320                  }
# Line 138 | Line 324 | char  *zfile, *oldfile;
324                          zbar[i] = NULL;
325          }
326                                          /* write out boundaries */
327 <        fputresolu(YMAJOR|YDECR, hresolu, vresolu, stdout);
327 >        fprtresolu(hres, vres, stdout);
328                                          /* recover file and compute first */
329          i = salvage(oldfile);
330 <        if (zfd != -1 && lseek(zfd, (long)i*hresolu*sizeof(float), 0) == -1)
331 <                error(SYSTEM, "z file seek error in render");
332 <        ypos = vresolu-1 - i;
333 <        fillscanline(scanbar[0], zbar[0], hresolu, ypos, psample);
334 <        ystep = psample;
330 >        if (zfd != -1 && i > 0 &&
331 >                        lseek(zfd, (long)i*hres*sizeof(float), 0) == -1)
332 >                error(SYSTEM, "z-file seek error in render");
333 >        pctdone = 100.0*i/vres;
334 >        if (ralrm > 0)                  /* report init stats */
335 >                report();
336 > #ifndef  BSD
337 >        else
338 > #endif
339 >        signal(SIGCONT, report);
340 >        ypos = vres-1 - i;
341 >        fillscanline(scanbar[0], zbar[0], sampdens, hres, ypos, hstep);
342                                                  /* compute scanlines */
343          for (ypos -= ystep; ypos > -ystep; ypos -= ystep) {
151                                                        /* record progress */
152                pctdone = 100.0*(vresolu-ypos-ystep)/vresolu;
344                                                          /* bottom adjust? */
345                  if (ypos < 0) {
346                          ystep += ypos;
# Line 162 | Line 353 | char  *zfile, *oldfile;
353                  zbar[ystep] = zbar[0];
354                  zbar[0] = zptr;
355                                                          /* fill base line */
356 <                fillscanline(scanbar[0], zbar[0], hresolu, ypos, psample);
356 >                fillscanline(scanbar[0], zbar[0], sampdens,
357 >                                hres, ypos, hstep);
358                                                          /* fill bar */
359 <                fillscanbar(scanbar, zbar, hresolu, ypos, ystep);
359 >                fillscanbar(scanbar, zbar, hres, ypos, ystep);
360                                                          /* write it out */
361 + #ifndef  BSD
362 +                signal(SIGCONT, SIG_IGN);       /* don't interrupt writes */
363 + #endif
364                  for (i = ystep; i > 0; i--) {
365                          if (zfd != -1 && write(zfd, (char *)zbar[i],
366 <                                        hresolu*sizeof(float))
367 <                                        < hresolu*sizeof(float))
366 >                                        hres*sizeof(float))
367 >                                        < hres*sizeof(float))
368                                  goto writerr;
369 <                        if (fwritescan(scanbar[i], hresolu, stdout) < 0)
369 >                        if (fwritescan(scanbar[i], hres, stdout) < 0)
370                                  goto writerr;
371                  }
372                  if (fflush(stdout) == EOF)
373                          goto writerr;
374 +                                                        /* record progress */
375 +                pctdone = 100.0*(vres-1-ypos)/vres;
376 +                if (ralrm > 0 && time((long *)0) >= tlastrept+ralrm)
377 +                        report();
378 + #ifndef  BSD
379 +                else
380 +                        signal(SIGCONT, report);
381 + #endif
382          }
383                                                  /* clean up */
384 +        signal(SIGCONT, SIG_IGN);
385          if (zfd != -1) {
386 <                if (write(zfd, (char *)zbar[0], hresolu*sizeof(float))
387 <                                < hresolu*sizeof(float))
386 >                if (write(zfd, (char *)zbar[0], hres*sizeof(float))
387 >                                < hres*sizeof(float))
388                          goto writerr;
389 <                close(zfd);
389 >                if (close(zfd) == -1)
390 >                        goto writerr;
391                  for (i = 0; i <= psample; i++)
392                          free((char *)zbar[i]);
393          }
394 <        fwritescan(scanbar[0], hresolu, stdout);
394 >        fwritescan(scanbar[0], hres, stdout);
395          if (fflush(stdout) == EOF)
396                  goto writerr;
397          for (i = 0; i <= psample; i++)
398                  free((char *)scanbar[i]);
399 +        if (sampdens != NULL)
400 +                free(sampdens);
401          pctdone = 100.0;
402 +        if (ralrm > 0)
403 +                report();
404 +        signal(SIGCONT, SIG_DFL);
405          return;
406   writerr:
407          error(SYSTEM, "write error in render");
# Line 200 | Line 410 | memerr:
410   }
411  
412  
413 < fillscanline(scanline, zline, xres, y, xstep)   /* fill scan line at y */
414 < register COLOR  *scanline;
415 < register float  *zline;
413 > fillscanline(scanline, zline, sd, xres, y, xstep)       /* fill scan at y */
414 > register COLOR  *scanline;
415 > register float  *zline;
416 > register char  *sd;
417   int  xres, y, xstep;
418   {
419 <        int  b = xstep;
420 <        double  z;
419 >        static int  nc = 0;             /* number of calls */
420 >        int  bl = xstep, b = xstep;
421 >        double  z;
422          register int  i;
423          
424          z = pixvalue(scanline[0], 0, y);
425          if (zline) zline[0] = z;
426 <
427 <        for (i = xstep; i < xres-1+xstep; i += xstep) {
426 >                                /* zig-zag start for quincunx pattern */
427 >        for (i = ++nc & 1 ? xstep : xstep/2; i < xres-1+xstep; i += xstep) {
428                  if (i >= xres) {
429                          xstep += xres-1-i;
430                          i = xres-1;
431                  }
432                  z = pixvalue(scanline[i], i, y);
433                  if (zline) zline[i] = z;
434 <                
435 <                b = fillsample(scanline+i-xstep, zline ? zline+i-xstep : NULL,
436 <                                i-xstep, y, xstep, 0, b/2);
434 >                if (sd) b = sd[0] > sd[1] ? sd[0] : sd[1];
435 >                if (i <= xstep)
436 >                        b = fillsample(scanline, zline, 0, y, i, 0, b/2);
437 >                else
438 >                        b = fillsample(scanline+i-xstep,
439 >                                        zline ? zline+i-xstep : NULL,
440 >                                        i-xstep, y, xstep, 0, b/2);
441 >                if (sd) *sd++ = nc & 1 ? bl : b;
442 >                bl = b;
443          }
444 +        if (sd && nc & 1) *sd = bl;
445   }
446  
447  
448   fillscanbar(scanbar, zbar, xres, y, ysize)      /* fill interior */
449 < register COLOR  *scanbar[];
450 < register float  *zbar[];
449 > register COLOR  *scanbar[];
450 > register float  *zbar[];
451   int  xres, y, ysize;
452   {
453          COLOR  vline[MAXDIV+1];
454          float  zline[MAXDIV+1];
455          int  b = ysize;
237        double  z;
456          register int  i, j;
457          
458          for (i = 0; i < xres; i++) {
# Line 259 | Line 477 | int  xres, y, ysize;
477  
478  
479   int
480 < fillsample(colline, zline, x, y, xlen, ylen, b) /* fill interior points */
481 < register COLOR  *colline;
482 < register float  *zline;
480 > fillsample(colline, zline, x, y, xlen, ylen, b) /* fill interior points */
481 > register COLOR  *colline;
482 > register float  *zline;
483   int  x, y;
484   int  xlen, ylen;
485   int  b;
486   {
487 <        extern double  fabs();
488 <        double  ratio;
271 <        double  z;
487 >        double  ratio;
488 >        double  z;
489          COLOR  ctmp;
490          int  ncut;
491          register int  len;
# Line 318 | Line 535 | pixvalue(col, x, y)            /* compute pixel value */
535   COLOR  col;                     /* returned color */
536   int  x, y;                      /* pixel position */
537   {
538 <        static RAY  thisray;    /* our ray for this pixel */
538 >        static RAY  thisray;
539  
540 <        viewray(thisray.rorg, thisray.rdir, &ourview,
541 <                        (x+pixjitter())/hresolu, (y+pixjitter())/vresolu);
540 >        if (viewray(thisray.rorg, thisray.rdir, &ourview,
541 >                        (x+pixjitter())/hres, (y+pixjitter())/vres) < 0) {
542 >                setcolor(col, 0.0, 0.0, 0.0);
543 >                return(0.0);
544 >        }
545  
546          rayorigin(&thisray, NULL, PRIMARY, 1.0);
547 <        
547 >
548 >        samplendx = pixnumber(x,y,hres,vres);   /* set pixel index */
549 >
550          rayvalue(&thisray);                     /* trace ray */
551  
552          copycolor(col, thisray.rcol);           /* return color */
553          
554 <        return(thisray.rot);                    /* return distance */
554 >        return(thisray.rt);                     /* return distance */
555   }
556  
557  
# Line 349 | Line 571 | char  *oldfile;
571                  error(WARNING, errmsg);
572                  return(0);
573          }
574 + #ifdef MSDOS
575 +        setmode(fileno(fp), O_BINARY);
576 + #endif
577                                  /* discard header */
578 <        getheader(fp, NULL);
578 >        getheader(fp, NULL, NULL);
579                                  /* get picture size */
580 <        if (fgetresolu(&x, &y, fp) != (YMAJOR|YDECR)) {
580 >        if (!fscnresolu(&x, &y, fp)) {
581                  sprintf(errmsg, "bad recover file \"%s\"", oldfile);
582                  error(WARNING, errmsg);
583                  fclose(fp);
584                  return(0);
585          }
586  
587 <        if (x != hresolu || y != vresolu) {
587 >        if (x != hres || y != vres) {
588                  sprintf(errmsg, "resolution mismatch in recover file \"%s\"",
589                                  oldfile);
590                  error(USER, errmsg);
591          }
592  
593 <        scanline = (COLR *)malloc(hresolu*sizeof(COLR));
593 >        scanline = (COLR *)malloc(hres*sizeof(COLR));
594          if (scanline == NULL)
595                  error(SYSTEM, "out of memory in salvage");
596 <        for (y = 0; y < vresolu; y++) {
597 <                if (freadcolrs(scanline, hresolu, fp) < 0)
596 >        for (y = 0; y < vres; y++) {
597 >                if (freadcolrs(scanline, hres, fp) < 0)
598                          break;
599 <                if (fwritecolrs(scanline, hresolu, stdout) < 0)
599 >                if (fwritecolrs(scanline, hres, stdout) < 0)
600                          goto writerr;
601          }
602          if (fflush(stdout) == EOF)
# Line 381 | Line 606 | char  *oldfile;
606          unlink(oldfile);
607          return(y);
608   writerr:
609 <        error(SYSTEM, "write error in salvage");
609 >        sprintf(errmsg, "write error during recovery of \"%s\"", oldfile);
610 >        error(SYSTEM, errmsg);
611 > }
612 >
613 >
614 > int
615 > pixnumber(x, y, xres, yres)             /* compute pixel index (brushed) */
616 > register int  x, y;
617 > int  xres, yres;
618 > {
619 >        x -= y;
620 >        while (x < 0)
621 >                x += xres;
622 >        return((((x>>2)*yres + y) << 2) + (x & 3));
623   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines