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

Comparing ray/src/px/pcomb.c (file contents):
Revision 2.10 by greg, Thu Apr 29 14:32:07 1993 UTC vs.
Revision 2.20 by greg, Thu Sep 19 12:10:46 1996 UTC

# Line 21 | Line 21 | static char SCCSid[] = "$SunId$ LBL";
21   #include "view.h"
22  
23   #define MAXINP          32              /* maximum number of input files */
24 < #define WINSIZ          9               /* scanline window size */
25 < #define MIDSCN          4               /* current scan position */
24 > #define WINSIZ          17              /* scanline window size */
25 > #define MIDSCN          ((WINSIZ-1)/2+1)
26  
27   struct {
28          char    *name;          /* file or command name */
29          FILE    *fp;            /* stream pointer */
30          VIEW    vw;             /* view for picture */
31          RESOLU  rs;             /* image resolution and orientation */
32 +        float   pa;             /* pixel aspect ratio */
33          COLOR   *scan[WINSIZ];  /* input scanline window */
34          COLOR   coef;           /* coefficient */
35          COLOR   expos;          /* recorded exposure */
# Line 36 | Line 37 | struct {
37  
38   int     nfiles;                         /* number of input files */
39  
40 + char    ourfmt[LPICFMT+1] = PICFMT;     /* input picture format */
41 +
42   char    Command[] = "<Command>";
43   char    vcolin[3][4] = {"ri", "gi", "bi"};
44   char    vcolout[3][4] = {"ro", "go", "bo"};
# Line 43 | Line 46 | char   vbrtin[] = "li";
46   char    vbrtout[] = "lo";
47   char    vcolexp[3][4] = {"re", "ge", "be"};
48   char    vbrtexp[] = "le";
49 + char    vpixaspect[] = "pa";
50  
51 < char    vray[6][4] = {"Ox", "Oy", "Oz", "Dx", "Dy", "Dz"};
51 > char    vray[7][4] = {"Ox", "Oy", "Oz", "Dx", "Dy", "Dz", "T"};
52  
53 + char    vpsize[] = "S";
54 +
55   char    vnfiles[] = "nfiles";
56 + char    vwhteff[] = "WE";
57   char    vxmax[] = "xmax";
58   char    vymax[] = "ymax";
59   char    vxres[] = "xres";
# Line 106 | Line 113 | char   *argv[];
113                          }
114                  break;
115          }
116 +        newheader("RADIANCE", stdout);  /* start header */
117                                          /* process files */
118          for (nfiles = 0; nfiles < MAXINP; nfiles++) {
119                  setcolor(input[nfiles].coef, 1.0, 1.0, 1.0);
120                  setcolor(input[nfiles].expos, 1.0, 1.0, 1.0);
121                  copystruct(&input[nfiles].vw, &stdview);
122 +                input[nfiles].pa = 1.0;
123          }
124          nfiles = 0;
125          original = 0;
# Line 202 | Line 211 | char   *argv[];
211          }
212                                                  /* complete header */
213          printargs(argc, argv, stdout);
214 <        fputformat(COLRFMT, stdout);
214 >        if (strcmp(ourfmt, PICFMT))
215 >                fputformat(ourfmt, stdout);     /* print format if known */
216          putchar('\n');
217          fprtresolu(xres, yres, stdout);
218                                                  /* combine pictures */
# Line 224 | Line 234 | char   *s;
234          double  d;
235          COLOR   ctmp;
236  
237 <        if (isformat(s)) {                      /* check format */
228 <                formatval(fmt, s);
229 <                wrongformat = strcmp(fmt, COLRFMT);
237 >        if (isheadid(s))                        /* header id */
238                  return;         /* don't echo */
239 +        if (formatval(fmt, s)) {                /* check format */
240 +                if (globmatch(ourfmt, fmt)) {
241 +                        wrongformat = 0;
242 +                        strcpy(ourfmt, fmt);
243 +                } else
244 +                        wrongformat = 1;
245 +                return;         /* don't echo */
246          }
247          if (isexpos(s)) {                       /* exposure */
248                  d = exposval(s);
# Line 235 | Line 250 | char   *s;
250          } else if (iscolcor(s)) {               /* color correction */
251                  colcorval(ctmp, s);
252                  multcolor(input[nfiles].expos, ctmp);
253 <        } else if (isview(s) && sscanview(&input[nfiles].vw, s) > 0)
253 >        } else if (isaspect(s))
254 >                input[nfiles].pa *= aspectval(s);
255 >        else if (isview(s) && sscanview(&input[nfiles].vw, s) > 0)
256                  gotview++;
257                                                  /* echo line */
258          putchar('\t');
# Line 278 | Line 295 | checkfile()                    /* ready a file */
295   }
296  
297  
298 + double
299 + rgb_bright(clr)
300 + COLOR  clr;
301 + {
302 +        return(bright(clr));
303 + }
304 +
305 +
306 + double
307 + xyz_bright(clr)
308 + COLOR  clr;
309 + {
310 +        return(clr[CIEY]);
311 + }
312 +
313 +
314 + double  (*ourbright)() = rgb_bright;
315 +
316 +
317   init()                                  /* perform final setup */
318   {
319 <        double  l_colin(), l_expos(), l_ray();
319 >        double  l_colin(), l_expos(), l_pixaspect(), l_ray(), l_psize();
320          register int    i;
321                                                  /* define constants */
322 +        varset("PI", ':', PI);
323          varset(vnfiles, ':', (double)nfiles);
324          varset(vxmax, ':', (double)xmax);
325          varset(vymax, ':', (double)ymax);
# Line 293 | Line 330 | init()                                 /* perform final setup */
330          }
331          funset(vbrtexp, 1, ':', l_expos);
332          funset(vbrtin, 1, '=', l_colin);
333 <        for (i = 0; i < 6; i++)
333 >        funset(vpixaspect, 1, ':', l_pixaspect);
334 >        for (i = 0; i < 7; i++)
335                  funset(vray[i], 1, '=', l_ray);
336 +        funset(vpsize, 1, '=', l_psize);
337 +                                                /* set brightness function */
338 +        if (!strcmp(ourfmt, CIEFMT)) {
339 +                varset(vwhteff, ':', 1.0);
340 +                ourbright = xyz_bright;
341 +        } else
342 +                varset(vwhteff, ':', WHTEFFICACY);
343   }
344  
345  
# Line 394 | Line 439 | register char  *nam;
439          if (fn < 0 || fn >= nfiles)
440                  return(1.0);
441          if (nam == vbrtexp)
442 <                return(bright(input[fn].expos));
442 >                return((*ourbright)(input[fn].expos));
443          n = 3;
444          while (n--)
445                  if (nam == vcolexp[n])
# Line 405 | Line 450 | register char  *nam;
450  
451  
452   double
453 + l_pixaspect()                   /* return pixel aspect ratio */
454 + {
455 +        register int    fn;
456 +
457 +        fn = argument(1) - .5;
458 +        if (fn < 0 || fn >= nfiles)
459 +                return(1.0);
460 +        return(input[fn].pa);
461 + }
462 +
463 +
464 + double
465   l_colin(nam)                    /* return color value for picture */
466   register char   *nam;
467   {
# Line 412 | Line 469 | register char  *nam;
469          register int    n, xoff, yoff;
470          double  d;
471  
472 <        d = argument(1);
416 <        if (d > -.5 && d < .5)
417 <                return((double)nfiles);
418 <        fn = d - .5;
472 >        fn = argument(1) - .5;
473          if (fn < 0 || fn >= nfiles) {
474                  errno = EDOM;
475                  return(0.0);
# Line 451 | Line 505 | register char  *nam;
505                  }
506          }
507          if (nam == vbrtin)
508 <                return(bright(input[fn].scan[MIDSCN+yoff][xscan+xoff]));
508 >                return((*ourbright)(input[fn].scan[MIDSCN+yoff][xscan+xoff]));
509          n = 3;
510          while (n--)
511              if (nam == vcolin[n])
# Line 465 | Line 519 | double
519   l_ray(nam)              /* return ray origin or direction */
520   register char   *nam;
521   {
522 <        static long     ltick[MAXINP];
522 >        static unsigned long    ltick[MAXINP];
523          static FVECT    lorg[MAXINP], ldir[MAXINP];
524 +        static double   ldist[MAXINP];
525          FLOAT   loc[2];
471        double  d;
526          int     fn;
527          register int    i;
528  
529 <        d = argument(1);
476 <        if (d > -.5 && d < .5)
477 <                return((double)nfiles);
478 <        fn = d - .5;
529 >        fn = argument(1) - .5;
530          if (fn < 0 || fn >= nfiles) {
531                  errno = EDOM;
532                  return(0.0);
# Line 483 | Line 534 | register char  *nam;
534          if (ltick[fn] < eclock) {               /* need to compute? */
535                  lorg[fn][0] = lorg[fn][1] = lorg[fn][2] = 0.0;
536                  ldir[fn][0] = ldir[fn][1] = ldir[fn][2] = 0.0;
537 +                ldist[fn] = -1.0;
538                  if (input[fn].vw.type == 0)
539 <                        errno = ERANGE;
539 >                        errno = EDOM;
540                  else {
541 <                        pix2loc(loc, &input[fn].rs, xpos, ypos);
542 <                        if (viewray(lorg[fn], ldir[fn],
543 <                                        &input[fn].vw, loc[0], loc[1]) < 0)
492 <                                errno = ERANGE;
541 >                        pix2loc(loc, &input[fn].rs, xscan, ymax-1-yscan);
542 >                        ldist[fn] = viewray(lorg[fn], ldir[fn],
543 >                                        &input[fn].vw, loc[0], loc[1]);
544                  }
545                  ltick[fn] = eclock;
546          }
547 <        i = 6;
547 >        if (nam == vray[i=6])
548 >                return(ldist[fn]);
549          while (i--)
550                  if (nam == vray[i])
551                          return(i < 3 ? lorg[fn][i] : ldir[fn][i-3]);
552          eputs("Bad call to l_ray()!\n");
553          quit(1);
554 + }
555 +
556 +
557 + double
558 + l_psize()                       /* compute pixel size in steradians */
559 + {
560 +        static unsigned long    ltick[MAXINP];
561 +        static double   psize[MAXINP];
562 +        FVECT   dir0, org, dirx, diry;
563 +        FLOAT   locx[2], locy[2];
564 +        double  d;
565 +        int     fn;
566 +        register int    i;
567 +
568 +        d = argument(1);
569 +        if (d < .5 || d >= nfiles+.5) {
570 +                errno = EDOM;
571 +                return(0.0);
572 +        }
573 +        fn = d - .5;
574 +        if (ltick[fn] < eclock) {               /* need to compute? */
575 +                psize[fn] = 0.0;
576 +                if (input[fn].vw.type == 0)
577 +                        errno = EDOM;
578 +                else if (input[fn].vw.type != VT_PAR &&
579 +                                funvalue(vray[6], 1, &d) >= 0) {
580 +                        for (i = 0; i < 3; i++)
581 +                                dir0[i] = funvalue(vray[3+i], 1, &d);
582 +                        pix2loc(locx, &input[fn].rs, xscan+1, ymax-1-yscan);
583 +                        pix2loc(locy, &input[fn].rs, xscan, ymax-yscan);
584 +                        if (viewray(org, dirx, &input[fn].vw,
585 +                                        locx[0], locx[1]) >= 0 &&
586 +                                        viewray(org, diry, &input[fn].vw,
587 +                                        locy[0], locy[1]) >= 0) {
588 +                                                /* approximate solid angle */
589 +                                for (i = 0; i < 3; i++) {
590 +                                        dirx[i] -= dir0[i];
591 +                                        diry[i] -= dir0[i];
592 +                                }
593 +                                fcross(dir0, dirx, diry);
594 +                                psize[fn] = 0.5 * sqrt(DOT(dir0,dir0));
595 +                        }
596 +                }
597 +                ltick[fn] = eclock;
598 +        }
599 +        return(psize[fn]);
600   }
601  
602  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines