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.17 by greg, Fri Aug 30 17:39:39 1996 UTC vs.
Revision 2.22 by greg, Sat Feb 22 02:07:27 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1992 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   *  Combine picture files according to calcomp functions.
6   *
# Line 14 | Line 11 | static char SCCSid[] = "$SunId$ LBL";
11  
12   #include "color.h"
13  
17 #include "resolu.h"
18
14   #include "calcomp.h"
15  
16   #include "view.h"
17  
18   #define MAXINP          32              /* maximum number of input files */
19 < #define WINSIZ          17              /* scanline window size */
19 > #define WINSIZ          64              /* scanline window size */
20   #define MIDSCN          ((WINSIZ-1)/2+1)
21  
22   struct {
# Line 46 | Line 41 | char   vbrtin[] = "li";
41   char    vbrtout[] = "lo";
42   char    vcolexp[3][4] = {"re", "ge", "be"};
43   char    vbrtexp[] = "le";
44 + char    vpixaspect[] = "pa";
45  
46 < char    vray[6][4] = {"Ox", "Oy", "Oz", "Dx", "Dy", "Dz"};
46 > char    vray[7][4] = {"Ox", "Oy", "Oz", "Dx", "Dy", "Dz", "T"};
47  
48   char    vpsize[] = "S";
49  
50   char    vnfiles[] = "nfiles";
51 + char    vwhteff[] = "WE";
52   char    vxmax[] = "xmax";
53   char    vymax[] = "ymax";
54   char    vxres[] = "xres";
# Line 112 | Line 109 | char   *argv[];
109                  break;
110          }
111          newheader("RADIANCE", stdout);  /* start header */
112 +        fputnow(stdout);
113                                          /* process files */
114          for (nfiles = 0; nfiles < MAXINP; nfiles++) {
115                  setcolor(input[nfiles].coef, 1.0, 1.0, 1.0);
# Line 169 | Line 167 | char   *argv[];
167                                          colval(input[nfiles].expos,GRN);
168                          colval(input[nfiles].coef,BLU) /=
169                                          colval(input[nfiles].expos,BLU);
170 +                        setcolor(input[nfiles].expos, 1.0, 1.0, 1.0);
171                  }
172                  nfiles++;
173                  original = 0;
# Line 225 | Line 224 | usage:
224   }
225  
226  
227 < tputs(s)                        /* put out string preceded by a tab */
227 > tabputs(s)                      /* put out string preceded by a tab */
228   char    *s;
229   {
230          char    fmt[32];
# Line 233 | Line 232 | char   *s;
232          COLOR   ctmp;
233  
234          if (isheadid(s))                        /* header id */
235 <                return;         /* don't echo */
235 >                return(0);      /* don't echo */
236          if (formatval(fmt, s)) {                /* check format */
237                  if (globmatch(ourfmt, fmt)) {
238                          wrongformat = 0;
239                          strcpy(ourfmt, fmt);
240                  } else
241 <                        wrongformat = 1;
242 <                return;         /* don't echo */
241 >                        wrongformat = globmatch(PICFMT, fmt) ? 1 : -1;
242 >                return(0);      /* don't echo */
243          }
244          if (isexpos(s)) {                       /* exposure */
245                  d = exposval(s);
# Line 248 | Line 247 | char   *s;
247          } else if (iscolcor(s)) {               /* color correction */
248                  colcorval(ctmp, s);
249                  multcolor(input[nfiles].expos, ctmp);
250 <        } else if (isaspect(s)) {
250 >        } else if (isaspect(s))
251                  input[nfiles].pa *= aspectval(s);
252 <        } else if (isview(s) && sscanview(&input[nfiles].vw, s) > 0)
252 >        else if (isview(s) && sscanview(&input[nfiles].vw, s) > 0)
253                  gotview++;
254                                                  /* echo line */
255          putchar('\t');
256 <        fputs(s, stdout);
256 >        return(fputs(s, stdout));
257   }
258  
259  
# Line 265 | Line 264 | checkfile()                    /* ready a file */
264          gotview = 0;
265          fputs(input[nfiles].name, stdout);
266          fputs(":\n", stdout);
267 <        getheader(input[nfiles].fp, tputs, NULL);
268 <        if (wrongformat) {
267 >        getheader(input[nfiles].fp, tabputs, NULL);
268 >        if (wrongformat < 0) {
269                  eputs(input[nfiles].name);
270 <                eputs(": not in Radiance picture format\n");
270 >                eputs(": not a Radiance picture\n");
271                  quit(1);
272          }
273 +        if (wrongformat > 0) {
274 +                wputs(input[nfiles].name);
275 +                wputs(": warning -- incompatible picture format\n");
276 +        }
277          if (!gotview || setview(&input[nfiles].vw) != NULL)
278                  input[nfiles].vw.type = 0;
279          if (!fgetsresolu(&input[nfiles].rs, input[nfiles].fp)) {
# Line 314 | Line 317 | double (*ourbright)() = rgb_bright;
317  
318   init()                                  /* perform final setup */
319   {
320 <        double  l_colin(), l_expos(), l_ray(), l_psize();
320 >        double  l_colin(), l_expos(), l_pixaspect(), l_ray(), l_psize();
321          register int    i;
322                                                  /* define constants */
323 +        varset("PI", ':', PI);
324          varset(vnfiles, ':', (double)nfiles);
325          varset(vxmax, ':', (double)xmax);
326          varset(vymax, ':', (double)ymax);
# Line 327 | Line 331 | init()                                 /* perform final setup */
331          }
332          funset(vbrtexp, 1, ':', l_expos);
333          funset(vbrtin, 1, '=', l_colin);
334 <        for (i = 0; i < 6; i++)
334 >        funset(vpixaspect, 1, ':', l_pixaspect);
335 >        for (i = 0; i < 7; i++)
336                  funset(vray[i], 1, '=', l_ray);
337          funset(vpsize, 1, '=', l_psize);
338                                                  /* set brightness function */
339 <        if (!strcmp(ourfmt, CIEFMT))
339 >        if (!strcmp(ourfmt, CIEFMT)) {
340 >                varset(vwhteff, ':', 1.0);
341                  ourbright = xyz_bright;
342 +        } else
343 +                varset(vwhteff, ':', WHTEFFICACY);
344   }
345  
346  
# Line 390 | Line 398 | combine()                      /* combine pictures */
398                      quit(1);
399              }
400          }
401 <        efree(scanout);
401 >        efree((char *)scanout);
402   }
403  
404  
# Line 443 | Line 451 | register char  *nam;
451  
452  
453   double
454 + l_pixaspect()                   /* return pixel aspect ratio */
455 + {
456 +        register int    fn;
457 +
458 +        fn = argument(1) - .5;
459 +        if (fn < 0 || fn >= nfiles)
460 +                return(1.0);
461 +        return(input[fn].pa);
462 + }
463 +
464 +
465 + double
466   l_colin(nam)                    /* return color value for picture */
467   register char   *nam;
468   {
# Line 450 | Line 470 | register char  *nam;
470          register int    n, xoff, yoff;
471          double  d;
472  
473 <        d = argument(1);
454 <        if (d > -.5 && d < .5)
455 <                return((double)nfiles);
456 <        fn = d - .5;
473 >        fn = argument(1) - .5;
474          if (fn < 0 || fn >= nfiles) {
475                  errno = EDOM;
476                  return(0.0);
# Line 505 | Line 522 | register char  *nam;
522   {
523          static unsigned long    ltick[MAXINP];
524          static FVECT    lorg[MAXINP], ldir[MAXINP];
525 +        static double   ldist[MAXINP];
526          FLOAT   loc[2];
509        double  d;
527          int     fn;
528          register int    i;
529  
530 <        d = argument(1);
514 <        if (d > -.5 && d < .5)
515 <                return((double)nfiles);
516 <        fn = d - .5;
530 >        fn = argument(1) - .5;
531          if (fn < 0 || fn >= nfiles) {
532                  errno = EDOM;
533                  return(0.0);
534          }
535 <        if (ltick[fn] < eclock) {               /* need to compute? */
535 >        if (ltick[fn] != eclock) {              /* need to compute? */
536                  lorg[fn][0] = lorg[fn][1] = lorg[fn][2] = 0.0;
537                  ldir[fn][0] = ldir[fn][1] = ldir[fn][2] = 0.0;
538 +                ldist[fn] = -1.0;
539                  if (input[fn].vw.type == 0)
540                          errno = EDOM;
541                  else {
542                          pix2loc(loc, &input[fn].rs, xscan, ymax-1-yscan);
543 <                        if (viewray(lorg[fn], ldir[fn],
544 <                                        &input[fn].vw, loc[0], loc[1]) < 0)
530 <                                errno = ERANGE;
531 <                        ltick[fn] = eclock;
543 >                        ldist[fn] = viewray(lorg[fn], ldir[fn],
544 >                                        &input[fn].vw, loc[0], loc[1]);
545                  }
546 +                ltick[fn] = eclock;
547          }
548 <        i = 6;
548 >        if (nam == vray[i=6])
549 >                return(ldist[fn]);
550          while (i--)
551                  if (nam == vray[i])
552                          return(i < 3 ? lorg[fn][i] : ldir[fn][i-3]);
# Line 545 | Line 560 | l_psize()                      /* compute pixel size in steradians */
560   {
561          static unsigned long    ltick[MAXINP];
562          static double   psize[MAXINP];
563 <        FVECT   dir0, org1, dir1;
564 <        FLOAT   loc[2];
563 >        FVECT   dir0, org, dirx, diry;
564 >        FLOAT   locx[2], locy[2];
565          double  d;
566          int     fn;
567 +        register int    i;
568  
569          d = argument(1);
570 <        if (d > -.5 && d < .5)
555 <                return((double)nfiles);
556 <        fn = d - .5;
557 <        if (fn < 0 || fn >= nfiles) {
570 >        if (d < .5 || d >= nfiles+.5) {
571                  errno = EDOM;
572                  return(0.0);
573          }
574 <        if (ltick[fn] < eclock)                 /* need to compute? */
575 <                if (input[fn].vw.type == 0 || input[fn].vw.type == VT_PAR)
574 >        fn = d - .5;
575 >        if (ltick[fn] != eclock) {              /* need to compute? */
576 >                psize[fn] = 0.0;
577 >                if (input[fn].vw.type == 0)
578                          errno = EDOM;
579 <                else {
580 <                        errno = 0;
581 <                        dir0[0] = funvalue(vray[3], 1, &d);
582 <                        if (errno)
583 <                                return(0.0);
584 <                        dir0[1] = funvalue(vray[4], 1, &d);
585 <                        if (errno)
586 <                                return(0.0);
587 <                        dir0[2] = funvalue(vray[5], 1, &d);
588 <                        if (errno)
574 <                                return(0.0);
575 <                        pix2loc(loc, &input[fn].rs, xscan+1, ymax-yscan);
576 <                        psize[fn] = 0.0;
577 <                        if (viewray(org1, dir1,
578 <                                        &input[fn].vw, loc[0], loc[1]) < 0)
579 <                                errno = ERANGE;
580 <                        else {
579 >                else if (input[fn].vw.type != VT_PAR &&
580 >                                funvalue(vray[6], 1, &d) >= 0) {
581 >                        for (i = 0; i < 3; i++)
582 >                                dir0[i] = funvalue(vray[3+i], 1, &d);
583 >                        pix2loc(locx, &input[fn].rs, xscan+1, ymax-1-yscan);
584 >                        pix2loc(locy, &input[fn].rs, xscan, ymax-yscan);
585 >                        if (viewray(org, dirx, &input[fn].vw,
586 >                                        locx[0], locx[1]) >= 0 &&
587 >                                        viewray(org, diry, &input[fn].vw,
588 >                                        locy[0], locy[1]) >= 0) {
589                                                  /* approximate solid angle */
590 <                                psize[fn] = dist2(dir0, dir1) * input[fn].pa /
591 <                                        (1.0 + input[fn].pa*input[fn].pa);
592 <                                ltick[fn] = eclock;
590 >                                for (i = 0; i < 3; i++) {
591 >                                        dirx[i] -= dir0[i];
592 >                                        diry[i] -= dir0[i];
593 >                                }
594 >                                fcross(dir0, dirx, diry);
595 >                                psize[fn] = sqrt(DOT(dir0,dir0));
596                          }
597                  }
598 +                ltick[fn] = eclock;
599 +        }
600          return(psize[fn]);
601   }
602  
603  
604 + void
605   wputs(msg)
606   char    *msg;
607   {
# Line 596 | Line 610 | char   *msg;
610   }
611  
612  
613 + void
614   eputs(msg)
615   char    *msg;
616   {
# Line 603 | Line 618 | char   *msg;
618   }
619  
620  
621 + void
622   quit(code)              /* exit gracefully */
623   int  code;
624   {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines