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 1.10 by greg, Wed Jan 3 15:33:44 1990 UTC vs.
Revision 1.12 by greg, Thu Jan 4 14:25:56 1990 UTC

# Line 17 | Line 17 | static char SCCSid[] = "$SunId$ LBL";
17   #define pscan(y)        (ourpict+(y)*ourview.hresolu)
18   #define zscan(y)        (ourzbuf+(y)*ourview.hresolu)
19  
20 + #define F_FORE  1                       /* fill foreground */
21 + #define F_BACK  2                       /* fill background */
22 +
23   #define ABS(x)          ((x)>0?(x):-(x))
24  
25   VIEW    ourview = STDVIEW(512);         /* desired view */
# Line 31 | Line 34 | char   *progname;
34   VIEW    theirview = STDVIEW(512);       /* input view */
35   int     gotview;                        /* got input view? */
36  
37 + int     fill = F_FORE|F_BACK;           /* selected fill algorithm */
38 + extern int      backfill();             /* fill functions */
39 + int     (*deffill)() = backfill;        /* selected fill function */
40 + COLR    backcolr = BLKCOLR;             /* background color */
41 +
42   double  theirs2ours[4][4];              /* transformation matrix */
43 < int     regdist = 0;                    /* regular distance? */
43 > int     normdist = 1;                   /* normalized distance? */
44  
45  
46   main(argc, argv)                        /* interpolate pictures */
# Line 40 | Line 48 | int    argc;
48   char    *argv[];
49   {
50   #define check(olen,narg)        if (argv[i][olen] || narg >= argc-i) goto badopt
51 +        extern double   atof();
52          int     gotvfile = 0;
53 +        char    *zfile = NULL;
54          char    *err;
55          int     i;
56  
# Line 52 | Line 62 | char   *argv[];
62                          check(2,1);
63                          zeps = atof(argv[++i]);
64                          break;
65 <                case 'r':                               /* regular distance */
65 >                case 'n':                               /* dist. normalized? */
66                          check(2,0);
67 <                        regdist = !regdist;
67 >                        normdist = !normdist;
68                          break;
69 +                case 'f':                               /* fill type */
70 +                        switch (argv[i][2]) {
71 +                        case '0':                               /* none */
72 +                                check(3,0);
73 +                                fill = 0;
74 +                                break;
75 +                        case 'f':                               /* foreground */
76 +                                check(3,0);
77 +                                fill = F_FORE;
78 +                                break;
79 +                        case 'b':                               /* background */
80 +                                check(3,0);
81 +                                fill = F_BACK;
82 +                                break;
83 +                        case 'a':                               /* all */
84 +                                check(3,0);
85 +                                fill = F_FORE|F_BACK;
86 +                                break;
87 +                        case 'c':                               /* color */
88 +                                check(3,3);
89 +                                deffill = backfill;
90 +                                setcolr(backcolr, atof(argv[i+1]),
91 +                                        atof(argv[i+2]), atof(argv[i+3]));
92 +                                i += 3;
93 +                                break;
94 +                        default:
95 +                                goto badopt;
96 +                        }
97 +                        break;
98 +                case 'z':                               /* z file */
99 +                        check(2,1);
100 +                        zfile = argv[++i];
101 +                        break;
102                  case 'x':                               /* x resolution */
103                          check(2,1);
104                          ourview.hresolu = atoi(argv[++i]);
# Line 127 | Line 170 | char   *argv[];
170                  exit(1);
171          }
172                                                  /* allocate frame */
173 <        ourpict = (COLR *)calloc(ourview.hresolu*ourview.vresolu,sizeof(COLR));
173 >        ourpict = (COLR *)malloc(ourview.hresolu*ourview.vresolu*sizeof(COLR));
174          ourzbuf = (float *)calloc(ourview.hresolu*ourview.vresolu,sizeof(float));
175          if (ourpict == NULL || ourzbuf == NULL) {
176                  perror(progname);
# Line 137 | Line 180 | char   *argv[];
180          for ( ; i < argc; i += 2)
181                  addpicture(argv[i], argv[i+1]);
182                                                          /* fill in spaces */
183 <        fillpicture();
183 >        if (fill&F_BACK)
184 >                backpicture();
185 >        else
186 >                fillpicture();
187                                                          /* add to header */
188          printargs(argc, argv, stdout);
189          if (gotvfile) {
# Line 146 | Line 192 | char   *argv[];
192                  printf("\n");
193          }
194          printf("\n");
195 <                                                        /* write output */
195 >                                                        /* write picture */
196          writepicture();
197 +                                                        /* write z file */
198 +        if (zfile != NULL)
199 +                writedistance(zfile);
200  
201          exit(0);
202   userr:
203          fprintf(stderr,
204 <        "Usage: %s [view opts][-t zthresh][-r] pfile zspec ..\n",
204 >        "Usage: %s [view opts][-t zthresh][-z zout][-fT][-n] pfile zspec ..\n",
205                          progname);
206          exit(1);
207   #undef check
# Line 294 | Line 343 | float  *zline;
343   int     *lasty;                 /* input/output */
344   float   *lastyz;                /* input/output */
345   {
346 <        extern double   sqrt(), fabs();
346 >        extern double   sqrt();
347          double  pos[3];
348          int     lastx = 0;
349          double  lastxz = 0;
# Line 307 | Line 356 | float  *lastyz;                /* input/output */
356                  pos[1] = y - .5*(theirview.vresolu-1);
357                  pos[2] = zline[x];
358                  if (theirview.type == VT_PER) {
359 <                        if (!regdist)   /* adjust for eye-ray distance */
359 >                        if (normdist)   /* adjust for eye-ray distance */
360                                  pos[2] /= sqrt( 1.
361                                          + pos[0]*pos[0]*theirview.vhn2
362                                          + pos[1]*pos[1]*theirview.vvn2 );
# Line 329 | Line 378 | float  *lastyz;                /* input/output */
378                                          /* add pixel to our image */
379                  zt = 2.*zeps*zline[x];
380                  addpixel(xpos, ypos,
381 <                        (fabs(zline[x]-lastxz) <= zt) ? lastx - xpos : 1,
382 <                        (fabs(zline[x]-lastyz[x]) <= zt) ? lasty[x] - ypos : 1,
381 >                        (fill&F_FORE && ABS(zline[x]-lastxz) <= zt)
382 >                                ? lastx - xpos : 1,
383 >                        (fill&F_FORE && ABS(zline[x]-lastyz[x]) <= zt)
384 >                                ? lasty[x] - ypos : 1,
385                          pline[x], pos[2]);
386                  lastx = xpos;
387                  lasty[x] = ypos;
# Line 368 | Line 419 | double z;
419   }
420  
421  
422 < fillpicture()                           /* fill in empty spaces */
422 > backpicture()                           /* background fill algorithm */
423   {
424          int     *yback, xback;
425          int     y;
# Line 411 | Line 462 | fillpicture()                          /* fill in empty spaces */
462                                   * Next, find background from left or right.
463                                   */
464                                  if (xback == -2) {
465 <                                        for (i = x+1; x < ourview.hresolu; i++)
465 >                                        for (i = x+1; i < ourview.hresolu; i++)
466                                                  if (zscan(y)[i] > 0)
467                                                          break;
468                                          if (i < ourview.hresolu
# Line 420 | Line 471 | fillpicture()                          /* fill in empty spaces */
471                                          else
472                                                  xback = x-1;
473                                  }
423                                if (xback < 0 && yback[x] < 0)
424                                        continue;       /* no background */
474                                  /*
475 +                                 * Check to see if we have no background for
476 +                                 * this pixel.  If not, use background color.
477 +                                 */
478 +                                if (xback < 0 && yback[x] < 0) {
479 +                                        (*deffill)(x,y);
480 +                                        continue;
481 +                                }
482 +                                /*
483                                   * Compare, and use the background that is
484                                   * farther, unless one of them is next to us.
485                                   */
486 <                                if (yback[x] < 0 || ABS(x-xback) <= 1
486 >                                if ( yback[x] < 0
487 >                                        || (xback >= 0 && ABS(x-xback) <= 1)
488                                          || ( ABS(y-yback[x]) > 1
489 <                                && zscan(yback[x])[x] < zscan(y)[xback] ))
489 >                                                && zscan(yback[x])[x]
490 >                                                < zscan(y)[xback] ) )
491                                          copycolr(pscan(y)[x],pscan(y)[xback]);
492                                  else
493                                          copycolr(pscan(y)[x],pscan(yback[x])[x]);
# Line 441 | Line 500 | fillpicture()                          /* fill in empty spaces */
500   }
501  
502  
503 + fillpicture()                           /* paint in empty pixels with default */
504 + {
505 +        register int    x, y;
506 +
507 +        for (y = 0; y < ourview.vresolu; y++)
508 +                for (x = 0; x < ourview.hresolu; x++)
509 +                        if (zscan(y)[x] <= 0)
510 +                                (*deffill)(x,y);
511 + }
512 +
513 +
514   writepicture()                          /* write out picture */
515   {
516          int     y;
# Line 454 | Line 524 | writepicture()                         /* write out picture */
524   }
525  
526  
527 + writedistance(fname)                    /* write out z file */
528 + char    *fname;
529 + {
530 +        extern double   sqrt();
531 +        int     donorm = normdist && ourview.type == VT_PER;
532 +        FILE    *fp;
533 +        int     y;
534 +        float   *zout;
535 +
536 +        if ((fp = fopen(fname, "w")) == NULL) {
537 +                perror(fname);
538 +                exit(1);
539 +        }
540 +        if (donorm
541 +        && (zout = (float *)malloc(ourview.hresolu*sizeof(float))) == NULL) {
542 +                perror(progname);
543 +                exit(1);
544 +        }
545 +        for (y = ourview.vresolu-1; y >= 0; y--) {
546 +                if (donorm) {
547 +                        double  vx, yzn2;
548 +                        register int    x;
549 +                        yzn2 = y - .5*(ourview.vresolu-1);
550 +                        yzn2 = 1. + yzn2*yzn2*ourview.vvn2;
551 +                        for (x = 0; x < ourview.hresolu; x++) {
552 +                                vx = x - .5*(ourview.hresolu-1);
553 +                                zout[x] = zscan(y)[x]
554 +                                        * sqrt(vx*vx*ourview.vhn2 + yzn2);
555 +                        }
556 +                } else
557 +                        zout = zscan(y);
558 +                if (fwrite(zout, sizeof(float), ourview.hresolu, fp)
559 +                                < ourview.hresolu) {
560 +                        perror(fname);
561 +                        exit(1);
562 +                }
563 +        }
564 +        if (donorm)
565 +                free((char *)zout);
566 +        fclose(fp);
567 + }
568 +
569 +
570   isfloat(s)                              /* see if string is floating number */
571   register char   *s;
572   {
# Line 462 | Line 575 | register char  *s;
575                                  && *s != 'e' && *s != 'E' && *s != '+')
576                          return(0);
577          return(1);
578 + }
579 +
580 +
581 + backfill(x, y)                          /* fill pixel with background */
582 + int     x, y;
583 + {
584 +        register BYTE   *dest = pscan(y)[x];
585 +
586 +        copycolr(dest, backcolr);
587   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines