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.10 by greg, Thu Apr 18 14:35:17 1991 UTC vs.
Revision 1.17 by greg, Fri May 24 17:14:49 1991 UTC

# Line 19 | Line 19 | static char SCCSid[] = "$SunId$ LBL";
19   #include "calcomp.h"
20  
21   #define MAXINP          32              /* maximum number of input files */
22 + #define WINSIZ          9               /* scanline window size */
23 + #define MIDSCN          4               /* current scan position */
24  
25 + #define BRT             (-1)            /* special index for brightness */
26 +
27   struct {
28          char    *name;          /* file name */
29          FILE    *fp;            /* stream pointer */
30 <        COLOR   *scan;          /* input scanline */
30 >        COLOR   *scan[WINSIZ];  /* input scanline window */
31          COLOR   coef;           /* coefficient */
32 +        COLOR   expos;          /* recorded exposure */
33   }       input[MAXINP];                  /* input pictures */
34  
35   int     nfiles;                         /* number of input files */
36  
37   char    *vcolin[3] = {"ri", "gi", "bi"};
38   char    *vcolout[3] = {"ro", "go", "bo"};
39 < #define vbrtin          "li"
40 < #define vbrtout         "lo"
39 > char    vbrtin[] = "li";
40 > char    vbrtout[] = "lo";
41 > char    *vcolexp[3] = {"re", "ge", "be"};
42 > char    vbrtexp[] = "le";
43  
44   #define vnfiles         "nfiles"
45   #define vxres           "xres"
# Line 51 | Line 58 | int    xpos, ypos;                     /* picture position */
58   int     wrongformat = 0;
59  
60  
54 tputs(s)                        /* put out string preceded by a tab */
55 char    *s;
56 {
57        char    fmt[32];
58        double  d;
59        COLOR   ctmp;
60
61        if (isformat(s)) {                      /* check format */
62                formatval(fmt, s);
63                wrongformat = strcmp(fmt, COLRFMT);
64        } else if (original && isexpos(s)) {    /* exposure */
65                d = 1.0/exposval(s);
66                scalecolor(input[nfiles].coef, d);
67        } else if (original && iscolcor(s)) {   /* color correction */
68                colcorval(ctmp, s);
69                colval(input[nfiles].coef,RED) /= colval(ctmp,RED);
70                colval(input[nfiles].coef,GRN) /= colval(ctmp,GRN);
71                colval(input[nfiles].coef,BLU) /= colval(ctmp,BLU);
72        } else {                                /* echo unaffected line */
73                putchar('\t');
74                fputs(s, stdout);
75        }
76
77 }
78
79
61   main(argc, argv)
62   int     argc;
63   char    *argv[];
64   {
84        extern double   l_redin(), l_grnin(), l_bluin(), l_brtin(), atof();
65          double  f;
66 <        int     a;
67 <        
68 <        funset(vcolin[RED], 1, l_redin);
89 <        funset(vcolin[GRN], 1, l_grnin);
90 <        funset(vcolin[BLU], 1, l_bluin);
91 <        funset(vbrtin, 1, l_brtin);
92 <        
93 <        for (a = 1; a < argc; a++)
66 >        int     a, i;
67 >                                                /* scan options */
68 >        for (a = 1; a < argc; a++) {
69                  if (argv[a][0] == '-')
70                          switch (argv[a][1]) {
96                        case '\0':
97                        case 's':
98                        case 'c':
99                                goto getfiles;
71                          case 'x':
72                                  xres = atoi(argv[++a]);
73 <                                break;
73 >                                continue;
74                          case 'y':
75                                  yres = atoi(argv[++a]);
76 <                                break;
76 >                                continue;
77                          case 'w':
78                                  nowarn = !nowarn;
79 <                                break;
109 <                        case 'o':
110 <                                original = !original;
111 <                                break;
79 >                                continue;
80                          case 'f':
113                                fcompile(argv[++a]);
114                                break;
81                          case 'e':
82 <                                scompile(argv[++a], NULL, 0);
83 <                                break;
118 <                        default:
119 <                                goto usage;
82 >                                a++;
83 >                                continue;
84                          }
85 <                else
86 <                        break;
87 < getfiles:
88 <        for (nfiles = 0; nfiles < MAXINP; nfiles++)
85 >                break;
86 >        }
87 >                                        /* process files */
88 >        for (nfiles = 0; nfiles < MAXINP; nfiles++) {
89                  setcolor(input[nfiles].coef, 1.0, 1.0, 1.0);
90 +                setcolor(input[nfiles].expos, 1.0, 1.0, 1.0);
91 +        }
92          nfiles = 0;
93          for ( ; a < argc; a++) {
94                  if (nfiles >= MAXINP) {
# Line 136 | Line 102 | getfiles:
102                                  input[nfiles].name = "<stdin>";
103                                  input[nfiles].fp = stdin;
104                                  break;
105 +                        case 'o':
106 +                                original++;
107 +                                break;
108                          case 's':
109                                  f = atof(argv[++a]);
110                                  scalecolor(input[nfiles].coef, f);
# Line 156 | Line 125 | getfiles:
125                                  quit(1);
126                          }
127                  }
128 <                fputs(input[nfiles].name, stdout);
129 <                fputs(":\n", stdout);
161 <                getheader(input[nfiles].fp, tputs, NULL);
162 <                if (wrongformat) {
163 <                        eputs(input[nfiles].name);
164 <                        eputs(": not in Radiance picture format\n");
165 <                        quit(1);
166 <                }
167 <                if (fgetresolu(&xpos, &ypos, input[nfiles].fp) !=
168 <                                (YMAJOR|YDECR)) {
169 <                        eputs(input[nfiles].name);
170 <                        eputs(": bad picture size\n");
171 <                        quit(1);
172 <                }
173 <                if (xres == 0 && yres == 0) {
174 <                        xres = xpos;
175 <                        yres = ypos;
176 <                } else if (xpos != xres || ypos != yres) {
177 <                        eputs(argv[0]);
178 <                        eputs(": resolution mismatch\n");
179 <                        quit(1);
180 <                }
181 <                input[nfiles].scan = (COLOR *)emalloc(xres*sizeof(COLOR));
128 >                checkfile();
129 >                original = 0;
130                  nfiles++;
131          }
132 +        init();                         /* set constant expressions */
133 +                                        /* go back and get expressions */
134 +        for (a = 1; a < argc; a++) {
135 +                if (argv[a][0] == '-')
136 +                        switch (argv[a][1]) {
137 +                        case 'x':
138 +                        case 'y':
139 +                                a++;
140 +                                continue;
141 +                        case 'w':
142 +                                continue;
143 +                        case 'f':
144 +                                fcompile(argv[++a]);
145 +                                continue;
146 +                        case 'e':
147 +                                scompile(argv[++a], NULL, 0);
148 +                                continue;
149 +                        }
150 +                break;
151 +        }
152 +                                                /* complete header */
153          printargs(argc, argv, stdout);
154          fputformat(COLRFMT, stdout);
155          putchar('\n');
156          fputresolu(YMAJOR|YDECR, xres, yres, stdout);
157 +                                                /* combine pictures */
158          combine();
159          quit(0);
160   usage:
# Line 196 | Line 166 | usage:
166   }
167  
168  
169 + tputs(s)                        /* put out string preceded by a tab */
170 + char    *s;
171 + {
172 +        char    fmt[32];
173 +        double  d;
174 +        COLOR   ctmp;
175 +
176 +        if (isformat(s)) {                      /* check format */
177 +                formatval(fmt, s);
178 +                wrongformat = strcmp(fmt, COLRFMT);
179 +                return;         /* don't echo */
180 +        }
181 +        if (isexpos(s)) {                       /* exposure */
182 +                d = exposval(s);
183 +                scalecolor(input[nfiles].expos, d);
184 +                if (original)
185 +                        scalecolor(input[nfiles].coef, 1.0/d);
186 +        } else if (iscolcor(s)) {               /* color correction */
187 +                colcorval(ctmp, s);
188 +                multcolor(input[nfiles].expos, ctmp);
189 +                if (original) {
190 +                        colval(input[nfiles].coef,RED) /= colval(ctmp,RED);
191 +                        colval(input[nfiles].coef,GRN) /= colval(ctmp,GRN);
192 +                        colval(input[nfiles].coef,BLU) /= colval(ctmp,BLU);
193 +                }
194 +        }
195 +                                                /* echo line */
196 +        putchar('\t');
197 +        fputs(s, stdout);
198 + }
199 +
200 +
201 + checkfile()                     /* ready a file */
202 + {
203 +        register int    i;
204 +                                        /* process header */
205 +        fputs(input[nfiles].name, stdout);
206 +        fputs(":\n", stdout);
207 +        getheader(input[nfiles].fp, tputs, NULL);
208 +        if (wrongformat) {
209 +                eputs(input[nfiles].name);
210 +                eputs(": not in Radiance picture format\n");
211 +                quit(1);
212 +        }
213 +        if (fgetresolu(&xpos, &ypos, input[nfiles].fp) != (YMAJOR|YDECR)) {
214 +                eputs(input[nfiles].name);
215 +                eputs(": bad picture size\n");
216 +                quit(1);
217 +        }
218 +        if (xres == 0 && yres == 0) {
219 +                xres = xpos;
220 +                yres = ypos;
221 +        } else if (xpos != xres || ypos != yres) {
222 +                eputs(input[nfiles].name);
223 +                eputs(": resolution mismatch\n");
224 +                quit(1);
225 +        }
226 +                                        /* allocate scanlines */
227 +        for (i = 0; i < WINSIZ; i++)
228 +                input[nfiles].scan[i] = (COLOR *)emalloc(xres*sizeof(COLOR));
229 + }
230 +
231 +
232 + init()                          /* perform final setup */
233 + {
234 +        double  l_colin(), l_expos();
235 +        register int    i;
236 +                                                /* prime input */
237 +        for (ypos = yres+(MIDSCN-1); ypos >= yres; ypos--)
238 +                advance();
239 +                                                /* define constants */
240 +        varset(vnfiles, ':', (double)nfiles);
241 +        varset(vxres, ':', (double)xres);
242 +        varset(vyres, ':', (double)yres);
243 +                                                /* set functions */
244 +        for (i = 0; i < 3; i++) {
245 +                funset(vcolexp[i], 1, ':', l_expos);
246 +                funset(vcolin[i], 1, '=', l_colin);
247 +        }
248 +        funset(vbrtexp, 1, ':', l_expos);
249 +        funset(vbrtin, 1, '=', l_colin);
250 + }
251 +
252 +
253   combine()                       /* combine pictures */
254   {
255          EPNODE  *coldef[3], *brtdef;
# Line 213 | Line 267 | combine()                      /* combine pictures */
267                  brtdef = eparse(vbrtout);
268          else
269                  brtdef = NULL;
216                                                /* predefine variables */
217        varset(vnfiles, (double)nfiles);
218        varset(vxres, (double)xres);
219        varset(vyres, (double)yres);
270                                                  /* allocate scanline */
271          scanout = (COLOR *)emalloc(xres*sizeof(COLOR));
272                                                  /* combine files */
273          for (ypos = yres-1; ypos >= 0; ypos--) {
274 <            for (i = 0; i < nfiles; i++)
275 <                    if (freadscan(input[i].scan, xres, input[i].fp) < 0) {
226 <                            eputs(input[i].name);
227 <                            eputs(": read error\n");
228 <                            quit(1);
229 <                    }
230 <            varset(vypos, (double)ypos);
274 >            advance();
275 >            varset(vypos, '=', (double)ypos);
276              for (xpos = 0; xpos < xres; xpos++) {
277 <                for (i = 0; i < nfiles; i++)
233 <                        multcolor(input[i].scan[xpos],input[i].coef);
234 <                varset(vxpos, (double)xpos);
277 >                varset(vxpos, '=', (double)xpos);
278                  eclock++;
279                  if (brtdef != NULL) {
280                      d = evalue(brtdef);
# Line 241 | Line 284 | combine()                      /* combine pictures */
284                  } else {
285                      for (j = 0; j < 3; j++) {
286                          if (coldef[j] != NULL) {
287 <                                colval(scanout[xpos],j) = evalue(coldef[j]);
287 >                                d = evalue(coldef[j]);
288                          } else {
289 <                            colval(scanout[xpos],j) = 0.0;
289 >                            d = 0.0;
290                              for (i = 0; i < nfiles; i++)
291 <                                colval(scanout[xpos],j) +=
249 <                                        colval(input[i].scan[xpos],j);
291 >                                d += colval(input[i].scan[MIDSCN][xpos],j);
292                          }
293 <                        if (colval(scanout[xpos],j) < 0.0)
294 <                            colval(scanout[xpos],j) = 0.0;
293 >                        if (d < 0.0)
294 >                            d = 0.0;
295 >                        colval(scanout[xpos],j) = d;
296                      }
297                  }
298              }
# Line 262 | Line 305 | combine()                      /* combine pictures */
305   }
306  
307  
308 < double
266 < colin(fn, ci)                   /* return color value for picture */
267 < register int    fn, ci;
308 > advance()                       /* read in next scanline */
309   {
310 <        if (fn == 0)
311 <                return((double)nfiles);
312 <        if (fn < 1 || fn > nfiles) {
313 <                errno = EDOM;
314 <                return(0.0);
310 >        register COLOR  *st;
311 >        register int    i, j;
312 >
313 >        for (i = 0; i < nfiles; i++) {
314 >                st = input[i].scan[WINSIZ-1];
315 >                for (j = WINSIZ-1; j > 0; j--)  /* rotate window */
316 >                        input[i].scan[j] = input[i].scan[j-1];
317 >                input[i].scan[0] = st;
318 >                if (ypos < MIDSCN)              /* hit bottom */
319 >                        continue;
320 >                if (freadscan(st, xres, input[i].fp) < 0) {
321 >                        eputs(input[i].name);
322 >                        eputs(": read error\n");
323 >                        quit(1);
324 >                }
325 >                for (j = 0; j < xres; j++)      /* adjust color */
326 >                        multcolor(st[j], input[i].coef);
327          }
275        return(colval(input[fn-1].scan[xpos],ci));
328   }
329  
330  
331   double
332 < l_redin()                       /* get red color */
332 > l_expos(nam)                    /* return picture exposure */
333 > register char   *nam;
334   {
335 <        return(colin((int)(argument(1)+.5), RED));
336 < }
335 >        register int    fn, n;
336 >        double  d;
337  
338 <
339 < double
340 < l_grnin()                       /* get green color */
341 < {
342 <        return(colin((int)(argument(1)+.5), GRN));
338 >        d = argument(1);
339 >        if (d > -.5 && d < .5)
340 >                return((double)nfiles);
341 >        fn = d - .5;
342 >        if (fn < 0 || fn >= nfiles) {
343 >                errno = EDOM;
344 >                return(0.0);
345 >        }
346 >        if (nam == vbrtexp)
347 >                return(bright(input[fn].expos));
348 >        n = 3;
349 >        while (n--)
350 >                if (nam == vcolexp[n])
351 >                        return(colval(input[fn].expos,n));
352 >        eputs("Bad call to l_expos()!\n");
353 >        quit(1);
354   }
355  
356  
357   double
358 < l_bluin()                       /* get blue color */
358 > l_colin(nam)                    /* return color value for picture */
359 > register char   *nam;
360   {
361 <        return(colin((int)(argument(1)+.5), BLU));
362 < }
361 >        int     fn;
362 >        register int    n, xoff, yoff;
363 >        double  d;
364  
365 <
366 < double
301 < l_brtin()                       /* get brightness value */
302 < {
303 <        register int    fn;
304 <
305 <        fn = argument(1)+.5;
306 <        if (fn == 0)
365 >        d = argument(1);
366 >        if (d > -.5 && d < .5)
367                  return((double)nfiles);
368 <        if (fn < 1 || fn > nfiles) {
368 >        fn = d - .5;
369 >        if (fn < 0 || fn >= nfiles) {
370                  errno = EDOM;
371                  return(0.0);
372          }
373 <        return(bright(input[fn-1].scan[xpos]));
373 >        xoff = yoff = 0;
374 >        n = nargum();
375 >        if (n >= 2) {
376 >                d = argument(2);
377 >                if (d < 0.0) {
378 >                        xoff = d-.5;
379 >                        if (xpos+xoff < 0)
380 >                                xoff = -xpos;
381 >                } else {
382 >                        xoff = d+.5;
383 >                        if (xpos+xoff >= xres)
384 >                                xoff = xres-1-xpos;
385 >                }
386 >        }
387 >        if (n >= 3) {
388 >                d = argument(3);
389 >                if (d < 0.0) {
390 >                        yoff = d-.5;
391 >                        if (yoff+MIDSCN < 0)
392 >                                yoff = -MIDSCN;
393 >                        if (ypos+yoff < 0)
394 >                                yoff = -ypos;
395 >                } else {
396 >                        yoff = d+.5;
397 >                        if (yoff+MIDSCN >= WINSIZ)
398 >                                yoff = WINSIZ-1-MIDSCN;
399 >                        if (ypos+yoff >= yres)
400 >                                yoff = yres-1-ypos;
401 >                }
402 >        }
403 >        if (nam == vbrtin)
404 >                return(bright(input[fn].scan[MIDSCN+yoff][xpos+xoff]));
405 >        n = 3;
406 >        while (n--)
407 >            if (nam == vcolin[n])
408 >                return(colval(input[fn].scan[MIDSCN+yoff][xpos+xoff],n));
409 >        eputs("Bad call to l_colin()!\n");
410 >        quit(1);
411   }
412  
413  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines