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 1.20 by greg, Thu May 30 10:14:39 1991 UTC vs.
Revision 2.18 by greg, Tue Sep 3 11:30:37 1996 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1991 Regents of the University of California */
1 > /* Copyright (c) 1992 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 10 | Line 10 | static char SCCSid[] = "$SunId$ LBL";
10   *      1/4/89
11   */
12  
13 < #include <stdio.h>
13 > #include "standard.h"
14  
15 #include <errno.h>
16
15   #include "color.h"
16  
17 + #include "resolu.h"
18 +
19   #include "calcomp.h"
20  
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  
25 #define BRT             (-1)            /* special index for brightness */
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 34 | Line 37 | struct {
37  
38   int     nfiles;                         /* number of input files */
39  
40 < char    *vcolin[3] = {"ri", "gi", "bi"};
41 < char    *vcolout[3] = {"ro", "go", "bo"};
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"};
45   char    vbrtin[] = "li";
46   char    vbrtout[] = "lo";
47 < char    *vcolexp[3] = {"re", "ge", "be"};
47 > char    vcolexp[3][4] = {"re", "ge", "be"};
48   char    vbrtexp[] = "le";
49 + char    vpixaspect[] = "pa";
50  
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 59 | Line 71 | int    xres, yres;                     /* output resolution */
71  
72   int     xpos, ypos;                     /* output position */
73  
74 + char    *progname;                      /* global argv[0] */
75 +
76   int     wrongformat = 0;
77 + int     gotview;
78  
79   FILE    *popen();
80  
81 + extern char     *emalloc();
82  
83 +
84   main(argc, argv)
85   int     argc;
86   char    *argv[];
87   {
71        char    buf[128];
88          int     original;
89          double  f;
90          int     a, i;
91 + #ifdef MSDOS
92 +        extern int  _fmode;
93 +        _fmode = O_BINARY;
94 +        setmode(fileno(stdin), O_BINARY);
95 +        setmode(fileno(stdout), O_BINARY);
96 + #endif
97 +        progname = argv[0];
98                                                  /* scan options */
99          for (a = 1; a < argc; a++) {
100                  if (argv[a][0] == '-')
# Line 90 | 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 111 | Line 137 | char   *argv[];
137                                  break;
138                          case 'o':
139                                  original++;
140 <                                break;
140 >                                continue;
141                          case 's':
142                                  f = atof(argv[++a]);
143                                  scalecolor(input[nfiles].coef, f);
# Line 125 | Line 151 | char   *argv[];
151                                  goto usage;
152                          }
153                  else {
154 <                        input[nfiles].name = argv[a];
155 <                        input[nfiles].fp = argv[a][0]=='!' ?
156 <                                        popen(argv[a]+1, "r") :
157 <                                        fopen(argv[a], "r");
154 >                        if (argv[a][0] == '!') {
155 >                                input[nfiles].name = Command;
156 >                                input[nfiles].fp = popen(argv[a]+1, "r");
157 >                        } else {
158 >                                input[nfiles].name = argv[a];
159 >                                input[nfiles].fp = fopen(argv[a], "r");
160 >                        }
161                          if (input[nfiles].fp == NULL) {
162                                  perror(argv[a]);
163                                  quit(1);
# Line 152 | Line 181 | char   *argv[];
181                  if (argv[a][0] == '-')
182                          switch (argv[a][1]) {
183                          case 'x':
184 <                                strcpy(buf, vxres);
156 <                                strcat(buf, ":");
157 <                                strcat(buf, argv[++a]);
158 <                                scompile(buf, NULL, 0);
184 >                                varset(vxres, ':', eval(argv[++a]));
185                                  continue;
186                          case 'y':
187 <                                strcpy(buf, vyres);
162 <                                strcat(buf, ":");
163 <                                strcat(buf, argv[++a]);
164 <                                scompile(buf, NULL, 0);
187 >                                varset(vyres, ':', eval(argv[++a]));
188                                  continue;
189                          case 'w':
190                                  continue;
# Line 188 | 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 <        fputresolu(YMAJOR|YDECR, xres, yres, stdout);
217 >        fprtresolu(xres, yres, stdout);
218                                                  /* combine pictures */
219          combine();
220          quit(0);
# Line 198 | Line 222 | usage:
222          eputs("Usage: ");
223          eputs(argv[0]);
224          eputs(
225 < " [-w][-x xr][-y yr][-e expr][-f file] [ [-s f][-c r g b] pic ..]\n");
225 > " [-w][-x xr][-y yr][-e expr][-f file] [ [-o][-s f][-c r g b] pic ..]\n");
226          quit(1);
227   }
228  
# Line 210 | Line 234 | char   *s;
234          double  d;
235          COLOR   ctmp;
236  
237 <        if (isformat(s)) {                      /* check format */
214 <                formatval(fmt, s);
215 <                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 221 | Line 250 | char   *s;
250          } else if (iscolcor(s)) {               /* color correction */
251                  colcorval(ctmp, s);
252                  multcolor(input[nfiles].expos, ctmp);
253 <        }
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');
259          fputs(s, stdout);
# Line 230 | Line 262 | char   *s;
262  
263   checkfile()                     /* ready a file */
264   {
233        int     xinp, yinp;
265          register int    i;
266                                          /* process header */
267 +        gotview = 0;
268          fputs(input[nfiles].name, stdout);
269          fputs(":\n", stdout);
270          getheader(input[nfiles].fp, tputs, NULL);
# Line 241 | Line 273 | checkfile()                    /* ready a file */
273                  eputs(": not in Radiance picture format\n");
274                  quit(1);
275          }
276 <        if (fgetresolu(&xinp, &yinp, input[nfiles].fp) != (YMAJOR|YDECR)) {
276 >        if (!gotview || setview(&input[nfiles].vw) != NULL)
277 >                input[nfiles].vw.type = 0;
278 >        if (!fgetsresolu(&input[nfiles].rs, input[nfiles].fp)) {
279                  eputs(input[nfiles].name);
280                  eputs(": bad picture size\n");
281                  quit(1);
282          }
283          if (xmax == 0 && ymax == 0) {
284 <                xmax = xinp;
285 <                ymax = yinp;
286 <        } else if (xinp != xmax || yinp != ymax) {
284 >                xmax = scanlen(&input[nfiles].rs);
285 >                ymax = numscans(&input[nfiles].rs);
286 >        } else if (scanlen(&input[nfiles].rs) != xmax ||
287 >                        numscans(&input[nfiles].rs) != ymax) {
288                  eputs(input[nfiles].name);
289                  eputs(": resolution mismatch\n");
290                  quit(1);
# Line 260 | 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();
319 >        double  l_colin(), l_expos(), l_pixaspect(), l_ray(), l_psize();
320          register int    i;
321                                                  /* define constants */
322          varset(vnfiles, ':', (double)nfiles);
# Line 275 | Line 329 | init()                                 /* perform final setup */
329          }
330          funset(vbrtexp, 1, ':', l_expos);
331          funset(vbrtin, 1, '=', l_colin);
332 +        funset(vpixaspect, 1, ':', l_pixaspect);
333 +        for (i = 0; i < 7; i++)
334 +                funset(vray[i], 1, '=', l_ray);
335 +        funset(vpsize, 1, '=', l_psize);
336 +                                                /* set brightness function */
337 +        if (!strcmp(ourfmt, CIEFMT)) {
338 +                varset(vwhteff, ':', 1.0);
339 +                ourbright = xyz_bright;
340 +        } else
341 +                varset(vwhteff, ':', WHTEFFICACY);
342   }
343  
344  
# Line 350 | Line 414 | advance()                      /* read in data for next scanline */
414                          input[i].scan[0] = st;
415                          if (yscan <= MIDSCN)            /* hit bottom? */
416                                  continue;
417 <                        if (freadscan(st, xmax, input[i].fp) < 0) {     /* read */
417 >                        if (freadscan(st, xmax, input[i].fp) < 0) {  /* read */
418                                  eputs(input[i].name);
419                                  eputs(": read error\n");
420                                  quit(1);
421                          }
422 <                        for (j = 0; j < xmax; j++)      /* adjust color */
423 <                                multcolor(st[j], input[i].coef);
422 >                        if (fabs(colval(input[i].coef,RED)-1.0) > 1e-3 ||
423 >                                fabs(colval(input[i].coef,GRN)-1.0) > 1e-3 ||
424 >                                fabs(colval(input[i].coef,BLU)-1.0) > 1e-3)
425 >                                for (j = 0; j < xmax; j++)  /* adjust color */
426 >                                        multcolor(st[j], input[i].coef);
427                  }
428   }
429  
# Line 371 | Line 438 | register char  *nam;
438          if (fn < 0 || fn >= nfiles)
439                  return(1.0);
440          if (nam == vbrtexp)
441 <                return(bright(input[fn].expos));
441 >                return((*ourbright)(input[fn].expos));
442          n = 3;
443          while (n--)
444                  if (nam == vcolexp[n])
# Line 382 | Line 449 | register char  *nam;
449  
450  
451   double
452 + l_pixaspect()                   /* return pixel aspect ratio */
453 + {
454 +        register int    fn;
455 +
456 +        fn = argument(1) - .5;
457 +        if (fn < 0 || fn >= nfiles)
458 +                return(1.0);
459 +        return(input[fn].pa);
460 + }
461 +
462 +
463 + double
464   l_colin(nam)                    /* return color value for picture */
465   register char   *nam;
466   {
# Line 389 | Line 468 | register char  *nam;
468          register int    n, xoff, yoff;
469          double  d;
470  
471 <        d = argument(1);
393 <        if (d > -.5 && d < .5)
394 <                return((double)nfiles);
395 <        fn = d - .5;
471 >        fn = argument(1) - .5;
472          if (fn < 0 || fn >= nfiles) {
473                  errno = EDOM;
474                  return(0.0);
# Line 428 | Line 504 | register char  *nam;
504                  }
505          }
506          if (nam == vbrtin)
507 <                return(bright(input[fn].scan[MIDSCN+yoff][xscan+xoff]));
507 >                return((*ourbright)(input[fn].scan[MIDSCN+yoff][xscan+xoff]));
508          n = 3;
509          while (n--)
510              if (nam == vcolin[n])
# Line 438 | Line 514 | register char  *nam;
514   }
515  
516  
517 + double
518 + l_ray(nam)              /* return ray origin or direction */
519 + register char   *nam;
520 + {
521 +        static unsigned long    ltick[MAXINP];
522 +        static FVECT    lorg[MAXINP], ldir[MAXINP];
523 +        static double   ldist[MAXINP];
524 +        FLOAT   loc[2];
525 +        int     fn;
526 +        register int    i;
527 +
528 +        fn = argument(1) - .5;
529 +        if (fn < 0 || fn >= nfiles) {
530 +                errno = EDOM;
531 +                return(0.0);
532 +        }
533 +        if (ltick[fn] < eclock) {               /* need to compute? */
534 +                lorg[fn][0] = lorg[fn][1] = lorg[fn][2] = 0.0;
535 +                ldir[fn][0] = ldir[fn][1] = ldir[fn][2] = 0.0;
536 +                if (input[fn].vw.type == 0)
537 +                        errno = EDOM;
538 +                else {
539 +                        pix2loc(loc, &input[fn].rs, xscan, ymax-1-yscan);
540 +                        ldist[fn] = viewray(lorg[fn], ldir[fn],
541 +                                        &input[fn].vw, loc[0], loc[1]);
542 +                }
543 +                ltick[fn] = eclock;
544 +        }
545 +        if (nam == vray[i=6])
546 +                return(ldist[fn]);
547 +        while (i--)
548 +                if (nam == vray[i])
549 +                        return(i < 3 ? lorg[fn][i] : ldir[fn][i-3]);
550 +        eputs("Bad call to l_ray()!\n");
551 +        quit(1);
552 + }
553 +
554 +
555 + double
556 + l_psize()                       /* compute pixel size in steradians */
557 + {
558 +        static unsigned long    ltick[MAXINP];
559 +        static double   psize[MAXINP];
560 +        FVECT   dir0, org, dirx, diry;
561 +        FLOAT   locx[2], locy[2];
562 +        double  d;
563 +        int     fn;
564 +        register int    i;
565 +
566 +        d = argument(1);
567 +        if (d < .5 || d >= nfiles+.5) {
568 +                errno = EDOM;
569 +                return(0.0);
570 +        }
571 +        fn = d - .5;
572 +        if (ltick[fn] < eclock) {               /* need to compute? */
573 +                psize[fn] = 0.0;
574 +                if (input[fn].vw.type == 0)
575 +                        errno = EDOM;
576 +                else if (input[fn].vw.type != VT_PAR &&
577 +                                funvalue(vray[6], 1, &d) >= 0) {
578 +                        for (i = 0; i < 3; i++)
579 +                                dir0[i] = funvalue(vray[3+i], 1, &d);
580 +                        pix2loc(locx, &input[fn].rs, xscan+1, ymax-1-yscan);
581 +                        pix2loc(locy, &input[fn].rs, xscan, ymax-yscan);
582 +                        if (viewray(org, dirx, &input[fn].vw,
583 +                                        locx[0], locx[1]) >= 0 &&
584 +                                        viewray(org, diry, &input[fn].vw,
585 +                                        locy[0], locy[1]) >= 0) {
586 +                                                /* approximate solid angle */
587 +                                for (i = 0; i < 3; i++) {
588 +                                        dirx[i] -= dir0[i];
589 +                                        diry[i] -= dir0[i];
590 +                                }
591 +                                fcross(dir0, dirx, diry);
592 +                                psize[fn] = 0.5 * sqrt(DOT(dir0,dir0));
593 +                        }
594 +                }
595 +                ltick[fn] = eclock;
596 +        }
597 +        return(psize[fn]);
598 + }
599 +
600 +
601   wputs(msg)
602   char    *msg;
603   {
# Line 453 | Line 613 | char   *msg;
613   }
614  
615  
616 < quit(code)
617 < int     code;
616 > quit(code)              /* exit gracefully */
617 > int  code;
618   {
619 +        register int  i;
620 +                                /* close input files */
621 +        for (i = 0; i < nfiles; i++)
622 +                if (input[i].name == Command)
623 +                        pclose(input[i].fp);
624 +                else
625 +                        fclose(input[i].fp);
626          exit(code);
627   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines