--- ray/src/px/pinterp.c 1990/01/08 14:47:15 1.17 +++ ray/src/px/pinterp.c 1990/01/17 15:12:37 1.21 @@ -10,10 +10,16 @@ static char SCCSid[] = "$SunId$ LBL"; #include "standard.h" +#include + #include "view.h" #include "color.h" +#ifndef BSD +#define vfork fork +#endif + #define pscan(y) (ourpict+(y)*hresolu) #define zscan(y) (ourzbuf+(y)*hresolu) @@ -31,6 +37,7 @@ struct position {int x,y; float z;}; VIEW ourview = STDVIEW; /* desired view */ int hresolu = 512; /* horizontal resolution */ int vresolu = 512; /* vertical resolution */ +double pixaspect = 1.0; /* pixel aspect ratio */ double zeps = .02; /* allowed z epsilon */ @@ -138,11 +145,15 @@ char *argv[]; check(2,1); vresolu = atoi(argv[++i]); break; + case 'p': /* pixel aspect */ + check(2,1); + pixaspect = atof(argv[++i]); + break; case 'v': /* view file */ if (argv[i][2] != 'f') goto badopt; check(3,1); - gotvfile = viewfile(argv[++i], &ourview); + gotvfile = viewfile(argv[++i], &ourview, 0, 0); if (gotvfile < 0) { perror(argv[i]); exit(1); @@ -167,6 +178,7 @@ char *argv[]; fprintf(stderr, "%s: %s\n", progname, err); exit(1); } + normaspect(viewaspect(&ourview), &pixaspect, &hresolu, &vresolu); /* allocate frame */ ourpict = (COLR *)malloc(hresolu*vresolu*sizeof(COLR)); ourzbuf = (float *)calloc(hresolu*vresolu,sizeof(float)); @@ -189,7 +201,9 @@ char *argv[]; fprintview(&ourview, stdout); printf("\n"); } - if (ourexp > 0 && ourexp != 1.0) + if (pixaspect < .99 || pixaspect > 1.01) + fputaspect(pixaspect, stdout); + if (ourexp > 0 && (ourexp < .995 || ourexp > 1.005)) fputexpos(ourexp, stdout); printf("\n"); /* write picture */ @@ -233,7 +247,8 @@ addpicture(pfile, zspec) /* add picture to output */ char *pfile, *zspec; { extern double atof(); - FILE *pfp, *zfp; + FILE *pfp; + int zfd; char *err; COLR *scanin; float *zin; @@ -271,7 +286,7 @@ char *pfile, *zspec; if (scanin == NULL || zin == NULL || plast == NULL) syserror(); /* get z specification or file */ - if ((zfp = fopen(zspec, "r")) == NULL) { + if ((zfd = open(zspec, O_RDONLY)) == -1) { double zvalue; register int x; if (!isfloat(zspec) || (zvalue = atof(zspec)) <= 0.0) { @@ -287,8 +302,8 @@ char *pfile, *zspec; fprintf(stderr, "%s: read error\n", pfile); exit(1); } - if (zfp != NULL - && fread(zin,sizeof(float),thresolu,zfp) < thresolu) { + if (zfd != -1 && read(zfd,zin,thresolu*sizeof(float)) + < thresolu*sizeof(float)) { fprintf(stderr, "%s: read error\n", zspec); exit(1); } @@ -299,8 +314,8 @@ char *pfile, *zspec; free((char *)zin); free((char *)plast); fclose(pfp); - if (zfp != NULL) - fclose(zfp); + if (zfd != -1) + close(zfd); } @@ -351,6 +366,7 @@ struct position *lasty; /* input/output */ struct position lastx, newpos; register int x; + lastx.z = 0; for (x = thresolu-1; x >= 0; x--) { pos[0] = (x+.5)/thresolu + theirview.hoff - .5; pos[1] = (y+.5)/tvresolu + theirview.voff - .5; @@ -552,11 +568,11 @@ char *fname; { extern double sqrt(); int donorm = normdist && ourview.type == VT_PER; - FILE *fp; + int fd; int y; float *zout; - if ((fp = fopen(fname, "w")) == NULL) { + if ((fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1) { perror(fname); exit(1); } @@ -576,14 +592,15 @@ char *fname; } } else zout = zscan(y); - if (fwrite(zout, sizeof(float), hresolu, fp) < hresolu) { + if (write(fd, zout, hresolu*sizeof(float)) + < hresolu*sizeof(float)) { perror(fname); exit(1); } } if (donorm) free((char *)zout); - fclose(fp); + close(fd); }