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 1.19 by greg, Thu Mar 1 08:19:01 1990 UTC

# Line 18 | Line 18 | static char SCCSid[] = "$SunId$ LBL";
18   #else
19   #include  <signal.h>
20   #endif
21 + #include  <fcntl.h>
22  
23   #include  "view.h"
24  
# Line 100 | Line 101 | report()               /* report progress */
101   render(zfile, oldfile)                          /* render the scene */
102   char  *zfile, *oldfile;
103   {
104 +        extern long  lseek();
105          COLOR  *scanbar[MAXDIV+1];      /* scanline arrays of pixel values */
106          float  *zbar[MAXDIV+1];         /* z values */
107          int  ypos;                      /* current scanline */
108 <        FILE  *zfp;
108 >        int  ystep;                     /* current y step size */
109 >        int  zfd;
110          COLOR  *colptr;
111          float  *zptr;
112          register int  i;
# Line 120 | Line 123 | char  *zfile, *oldfile;
123          }
124                                          /* open z file */
125          if (zfile != NULL) {
126 <                if ((zfp = fopen(zfile, "a+")) == NULL) {
126 >                if ((zfd = open(zfile, O_WRONLY|O_CREAT, 0666)) == -1) {
127                          sprintf(errmsg, "cannot open z file \"%s\"", zfile);
128                          error(SYSTEM, errmsg);
129                  }
# Line 130 | Line 133 | char  *zfile, *oldfile;
133                                  goto memerr;
134                  }
135          } else {
136 <                zfp = NULL;
136 >                zfd = -1;
137                  for (i = 0; i <= psample; i++)
138                          zbar[i] = NULL;
139          }
# Line 138 | Line 141 | char  *zfile, *oldfile;
141          fputresolu(YMAJOR|YDECR, hresolu, vresolu, stdout);
142                                          /* recover file and compute first */
143          i = salvage(oldfile);
144 <        if (zfp != NULL && fseek(zfp, (long)i*hresolu*sizeof(float), 0) == EOF)
144 >        if (zfd != -1 && lseek(zfd, (long)i*hresolu*sizeof(float), 0) == -1)
145                  error(SYSTEM, "z file seek error in render");
146          ypos = vresolu-1 - i;
147          fillscanline(scanbar[0], zbar[0], hresolu, ypos, psample);
148 +        ystep = psample;
149                                                  /* compute scanlines */
150 <        for (ypos -= psample; ypos >= 0; ypos -= psample) {
151 <        
152 <                pctdone = 100.0*(vresolu-ypos-psample)/vresolu;
153 <
154 <                colptr = scanbar[psample];              /* move base to top */
155 <                scanbar[psample] = scanbar[0];
150 >        for (ypos -= ystep; ypos > -ystep; ypos -= ystep) {
151 >                                                        /* record progress */
152 >                pctdone = 100.0*(vresolu-1-ypos-ystep)/vresolu;
153 >                                                        /* bottom adjust? */
154 >                if (ypos < 0) {
155 >                        ystep += ypos;
156 >                        ypos = 0;
157 >                }
158 >                colptr = scanbar[ystep];                /* move base to top */
159 >                scanbar[ystep] = scanbar[0];
160                  scanbar[0] = colptr;
161 <                zptr = zbar[psample];
162 <                zbar[psample] = zbar[0];
161 >                zptr = zbar[ystep];
162 >                zbar[ystep] = zbar[0];
163                  zbar[0] = zptr;
164                                                          /* fill base line */
165                  fillscanline(scanbar[0], zbar[0], hresolu, ypos, psample);
166                                                          /* fill bar */
167 <                fillscanbar(scanbar, zbar, hresolu, ypos, psample);
167 >                fillscanbar(scanbar, zbar, hresolu, ypos, ystep);
168                                                          /* write it out */
169 <                for (i = psample; i > 0; i--) {
170 <                        if (zfp != NULL && fwrite(zbar[i],sizeof(float),hresolu,zfp) != hresolu)
169 >                for (i = ystep; i > 0; i--) {
170 >                        if (zfd != -1 && write(zfd, (char *)zbar[i],
171 >                                        hresolu*sizeof(float))
172 >                                        < hresolu*sizeof(float))
173                                  goto writerr;
174 <                        if (fwritescan(scanbar[i],hresolu,stdout) < 0)
174 >                        if (fwritescan(scanbar[i], hresolu, stdout) < 0)
175                                  goto writerr;
176                  }
167                if (zfp != NULL && fflush(zfp) == EOF)
168                        goto writerr;
177                  if (fflush(stdout) == EOF)
178                          goto writerr;
179          }
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        }
180                                                  /* clean up */
181 <        if (zfp != NULL) {
182 <                if (fclose(zfp) == EOF)
181 >        if (zfd != -1) {
182 >                if (write(zfd, (char *)zbar[0], hresolu*sizeof(float))
183 >                                < hresolu*sizeof(float))
184                          goto writerr;
185 +                close(zfd);
186                  for (i = 0; i <= psample; i++)
187                          free((char *)zbar[i]);
188          }
189 +        fwritescan(scanbar[0], hresolu, stdout);
190          if (fflush(stdout) == EOF)
191                  goto writerr;
192          for (i = 0; i <= psample; i++)
# Line 218 | Line 212 | int  xres, y, xstep;
212          z = pixvalue(scanline[0], 0, y);
213          if (zline) zline[0] = z;
214  
215 <        for (i = xstep; i < xres; i += xstep) {
216 <        
215 >        for (i = xstep; i < xres-1+xstep; i += xstep) {
216 >                if (i >= xres) {
217 >                        xstep += xres-1-i;
218 >                        i = xres-1;
219 >                }
220                  z = pixvalue(scanline[i], i, y);
221                  if (zline) zline[i] = z;
222                  
223                  b = fillsample(scanline+i-xstep, zline ? zline+i-xstep : NULL,
224                                  i-xstep, y, xstep, 0, b/2);
228        }
229        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);
225          }
226   }
227  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines