--- ray/src/px/pinterp.c 1990/12/21 17:20:07 1.31 +++ ray/src/px/pinterp.c 1991/11/12 16:04:39 2.1 @@ -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 */ @@ -211,6 +216,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 +239,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); @@ -270,10 +282,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 +298,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 +312,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 +392,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 */ @@ -465,6 +477,8 @@ FVECT pos; { FVECT pt, direc; + if (pos[2] <= 0) /* empty pixel */ + return(-1); if (hasmatrix) { pos[0] += theirview.hoff - .5; pos[1] += theirview.voff - .5; @@ -492,7 +506,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); @@ -610,7 +624,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();