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.2 by greg, Fri Mar 27 10:04:12 1992 UTC vs.
Revision 2.39 by greg, Fri Sep 8 21:38:25 2006 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1991 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 <stdio.h>
11 <
12 < #include <errno.h>
16 <
10 > #include "platform.h"
11 > #include "standard.h"
12 > #include "rtprocess.h"
13   #include "color.h"
18
19 #include  "resolu.h"
20
14   #include "calcomp.h"
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 */
17 > #define MAXINP          512             /* maximum number of input files */
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 34 | 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"};
40   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[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 59 | Line 66 | int    xres, yres;                     /* output resolution */
66  
67   int     xpos, ypos;                     /* output position */
68  
69 + char    *progname;                      /* global argv[0] */
70 +
71 + int     echoheader = 1;
72   int     wrongformat = 0;
73 + int     gotview;
74  
64 FILE    *popen();
75  
76 + static gethfunc headline;
77 + static void checkfile(void);
78 + static double rgb_bright(COLOR  clr);
79 + static double xyz_bright(COLOR  clr);
80 + static void init(void);
81 + static void combine(void);
82 + static void advance(void);
83 + static double l_expos(char      *nam);
84 + static double l_pixaspect(char *nm);
85 + static double l_colin(char      *nam);
86 + static double l_ray(char        *nam);
87 + static double l_psize(char *nm);
88  
89 < main(argc, argv)
90 < int     argc;
91 < char    *argv[];
89 >
90 > int
91 > main(
92 >        int     argc,
93 >        char    *argv[]
94 > )
95   {
96          int     original;
97          double  f;
98 <        int     a, i;
98 >        int     a;
99 >        SET_DEFAULT_BINARY();
100 >        SET_FILE_BINARY(stdin);
101 >        SET_FILE_BINARY(stdout);
102 >        progname = argv[0];
103                                                  /* scan options */
104          for (a = 1; a < argc; a++) {
105                  if (argv[a][0] == '-')
# Line 82 | Line 111 | char   *argv[];
111                          case 'w':
112                                  nowarn = !nowarn;
113                                  continue;
114 +                        case 'h':
115 +                                echoheader = !echoheader;
116 +                                continue;
117                          case 'f':
118                          case 'e':
119                                  a++;
# Line 89 | Line 121 | char   *argv[];
121                          }
122                  break;
123          }
124 +        newheader("RADIANCE", stdout);  /* start header */
125 +        fputnow(stdout);
126                                          /* process files */
127          for (nfiles = 0; nfiles < MAXINP; nfiles++) {
128                  setcolor(input[nfiles].coef, 1.0, 1.0, 1.0);
129                  setcolor(input[nfiles].expos, 1.0, 1.0, 1.0);
130 +                input[nfiles].vw = stdview;
131 +                input[nfiles].pa = 1.0;
132          }
133          nfiles = 0;
134          original = 0;
# Line 105 | Line 141 | char   *argv[];
141                  if (argv[a][0] == '-')
142                          switch (argv[a][1]) {
143                          case '\0':
144 <                                input[nfiles].name = "<stdin>";
144 >                                input[nfiles].name = StandardInput;
145                                  input[nfiles].fp = stdin;
146                                  break;
147                          case 'o':
# Line 125 | Line 161 | char   *argv[];
161                          }
162                  else {
163                          if (argv[a][0] == '!') {
164 <                                input[nfiles].name = "<Command>";
164 >                                input[nfiles].name = Command;
165                                  input[nfiles].fp = popen(argv[a]+1, "r");
166                          } else {
167                                  input[nfiles].name = argv[a];
# Line 144 | Line 180 | char   *argv[];
180                                          colval(input[nfiles].expos,GRN);
181                          colval(input[nfiles].coef,BLU) /=
182                                          colval(input[nfiles].expos,BLU);
183 +                        setcolor(input[nfiles].expos, 1.0, 1.0, 1.0);
184                  }
185                  nfiles++;
186                  original = 0;
# Line 184 | Line 221 | char   *argv[];
221          }
222                                                  /* complete header */
223          printargs(argc, argv, stdout);
224 <        fputformat(COLRFMT, stdout);
224 >        if (strcmp(ourfmt, PICFMT))
225 >                fputformat(ourfmt, stdout);     /* print format if known */
226          putchar('\n');
227          fprtresolu(xres, yres, stdout);
228                                                  /* combine pictures */
# Line 194 | Line 232 | usage:
232          eputs("Usage: ");
233          eputs(argv[0]);
234          eputs(
235 < " [-w][-x xr][-y yr][-e expr][-f file] [ [-s f][-c r g b] pic ..]\n");
235 > " [-w][-h][-x xr][-y yr][-e expr][-f file] [ [-o][-s f][-c r g b] pic ..]\n");
236          quit(1);
237 +        return 1; /* pro forma return */
238   }
239  
240  
241 < tputs(s)                        /* put out string preceded by a tab */
242 < char    *s;
241 > static int
242 > headline(                       /* check header line & echo if requested */
243 >        char    *s,
244 >        void    *p
245 > )
246   {
247          char    fmt[32];
248          double  d;
249          COLOR   ctmp;
250  
251 <        if (isformat(s)) {                      /* check format */
252 <                formatval(fmt, s);
253 <                wrongformat = strcmp(fmt, COLRFMT);
254 <                return;         /* don't echo */
251 >        if (isheadid(s))                        /* header id */
252 >                return(0);      /* don't echo */
253 >        if (formatval(fmt, s)) {                /* check format */
254 >                if (globmatch(ourfmt, fmt)) {
255 >                        wrongformat = 0;
256 >                        strcpy(ourfmt, fmt);
257 >                } else
258 >                        wrongformat = globmatch(PICFMT, fmt) ? 1 : -1;
259 >                return(0);      /* don't echo */
260          }
261          if (isexpos(s)) {                       /* exposure */
262                  d = exposval(s);
# Line 217 | Line 264 | char   *s;
264          } else if (iscolcor(s)) {               /* color correction */
265                  colcorval(ctmp, s);
266                  multcolor(input[nfiles].expos, ctmp);
267 +        } else if (isaspect(s))
268 +                input[nfiles].pa *= aspectval(s);
269 +        else if (isview(s) && sscanview(&input[nfiles].vw, s) > 0)
270 +                gotview++;
271 +
272 +        if (echoheader) {                       /* echo line */
273 +                putchar('\t');
274 +                return(fputs(s, stdout));
275          }
276 <                                                /* echo line */
222 <        putchar('\t');
223 <        fputs(s, stdout);
276 >        return(0);
277   }
278  
279  
280 < checkfile()                     /* ready a file */
280 > static void
281 > checkfile(void)                 /* ready a file */
282   {
229        int     xinp, yinp;
283          register int    i;
284                                          /* process header */
285 <        fputs(input[nfiles].name, stdout);
286 <        fputs(":\n", stdout);
287 <        getheader(input[nfiles].fp, tputs, NULL);
288 <        if (wrongformat) {
285 >        gotview = 0;
286 >        if (echoheader) {
287 >                fputs(input[nfiles].name, stdout);
288 >                fputs(":\n", stdout);
289 >        }
290 >        getheader(input[nfiles].fp, headline, NULL);
291 >        if (wrongformat < 0) {
292                  eputs(input[nfiles].name);
293 <                eputs(": not in Radiance picture format\n");
293 >                eputs(": not a Radiance picture\n");
294                  quit(1);
295          }
296 <        if (fgetresolu(&xinp, &yinp, input[nfiles].fp) < 0) {
296 >        if (wrongformat > 0) {
297 >                wputs(input[nfiles].name);
298 >                wputs(": warning -- incompatible picture format\n");
299 >        }
300 >        if (!gotview || setview(&input[nfiles].vw) != NULL)
301 >                input[nfiles].vw.type = 0;
302 >        if (!fgetsresolu(&input[nfiles].rs, input[nfiles].fp)) {
303                  eputs(input[nfiles].name);
304                  eputs(": bad picture size\n");
305                  quit(1);
306          }
307          if (xmax == 0 && ymax == 0) {
308 <                xmax = xinp;
309 <                ymax = yinp;
310 <        } else if (xinp != xmax || yinp != ymax) {
308 >                xmax = scanlen(&input[nfiles].rs);
309 >                ymax = numscans(&input[nfiles].rs);
310 >        } else if (scanlen(&input[nfiles].rs) != xmax ||
311 >                        numscans(&input[nfiles].rs) != ymax) {
312                  eputs(input[nfiles].name);
313                  eputs(": resolution mismatch\n");
314                  quit(1);
# Line 256 | Line 319 | checkfile()                    /* ready a file */
319   }
320  
321  
322 < init()                                  /* perform final setup */
322 > static double
323 > rgb_bright(
324 >        COLOR  clr
325 > )
326   {
327 <        double  l_colin(), l_expos();
327 >        return(bright(clr));
328 > }
329 >
330 >
331 > static double
332 > xyz_bright(
333 >        COLOR  clr
334 > )
335 > {
336 >        return(clr[CIEY]);
337 > }
338 >
339 >
340 > double  (*ourbright)() = rgb_bright;
341 >
342 >
343 > static void
344 > init(void)                                      /* perform final setup */
345 > {
346          register int    i;
347                                                  /* define constants */
348 +        varset("PI", ':', PI);
349          varset(vnfiles, ':', (double)nfiles);
350          varset(vxmax, ':', (double)xmax);
351          varset(vymax, ':', (double)ymax);
# Line 271 | Line 356 | init()                                 /* perform final setup */
356          }
357          funset(vbrtexp, 1, ':', l_expos);
358          funset(vbrtin, 1, '=', l_colin);
359 +        funset(vpixaspect, 1, ':', l_pixaspect);
360 +        for (i = 0; i < 7; i++)
361 +                funset(vray[i], 1, '=', l_ray);
362 +        funset(vpsize, 1, '=', l_psize);
363 +                                                /* set brightness function */
364 +        if (!strcmp(ourfmt, CIEFMT)) {
365 +                varset(vwhteff, ':', 1.0);
366 +                ourbright = xyz_bright;
367 +        } else
368 +                varset(vwhteff, ':', WHTEFFICACY);
369   }
370  
371  
372 < combine()                       /* combine pictures */
372 > static void
373 > combine(void)                   /* combine pictures */
374   {
375          EPNODE  *coldef[3], *brtdef;
376          COLOR   *scanout;
# Line 328 | Line 424 | combine()                      /* combine pictures */
424                      quit(1);
425              }
426          }
427 <        efree(scanout);
427 >        efree((char *)scanout);
428   }
429  
430  
431 < advance()                       /* read in data for next scanline */
431 > static void
432 > advance(void)                   /* read in data for next scanline */
433   {
434          int     ytarget;
435          register COLOR  *st;
# Line 346 | Line 443 | advance()                      /* read in data for next scanline */
443                          input[i].scan[0] = st;
444                          if (yscan <= MIDSCN)            /* hit bottom? */
445                                  continue;
446 <                        if (freadscan(st, xmax, input[i].fp) < 0) {     /* read */
446 >                        if (freadscan(st, xmax, input[i].fp) < 0) {  /* read */
447                                  eputs(input[i].name);
448                                  eputs(": read error\n");
449                                  quit(1);
# Line 357 | Line 454 | advance()                      /* read in data for next scanline */
454   }
455  
456  
457 < double
458 < l_expos(nam)                    /* return picture exposure */
459 < register char   *nam;
457 > static double
458 > l_expos(                        /* return picture exposure */
459 >        register char   *nam
460 > )
461   {
462          register int    fn, n;
463  
# Line 367 | Line 465 | register char  *nam;
465          if (fn < 0 || fn >= nfiles)
466                  return(1.0);
467          if (nam == vbrtexp)
468 <                return(bright(input[fn].expos));
468 >                return((*ourbright)(input[fn].expos));
469          n = 3;
470          while (n--)
471                  if (nam == vcolexp[n])
472                          return(colval(input[fn].expos,n));
473          eputs("Bad call to l_expos()!\n");
474          quit(1);
475 +        return 1; /* pro forma return */
476   }
477  
478  
479 < double
480 < l_colin(nam)                    /* return color value for picture */
382 < register char   *nam;
479 > static double
480 > l_pixaspect(char *nm)           /* return pixel aspect ratio */
481   {
482 +        register int    fn;
483 +
484 +        fn = argument(1) - .5;
485 +        if (fn < 0 || fn >= nfiles)
486 +                return(1.0);
487 +        return(input[fn].pa);
488 + }
489 +
490 +
491 + static double
492 + l_colin(                        /* return color value for picture */
493 +        register char   *nam
494 + )
495 + {
496          int     fn;
497          register int    n, xoff, yoff;
498          double  d;
499  
500 <        d = argument(1);
389 <        if (d > -.5 && d < .5)
390 <                return((double)nfiles);
391 <        fn = d - .5;
500 >        fn = argument(1) - .5;
501          if (fn < 0 || fn >= nfiles) {
502                  errno = EDOM;
503                  return(0.0);
# Line 424 | Line 533 | register char  *nam;
533                  }
534          }
535          if (nam == vbrtin)
536 <                return(bright(input[fn].scan[MIDSCN+yoff][xscan+xoff]));
536 >                return((*ourbright)(input[fn].scan[MIDSCN+yoff][xscan+xoff]));
537          n = 3;
538          while (n--)
539              if (nam == vcolin[n])
540                  return(colval(input[fn].scan[MIDSCN+yoff][xscan+xoff],n));
541          eputs("Bad call to l_colin()!\n");
542          quit(1);
543 +        return 1; /* pro forma return */
544   }
545  
546  
547 < wputs(msg)
548 < char    *msg;
547 > static double
548 > l_ray(          /* return ray origin or direction */
549 >        register char   *nam
550 > )
551   {
552 +        static unsigned long    ltick[MAXINP];
553 +        static FVECT    lorg[MAXINP], ldir[MAXINP];
554 +        static double   ldist[MAXINP];
555 +        RREAL   loc[2];
556 +        int     fn;
557 +        register int    i;
558 +
559 +        fn = argument(1) - .5;
560 +        if (fn < 0 || fn >= nfiles) {
561 +                errno = EDOM;
562 +                return(0.0);
563 +        }
564 +        if (ltick[fn] != eclock) {              /* need to compute? */
565 +                lorg[fn][0] = lorg[fn][1] = lorg[fn][2] = 0.0;
566 +                ldir[fn][0] = ldir[fn][1] = ldir[fn][2] = 0.0;
567 +                ldist[fn] = -1.0;
568 +                if (input[fn].vw.type == 0)
569 +                        errno = EDOM;
570 +                else {
571 +                        pix2loc(loc, &input[fn].rs, xscan, ymax-1-yscan);
572 +                        ldist[fn] = viewray(lorg[fn], ldir[fn],
573 +                                        &input[fn].vw, loc[0], loc[1]);
574 +                }
575 +                ltick[fn] = eclock;
576 +        }
577 +        if (nam == vray[i=6])
578 +                return(ldist[fn]);
579 +        while (i--)
580 +                if (nam == vray[i])
581 +                        return(i < 3 ? lorg[fn][i] : ldir[fn][i-3]);
582 +        eputs("Bad call to l_ray()!\n");
583 +        quit(1);
584 +        return 1; /* pro forma return */
585 + }
586 +
587 +
588 + static double
589 + l_psize(char *nm)               /* compute pixel size in steradians */
590 + {
591 +        static unsigned long    ltick[MAXINP];
592 +        static double   psize[MAXINP];
593 +        FVECT   dir0, org, dirx, diry;
594 +        RREAL   locx[2], locy[2];
595 +        double  d;
596 +        int     fn;
597 +        register int    i;
598 +
599 +        d = argument(1);
600 +        if (d < .5 || d >= nfiles+.5) {
601 +                errno = EDOM;
602 +                return(0.0);
603 +        }
604 +        fn = d - .5;
605 +        if (ltick[fn] != eclock) {              /* need to compute? */
606 +                psize[fn] = 0.0;
607 +                if (input[fn].vw.type == 0)
608 +                        errno = EDOM;
609 +                else if (input[fn].vw.type != VT_PAR &&
610 +                                funvalue(vray[6], 1, &d) >= -FTINY) {
611 +                        for (i = 0; i < 3; i++)
612 +                                dir0[i] = funvalue(vray[3+i], 1, &d);
613 +                        pix2loc(locx, &input[fn].rs, xscan+1, ymax-1-yscan);
614 +                        pix2loc(locy, &input[fn].rs, xscan, ymax-yscan);
615 +                        if (viewray(org, dirx, &input[fn].vw,
616 +                                        locx[0], locx[1]) >= -FTINY &&
617 +                                        viewray(org, diry, &input[fn].vw,
618 +                                        locy[0], locy[1]) >= -FTINY) {
619 +                                                /* approximate solid angle */
620 +                                for (i = 0; i < 3; i++) {
621 +                                        dirx[i] -= dir0[i];
622 +                                        diry[i] -= dir0[i];
623 +                                }
624 +                                fcross(dir0, dirx, diry);
625 +                                psize[fn] = VLEN(dir0);
626 +                        }
627 +                }
628 +                ltick[fn] = eclock;
629 +        }
630 +        return(psize[fn]);
631 + }
632 +
633 +
634 + extern void
635 + wputs(char      *msg)
636 + {
637          if (!nowarn)
638                  eputs(msg);
639   }
640  
641  
642 < eputs(msg)
643 < char    *msg;
642 > extern void
643 > eputs(char *msg)
644   {
645          fputs(msg, stderr);
646   }
647  
648  
649 < quit(code)
650 < int     code;
649 > extern void
650 > quit(int code)          /* exit gracefully */
651   {
652 +        register int  i;
653 +                                /* close input files */
654 +        for (i = 0; i < nfiles; i++)
655 +                if (input[i].name == Command)
656 +                        pclose(input[i].fp);
657 +                else
658 +                        fclose(input[i].fp);
659          exit(code);
660   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines