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.2 by greg, Tue May 9 10:07:04 1989 UTC vs.
Revision 1.9 by greg, Thu Apr 18 10:19:48 1991 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1989 Regents of the University of California */
1 > /* Copyright (c) 1991 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 18 | Line 18 | static char SCCSid[] = "$SunId$ LBL";
18  
19   #include "calcomp.h"
20  
21 < #define MAXINP          16              /* maximum number of input files */
21 > #define MAXINP          32              /* maximum number of input files */
22  
23   struct {
24          char    *name;          /* file name */
25          FILE    *fp;            /* stream pointer */
26          COLOR   *scan;          /* input scanline */
27 +        COLOR   coef;           /* coefficient */
28   }       input[MAXINP];                  /* input pictures */
29  
30   int     nfiles;                         /* number of input files */
31  
32   char    *vcolin[3] = {"ri", "gi", "bi"};
33   char    *vcolout[3] = {"ro", "go", "bo"};
34 + #define vbrtin          "li"
35 + #define vbrtout         "lo"
36  
37 + #define vnfiles         "nfiles"
38 + #define vxres           "xres"
39 + #define vyres           "yres"
40   #define vxpos           "x"
41   #define vypos           "y"
42  
43   int     nowarn = 0;                     /* no warning messages? */
44  
45 + int     original = 0;                   /* origninal values? */
46 +
47   int     xres=0, yres=0;                 /* picture resolution */
48  
49   int     xpos, ypos;                     /* picture position */
# Line 44 | Line 52 | int    xpos, ypos;                     /* picture position */
52   tputs(s)                        /* put out string preceded by a tab */
53   char    *s;
54   {
55 +        double  d;
56 +        COLOR   ctmp;
57 +                                /* echo header line */
58          putchar('\t');
59          fputs(s, stdout);
60 +        if (!original)
61 +                return;
62 +                                /* check for exposure */
63 +        if (isexpos(s)) {
64 +                d = 1.0/exposval(s);
65 +                scalecolor(input[nfiles].coef, d);
66 +        } else if (iscolcor(s)) {
67 +                colcorval(ctmp, s);
68 +                colval(input[nfiles].coef,RED) /= colval(ctmp,RED);
69 +                colval(input[nfiles].coef,GRN) /= colval(ctmp,GRN);
70 +                colval(input[nfiles].coef,BLU) /= colval(ctmp,BLU);
71 +        }
72   }
73  
74  
# Line 53 | Line 76 | main(argc, argv)
76   int     argc;
77   char    *argv[];
78   {
79 <        extern double   l_redin(), l_grnin(), l_bluin();
79 >        extern double   l_redin(), l_grnin(), l_bluin(), l_brtin(), atof();
80 >        double  f;
81          int     a;
82          
83          funset(vcolin[RED], 1, l_redin);
84          funset(vcolin[GRN], 1, l_grnin);
85          funset(vcolin[BLU], 1, l_bluin);
86 +        funset(vbrtin, 1, l_brtin);
87          
88          for (a = 1; a < argc; a++)
89                  if (argv[a][0] == '-')
90                          switch (argv[a][1]) {
91                          case '\0':
92 +                        case 's':
93 +                        case 'c':
94                                  goto getfiles;
95                          case 'x':
96                                  xres = atoi(argv[++a]);
# Line 74 | Line 101 | char   *argv[];
101                          case 'w':
102                                  nowarn = !nowarn;
103                                  break;
104 +                        case 'o':
105 +                                original = !original;
106 +                                break;
107                          case 'f':
108                                  fcompile(argv[++a]);
109                                  break;
110                          case 'e':
111 <                                scompile(NULL, argv[++a]);
111 >                                scompile(argv[++a], NULL, 0);
112                                  break;
113                          default:
114 <                                eputs("Usage: ");
85 <                                eputs(argv[0]);
86 <        eputs(" [-w][-x xres][-y yres][-e expr][-f file] [picture ..]\n");
87 <                                quit(1);
114 >                                goto usage;
115                          }
116                  else
117                          break;
118   getfiles:
119 +        for (nfiles = 0; nfiles < MAXINP; nfiles++)
120 +                setcolor(input[nfiles].coef, 1.0, 1.0, 1.0);
121          nfiles = 0;
122          for ( ; a < argc; a++) {
123                  if (nfiles >= MAXINP) {
# Line 96 | Line 125 | getfiles:
125                          eputs(": too many picture files\n");
126                          quit(1);
127                  }
128 <                if (argv[a][0] == '-') {
129 <                        input[nfiles].name = "<stdin>";
130 <                        input[nfiles].fp = stdin;
131 <                } else {
128 >                if (argv[a][0] == '-')
129 >                        switch (argv[a][1]) {
130 >                        case '\0':
131 >                                input[nfiles].name = "<stdin>";
132 >                                input[nfiles].fp = stdin;
133 >                                break;
134 >                        case 's':
135 >                                f = atof(argv[++a]);
136 >                                scalecolor(input[nfiles].coef, f);
137 >                                continue;
138 >                        case 'c':
139 >                                colval(input[nfiles].coef,RED)*=atof(argv[++a]);
140 >                                colval(input[nfiles].coef,GRN)*=atof(argv[++a]);
141 >                                colval(input[nfiles].coef,BLU)*=atof(argv[++a]);
142 >                                continue;
143 >                        default:
144 >                                goto usage;
145 >                        }
146 >                else {
147                          input[nfiles].name = argv[a];
148                          input[nfiles].fp = fopen(argv[a], "r");
149                          if (input[nfiles].fp == NULL) {
150 <                                eputs(argv[a]);
107 <                                eputs(": cannot open\n");
150 >                                perror(argv[a]);
151                                  quit(1);
152                          }
153                  }
154                  fputs(input[nfiles].name, stdout);
155                  fputs(":\n", stdout);
156                  getheader(input[nfiles].fp, tputs);
157 <                if (fscanf(input[nfiles].fp, "-Y %d +X %d\n", &ypos, &xpos) != 2) {
157 >                if (fgetresolu(&xpos, &ypos, input[nfiles].fp) !=
158 >                                (YMAJOR|YDECR)) {
159                          eputs(input[nfiles].name);
160                          eputs(": bad picture size\n");
161                          quit(1);
# Line 129 | Line 173 | getfiles:
173          }
174          printargs(argc, argv, stdout);
175          putchar('\n');
176 <        printf("-Y %d +X %d\n", yres, xres);
176 >        fputresolu(YMAJOR|YDECR, xres, yres, stdout);
177          combine();
178          quit(0);
179 + usage:
180 +        eputs("Usage: ");
181 +        eputs(argv[0]);
182 +        eputs(
183 + " [-w][-h][-x xr][-y yr][-e expr][-f file] [ [-s f][-c r g b] pic ..]\n");
184 +        quit(1);
185   }
186  
187  
188   combine()                       /* combine pictures */
189   {
190 <        int     coldef[3];
190 >        EPNODE  *coldef[3], *brtdef;
191          COLOR   *scanout;
192 +        double  d;
193          register int    i, j;
194                                                  /* check defined variables */
195 <        for (j = 0; j < 3; j++)
196 <                coldef[j] = vardefined(vcolout[j]);
195 >        for (j = 0; j < 3; j++) {
196 >                if (vardefined(vcolout[j]))
197 >                        coldef[j] = eparse(vcolout[j]);
198 >                else
199 >                        coldef[j] = NULL;
200 >        }
201 >        if (vardefined(vbrtout))
202 >                brtdef = eparse(vbrtout);
203 >        else
204 >                brtdef = NULL;
205 >                                                /* predefine variables */
206 >        varset(vnfiles, (double)nfiles);
207 >        varset(vxres, (double)xres);
208 >        varset(vyres, (double)yres);
209                                                  /* allocate scanline */
210          scanout = (COLOR *)emalloc(xres*sizeof(COLOR));
211                                                  /* combine files */
212          for (ypos = yres-1; ypos >= 0; ypos--) {
213 +            for (i = 0; i < nfiles; i++)
214 +                    if (freadscan(input[i].scan, xres, input[i].fp) < 0) {
215 +                            eputs(input[i].name);
216 +                            eputs(": read error\n");
217 +                            quit(1);
218 +                    }
219 +            varset(vypos, (double)ypos);
220 +            for (xpos = 0; xpos < xres; xpos++) {
221                  for (i = 0; i < nfiles; i++)
222 <                        if (freadscan(input[i].scan, xres, input[i].fp) < 0) {
223 <                                eputs(input[i].name);
224 <                                eputs(": read error\n");
225 <                                quit(1);
222 >                        multcolor(input[i].scan[xpos],input[i].coef);
223 >                varset(vxpos, (double)xpos);
224 >                eclock++;
225 >                if (brtdef != NULL) {
226 >                    d = evalue(brtdef);
227 >                    if (d < 0.0)
228 >                        d = 0.0;
229 >                    setcolor(scanout[xpos], d, d, d);
230 >                } else {
231 >                    for (j = 0; j < 3; j++) {
232 >                        if (coldef[j] != NULL) {
233 >                                colval(scanout[xpos],j) = evalue(coldef[j]);
234 >                        } else {
235 >                            colval(scanout[xpos],j) = 0.0;
236 >                            for (i = 0; i < nfiles; i++)
237 >                                colval(scanout[xpos],j) +=
238 >                                        colval(input[i].scan[xpos],j);
239                          }
240 <                varset(vypos, (double)ypos);
241 <                for (xpos = 0; xpos < xres; xpos++) {
242 <                        varset(vxpos, (double)xpos);
159 <                        eclock++;
160 <                        for (j = 0; j < 3; j++)
161 <                                if (coldef[j]) {
162 <                                        colval(scanout[xpos],j) = varvalue(vcolout[j]);
163 <                                        if (colval(scanout[xpos],j) < 0.0)
164 <                                                colval(scanout[xpos],j) = 0.0;
165 <                                } else {
166 <                                        colval(scanout[xpos],j) = 0.0;
167 <                                        for (i = 0; i < nfiles; i++)
168 <                                                colval(scanout[xpos],j) += colval(input[i].scan[xpos],j);
169 <                                }
240 >                        if (colval(scanout[xpos],j) < 0.0)
241 >                            colval(scanout[xpos],j) = 0.0;
242 >                    }
243                  }
244 <                if (fwritescan(scanout, xres, stdout) < 0) {
245 <                        eputs("write error\n");
246 <                        quit(1);
247 <                }
244 >            }
245 >            if (fwritescan(scanout, xres, stdout) < 0) {
246 >                    perror("write error");
247 >                    quit(1);
248 >            }
249          }
250          efree(scanout);
251   }
# Line 209 | Line 283 | double
283   l_bluin()                       /* get blue color */
284   {
285          return(colin((int)(argument(1)+.5), BLU));
286 + }
287 +
288 +
289 + double
290 + l_brtin()                       /* get brightness value */
291 + {
292 +        register int    fn;
293 +
294 +        fn = argument(1)+.5;
295 +        if (fn == 0)
296 +                return((double)nfiles);
297 +        if (fn < 1 || fn > nfiles) {
298 +                errno = EDOM;
299 +                return(0.0);
300 +        }
301 +        return(bright(input[fn-1].scan[xpos]));
302   }
303  
304  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines