--- ray/src/px/pinterp.c 2003/10/20 16:01:55 2.38 +++ ray/src/px/pinterp.c 2013/03/24 19:00:33 2.44 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: pinterp.c,v 2.38 2003/10/20 16:01:55 greg Exp $"; +static const char RCSid[] = "$Id: pinterp.c,v 2.44 2013/03/24 19:00:33 greg Exp $"; #endif /* * Interpolate and extrapolate pictures with different view parameters. @@ -12,8 +12,8 @@ static const char RCSid[] = "$Id: pinterp.c,v 2.38 200 #include #include -#include "standard.h" #include "platform.h" +#include "standard.h" #include "rtprocess.h" /* Windows: must come before color.h */ #include "view.h" #include "color.h" @@ -68,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 */ @@ -92,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)) \ @@ -109,6 +134,9 @@ char *argv[]; char *expcomp = NULL; int i, an, rval; + SET_DEFAULT_BINARY(); + SET_FILE_BINARY(stdout); + progname = argv[0]; for (an = 1; an < argc && argv[an][0] == '-'; an++) { @@ -327,9 +355,11 @@ userr: } -int -headline(s) /* process header string */ -char *s; +static int +headline( /* process header string */ + char *s, + void *p +) { char fmt[32]; @@ -357,12 +387,14 @@ 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; - register int i; + int i; if (fp != NULL) { do /* get new view */ @@ -385,6 +417,7 @@ FILE *fp; avgview.vdir[i] += ourview.vdir[i]; avgview.vup[i] += ourview.vup[i]; } + avgview.vdist += ourview.vdist; avgview.horiz += ourview.horiz; avgview.vert += ourview.vert; avgview.hoff += ourview.hoff; @@ -395,9 +428,10 @@ FILE *fp; } -compavgview() /* compute average view */ +static void +compavgview(void) /* compute average view */ { - register int i; + int i; double f; if (nvavg < 2) @@ -408,6 +442,7 @@ compavgview() /* compute average view */ avgview.vdir[i] *= f; avgview.vup[i] *= f; } + avgview.vdist *= f; avgview.horiz *= f; avgview.vert *= f; avgview.hoff *= f; @@ -420,8 +455,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; @@ -461,7 +499,7 @@ char *pfile, *zspec; syserror(progname); if ((zfd = open(zspec, O_RDONLY)) == -1) { double zvalue; - register int x; + int x; if (!isflt(zspec) || (zvalue = atof(zspec)) <= 0.0) syserror(zspec); for (x = scanlen(&tresolu); x-- > 0; ) @@ -518,11 +556,14 @@ 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 */ + MAT4 xfmat, + VIEW *vw1, + VIEW *vw2 +) { - double m4t[4][4]; + MAT4 m4t; if ((vw1->type != VT_PER) & (vw1->type != VT_PAR)) return(0); @@ -559,17 +600,19 @@ 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; double wt; - register int x; + int x; lastx.z = 0; for (x = xl->max; x >= xl->min; x--) { @@ -591,11 +634,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 */ @@ -603,7 +650,7 @@ double z; int l1, l2, c1, c2; /* side lengths and counters */ int p1isy; /* p0p1 along y? */ int x1, y1; /* p1 position */ - register int x, y; /* final position */ + int x, y; /* final position */ /* compute vector p0p1 */ if (fillo&F_FORE && ABS(p1->z-p0->z) <= zt) { @@ -668,9 +715,10 @@ double z; } -double -movepixel(pos) /* reposition image point */ -register FVECT pos; +static double +movepixel( /* reposition image point */ + FVECT pos +) { FVECT pt, tdir, odir; double d; @@ -733,15 +781,17 @@ 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 */ + struct bound *xl, + struct bound *yl, + float *zline, + int zfd +) { int step; FVECT pos; - register int x, y; + int x, y; /* set up step size */ if (scanlen(&tresolu) < numscans(&tresolu)) step = scanlen(&tresolu)/NSTEPS; @@ -817,13 +867,15 @@ 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; - register int x, i; + int x, i; /* get back buffer */ yback = (int *)malloc(hresolu*sizeof(int)); if (yback == NULL) @@ -925,10 +977,12 @@ 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; + int x, y; for (y = 0; y < vresolu; y++) for (x = 0; x < hresolu; x++) @@ -939,9 +993,10 @@ int (*fill)(); } -clipaft() /* perform aft clipping as indicated */ +static int +clipaft(void) /* perform aft clipping as indicated */ { - register int x, y; + int x, y; int adjtest = (ourview.type == VT_PER) & zisnorm; double tstdist; double yzn2, vx; @@ -975,11 +1030,12 @@ clipaft() /* perform aft clipping as indicated */ } -addblur() /* add to blurred picture */ +static int +addblur(void) /* add to blurred picture */ { COLOR cval; double d; - register int i; + int i; if (!blurring) return(0); @@ -1015,10 +1071,11 @@ 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; + int x; double d; fprtresolu(hresolu, vresolu, stdout); @@ -1046,8 +1103,10 @@ 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; @@ -1059,7 +1118,7 @@ char *fname; for (y = vresolu-1; y >= 0; y--) { if (donorm) { double vx, yzn2, d; - register int x; + int x; yzn2 = (y+.5)/vresolu + ourview.voff - .5; yzn2 = 1. + yzn2*yzn2*ourview.vn2; for (x = 0; x < hresolu; x++) { @@ -1079,8 +1138,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); @@ -1091,13 +1153,16 @@ 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]; int rval; - register char **wp, *cp; + char **wp, *cp; if (PDesc.running) { fprintf(stderr, "%s: too many calculations\n", progname); @@ -1131,7 +1196,8 @@ char *prog, *args; } -caldone() /* done with calculation */ +static void +caldone(void) /* done with calculation */ { if (!PDesc.running) return; @@ -1140,8 +1206,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(); @@ -1152,12 +1221,13 @@ int x, y; } -clearqueue() /* process queue */ +static void +clearqueue(void) /* process queue */ { FVECT orig, dir; float fbuf[6*(PACKSIZ+1)]; - register float *fbp; - register int i; + float *fbp; + int i; double vx, vy; if (queuesiz == 0) @@ -1208,8 +1278,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);