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.16 by greg, Mon Oct 16 12:04:33 1995 UTC vs.
Revision 2.23 by schorsch, Thu Jun 5 19:29:34 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 11 | Line 8 | static char SCCSid[] = "$SunId$ LBL";
8   */
9  
10   #include "standard.h"
14
11   #include "color.h"
16
17 #include "resolu.h"
18
12   #include "calcomp.h"
20
13   #include "view.h"
14  
15   #define MAXINP          32              /* maximum number of input files */
16 < #define WINSIZ          17              /* scanline window size */
16 > #define WINSIZ          64              /* scanline window size */
17   #define MIDSCN          ((WINSIZ-1)/2+1)
18  
19   struct {
# Line 29 | Line 21 | struct {
21          FILE    *fp;            /* stream pointer */
22          VIEW    vw;             /* view for picture */
23          RESOLU  rs;             /* image resolution and orientation */
24 +        float   pa;             /* pixel aspect ratio */
25          COLOR   *scan[WINSIZ];  /* input scanline window */
26          COLOR   coef;           /* coefficient */
27          COLOR   expos;          /* recorded exposure */
# Line 45 | Line 38 | char   vbrtin[] = "li";
38   char    vbrtout[] = "lo";
39   char    vcolexp[3][4] = {"re", "ge", "be"};
40   char    vbrtexp[] = "le";
41 + char    vpixaspect[] = "pa";
42  
43 < char    vray[6][4] = {"Ox", "Oy", "Oz", "Dx", "Dy", "Dz"};
43 > char    vray[7][4] = {"Ox", "Oy", "Oz", "Dx", "Dy", "Dz", "T"};
44  
45 + char    vpsize[] = "S";
46 +
47   char    vnfiles[] = "nfiles";
48 + char    vwhteff[] = "WE";
49   char    vxmax[] = "xmax";
50   char    vymax[] = "ymax";
51   char    vxres[] = "xres";
# Line 83 | Line 80 | char   *argv[];
80          int     original;
81          double  f;
82          int     a, i;
83 < #ifdef MSDOS
84 <        extern int  _fmode;
85 <        _fmode = O_BINARY;
89 <        setmode(fileno(stdin), O_BINARY);
90 <        setmode(fileno(stdout), O_BINARY);
91 < #endif
83 >        SET_DEFAULT_BINARY();
84 >        SET_FILE_BINARY(stdin);
85 >        SET_FILE_BINARY(stdout);
86          progname = argv[0];
87                                                  /* scan options */
88          for (a = 1; a < argc; a++) {
# Line 109 | Line 103 | char   *argv[];
103                  break;
104          }
105          newheader("RADIANCE", stdout);  /* start header */
106 +        fputnow(stdout);
107                                          /* process files */
108          for (nfiles = 0; nfiles < MAXINP; nfiles++) {
109                  setcolor(input[nfiles].coef, 1.0, 1.0, 1.0);
110                  setcolor(input[nfiles].expos, 1.0, 1.0, 1.0);
111                  copystruct(&input[nfiles].vw, &stdview);
112 +                input[nfiles].pa = 1.0;
113          }
114          nfiles = 0;
115          original = 0;
# Line 165 | Line 161 | char   *argv[];
161                                          colval(input[nfiles].expos,GRN);
162                          colval(input[nfiles].coef,BLU) /=
163                                          colval(input[nfiles].expos,BLU);
164 +                        setcolor(input[nfiles].expos, 1.0, 1.0, 1.0);
165                  }
166                  nfiles++;
167                  original = 0;
# Line 221 | Line 218 | usage:
218   }
219  
220  
221 < tputs(s)                        /* put out string preceded by a tab */
221 > tabputs(s)                      /* put out string preceded by a tab */
222   char    *s;
223   {
224          char    fmt[32];
# Line 229 | Line 226 | char   *s;
226          COLOR   ctmp;
227  
228          if (isheadid(s))                        /* header id */
229 <                return;         /* don't echo */
229 >                return(0);      /* don't echo */
230          if (formatval(fmt, s)) {                /* check format */
231                  if (globmatch(ourfmt, fmt)) {
232                          wrongformat = 0;
233                          strcpy(ourfmt, fmt);
234                  } else
235 <                        wrongformat = 1;
236 <                return;         /* don't echo */
235 >                        wrongformat = globmatch(PICFMT, fmt) ? 1 : -1;
236 >                return(0);      /* don't echo */
237          }
238          if (isexpos(s)) {                       /* exposure */
239                  d = exposval(s);
# Line 244 | Line 241 | char   *s;
241          } else if (iscolcor(s)) {               /* color correction */
242                  colcorval(ctmp, s);
243                  multcolor(input[nfiles].expos, ctmp);
244 <        } else if (isview(s) && sscanview(&input[nfiles].vw, s) > 0)
244 >        } else if (isaspect(s))
245 >                input[nfiles].pa *= aspectval(s);
246 >        else if (isview(s) && sscanview(&input[nfiles].vw, s) > 0)
247                  gotview++;
248                                                  /* echo line */
249          putchar('\t');
250 <        fputs(s, stdout);
250 >        return(fputs(s, stdout));
251   }
252  
253  
# Line 259 | Line 258 | checkfile()                    /* ready a file */
258          gotview = 0;
259          fputs(input[nfiles].name, stdout);
260          fputs(":\n", stdout);
261 <        getheader(input[nfiles].fp, tputs, NULL);
262 <        if (wrongformat) {
261 >        getheader(input[nfiles].fp, tabputs, NULL);
262 >        if (wrongformat < 0) {
263                  eputs(input[nfiles].name);
264 <                eputs(": not in Radiance picture format\n");
264 >                eputs(": not a Radiance picture\n");
265                  quit(1);
266          }
267 +        if (wrongformat > 0) {
268 +                wputs(input[nfiles].name);
269 +                wputs(": warning -- incompatible picture format\n");
270 +        }
271          if (!gotview || setview(&input[nfiles].vw) != NULL)
272                  input[nfiles].vw.type = 0;
273          if (!fgetsresolu(&input[nfiles].rs, input[nfiles].fp)) {
# Line 308 | Line 311 | double (*ourbright)() = rgb_bright;
311  
312   init()                                  /* perform final setup */
313   {
314 <        double  l_colin(), l_expos(), l_ray();
314 >        double  l_colin(), l_expos(), l_pixaspect(), l_ray(), l_psize();
315          register int    i;
316                                                  /* define constants */
317 +        varset("PI", ':', PI);
318          varset(vnfiles, ':', (double)nfiles);
319          varset(vxmax, ':', (double)xmax);
320          varset(vymax, ':', (double)ymax);
# Line 321 | Line 325 | init()                                 /* perform final setup */
325          }
326          funset(vbrtexp, 1, ':', l_expos);
327          funset(vbrtin, 1, '=', l_colin);
328 <        for (i = 0; i < 6; i++)
328 >        funset(vpixaspect, 1, ':', l_pixaspect);
329 >        for (i = 0; i < 7; i++)
330                  funset(vray[i], 1, '=', l_ray);
331 +        funset(vpsize, 1, '=', l_psize);
332                                                  /* set brightness function */
333 <        if (!strcmp(ourfmt, CIEFMT))
333 >        if (!strcmp(ourfmt, CIEFMT)) {
334 >                varset(vwhteff, ':', 1.0);
335                  ourbright = xyz_bright;
336 +        } else
337 +                varset(vwhteff, ':', WHTEFFICACY);
338   }
339  
340  
# Line 383 | Line 392 | combine()                      /* combine pictures */
392                      quit(1);
393              }
394          }
395 <        efree(scanout);
395 >        efree((char *)scanout);
396   }
397  
398  
# Line 436 | Line 445 | register char  *nam;
445  
446  
447   double
448 + l_pixaspect()                   /* return pixel aspect ratio */
449 + {
450 +        register int    fn;
451 +
452 +        fn = argument(1) - .5;
453 +        if (fn < 0 || fn >= nfiles)
454 +                return(1.0);
455 +        return(input[fn].pa);
456 + }
457 +
458 +
459 + double
460   l_colin(nam)                    /* return color value for picture */
461   register char   *nam;
462   {
# Line 443 | Line 464 | register char  *nam;
464          register int    n, xoff, yoff;
465          double  d;
466  
467 <        d = argument(1);
447 <        if (d > -.5 && d < .5)
448 <                return((double)nfiles);
449 <        fn = d - .5;
467 >        fn = argument(1) - .5;
468          if (fn < 0 || fn >= nfiles) {
469                  errno = EDOM;
470                  return(0.0);
# Line 498 | Line 516 | register char  *nam;
516   {
517          static unsigned long    ltick[MAXINP];
518          static FVECT    lorg[MAXINP], ldir[MAXINP];
519 +        static double   ldist[MAXINP];
520          FLOAT   loc[2];
502        double  d;
521          int     fn;
522          register int    i;
523  
524 <        d = argument(1);
507 <        if (d > -.5 && d < .5)
508 <                return((double)nfiles);
509 <        fn = d - .5;
524 >        fn = argument(1) - .5;
525          if (fn < 0 || fn >= nfiles) {
526                  errno = EDOM;
527                  return(0.0);
528          }
529 <        if (ltick[fn] < eclock) {               /* need to compute? */
529 >        if (ltick[fn] != eclock) {              /* need to compute? */
530                  lorg[fn][0] = lorg[fn][1] = lorg[fn][2] = 0.0;
531                  ldir[fn][0] = ldir[fn][1] = ldir[fn][2] = 0.0;
532 +                ldist[fn] = -1.0;
533                  if (input[fn].vw.type == 0)
534                          errno = EDOM;
535                  else {
536                          pix2loc(loc, &input[fn].rs, xscan, ymax-1-yscan);
537 <                        if (viewray(lorg[fn], ldir[fn],
538 <                                        &input[fn].vw, loc[0], loc[1]) < 0)
523 <                                errno = ERANGE;
537 >                        ldist[fn] = viewray(lorg[fn], ldir[fn],
538 >                                        &input[fn].vw, loc[0], loc[1]);
539                  }
540                  ltick[fn] = eclock;
541          }
542 <        i = 6;
542 >        if (nam == vray[i=6])
543 >                return(ldist[fn]);
544          while (i--)
545                  if (nam == vray[i])
546                          return(i < 3 ? lorg[fn][i] : ldir[fn][i-3]);
# Line 533 | Line 549 | register char  *nam;
549   }
550  
551  
552 + double
553 + l_psize()                       /* compute pixel size in steradians */
554 + {
555 +        static unsigned long    ltick[MAXINP];
556 +        static double   psize[MAXINP];
557 +        FVECT   dir0, org, dirx, diry;
558 +        FLOAT   locx[2], locy[2];
559 +        double  d;
560 +        int     fn;
561 +        register int    i;
562 +
563 +        d = argument(1);
564 +        if (d < .5 || d >= nfiles+.5) {
565 +                errno = EDOM;
566 +                return(0.0);
567 +        }
568 +        fn = d - .5;
569 +        if (ltick[fn] != eclock) {              /* need to compute? */
570 +                psize[fn] = 0.0;
571 +                if (input[fn].vw.type == 0)
572 +                        errno = EDOM;
573 +                else if (input[fn].vw.type != VT_PAR &&
574 +                                funvalue(vray[6], 1, &d) >= 0) {
575 +                        for (i = 0; i < 3; i++)
576 +                                dir0[i] = funvalue(vray[3+i], 1, &d);
577 +                        pix2loc(locx, &input[fn].rs, xscan+1, ymax-1-yscan);
578 +                        pix2loc(locy, &input[fn].rs, xscan, ymax-yscan);
579 +                        if (viewray(org, dirx, &input[fn].vw,
580 +                                        locx[0], locx[1]) >= 0 &&
581 +                                        viewray(org, diry, &input[fn].vw,
582 +                                        locy[0], locy[1]) >= 0) {
583 +                                                /* approximate solid angle */
584 +                                for (i = 0; i < 3; i++) {
585 +                                        dirx[i] -= dir0[i];
586 +                                        diry[i] -= dir0[i];
587 +                                }
588 +                                fcross(dir0, dirx, diry);
589 +                                psize[fn] = sqrt(DOT(dir0,dir0));
590 +                        }
591 +                }
592 +                ltick[fn] = eclock;
593 +        }
594 +        return(psize[fn]);
595 + }
596 +
597 +
598 + void
599   wputs(msg)
600   char    *msg;
601   {
# Line 541 | Line 604 | char   *msg;
604   }
605  
606  
607 + void
608   eputs(msg)
609   char    *msg;
610   {
# Line 548 | Line 612 | char   *msg;
612   }
613  
614  
615 + void
616   quit(code)              /* exit gracefully */
617   int  code;
618   {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines