ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/pinterp.c
(Generate patch)

Comparing ray/src/px/pinterp.c (file contents):
Revision 2.37 by schorsch, Sun Jul 27 22:12:03 2003 UTC vs.
Revision 2.45 by greg, Mon May 20 21:52:06 2013 UTC

# Line 12 | Line 12 | static const char      RCSid[] = "$Id$";
12   #include <ctype.h>
13   #include <string.h>
14  
15 + #include "platform.h"
16   #include "standard.h"
17   #include "rtprocess.h" /* Windows: must come before color.h */
18   #include "view.h"
# Line 67 | Line 68 | char   *progname;
68  
69   int     fillo = F_FORE|F_BACK;          /* selected fill options */
70   int     fillsamp = 0;                   /* sample separation (0 == inf) */
70 extern int      backfill(), rcalfill(); /* fill functions */
71 int     (*fillfunc)() = backfill;       /* selected fill function */
71   COLR    backcolr = BLKCOLR;             /* background color */
72   COLOR   backcolor = BLKCOLOR;           /* background color (float) */
73   double  backz = 0.0;                    /* background z value */
# Line 91 | Line 90 | unsigned short queue[PACKSIZ][2];      /* pending pixels */
90   int     packsiz;                        /* actual packet size */
91   int     queuesiz = 0;                   /* number of pixels pending */
92  
93 < extern double   movepixel();
93 > typedef void fillfunc_t(int x, int y);
94  
95 + static gethfunc headline;
96 + static int nextview(FILE *fp);
97 + static void compavgview(void);
98 + static void addpicture(char *pfile, char *zspec);
99 + static int pixform(MAT4 xfmat, VIEW *vw1, VIEW *vw2);
100 + static void addscanline(struct bound *xl, int y,
101 +        COLR *pline, float *zline, struct position *lasty);
102 + static void addpixel(struct position *p0, struct position *p1,
103 +        struct position *p2, COLR pix, double w, double z);
104 + static double movepixel(FVECT pos);
105 + static int getperim(struct bound *xl, struct bound *yl, float *zline, int zfd);
106 + static void backpicture(fillfunc_t *fill, int samp);
107 + static void fillpicture(fillfunc_t *fill);
108 + static int clipaft(void);
109 + static int addblur(void);
110 + static void writepicture(void);
111 + static void writedistance(char *fname);
112 + static fillfunc_t backfill;
113 + static fillfunc_t rcalfill;
114 + static void calstart(char *prog, char *args);
115 + static void caldone(void);
116 + static void clearqueue(void);
117 + static void syserror(char *s);
118  
119 < main(argc, argv)                        /* interpolate pictures */
120 < int     argc;
121 < char    *argv[];
119 > fillfunc_t *fillfunc = backfill;        /* selected fill function */
120 >
121 > int
122 > main(                   /* interpolate pictures */
123 >        int     argc,
124 >        char    *argv[]
125 > )
126   {
127   #define  check(ol,al)           if (argv[an][ol] || \
128                                  badarg(argc-an-1,argv+an+1,al)) \
# Line 108 | Line 134 | char   *argv[];
134          char    *expcomp = NULL;
135          int     i, an, rval;
136  
137 +        SET_DEFAULT_BINARY();
138 +        SET_FILE_BINARY(stdout);
139 +
140          progname = argv[0];
141  
142          for (an = 1; an < argc && argv[an][0] == '-'; an++) {
# Line 326 | Line 355 | userr:
355   }
356  
357  
358 < int
359 < headline(s)                             /* process header string */
360 < char    *s;
358 > static int
359 > headline(                               /* process header string */
360 >        char    *s,
361 >        void    *p
362 > )
363   {
364          char    fmt[32];
365  
# Line 356 | Line 387 | char   *s;
387   }
388  
389  
390 < nextview(fp)                            /* get and set next view */
391 < FILE    *fp;
390 > static int
391 > nextview(                               /* get and set next view */
392 >        FILE    *fp
393 > )
394   {
395          char    linebuf[256];
396          char    *err;
397 <        register int    i;
397 >        int     i;
398  
399          if (fp != NULL) {
400                  do                      /* get new view */
# Line 384 | Line 417 | FILE   *fp;
417                  avgview.vdir[i] += ourview.vdir[i];
418                  avgview.vup[i] += ourview.vup[i];
419          }
420 +        avgview.vdist += ourview.vdist;
421          avgview.horiz += ourview.horiz;
422          avgview.vert += ourview.vert;
423          avgview.hoff += ourview.hoff;
# Line 394 | Line 428 | FILE   *fp;
428   }
429  
430  
431 < compavgview()                           /* compute average view */
431 > static void
432 > compavgview(void)                               /* compute average view */
433   {
434 <        register int    i;
434 >        int     i;
435          double  f;
436  
437          if (nvavg < 2)
# Line 407 | Line 442 | compavgview()                          /* compute average view */
442                  avgview.vdir[i] *= f;
443                  avgview.vup[i] *= f;
444          }
445 +        avgview.vdist *= f;
446          avgview.horiz *= f;
447          avgview.vert *= f;
448          avgview.hoff *= f;
# Line 419 | Line 455 | compavgview()                          /* compute average view */
455   }
456  
457  
458 < addpicture(pfile, zspec)                /* add picture to output */
459 < char    *pfile, *zspec;
458 > static void
459 > addpicture(             /* add picture to output */
460 >        char    *pfile,
461 >        char    *zspec
462 > )
463   {
464          FILE    *pfp;
465          int     zfd;
# Line 460 | Line 499 | char   *pfile, *zspec;
499                  syserror(progname);
500          if ((zfd = open(zspec, O_RDONLY)) == -1) {
501                  double  zvalue;
502 <                register int    x;
502 >                int     x;
503                  if (!isflt(zspec) || (zvalue = atof(zspec)) <= 0.0)
504                          syserror(zspec);
505                  for (x = scanlen(&tresolu); x-- > 0; )
# Line 491 | Line 530 | char   *pfile, *zspec;
530                          exit(1);
531                  }
532          if (zfd != -1 && lseek(zfd,
533 <                        (off_t)ylim.min*scanlen(&tresolu)*sizeof(float), 0) < 0)
533 >                        (off_t)ylim.min*scanlen(&tresolu)*sizeof(float),
534 >                        SEEK_SET) < 0)
535                  syserror(zspec);
536                                          /* load image */
537          for (y = ylim.min; y <= ylim.max; y++) {
# Line 516 | Line 556 | char   *pfile, *zspec;
556   }
557  
558  
559 < pixform(xfmat, vw1, vw2)                /* compute view1 to view2 matrix */
560 < register MAT4   xfmat;
561 < register VIEW   *vw1, *vw2;
559 > static int
560 > pixform(                /* compute view1 to view2 matrix */
561 >        MAT4    xfmat,
562 >        VIEW    *vw1,
563 >        VIEW    *vw2
564 > )
565   {
566 <        double  m4t[4][4];
566 >        MAT4    m4t;
567  
568          if ((vw1->type != VT_PER) & (vw1->type != VT_PAR))
569                  return(0);
# Line 557 | Line 600 | register VIEW  *vw1, *vw2;
600   }
601  
602  
603 < addscanline(xl, y, pline, zline, lasty) /* add scanline to output */
604 < struct bound    *xl;
605 < int     y;
606 < COLR    *pline;
607 < float   *zline;
608 < struct position *lasty;         /* input/output */
603 > static void
604 > addscanline(    /* add scanline to output */
605 >        struct bound    *xl,
606 >        int     y,
607 >        COLR    *pline,
608 >        float   *zline,
609 >        struct position *lasty          /* input/output */
610 > )
611   {
612          FVECT   pos;
613          struct position lastx, newpos;
614          double  wt;
615 <        register int    x;
615 >        int     x;
616  
617          lastx.z = 0;
618          for (x = xl->max; x >= xl->min; x--) {
# Line 589 | Line 634 | struct position        *lasty;         /* input/output */
634   }
635  
636  
637 < addpixel(p0, p1, p2, pix, w, z)         /* fill in pixel parallelogram */
638 < struct position *p0, *p1, *p2;
639 < COLR    pix;
640 < double  w;
641 < double  z;
637 > static void
638 > addpixel(               /* fill in pixel parallelogram */
639 >        struct position *p0,
640 >        struct position *p1,
641 >        struct position *p2,
642 >        COLR    pix,
643 >        double  w,
644 >        double  z
645 > )
646   {
647          double  zt = 2.*zeps*p0->z;             /* threshold */
648          COLOR   pval;                           /* converted+weighted pixel */
# Line 601 | Line 650 | double z;
650          int     l1, l2, c1, c2;                 /* side lengths and counters */
651          int     p1isy;                          /* p0p1 along y? */
652          int     x1, y1;                         /* p1 position */
653 <        register int    x, y;                   /* final position */
653 >        int     x, y;                   /* final position */
654  
655                                          /* compute vector p0p1 */
656          if (fillo&F_FORE && ABS(p1->z-p0->z) <= zt) {
# Line 666 | Line 715 | double z;
715   }
716  
717  
718 < double
719 < movepixel(pos)                          /* reposition image point */
720 < register FVECT  pos;
718 > static double
719 > movepixel(                              /* reposition image point */
720 >        FVECT   pos
721 > )
722   {
723          FVECT   pt, tdir, odir;
724          double  d;
# Line 703 | Line 753 | register FVECT pos;
753                  if (viewray(pt, tdir, &theirview, pos[0], pos[1]) < -FTINY)
754                          return(0);
755                  if ((!normdist) & (theirview.type == VT_PER))   /* adjust */
756 <                        pos[2] *= sqrt(1. + pos[0]*pos[0]*theirview.hn2
707 <                                        + pos[1]*pos[1]*theirview.vn2);
756 >                        pos[2] /= DOT(theirview.vdir, tdir);
757                  pt[0] += tdir[0]*pos[2];
758                  pt[1] += tdir[1]*pos[2];
759                  pt[2] += tdir[2]*pos[2];
# Line 731 | Line 780 | register FVECT pos;
780   }
781  
782  
783 < getperim(xl, yl, zline, zfd)            /* compute overlapping image area */
784 < register struct bound   *xl;
785 < struct bound    *yl;
786 < float   *zline;
787 < int     zfd;
783 > static int
784 > getperim(               /* compute overlapping image area */
785 >        struct bound    *xl,
786 >        struct bound    *yl,
787 >        float   *zline,
788 >        int     zfd
789 > )
790   {
791          int     step;
792          FVECT   pos;
793 <        register int    x, y;
793 >        int     x, y;
794                                                  /* set up step size */
795          if (scanlen(&tresolu) < numscans(&tresolu))
796                  step = scanlen(&tresolu)/NSTEPS;
# Line 759 | Line 810 | int    zfd;
810          for (y = step - 1; y < numscans(&tresolu); y += step) {
811                  if (zfd != -1) {
812                          if (lseek(zfd, (off_t)y*scanlen(&tresolu)*sizeof(float),
813 <                                        0) < 0)
813 >                                        SEEK_SET) < 0)
814                                  syserror("lseek");
815                          if (read(zfd, (char *)zline,
816                                          scanlen(&tresolu)*sizeof(float))
# Line 815 | Line 866 | int    zfd;
866   }
867  
868  
869 < backpicture(fill, samp)                 /* background fill algorithm */
870 < int     (*fill)();
871 < int     samp;
869 > static void
870 > backpicture(                    /* background fill algorithm */
871 >        fillfunc_t *fill,
872 >        int     samp
873 > )
874   {
875          int     *yback, xback;
876          int     y;
877 <        register int    x, i;
877 >        int     x, i;
878                                                          /* get back buffer */
879          yback = (int *)malloc(hresolu*sizeof(int));
880          if (yback == NULL)
# Line 923 | Line 976 | int    samp;
976   }
977  
978  
979 < fillpicture(fill)               /* paint in empty pixels using fill */
980 < int     (*fill)();
979 > static void
980 > fillpicture(            /* paint in empty pixels using fill */
981 >        fillfunc_t *fill
982 > )
983   {
984 <        register int    x, y;
984 >        int     x, y;
985  
986          for (y = 0; y < vresolu; y++)
987                  for (x = 0; x < hresolu; x++)
# Line 937 | Line 992 | int    (*fill)();
992   }
993  
994  
995 < clipaft()                       /* perform aft clipping as indicated */
995 > static int
996 > clipaft(void)                   /* perform aft clipping as indicated */
997   {
998 <        register int    x, y;
998 >        int     x, y;
999          int     adjtest = (ourview.type == VT_PER) & zisnorm;
1000          double  tstdist;
1001          double  yzn2, vx;
# Line 973 | Line 1029 | clipaft()                      /* perform aft clipping as indicated */
1029   }
1030  
1031  
1032 < addblur()                               /* add to blurred picture */
1032 > static int
1033 > addblur(void)                           /* add to blurred picture */
1034   {
1035          COLOR   cval;
1036          double  d;
1037 <        register int    i;
1037 >        int     i;
1038  
1039          if (!blurring)
1040                  return(0);
# Line 1013 | Line 1070 | addblur()                              /* add to blurred picture */
1070   }
1071  
1072  
1073 < writepicture()                          /* write out picture (alters buffer) */
1073 > static void
1074 > writepicture(void)                              /* write out picture (alters buffer) */
1075   {
1076          int     y;
1077 <        register int    x;
1077 >        int     x;
1078          double  d;
1079  
1080          fprtresolu(hresolu, vresolu, stdout);
# Line 1044 | Line 1102 | writepicture()                         /* write out picture (alters buffer)
1102   }
1103  
1104  
1105 < writedistance(fname)                    /* write out z file (alters buffer) */
1106 < char    *fname;
1105 > static void
1106 > writedistance(                  /* write out z file (alters buffer) */
1107 >        char    *fname
1108 > )
1109   {
1110          int     donorm = normdist & !zisnorm ? 1 :
1111                          (ourview.type == VT_PER) & !normdist & zisnorm ? -1 : 0;
# Line 1057 | Line 1117 | char   *fname;
1117          for (y = vresolu-1; y >= 0; y--) {
1118                  if (donorm) {
1119                          double  vx, yzn2, d;
1120 <                        register int    x;
1120 >                        int     x;
1121                          yzn2 = (y+.5)/vresolu + ourview.voff - .5;
1122                          yzn2 = 1. + yzn2*yzn2*ourview.vn2;
1123                          for (x = 0; x < hresolu; x++) {
# Line 1077 | Line 1137 | char   *fname;
1137   }
1138  
1139  
1140 < backfill(x, y)                          /* fill pixel with background */
1141 < int     x, y;
1140 > static void
1141 > backfill(                               /* fill pixel with background */
1142 >        int     x,
1143 >        int     y
1144 > )
1145   {
1146          if (averaging) {
1147                  copycolor(sscan(y)[x], backcolor);
# Line 1089 | Line 1152 | int    x, y;
1152   }
1153  
1154  
1155 < calstart(prog, args)                    /* start fill calculation */
1156 < char    *prog, *args;
1155 > static void
1156 > calstart(                    /* start fill calculation */
1157 >        char    *prog,
1158 >        char    *args
1159 > )
1160   {
1161          char    combuf[512];
1162          char    *argv[64];
1163          int     rval;
1164 <        register char   **wp, *cp;
1164 >        char    **wp, *cp;
1165  
1166          if (PDesc.running) {
1167                  fprintf(stderr, "%s: too many calculations\n", progname);
# Line 1129 | Line 1195 | char   *prog, *args;
1195   }
1196  
1197  
1198 < caldone()                               /* done with calculation */
1198 > static void
1199 > caldone(void)                               /* done with calculation */
1200   {
1201          if (!PDesc.running)
1202                  return;
# Line 1138 | Line 1205 | caldone()                               /* done with c
1205   }
1206  
1207  
1208 < rcalfill(x, y)                          /* fill with ray-calculated pixel */
1209 < int     x, y;
1208 > static void
1209 > rcalfill(                               /* fill with ray-calculated pixel */
1210 >        int     x,
1211 >        int     y
1212 > )
1213   {
1214          if (queuesiz >= packsiz)        /* flush queue if needed */
1215                  clearqueue();
# Line 1150 | Line 1220 | int    x, y;
1220   }
1221  
1222  
1223 < clearqueue()                            /* process queue */
1223 > static void
1224 > clearqueue(void)                                /* process queue */
1225   {
1226          FVECT   orig, dir;
1227          float   fbuf[6*(PACKSIZ+1)];
1228 <        register float  *fbp;
1229 <        register int    i;
1228 >        float   *fbp;
1229 >        int     i;
1230          double  vx, vy;
1231  
1232          if (queuesiz == 0)
# Line 1206 | Line 1277 | clearqueue()                           /* process queue */
1277   }
1278  
1279  
1280 < syserror(s)                     /* report error and exit */
1281 < char    *s;
1280 > static void
1281 > syserror(                       /* report error and exit */
1282 >        char    *s
1283 > )
1284   {
1285          perror(s);
1286          exit(1);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines