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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines