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.12 by greg, Mon May 3 12:13:03 1993 UTC vs.
Revision 2.31 by greg, Mon Mar 15 21:16:54 2004 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   *
7   *      1/4/89
8   */
9  
10 < #include "standard.h"
11 <
10 > #include "platform.h"
11 > #include "rtprocess.h"
12 > #include "rterror.h"
13   #include "color.h"
16
17 #include "resolu.h"
18
14   #include "calcomp.h"
20
15   #include "view.h"
16  
17   #define MAXINP          32              /* maximum number of input files */
18 < #define WINSIZ          9               /* scanline window size */
19 < #define MIDSCN          4               /* current scan position */
18 > #define WINSIZ          64              /* scanline window size */
19 > #define MIDSCN          ((WINSIZ-1)/2+1)
20  
21   struct {
22          char    *name;          /* file or command name */
23          FILE    *fp;            /* stream pointer */
24          VIEW    vw;             /* view for picture */
25          RESOLU  rs;             /* image resolution and orientation */
26 +        float   pa;             /* pixel aspect ratio */
27          COLOR   *scan[WINSIZ];  /* input scanline window */
28          COLOR   coef;           /* coefficient */
29          COLOR   expos;          /* recorded exposure */
# Line 36 | Line 31 | struct {
31  
32   int     nfiles;                         /* number of input files */
33  
34 + char    ourfmt[LPICFMT+1] = PICFMT;     /* input picture format */
35 +
36 + char    StandardInput[] = "<stdin>";
37   char    Command[] = "<Command>";
38   char    vcolin[3][4] = {"ri", "gi", "bi"};
39   char    vcolout[3][4] = {"ro", "go", "bo"};
# Line 43 | 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 69 | Line 71 | char   *progname;                      /* global argv[0] */
71   int     wrongformat = 0;
72   int     gotview;
73  
72 FILE    *popen();
74  
75   extern char     *emalloc();
76  
77 + static gethfunc tabputs;
78  
79   main(argc, argv)
80   int     argc;
# Line 81 | Line 83 | char   *argv[];
83          int     original;
84          double  f;
85          int     a, i;
86 < #ifdef MSDOS
87 <        extern int  _fmode;
88 <        _fmode = O_BINARY;
87 <        setmode(fileno(stdin), O_BINARY);
88 <        setmode(fileno(stdout), O_BINARY);
89 < #endif
86 >        SET_DEFAULT_BINARY();
87 >        SET_FILE_BINARY(stdin);
88 >        SET_FILE_BINARY(stdout);
89          progname = argv[0];
90                                                  /* scan options */
91          for (a = 1; a < argc; a++) {
# Line 106 | Line 105 | char   *argv[];
105                          }
106                  break;
107          }
108 +        newheader("RADIANCE", stdout);  /* start header */
109 +        fputnow(stdout);
110                                          /* process files */
111          for (nfiles = 0; nfiles < MAXINP; nfiles++) {
112                  setcolor(input[nfiles].coef, 1.0, 1.0, 1.0);
113                  setcolor(input[nfiles].expos, 1.0, 1.0, 1.0);
114 <                copystruct(&input[nfiles].vw, &stdview);
114 >                input[nfiles].vw = stdview;
115 >                input[nfiles].pa = 1.0;
116          }
117          nfiles = 0;
118          original = 0;
# Line 123 | Line 125 | char   *argv[];
125                  if (argv[a][0] == '-')
126                          switch (argv[a][1]) {
127                          case '\0':
128 <                                input[nfiles].name = "<stdin>";
128 >                                input[nfiles].name = StandardInput;
129                                  input[nfiles].fp = stdin;
130                                  break;
131                          case 'o':
# Line 162 | Line 164 | char   *argv[];
164                                          colval(input[nfiles].expos,GRN);
165                          colval(input[nfiles].coef,BLU) /=
166                                          colval(input[nfiles].expos,BLU);
167 +                        setcolor(input[nfiles].expos, 1.0, 1.0, 1.0);
168                  }
169                  nfiles++;
170                  original = 0;
# Line 202 | Line 205 | char   *argv[];
205          }
206                                                  /* complete header */
207          printargs(argc, argv, stdout);
208 <        fputformat(COLRFMT, stdout);
208 >        if (strcmp(ourfmt, PICFMT))
209 >                fputformat(ourfmt, stdout);     /* print format if known */
210          putchar('\n');
211          fprtresolu(xres, yres, stdout);
212                                                  /* combine pictures */
# Line 217 | Line 221 | usage:
221   }
222  
223  
224 < tputs(s)                        /* put out string preceded by a tab */
225 < char    *s;
224 > static int
225 > tabputs(                        /* put out string preceded by a tab */
226 >        char    *s,
227 >        void    *p
228 > )
229   {
230          char    fmt[32];
231          double  d;
232          COLOR   ctmp;
233  
234 <        if (isformat(s)) {                      /* check format */
235 <                formatval(fmt, s);
236 <                wrongformat = strcmp(fmt, COLRFMT);
237 <                return;         /* don't echo */
234 >        if (isheadid(s))                        /* header id */
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 = globmatch(PICFMT, fmt) ? 1 : -1;
242 >                return(0);      /* don't echo */
243          }
244          if (isexpos(s)) {                       /* exposure */
245                  d = exposval(s);
# Line 235 | Line 247 | char   *s;
247          } else if (iscolcor(s)) {               /* color correction */
248                  colcorval(ctmp, s);
249                  multcolor(input[nfiles].expos, ctmp);
250 <        } else if (isview(s) && sscanview(&input[nfiles].vw, s) > 0)
250 >        } else if (isaspect(s))
251 >                input[nfiles].pa *= aspectval(s);
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 250 | 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 278 | Line 296 | checkfile()                    /* ready a file */
296   }
297  
298  
299 + double
300 + rgb_bright(clr)
301 + COLOR  clr;
302 + {
303 +        return(bright(clr));
304 + }
305 +
306 +
307 + double
308 + xyz_bright(clr)
309 + COLOR  clr;
310 + {
311 +        return(clr[CIEY]);
312 + }
313 +
314 +
315 + double  (*ourbright)() = rgb_bright;
316 +
317 +
318   init()                                  /* perform final setup */
319   {
320 <        double  l_colin(), l_expos(), l_ray();
320 >        double  l_colin(char *), l_expos(char *), l_pixaspect(char *),
321 >                        l_ray(char *), l_psize(char *);
322          register int    i;
323                                                  /* define constants */
324 +        varset("PI", ':', PI);
325          varset(vnfiles, ':', (double)nfiles);
326          varset(vxmax, ':', (double)xmax);
327          varset(vymax, ':', (double)ymax);
# Line 293 | Line 332 | init()                                 /* perform final setup */
332          }
333          funset(vbrtexp, 1, ':', l_expos);
334          funset(vbrtin, 1, '=', l_colin);
335 <        for (i = 0; i < 6; i++)
335 >        funset(vpixaspect, 1, ':', l_pixaspect);
336 >        for (i = 0; i < 7; i++)
337                  funset(vray[i], 1, '=', l_ray);
338 +        funset(vpsize, 1, '=', l_psize);
339 +                                                /* set brightness function */
340 +        if (!strcmp(ourfmt, CIEFMT)) {
341 +                varset(vwhteff, ':', 1.0);
342 +                ourbright = xyz_bright;
343 +        } else
344 +                varset(vwhteff, ':', WHTEFFICACY);
345   }
346  
347  
# Line 352 | Line 399 | combine()                      /* combine pictures */
399                      quit(1);
400              }
401          }
402 <        efree(scanout);
402 >        efree((char *)scanout);
403   }
404  
405  
# Line 394 | Line 441 | register char  *nam;
441          if (fn < 0 || fn >= nfiles)
442                  return(1.0);
443          if (nam == vbrtexp)
444 <                return(bright(input[fn].expos));
444 >                return((*ourbright)(input[fn].expos));
445          n = 3;
446          while (n--)
447                  if (nam == vcolexp[n])
# Line 405 | Line 452 | register char  *nam;
452  
453  
454   double
455 + l_pixaspect(char *nm)           /* return pixel aspect ratio */
456 + {
457 +        register int    fn;
458 +
459 +        fn = argument(1) - .5;
460 +        if (fn < 0 || fn >= nfiles)
461 +                return(1.0);
462 +        return(input[fn].pa);
463 + }
464 +
465 +
466 + double
467   l_colin(nam)                    /* return color value for picture */
468   register char   *nam;
469   {
# Line 412 | Line 471 | register char  *nam;
471          register int    n, xoff, yoff;
472          double  d;
473  
474 <        d = argument(1);
416 <        if (d > -.5 && d < .5)
417 <                return((double)nfiles);
418 <        fn = d - .5;
474 >        fn = argument(1) - .5;
475          if (fn < 0 || fn >= nfiles) {
476                  errno = EDOM;
477                  return(0.0);
# Line 451 | Line 507 | register char  *nam;
507                  }
508          }
509          if (nam == vbrtin)
510 <                return(bright(input[fn].scan[MIDSCN+yoff][xscan+xoff]));
510 >                return((*ourbright)(input[fn].scan[MIDSCN+yoff][xscan+xoff]));
511          n = 3;
512          while (n--)
513              if (nam == vcolin[n])
# Line 465 | Line 521 | double
521   l_ray(nam)              /* return ray origin or direction */
522   register char   *nam;
523   {
524 <        static long     ltick[MAXINP];
524 >        static unsigned long    ltick[MAXINP];
525          static FVECT    lorg[MAXINP], ldir[MAXINP];
526 <        FLOAT   loc[2];
527 <        double  d;
526 >        static double   ldist[MAXINP];
527 >        RREAL   loc[2];
528          int     fn;
529          register int    i;
530  
531 <        d = argument(1);
476 <        if (d > -.5 && d < .5)
477 <                return((double)nfiles);
478 <        fn = d - .5;
531 >        fn = argument(1) - .5;
532          if (fn < 0 || fn >= nfiles) {
533                  errno = EDOM;
534                  return(0.0);
535          }
536 <        if (ltick[fn] < eclock) {               /* need to compute? */
536 >        if (ltick[fn] != eclock) {              /* need to compute? */
537                  lorg[fn][0] = lorg[fn][1] = lorg[fn][2] = 0.0;
538                  ldir[fn][0] = ldir[fn][1] = ldir[fn][2] = 0.0;
539 +                ldist[fn] = -1.0;
540                  if (input[fn].vw.type == 0)
541                          errno = EDOM;
542                  else {
543                          pix2loc(loc, &input[fn].rs, xscan, ymax-1-yscan);
544 <                        if (viewray(lorg[fn], ldir[fn],
545 <                                        &input[fn].vw, loc[0], loc[1]) < 0)
492 <                                errno = ERANGE;
544 >                        ldist[fn] = viewray(lorg[fn], ldir[fn],
545 >                                        &input[fn].vw, loc[0], loc[1]);
546                  }
547                  ltick[fn] = eclock;
548          }
549 <        i = 6;
549 >        if (nam == vray[i=6])
550 >                return(ldist[fn]);
551          while (i--)
552                  if (nam == vray[i])
553                          return(i < 3 ? lorg[fn][i] : ldir[fn][i-3]);
# Line 502 | Line 556 | register char  *nam;
556   }
557  
558  
559 < wputs(msg)
560 < char    *msg;
559 > double
560 > l_psize(char *nm)               /* compute pixel size in steradians */
561   {
562 +        static unsigned long    ltick[MAXINP];
563 +        static double   psize[MAXINP];
564 +        FVECT   dir0, org, dirx, diry;
565 +        RREAL   locx[2], locy[2];
566 +        double  d;
567 +        int     fn;
568 +        register int    i;
569 +
570 +        d = argument(1);
571 +        if (d < .5 || d >= nfiles+.5) {
572 +                errno = EDOM;
573 +                return(0.0);
574 +        }
575 +        fn = d - .5;
576 +        if (ltick[fn] != eclock) {              /* need to compute? */
577 +                psize[fn] = 0.0;
578 +                if (input[fn].vw.type == 0)
579 +                        errno = EDOM;
580 +                else if (input[fn].vw.type != VT_PAR &&
581 +                                funvalue(vray[6], 1, &d) >= 0) {
582 +                        for (i = 0; i < 3; i++)
583 +                                dir0[i] = funvalue(vray[3+i], 1, &d);
584 +                        pix2loc(locx, &input[fn].rs, xscan+1, ymax-1-yscan);
585 +                        pix2loc(locy, &input[fn].rs, xscan, ymax-yscan);
586 +                        if (viewray(org, dirx, &input[fn].vw,
587 +                                        locx[0], locx[1]) >= 0 &&
588 +                                        viewray(org, diry, &input[fn].vw,
589 +                                        locy[0], locy[1]) >= 0) {
590 +                                                /* approximate solid angle */
591 +                                for (i = 0; i < 3; i++) {
592 +                                        dirx[i] -= dir0[i];
593 +                                        diry[i] -= dir0[i];
594 +                                }
595 +                                fcross(dir0, dirx, diry);
596 +                                psize[fn] = sqrt(DOT(dir0,dir0));
597 +                        }
598 +                }
599 +                ltick[fn] = eclock;
600 +        }
601 +        return(psize[fn]);
602 + }
603 +
604 +
605 + extern void
606 + wputs(char      *msg)
607 + {
608          if (!nowarn)
609                  eputs(msg);
610   }
611  
612  
613 < eputs(msg)
614 < char    *msg;
613 > extern void
614 > eputs(char *msg)
615   {
616          fputs(msg, stderr);
617   }
618  
619  
620 < quit(code)              /* exit gracefully */
621 < int  code;
620 > extern void
621 > quit(int code)          /* exit gracefully */
622   {
623          register int  i;
624                                  /* close input files */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines