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.14 by greg, Thu May 23 13:46:05 1991 UTC vs.
Revision 1.16 by greg, Fri May 24 15:47:53 1991 UTC

# Line 35 | Line 35 | int    nfiles;                         /* number of input files */
35  
36   char    *vcolin[3] = {"ri", "gi", "bi"};
37   char    *vcolout[3] = {"ro", "go", "bo"};
38 < #define vbrtin          "li"
39 < #define vbrtout         "lo"
38 > char    vbrtin[] = "li";
39 > char    vbrtout[] = "lo";
40 > char    *vcolcoef[3] = {"rc", "gc", "bc"};
41 > char    vbrtcoef[] = "lc";
42  
43   #define vnfiles         "nfiles"
44   #define vxres           "xres"
# Line 55 | Line 57 | int    xpos, ypos;                     /* picture position */
57   int     wrongformat = 0;
58  
59  
58 tputs(s)                        /* put out string preceded by a tab */
59 char    *s;
60 {
61        char    fmt[32];
62        double  d;
63        COLOR   ctmp;
64
65        if (isformat(s)) {                      /* check format */
66                formatval(fmt, s);
67                wrongformat = strcmp(fmt, COLRFMT);
68        } else if (original && isexpos(s)) {    /* exposure */
69                d = 1.0/exposval(s);
70                scalecolor(input[nfiles].coef, d);
71        } else if (original && iscolcor(s)) {   /* color correction */
72                colcorval(ctmp, s);
73                colval(input[nfiles].coef,RED) /= colval(ctmp,RED);
74                colval(input[nfiles].coef,GRN) /= colval(ctmp,GRN);
75                colval(input[nfiles].coef,BLU) /= colval(ctmp,BLU);
76        } else {                                /* echo unaffected line */
77                putchar('\t');
78                fputs(s, stdout);
79        }
80
81 }
82
83
60   main(argc, argv)
61   int     argc;
62   char    *argv[];
63   {
88        extern double   l_redin(), l_grnin(), l_bluin(), l_brtin(), atof();
64          double  f;
65          int     a, i;
66 <        
67 <        funset(vcolin[RED], 1, '=', l_redin);
93 <        funset(vcolin[GRN], 1, '=', l_grnin);
94 <        funset(vcolin[BLU], 1, '=', l_bluin);
95 <        funset(vbrtin, 1, '=', l_brtin);
96 <        
97 <        for (a = 1; a < argc; a++)
66 >                                                /* scan options */
67 >        for (a = 1; a < argc; a++) {
68                  if (argv[a][0] == '-')
69                          switch (argv[a][1]) {
100                        case '\0':
101                        case 's':
102                        case 'c':
103                                goto getfiles;
70                          case 'x':
71                                  xres = atoi(argv[++a]);
72 <                                break;
72 >                                continue;
73                          case 'y':
74                                  yres = atoi(argv[++a]);
75 <                                break;
75 >                                continue;
76                          case 'w':
77                                  nowarn = !nowarn;
78 <                                break;
78 >                                continue;
79                          case 'o':
80                                  original = !original;
81 <                                break;
81 >                                continue;
82                          case 'f':
117                                fcompile(argv[++a]);
118                                break;
83                          case 'e':
84 <                                scompile(argv[++a], NULL, 0);
85 <                                break;
122 <                        default:
123 <                                goto usage;
84 >                                a++;
85 >                                continue;
86                          }
87 <                else
88 <                        break;
89 < getfiles:
87 >                break;
88 >        }
89 >                                        /* process files */
90          for (nfiles = 0; nfiles < MAXINP; nfiles++)
91                  setcolor(input[nfiles].coef, 1.0, 1.0, 1.0);
92          nfiles = 0;
# Line 160 | Line 122 | getfiles:
122                                  quit(1);
123                          }
124                  }
125 <                fputs(input[nfiles].name, stdout);
164 <                fputs(":\n", stdout);
165 <                getheader(input[nfiles].fp, tputs, NULL);
166 <                if (wrongformat) {
167 <                        eputs(input[nfiles].name);
168 <                        eputs(": not in Radiance picture format\n");
169 <                        quit(1);
170 <                }
171 <                if (fgetresolu(&xpos, &ypos, input[nfiles].fp) !=
172 <                                (YMAJOR|YDECR)) {
173 <                        eputs(input[nfiles].name);
174 <                        eputs(": bad picture size\n");
175 <                        quit(1);
176 <                }
177 <                if (xres == 0 && yres == 0) {
178 <                        xres = xpos;
179 <                        yres = ypos;
180 <                } else if (xpos != xres || ypos != yres) {
181 <                        eputs(argv[0]);
182 <                        eputs(": resolution mismatch\n");
183 <                        quit(1);
184 <                }
185 <                for (i = 0; i < WINSIZ; i++)
186 <                        input[nfiles].scan[i] =
187 <                                        (COLOR *)emalloc(xres*sizeof(COLOR));
125 >                checkfile();
126                  nfiles++;
127          }
128 +        init();                         /* set constant expressions */
129 +                                        /* go back and get expressions */
130 +        for (a = 1; a < argc; a++) {
131 +                if (argv[a][0] == '-')
132 +                        switch (argv[a][1]) {
133 +                        case 'x':
134 +                        case 'y':
135 +                                a++;
136 +                                continue;
137 +                        case 'w':
138 +                        case 'o':
139 +                                continue;
140 +                        case 'f':
141 +                                fcompile(argv[++a]);
142 +                                continue;
143 +                        case 'e':
144 +                                scompile(argv[++a], NULL, 0);
145 +                                continue;
146 +                        }
147 +                break;
148 +        }
149 +                                                /* complete header */
150          printargs(argc, argv, stdout);
151          fputformat(COLRFMT, stdout);
152          putchar('\n');
153          fputresolu(YMAJOR|YDECR, xres, yres, stdout);
154 +                                                /* combine pictures */
155          combine();
156          quit(0);
157   usage:
# Line 202 | Line 163 | usage:
163   }
164  
165  
166 + tputs(s)                        /* put out string preceded by a tab */
167 + char    *s;
168 + {
169 +        char    fmt[32];
170 +        double  d;
171 +        COLOR   ctmp;
172 +
173 +        if (isformat(s)) {                      /* check format */
174 +                formatval(fmt, s);
175 +                wrongformat = strcmp(fmt, COLRFMT);
176 +        } else if (original && isexpos(s)) {    /* exposure */
177 +                d = 1.0/exposval(s);
178 +                scalecolor(input[nfiles].coef, d);
179 +        } else if (original && iscolcor(s)) {   /* color correction */
180 +                colcorval(ctmp, s);
181 +                colval(input[nfiles].coef,RED) /= colval(ctmp,RED);
182 +                colval(input[nfiles].coef,GRN) /= colval(ctmp,GRN);
183 +                colval(input[nfiles].coef,BLU) /= colval(ctmp,BLU);
184 +        } else {                                /* echo unaffected line */
185 +                putchar('\t');
186 +                fputs(s, stdout);
187 +        }
188 + }
189 +
190 +
191 + checkfile()                     /* ready a file */
192 + {
193 +        register int    i;
194 +                                        /* process header */
195 +        fputs(input[nfiles].name, stdout);
196 +        fputs(":\n", stdout);
197 +        getheader(input[nfiles].fp, tputs, NULL);
198 +        if (wrongformat) {
199 +                eputs(input[nfiles].name);
200 +                eputs(": not in Radiance picture format\n");
201 +                quit(1);
202 +        }
203 +        if (fgetresolu(&xpos, &ypos, input[nfiles].fp) != (YMAJOR|YDECR)) {
204 +                eputs(input[nfiles].name);
205 +                eputs(": bad picture size\n");
206 +                quit(1);
207 +        }
208 +        if (xres == 0 && yres == 0) {
209 +                xres = xpos;
210 +                yres = ypos;
211 +        } else if (xpos != xres || ypos != yres) {
212 +                eputs(input[nfiles].name);
213 +                eputs(": resolution mismatch\n");
214 +                quit(1);
215 +        }
216 +                                        /* allocate scanlines */
217 +        for (i = 0; i < WINSIZ; i++)
218 +                input[nfiles].scan[i] = (COLOR *)emalloc(xres*sizeof(COLOR));
219 + }
220 +
221 +
222 + init()                          /* perform final setup */
223 + {
224 +        double  l_colin(), l_coef();
225 +        register int    i;
226 +                                                /* prime input */
227 +        for (ypos = yres+(MIDSCN-1); ypos >= yres; ypos--)
228 +                advance();
229 +                                                /* define constants */
230 +        varset(vnfiles, ':', (double)nfiles);
231 +        varset(vxres, ':', (double)xres);
232 +        varset(vyres, ':', (double)yres);
233 +                                                /* set functions */
234 +        for (i = 0; i < 3; i++) {
235 +                funset(vcolcoef[i], 1, ':', l_coef);
236 +                funset(vcolin[i], 1, '=', l_colin);
237 +        }
238 +        funset(vbrtcoef, 1, ':', l_coef);
239 +        funset(vbrtin, 1, '=', l_colin);
240 + }
241 +
242 +
243   combine()                       /* combine pictures */
244   {
245          EPNODE  *coldef[3], *brtdef;
# Line 219 | Line 257 | combine()                      /* combine pictures */
257                  brtdef = eparse(vbrtout);
258          else
259                  brtdef = NULL;
222                                                /* define constants */
223        varset(vnfiles, ':', (double)nfiles);
224        varset(vxres, ':', (double)xres);
225        varset(vyres, ':', (double)yres);
260                                                  /* allocate scanline */
261          scanout = (COLOR *)emalloc(xres*sizeof(COLOR));
228                                                /* initialize input */
229        initinp();
262                                                  /* combine files */
263          for (ypos = yres-1; ypos >= 0; ypos--) {
264              advance();
# Line 263 | Line 295 | combine()                      /* combine pictures */
295   }
296  
297  
266 initinp()                       /* initilize scan windows */
267 {
268        for (ypos = yres+(MIDSCN-1); ypos >= yres; ypos--)
269                advance();
270 }
271
272
298   advance()                       /* read in next scanline */
299   {
300          register COLOR  *st;
# Line 294 | Line 319 | advance()                      /* read in next scanline */
319  
320  
321   double
322 < colin(ci)                       /* return color value for picture */
323 < register int    ci;
322 > l_coef(nam)                     /* return picture coefficients */
323 > register char   *nam;
324   {
325 <        int     n, fn;
301 <        register int    xoff, yoff;
325 >        register int    fn, n;
326          double  d;
327  
328 <        fn = (d = argument(1)) - .5;
329 <        if (d <= -.5 || fn >= nfiles) {
328 >        d = argument(1);
329 >        if (d > -.5 && d < .5)
330 >                return((double)nfiles);
331 >        fn = d - .5;
332 >        if (fn < 0 || fn >= nfiles) {
333                  errno = EDOM;
334                  return(0.0);
335          }
336 <        if (d < .5)
336 >        if (nam == vbrtcoef)
337 >                return(bright(input[fn].coef));
338 >        n = 3;
339 >        while (n--)
340 >                if (nam == vcolcoef[n])
341 >                        return(colval(input[fn].coef,n));
342 >        eputs("Bad call to l_coef()!\n");
343 >        quit(1);
344 > }
345 >
346 >
347 > double
348 > l_colin(nam)                    /* return color value for picture */
349 > register char   *nam;
350 > {
351 >        int     fn;
352 >        register int    n, xoff, yoff;
353 >        double  d;
354 >
355 >        d = argument(1);
356 >        if (d > -.5 && d < .5)
357                  return((double)nfiles);
358 +        fn = d - .5;
359 +        if (fn < 0 || fn >= nfiles) {
360 +                errno = EDOM;
361 +                return(0.0);
362 +        }
363          xoff = yoff = 0;
364          n = nargum();
365          if (n >= 2) {
# Line 338 | Line 390 | register int   ci;
390                                  yoff = yres-1-ypos;
391                  }
392          }
393 <        if (ci == BRT)
393 >        if (nam == vbrtin)
394                  return(bright(input[fn].scan[MIDSCN+yoff][xpos+xoff]));
395 <        return(colval(input[fn].scan[MIDSCN+yoff][xpos+xoff],ci));
396 < }
397 <
398 <
399 < double
400 < l_redin()                       /* get red color */
349 < {
350 <        return(colin(RED));
351 < }
352 <
353 <
354 < double
355 < l_grnin()                       /* get green color */
356 < {
357 <        return(colin(GRN));
358 < }
359 <
360 <
361 < double
362 < l_bluin()                       /* get blue color */
363 < {
364 <        return(colin(BLU));
365 < }
366 <
367 <
368 < double
369 < l_brtin()                       /* get brightness value */
370 < {
371 <        return(colin(BRT));
395 >        n = 3;
396 >        while (n--)
397 >            if (nam == vcolin[n])
398 >                return(colval(input[fn].scan[MIDSCN+yoff][xpos+xoff],n));
399 >        eputs("Bad call to l_colin()!\n");
400 >        quit(1);
401   }
402  
403  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines