--- ray/src/px/pinterp.c 2003/07/21 22:30:18 2.36 +++ ray/src/px/pinterp.c 2004/03/28 20:33:14 2.41 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: pinterp.c,v 2.36 2003/07/21 22:30:18 schorsch Exp $"; +static const char RCSid[] = "$Id: pinterp.c,v 2.41 2004/03/28 20:33:14 schorsch Exp $"; #endif /* * Interpolate and extrapolate pictures with different view parameters. @@ -12,6 +12,7 @@ static const char RCSid[] = "$Id: pinterp.c,v 2.36 200 #include #include +#include "platform.h" #include "standard.h" #include "rtprocess.h" /* Windows: must come before color.h */ #include "view.h" @@ -27,7 +28,7 @@ static const char RCSid[] = "$Id: pinterp.c,v 2.36 200 #define averaging (ourweigh != NULL) #define blurring (ourbpict != NULL) #define usematrix (hasmatrix & !averaging) -#define zisnorm (!usematrix | ourview.type != VT_PER) +#define zisnorm ((!usematrix) | (ourview.type != VT_PER)) #define MAXWT 1000. /* maximum pixel weight (averaging) */ @@ -67,8 +68,6 @@ char *progname; int fillo = F_FORE|F_BACK; /* selected fill options */ int fillsamp = 0; /* sample separation (0 == inf) */ -extern int backfill(), rcalfill(); /* fill functions */ -int (*fillfunc)() = backfill; /* selected fill function */ COLR backcolr = BLKCOLR; /* background color */ COLOR backcolor = BLKCOLOR; /* background color (float) */ double backz = 0.0; /* background z value */ @@ -91,12 +90,39 @@ unsigned short queue[PACKSIZ][2]; /* pending pixels */ int packsiz; /* actual packet size */ int queuesiz = 0; /* number of pixels pending */ -extern double movepixel(); +typedef void fillfunc_t(int x, int y); +static gethfunc headline; +static int nextview(FILE *fp); +static void compavgview(void); +static void addpicture(char *pfile, char *zspec); +static int pixform(MAT4 xfmat, VIEW *vw1, VIEW *vw2); +static void addscanline(struct bound *xl, int y, + COLR *pline, float *zline, struct position *lasty); +static void addpixel(struct position *p0, struct position *p1, + struct position *p2, COLR pix, double w, double z); +static double movepixel(FVECT pos); +static int getperim(struct bound *xl, struct bound *yl, float *zline, int zfd); +static void backpicture(fillfunc_t *fill, int samp); +static void fillpicture(fillfunc_t *fill); +static int clipaft(void); +static int addblur(void); +static void writepicture(void); +static void writedistance(char *fname); +static fillfunc_t backfill; +static fillfunc_t rcalfill; +static void calstart(char *prog, char *args); +static void caldone(void); +static void clearqueue(void); +static void syserror(char *s); -main(argc, argv) /* interpolate pictures */ -int argc; -char *argv[]; +fillfunc_t *fillfunc = backfill; /* selected fill function */ + +int +main( /* interpolate pictures */ + int argc, + char *argv[] +) { #define check(ol,al) if (argv[an][ol] || \ badarg(argc-an-1,argv+an+1,al)) \ @@ -233,7 +259,7 @@ char *argv[]; if (doavg < 0) doavg = (argc-an) > 2; if (expcomp != NULL) { - if (expcomp[0] == '+' | expcomp[0] == '-') { + if ((expcomp[0] == '+') | (expcomp[0] == '-')) { expadj = atof(expcomp) + (expcomp[0]=='+' ? .5 : -.5); if (doavg | doblur) rexpadj = pow(2.0, atof(expcomp)); @@ -259,7 +285,7 @@ char *argv[]; if (doavg) { ourspict = (COLOR *)bmalloc(hresolu*vresolu*sizeof(COLOR)); ourweigh = (float *)bmalloc(hresolu*vresolu*sizeof(float)); - if (ourspict == NULL | ourweigh == NULL) + if ((ourspict == NULL) | (ourweigh == NULL)) syserror(progname); } else { ourpict = (COLR *)bmalloc(hresolu*vresolu*sizeof(COLR)); @@ -299,13 +325,13 @@ char *argv[]; fprintview(&avgview, stdout); putc('\n', stdout); } - if (pixaspect < .99 | pixaspect > 1.01) + if ((pixaspect < .99) | (pixaspect > 1.01)) fputaspect(pixaspect, stdout); if (ourexp > 0) ourexp *= rexpadj; else ourexp = rexpadj; - if (ourexp < .995 | ourexp > 1.005) + if ((ourexp < .995) | (ourexp > 1.005)) fputexpos(ourexp, stdout); if (strcmp(ourfmt, PICFMT)) /* print format if known */ fputformat(ourfmt, stdout); @@ -326,9 +352,11 @@ userr: } -int -headline(s) /* process header string */ -char *s; +static int +headline( /* process header string */ + char *s, + void *p +) { char fmt[32]; @@ -356,8 +384,10 @@ char *s; } -nextview(fp) /* get and set next view */ -FILE *fp; +static int +nextview( /* get and set next view */ + FILE *fp +) { char linebuf[256]; char *err; @@ -394,7 +424,8 @@ FILE *fp; } -compavgview() /* compute average view */ +static void +compavgview(void) /* compute average view */ { register int i; double f; @@ -419,8 +450,11 @@ compavgview() /* compute average view */ } -addpicture(pfile, zspec) /* add picture to output */ -char *pfile, *zspec; +static void +addpicture( /* add picture to output */ + char *pfile, + char *zspec +) { FILE *pfp; int zfd; @@ -448,7 +482,7 @@ char *pfile, *zspec; ourexp = theirexp; else if (ABS(theirexp-ourexp) > .01*ourexp) fprintf(stderr, "%s: different exposure (warning)\n", pfile); - if (err = setview(&theirview)) { + if ( (err = setview(&theirview)) ) { fprintf(stderr, "%s: %s\n", pfile, err); exit(1); } @@ -482,7 +516,7 @@ char *pfile, *zspec; scanin = (COLR *)malloc(scanlen(&tresolu)*sizeof(COLR)); plast = (struct position *)calloc(scanlen(&tresolu), sizeof(struct position)); - if (scanin == NULL | plast == NULL) + if ((scanin == NULL) | (plast == NULL)) syserror(progname); /* skip to starting point */ for (y = 0; y < ylim.min; y++) @@ -491,7 +525,8 @@ char *pfile, *zspec; exit(1); } if (zfd != -1 && lseek(zfd, - (off_t)ylim.min*scanlen(&tresolu)*sizeof(float), 0) < 0) + (off_t)ylim.min*scanlen(&tresolu)*sizeof(float), + SEEK_SET) < 0) syserror(zspec); /* load image */ for (y = ylim.min; y <= ylim.max; y++) { @@ -516,15 +551,18 @@ char *pfile, *zspec; } -pixform(xfmat, vw1, vw2) /* compute view1 to view2 matrix */ -register MAT4 xfmat; -register VIEW *vw1, *vw2; +static int +pixform( /* compute view1 to view2 matrix */ + register MAT4 xfmat, + register VIEW *vw1, + register VIEW *vw2 +) { double m4t[4][4]; - if (vw1->type != VT_PER & vw1->type != VT_PAR) + if ((vw1->type != VT_PER) & (vw1->type != VT_PAR)) return(0); - if (vw2->type != VT_PER & vw2->type != VT_PAR) + if ((vw2->type != VT_PER) & (vw2->type != VT_PAR)) return(0); setident4(xfmat); xfmat[0][0] = vw1->hvec[0]; @@ -557,12 +595,14 @@ register VIEW *vw1, *vw2; } -addscanline(xl, y, pline, zline, lasty) /* add scanline to output */ -struct bound *xl; -int y; -COLR *pline; -float *zline; -struct position *lasty; /* input/output */ +static void +addscanline( /* add scanline to output */ + struct bound *xl, + int y, + COLR *pline, + float *zline, + struct position *lasty /* input/output */ +) { FVECT pos; struct position lastx, newpos; @@ -589,11 +629,15 @@ struct position *lasty; /* input/output */ } -addpixel(p0, p1, p2, pix, w, z) /* fill in pixel parallelogram */ -struct position *p0, *p1, *p2; -COLR pix; -double w; -double z; +static void +addpixel( /* fill in pixel parallelogram */ + struct position *p0, + struct position *p1, + struct position *p2, + COLR pix, + double w, + double z +) { double zt = 2.*zeps*p0->z; /* threshold */ COLOR pval; /* converted+weighted pixel */ @@ -608,7 +652,7 @@ double z; s1x = p1->x - p0->x; s1y = p1->y - p0->y; l1 = ABS(s1x); - if (p1isy = (ABS(s1y) > l1)) + if ( (p1isy = (ABS(s1y) > l1)) ) l1 = ABS(s1y); else if (l1 < 1) l1 = 1; @@ -641,10 +685,10 @@ double z; y1 = p0->y + c1*s1y/l1; for (c2 = l2; c2-- > 0; ) { x = x1 + c2*s2x/l2; - if (x < 0 | x >= hresolu) + if ((x < 0) | (x >= hresolu)) continue; y = y1 + c2*s2y/l2; - if (y < 0 | y >= vresolu) + if ((y < 0) | (y >= vresolu)) continue; if (averaging) { if (zscan(y)[x] <= 0 || zscan(y)[x]-z @@ -666,9 +710,10 @@ double z; } -double -movepixel(pos) /* reposition image point */ -register FVECT pos; +static double +movepixel( /* reposition image point */ + register FVECT pos +) { FVECT pt, tdir, odir; double d; @@ -678,7 +723,7 @@ register FVECT pos; if (usematrix) { pos[0] += theirview.hoff - .5; pos[1] += theirview.voff - .5; - if (normdist & theirview.type == VT_PER) + if (normdist & (theirview.type == VT_PER)) d = sqrt(1. + pos[0]*pos[0]*theirview.hn2 + pos[1]*pos[1]*theirview.vn2); else @@ -702,7 +747,7 @@ register FVECT pos; } else { if (viewray(pt, tdir, &theirview, pos[0], pos[1]) < -FTINY) return(0); - if (!normdist & theirview.type == VT_PER) /* adjust */ + if ((!normdist) & (theirview.type == VT_PER)) /* adjust */ pos[2] *= sqrt(1. + pos[0]*pos[0]*theirview.hn2 + pos[1]*pos[1]*theirview.vn2); pt[0] += tdir[0]*pos[2]; @@ -712,7 +757,7 @@ register FVECT pos; if (pos[2] <= 0) return(0); } - if (pos[0] < 0 | pos[0] >= 1-FTINY | pos[1] < 0 | pos[1] >= 1-FTINY) + if ((pos[0] < 0) | (pos[0] >= 1-FTINY) | (pos[1] < 0) | (pos[1] >= 1-FTINY)) return(0); if (!averaging) return(1); @@ -731,11 +776,13 @@ register FVECT pos; } -getperim(xl, yl, zline, zfd) /* compute overlapping image area */ -register struct bound *xl; -struct bound *yl; -float *zline; -int zfd; +static int +getperim( /* compute overlapping image area */ + register struct bound *xl, + struct bound *yl, + float *zline, + int zfd +) { int step; FVECT pos; @@ -759,7 +806,7 @@ int zfd; for (y = step - 1; y < numscans(&tresolu); y += step) { if (zfd != -1) { if (lseek(zfd, (off_t)y*scanlen(&tresolu)*sizeof(float), - 0) < 0) + SEEK_SET) < 0) syserror("lseek"); if (read(zfd, (char *)zline, scanlen(&tresolu)*sizeof(float)) @@ -815,9 +862,11 @@ int zfd; } -backpicture(fill, samp) /* background fill algorithm */ -int (*fill)(); -int samp; +static void +backpicture( /* background fill algorithm */ + fillfunc_t *fill, + int samp +) { int *yback, xback; int y; @@ -923,8 +972,10 @@ int samp; } -fillpicture(fill) /* paint in empty pixels using fill */ -int (*fill)(); +static void +fillpicture( /* paint in empty pixels using fill */ + fillfunc_t *fill +) { register int x, y; @@ -937,10 +988,11 @@ int (*fill)(); } -clipaft() /* perform aft clipping as indicated */ +static int +clipaft(void) /* perform aft clipping as indicated */ { register int x, y; - int adjtest = ourview.type == VT_PER & zisnorm; + int adjtest = (ourview.type == VT_PER) & zisnorm; double tstdist; double yzn2, vx; @@ -973,7 +1025,8 @@ clipaft() /* perform aft clipping as indicated */ } -addblur() /* add to blurred picture */ +static int +addblur(void) /* add to blurred picture */ { COLOR cval; double d; @@ -1013,7 +1066,8 @@ addblur() /* add to blurred picture */ } -writepicture() /* write out picture (alters buffer) */ +static void +writepicture(void) /* write out picture (alters buffer) */ { int y; register int x; @@ -1044,11 +1098,13 @@ writepicture() /* write out picture (alters buffer) } -writedistance(fname) /* write out z file (alters buffer) */ -char *fname; +static void +writedistance( /* write out z file (alters buffer) */ + char *fname +) { int donorm = normdist & !zisnorm ? 1 : - ourview.type == VT_PER & !normdist & zisnorm ? -1 : 0; + (ourview.type == VT_PER) & !normdist & zisnorm ? -1 : 0; int fd; int y; @@ -1077,8 +1133,11 @@ char *fname; } -backfill(x, y) /* fill pixel with background */ -int x, y; +static void +backfill( /* fill pixel with background */ + int x, + int y +) { if (averaging) { copycolor(sscan(y)[x], backcolor); @@ -1089,8 +1148,11 @@ int x, y; } -calstart(prog, args) /* start fill calculation */ -char *prog, *args; +static void +calstart( /* start fill calculation */ + char *prog, + char *args +) { char combuf[512]; char *argv[64]; @@ -1129,7 +1191,8 @@ char *prog, *args; } -caldone() /* done with calculation */ +static void +caldone(void) /* done with calculation */ { if (!PDesc.running) return; @@ -1138,8 +1201,11 @@ caldone() /* done with c } -rcalfill(x, y) /* fill with ray-calculated pixel */ -int x, y; +static void +rcalfill( /* fill with ray-calculated pixel */ + int x, + int y +) { if (queuesiz >= packsiz) /* flush queue if needed */ clearqueue(); @@ -1150,7 +1216,8 @@ int x, y; } -clearqueue() /* process queue */ +static void +clearqueue(void) /* process queue */ { FVECT orig, dir; float fbuf[6*(PACKSIZ+1)]; @@ -1206,8 +1273,10 @@ clearqueue() /* process queue */ } -syserror(s) /* report error and exit */ -char *s; +static void +syserror( /* report error and exit */ + char *s +) { perror(s); exit(1);