--- ray/src/px/pinterp.c 1991/02/11 18:10:56 1.32 +++ ray/src/px/pinterp.c 1991/12/19 14:51:55 2.2 @@ -1,3 +1,5 @@ +/* Copyright (c) 1991 Regents of the University of California */ + #ifndef lint static char SCCSid[] = "$SunId$ LBL"; #endif @@ -16,6 +18,8 @@ static char SCCSid[] = "$SunId$ LBL"; #include "color.h" +#include "resolu.h" + #ifndef BSD #define vfork fork #endif @@ -57,7 +61,8 @@ double ourexp = -1; /* output picture exposure */ VIEW theirview = STDVIEW; /* input view */ int gotview; /* got input view? */ -int thresolu, tvresolu; /* input resolution */ +int wrongformat = 0; /* input in another format? */ +RESOLU tresolu; /* input resolution */ double theirexp; /* input picture exposure */ double theirs2ours[4][4]; /* transformation matrix */ int hasmatrix = 0; /* has transformation matrix */ @@ -73,7 +78,6 @@ int argc; char *argv[]; { #define check(olen,narg) if (argv[i][olen] || narg >= argc-i) goto badopt - extern double atof(); int gotvfile = 0; char *zfile = NULL; char *err; @@ -211,6 +215,7 @@ char *argv[]; fputaspect(pixaspect, stdout); if (ourexp > 0 && (ourexp < .995 || ourexp > 1.005)) fputexpos(ourexp, stdout); + fputformat(COLRFMT, stdout); putc('\n', stdout); /* write picture */ writepicture(); @@ -233,7 +238,13 @@ char *s; { static char *altname[] = {VIEWSTR,"rpict","rview","pinterp",NULL}; register char **an; + char fmt[32]; + if (isformat(s)) { + formatval(fmt, s); + wrongformat = strcmp(fmt, COLRFMT); + return; + } putc('\t', stdout); fputs(s, stdout); @@ -253,7 +264,6 @@ char *s; addpicture(pfile, zspec) /* add picture to output */ char *pfile, *zspec; { - extern double atof(); FILE *pfp; int zfd; char *err; @@ -270,10 +280,9 @@ char *pfile, *zspec; theirexp = 1.0; gotview = 0; printf("%s:\n", pfile); - getheader(pfp, headline); - if (!gotview || fgetresolu(&thresolu, &tvresolu, pfp) - != (YMAJOR|YDECR)) { - fprintf(stderr, "%s: picture view error\n", pfile); + getheader(pfp, headline, NULL); + if (wrongformat || !gotview || !fgetsresolu(&tresolu, pfp)) { + fprintf(stderr, "%s: picture format error\n", pfile); exit(1); } if (ourexp <= 0) @@ -287,9 +296,10 @@ char *pfile, *zspec; /* compute transformation */ hasmatrix = pixform(theirs2ours, &theirview, &ourview); /* allocate scanlines */ - scanin = (COLR *)malloc(thresolu*sizeof(COLR)); - zin = (float *)malloc(thresolu*sizeof(float)); - plast = (struct position *)calloc(thresolu, sizeof(struct position)); + scanin = (COLR *)malloc(scanlen(&tresolu)*sizeof(COLR)); + zin = (float *)malloc(scanlen(&tresolu)*sizeof(float)); + plast = (struct position *)calloc(scanlen(&tresolu), + sizeof(struct position)); if (scanin == NULL || zin == NULL || plast == NULL) syserror(); /* get z specification or file */ @@ -300,17 +310,18 @@ char *pfile, *zspec; perror(zspec); exit(1); } - for (x = 0; x < thresolu; x++) + for (x = scanlen(&tresolu); x-- > 0; ) zin[x] = zvalue; } /* load image */ - for (y = tvresolu-1; y >= 0; y--) { - if (freadcolrs(scanin, thresolu, pfp) < 0) { + for (y = 0; y < numscans(&tresolu); y++) { + if (freadcolrs(scanin, scanlen(&tresolu), pfp) < 0) { fprintf(stderr, "%s: read error\n", pfile); exit(1); } - if (zfd != -1 && read(zfd,(char *)zin,thresolu*sizeof(float)) - < thresolu*sizeof(float)) { + if (zfd != -1 && read(zfd,(char *)zin, + scanlen(&tresolu)*sizeof(float)) + < scanlen(&tresolu)*sizeof(float)) { fprintf(stderr, "%s: read error\n", zspec); exit(1); } @@ -379,9 +390,8 @@ struct position *lasty; /* input/output */ register int x; lastx.z = 0; - for (x = thresolu-1; x >= 0; x--) { - pos[0] = (x+.5)/thresolu; - pos[1] = (y+.5)/tvresolu; + for (x = scanlen(&tresolu); x-- > 0; ) { + pix2loc(pos, &tresolu, x, y); pos[2] = zline[x]; if (movepixel(pos) < 0) { lasty[x].z = lastx.z = 0; /* mark invalid */ @@ -494,7 +504,7 @@ FVECT pos; pt[0] += direc[0]*pos[2]; pt[1] += direc[1]*pos[2]; pt[2] += direc[2]*pos[2]; - viewpixel(&pos[0], &pos[1], &pos[2], &ourview, pt); + viewloc(pos, &ourview, pt); if (pos[2] <= 0) return(-1); return(0); @@ -612,7 +622,7 @@ writepicture() /* write out picture */ { int y; - fputresolu(YMAJOR|YDECR, hresolu, vresolu, stdout); + fprtresolu(hresolu, vresolu, stdout); for (y = vresolu-1; y >= 0; y--) if (fwritecolrs(pscan(y), hresolu, stdout) < 0) syserror();