--- ray/src/rt/rpict.c 1990/01/12 09:27:11 1.15 +++ ray/src/rt/rpict.c 1990/11/01 12:06:01 1.23 @@ -18,6 +18,7 @@ static char SCCSid[] = "$SunId$ LBL"; #else #include #endif +#include #include "view.h" @@ -100,11 +101,12 @@ report() /* report progress */ render(zfile, oldfile) /* render the scene */ char *zfile, *oldfile; { + extern long lseek(); COLOR *scanbar[MAXDIV+1]; /* scanline arrays of pixel values */ float *zbar[MAXDIV+1]; /* z values */ int ypos; /* current scanline */ int ystep; /* current y step size */ - FILE *zfp; + int zfd; COLOR *colptr; float *zptr; register int i; @@ -121,7 +123,7 @@ char *zfile, *oldfile; } /* open z file */ if (zfile != NULL) { - if ((zfp = fopen(zfile, "a+")) == NULL) { + if ((zfd = open(zfile, O_WRONLY|O_CREAT, 0666)) == -1) { sprintf(errmsg, "cannot open z file \"%s\"", zfile); error(SYSTEM, errmsg); } @@ -131,7 +133,7 @@ char *zfile, *oldfile; goto memerr; } } else { - zfp = NULL; + zfd = -1; for (i = 0; i <= psample; i++) zbar[i] = NULL; } @@ -139,7 +141,8 @@ char *zfile, *oldfile; fputresolu(YMAJOR|YDECR, hresolu, vresolu, stdout); /* recover file and compute first */ i = salvage(oldfile); - if (zfp != NULL && fseek(zfp, (long)i*hresolu*sizeof(float), 0) == EOF) + if (zfd != -1 && i > 0 && + lseek(zfd, (long)i*hresolu*sizeof(float), 0) == -1) error(SYSTEM, "z file seek error in render"); ypos = vresolu-1 - i; fillscanline(scanbar[0], zbar[0], hresolu, ypos, psample); @@ -147,7 +150,7 @@ char *zfile, *oldfile; /* compute scanlines */ for (ypos -= ystep; ypos > -ystep; ypos -= ystep) { /* record progress */ - pctdone = 100.0*(vresolu-ypos-ystep)/vresolu; + pctdone = 100.0*(vresolu-1-ypos-ystep)/vresolu; /* bottom adjust? */ if (ypos < 0) { ystep += ypos; @@ -165,21 +168,23 @@ char *zfile, *oldfile; fillscanbar(scanbar, zbar, hresolu, ypos, ystep); /* write it out */ for (i = ystep; i > 0; i--) { - if (zfp != NULL && fwrite(zbar[i],sizeof(float),hresolu,zfp) != hresolu) + if (zfd != -1 && write(zfd, (char *)zbar[i], + hresolu*sizeof(float)) + < hresolu*sizeof(float)) goto writerr; - if (fwritescan(scanbar[i],hresolu,stdout) < 0) + if (fwritescan(scanbar[i], hresolu, stdout) < 0) goto writerr; } - if (zfp != NULL && fflush(zfp) == EOF) - goto writerr; if (fflush(stdout) == EOF) goto writerr; } /* clean up */ - if (zfp != NULL) { - fwrite(zbar[0], sizeof(float), hresolu, zfp); - if (fclose(zfp) == EOF) + if (zfd != -1) { + if (write(zfd, (char *)zbar[0], hresolu*sizeof(float)) + < hresolu*sizeof(float)) goto writerr; + if (close(zfd) == -1) + goto writerr; for (i = 0; i <= psample; i++) free((char *)zbar[i]); } @@ -231,7 +236,6 @@ int xres, y, ysize; COLOR vline[MAXDIV+1]; float zline[MAXDIV+1]; int b = ysize; - double z; register int i, j; for (i = 0; i < xres; i++) { @@ -317,8 +321,11 @@ int x, y; /* pixel position */ { static RAY thisray; /* our ray for this pixel */ - viewray(thisray.rorg, thisray.rdir, &ourview, - (x+pixjitter())/hresolu, (y+pixjitter())/vresolu); + if (viewray(thisray.rorg, thisray.rdir, &ourview, + (x+pixjitter())/hresolu, (y+pixjitter())/vresolu) < 0) { + setcolor(col, 0.0, 0.0, 0.0); + return(0.0); + } rayorigin(&thisray, NULL, PRIMARY, 1.0); @@ -326,7 +333,7 @@ int x, y; /* pixel position */ copycolor(col, thisray.rcol); /* return color */ - return(thisray.rot); /* return distance */ + return(thisray.rt); /* return distance */ }