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.15 by greg, Fri Jan 12 09:27:11 1990 UTC vs.
Revision 1.23 by greg, Thu Nov 1 12:06: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          int  ystep;                     /* current y step size */
109 <        FILE  *zfp;
109 >        int  zfd;
110          COLOR  *colptr;
111          float  *zptr;
112          register int  i;
# Line 121 | 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 131 | 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 139 | 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 && i > 0 &&
145 >                        lseek(zfd, (long)i*hresolu*sizeof(float), 0) == -1)
146                  error(SYSTEM, "z file seek error in render");
147          ypos = vresolu-1 - i;
148          fillscanline(scanbar[0], zbar[0], hresolu, ypos, psample);
# Line 147 | Line 150 | char  *zfile, *oldfile;
150                                                  /* compute scanlines */
151          for (ypos -= ystep; ypos > -ystep; ypos -= ystep) {
152                                                          /* record progress */
153 <                pctdone = 100.0*(vresolu-ypos-ystep)/vresolu;
153 >                pctdone = 100.0*(vresolu-1-ypos-ystep)/vresolu;
154                                                          /* bottom adjust? */
155                  if (ypos < 0) {
156                          ystep += ypos;
# Line 165 | Line 168 | char  *zfile, *oldfile;
168                  fillscanbar(scanbar, zbar, hresolu, ypos, ystep);
169                                                          /* write it out */
170                  for (i = ystep; i > 0; i--) {
171 <                        if (zfp != NULL && fwrite(zbar[i],sizeof(float),hresolu,zfp) != hresolu)
171 >                        if (zfd != -1 && write(zfd, (char *)zbar[i],
172 >                                        hresolu*sizeof(float))
173 >                                        < hresolu*sizeof(float))
174                                  goto writerr;
175 <                        if (fwritescan(scanbar[i],hresolu,stdout) < 0)
175 >                        if (fwritescan(scanbar[i], hresolu, stdout) < 0)
176                                  goto writerr;
177                  }
173                if (zfp != NULL && fflush(zfp) == EOF)
174                        goto writerr;
178                  if (fflush(stdout) == EOF)
179                          goto writerr;
180          }
181                                                  /* clean up */
182 <        if (zfp != NULL) {
183 <                fwrite(zbar[0], sizeof(float), hresolu, zfp);
184 <                if (fclose(zfp) == EOF)
182 >        if (zfd != -1) {
183 >                if (write(zfd, (char *)zbar[0], hresolu*sizeof(float))
184 >                                < hresolu*sizeof(float))
185                          goto writerr;
186 +                if (close(zfd) == -1)
187 +                        goto writerr;
188                  for (i = 0; i <= psample; i++)
189                          free((char *)zbar[i]);
190          }
# Line 231 | Line 236 | int  xres, y, ysize;
236          COLOR  vline[MAXDIV+1];
237          float  zline[MAXDIV+1];
238          int  b = ysize;
234        double  z;
239          register int  i, j;
240          
241          for (i = 0; i < xres; i++) {
# Line 317 | Line 321 | int  x, y;                     /* pixel position */
321   {
322          static RAY  thisray;    /* our ray for this pixel */
323  
324 <        viewray(thisray.rorg, thisray.rdir, &ourview,
325 <                        (x+pixjitter())/hresolu, (y+pixjitter())/vresolu);
324 >        if (viewray(thisray.rorg, thisray.rdir, &ourview,
325 >                        (x+pixjitter())/hresolu, (y+pixjitter())/vresolu) < 0) {
326 >                setcolor(col, 0.0, 0.0, 0.0);
327 >                return(0.0);
328 >        }
329  
330          rayorigin(&thisray, NULL, PRIMARY, 1.0);
331          
# Line 326 | Line 333 | int  x, y;                     /* pixel position */
333  
334          copycolor(col, thisray.rcol);           /* return color */
335          
336 <        return(thisray.rot);                    /* return distance */
336 >        return(thisray.rt);                     /* return distance */
337   }
338  
339  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines