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.15 by greg, Fri May 24 14:46:14 1991 UTC vs.
Revision 1.17 by greg, Fri May 24 17:14:49 1991 UTC

# Line 29 | Line 29 | struct {
29          FILE    *fp;            /* stream pointer */
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 */
# Line 37 | Line 38 | char   *vcolin[3] = {"ri", "gi", "bi"};
38   char    *vcolout[3] = {"ro", "go", "bo"};
39   char    vbrtin[] = "li";
40   char    vbrtout[] = "lo";
41 < char    *vcolcoef[3] = {"rc", "gc", "bc"};
42 < char    vbrtcoef[] = "lc";
41 > char    *vcolexp[3] = {"re", "ge", "be"};
42 > char    vbrtexp[] = "le";
43  
44   #define vnfiles         "nfiles"
45   #define vxres           "xres"
# Line 76 | Line 77 | char   *argv[];
77                          case 'w':
78                                  nowarn = !nowarn;
79                                  continue;
79                        case 'o':
80                                original = !original;
81                                continue;
80                          case 'f':
81                          case 'e':
82 +                                a++;
83                                  continue;
84                          }
85                  break;
86          }
87                                          /* process files */
88 <        for (nfiles = 0; nfiles < MAXINP; nfiles++)
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 101 | Line 102 | char   *argv[];
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 121 | Line 125 | char   *argv[];
125                                  quit(1);
126                          }
127                  }
128 +                checkfile();
129 +                original = 0;
130                  nfiles++;
131          }
132 <        initfiles();            /* initialize files and variables */
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':
134                        case 'o':
142                                  continue;
143                          case 'f':
144                                  fcompile(argv[++a]);
# Line 169 | Line 176 | char   *s;
176          if (isformat(s)) {                      /* check format */
177                  formatval(fmt, s);
178                  wrongformat = strcmp(fmt, COLRFMT);
179 <        } else if (original && isexpos(s)) {    /* exposure */
180 <                d = 1.0/exposval(s);
181 <                scalecolor(input[nfiles].coef, d);
182 <        } else if (original && iscolcor(s)) {   /* color correction */
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 <                colval(input[nfiles].coef,RED) /= colval(ctmp,RED);
189 <                colval(input[nfiles].coef,GRN) /= colval(ctmp,GRN);
190 <                colval(input[nfiles].coef,BLU) /= colval(ctmp,BLU);
191 <        } else {                                /* echo unaffected line */
192 <                putchar('\t');
193 <                fputs(s, stdout);
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 <
195 >                                                /* echo line */
196 >        putchar('\t');
197 >        fputs(s, stdout);
198   }
199  
200  
201 < initfiles()                     /* ready files and set variables */
201 > checkfile()                     /* ready a file */
202   {
203 <        double  l_colin(), l_coef();
204 <        register int    n, i;
205 <                                        /* process picture headers */
206 <        for (n = 0; n < nfiles; n++) {
207 <                fputs(input[n].name, stdout);
208 <                fputs(":\n", stdout);
209 <                getheader(input[n].fp, tputs, NULL);
210 <                if (wrongformat) {
211 <                        eputs(input[n].name);
199 <                        eputs(": not in Radiance picture format\n");
200 <                        quit(1);
201 <                }
202 <                if (fgetresolu(&xpos, &ypos, input[n].fp) != (YMAJOR|YDECR)) {
203 <                        eputs(input[n].name);
204 <                        eputs(": bad picture size\n");
205 <                        quit(1);
206 <                }
207 <                if (xres == 0 && yres == 0) {
208 <                        xres = xpos;
209 <                        yres = ypos;
210 <                } else if (xpos != xres || ypos != yres) {
211 <                        eputs(input[n].name);
212 <                        eputs(": resolution mismatch\n");
213 <                        quit(1);
214 <                }
215 <                for (i = 0; i < WINSIZ; i++)
216 <                        input[n].scan[i] = (COLOR *)emalloc(xres*sizeof(COLOR));
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();
# Line 224 | Line 242 | initfiles()                    /* ready files and set variables */
242          varset(vyres, ':', (double)yres);
243                                                  /* set functions */
244          for (i = 0; i < 3; i++) {
245 <                funset(vcolcoef[i], 1, ':', l_coef);
245 >                funset(vcolexp[i], 1, ':', l_expos);
246                  funset(vcolin[i], 1, '=', l_colin);
247          }
248 <        funset(vbrtcoef, 1, ':', l_coef);
248 >        funset(vbrtexp, 1, ':', l_expos);
249          funset(vbrtin, 1, '=', l_colin);
250   }
251  
# Line 311 | Line 329 | advance()                      /* read in next scanline */
329  
330  
331   double
332 < l_coef(nam)                     /* return picture coefficients */
332 > l_expos(nam)                    /* return picture exposure */
333   register char   *nam;
334   {
335          register int    fn, n;
336          double  d;
337  
338 <        fn = (d = argument(1)) - .5;
339 <        if (d <= -.5 || fn >= nfiles) {
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 (d < .5)
347 <                return((double)nfiles);
327 <        if (nam == vbrtcoef)
328 <                return(bright(input[fn].coef));
346 >        if (nam == vbrtexp)
347 >                return(bright(input[fn].expos));
348          n = 3;
349          while (n--)
350 <                if (nam == vcolcoef[n])
351 <                        return(colval(input[fn].coef,n));
352 <        eputs("Bad call to l_coef()!\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  
# Line 343 | Line 362 | register char  *nam;
362          register int    n, xoff, yoff;
363          double  d;
364  
365 <        fn = (d = argument(1)) - .5;
366 <        if (d <= -.5 || fn >= nfiles) {
365 >        d = argument(1);
366 >        if (d > -.5 && d < .5)
367 >                return((double)nfiles);
368 >        fn = d - .5;
369 >        if (fn < 0 || fn >= nfiles) {
370                  errno = EDOM;
371                  return(0.0);
372          }
351        if (d < .5)
352                return((double)nfiles);
373          xoff = yoff = 0;
374          n = nargum();
375          if (n >= 2) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines