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 2.24 by schorsch, Sun Jun 8 12:03:10 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1991 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   *  Combine picture files according to calcomp functions.
6   *
7   *      1/4/89
8   */
9  
10 < #include <stdio.h>
11 <
15 < #include <errno.h>
16 <
10 > #include "standard.h"
11 > #include "platform.h"
12   #include "color.h"
18
13   #include "calcomp.h"
14 + #include "view.h"
15  
16   #define MAXINP          32              /* maximum number of input files */
17 + #define WINSIZ          64              /* scanline window size */
18 + #define MIDSCN          ((WINSIZ-1)/2+1)
19  
20   struct {
21 <        char    *name;          /* file name */
21 >        char    *name;          /* file or command name */
22          FILE    *fp;            /* stream pointer */
23 <        COLOR   *scan;          /* input scanline */
23 >        VIEW    vw;             /* view for picture */
24 >        RESOLU  rs;             /* image resolution and orientation */
25 >        float   pa;             /* pixel aspect ratio */
26 >        COLOR   *scan[WINSIZ];  /* input scanline window */
27          COLOR   coef;           /* coefficient */
28 +        COLOR   expos;          /* recorded exposure */
29   }       input[MAXINP];                  /* input pictures */
30  
31   int     nfiles;                         /* number of input files */
32  
33 < char    *vcolin[3] = {"ri", "gi", "bi"};
33 < char    *vcolout[3] = {"ro", "go", "bo"};
34 < #define vbrtin          "li"
35 < #define vbrtout         "lo"
33 > char    ourfmt[LPICFMT+1] = PICFMT;     /* input picture format */
34  
35 < #define vnfiles         "nfiles"
36 < #define vxres           "xres"
37 < #define vyres           "yres"
38 < #define vxpos           "x"
39 < #define vypos           "y"
35 > char    Command[] = "<Command>";
36 > char    vcolin[3][4] = {"ri", "gi", "bi"};
37 > char    vcolout[3][4] = {"ro", "go", "bo"};
38 > char    vbrtin[] = "li";
39 > char    vbrtout[] = "lo";
40 > char    vcolexp[3][4] = {"re", "ge", "be"};
41 > char    vbrtexp[] = "le";
42 > char    vpixaspect[] = "pa";
43  
44 + char    vray[7][4] = {"Ox", "Oy", "Oz", "Dx", "Dy", "Dz", "T"};
45 +
46 + char    vpsize[] = "S";
47 +
48 + char    vnfiles[] = "nfiles";
49 + char    vwhteff[] = "WE";
50 + char    vxmax[] = "xmax";
51 + char    vymax[] = "ymax";
52 + char    vxres[] = "xres";
53 + char    vyres[] = "yres";
54 + char    vxpos[] = "x";
55 + char    vypos[] = "y";
56 +
57   int     nowarn = 0;                     /* no warning messages? */
58  
59 < int     original = 0;                   /* origninal values? */
59 > int     xmax = 0, ymax = 0;             /* input resolution */
60  
61 < int     xres=0, yres=0;                 /* picture resolution */
61 > int     xscan, yscan;                   /* input position */
62  
63 < int     xpos, ypos;                     /* picture position */
63 > int     xres, yres;                     /* output resolution */
64  
65 < int     wrongformat = 0;
65 > int     xpos, ypos;                     /* output position */
66  
67 + char    *progname;                      /* global argv[0] */
68  
69 < tputs(s)                        /* put out string preceded by a tab */
70 < char    *s;
56 < {
57 <        char    fmt[32];
58 <        double  d;
59 <        COLOR   ctmp;
69 > int     wrongformat = 0;
70 > int     gotview;
71  
72 <        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 <        }
72 > FILE    *popen();
73  
74 < }
74 > extern char     *emalloc();
75  
76  
77   main(argc, argv)
78   int     argc;
79   char    *argv[];
80   {
81 <        extern double   l_redin(), l_grnin(), l_bluin(), l_brtin(), atof();
81 >        int     original;
82          double  f;
83 <        int     a;
84 <        
85 <        funset(vcolin[RED], 1, l_redin);
86 <        funset(vcolin[GRN], 1, l_grnin);
87 <        funset(vcolin[BLU], 1, l_bluin);
88 <        funset(vbrtin, 1, l_brtin);
89 <        
93 <        for (a = 1; a < argc; a++)
83 >        int     a, i;
84 >        SET_DEFAULT_BINARY();
85 >        SET_FILE_BINARY(stdin);
86 >        SET_FILE_BINARY(stdout);
87 >        progname = argv[0];
88 >                                                /* scan options */
89 >        for (a = 1; a < argc; a++) {
90                  if (argv[a][0] == '-')
91                          switch (argv[a][1]) {
96                        case '\0':
97                        case 's':
98                        case 'c':
99                                goto getfiles;
92                          case 'x':
101                                xres = atoi(argv[++a]);
102                                break;
93                          case 'y':
94 <                                yres = atoi(argv[++a]);
95 <                                break;
94 >                                a++;
95 >                                continue;
96                          case 'w':
97                                  nowarn = !nowarn;
98 <                                break;
109 <                        case 'o':
110 <                                original = !original;
111 <                                break;
98 >                                continue;
99                          case 'f':
113                                fcompile(argv[++a]);
114                                break;
100                          case 'e':
101 <                                scompile(argv[++a], NULL, 0);
102 <                                break;
118 <                        default:
119 <                                goto usage;
101 >                                a++;
102 >                                continue;
103                          }
104 <                else
105 <                        break;
106 < getfiles:
107 <        for (nfiles = 0; nfiles < MAXINP; nfiles++)
104 >                break;
105 >        }
106 >        newheader("RADIANCE", stdout);  /* start header */
107 >        fputnow(stdout);
108 >                                        /* process files */
109 >        for (nfiles = 0; nfiles < MAXINP; nfiles++) {
110                  setcolor(input[nfiles].coef, 1.0, 1.0, 1.0);
111 +                setcolor(input[nfiles].expos, 1.0, 1.0, 1.0);
112 +                copystruct(&input[nfiles].vw, &stdview);
113 +                input[nfiles].pa = 1.0;
114 +        }
115          nfiles = 0;
116 +        original = 0;
117          for ( ; a < argc; a++) {
118                  if (nfiles >= MAXINP) {
119                          eputs(argv[0]);
# Line 136 | Line 126 | getfiles:
126                                  input[nfiles].name = "<stdin>";
127                                  input[nfiles].fp = stdin;
128                                  break;
129 +                        case 'o':
130 +                                original++;
131 +                                continue;
132                          case 's':
133                                  f = atof(argv[++a]);
134                                  scalecolor(input[nfiles].coef, f);
# Line 149 | Line 142 | getfiles:
142                                  goto usage;
143                          }
144                  else {
145 <                        input[nfiles].name = argv[a];
146 <                        input[nfiles].fp = fopen(argv[a], "r");
145 >                        if (argv[a][0] == '!') {
146 >                                input[nfiles].name = Command;
147 >                                input[nfiles].fp = popen(argv[a]+1, "r");
148 >                        } else {
149 >                                input[nfiles].name = argv[a];
150 >                                input[nfiles].fp = fopen(argv[a], "r");
151 >                        }
152                          if (input[nfiles].fp == NULL) {
153                                  perror(argv[a]);
154                                  quit(1);
155                          }
156                  }
157 <                fputs(input[nfiles].name, stdout);
158 <                fputs(":\n", stdout);
159 <                getheader(input[nfiles].fp, tputs, NULL);
160 <                if (wrongformat) {
161 <                        eputs(input[nfiles].name);
162 <                        eputs(": not in Radiance picture format\n");
163 <                        quit(1);
157 >                checkfile();
158 >                if (original) {
159 >                        colval(input[nfiles].coef,RED) /=
160 >                                        colval(input[nfiles].expos,RED);
161 >                        colval(input[nfiles].coef,GRN) /=
162 >                                        colval(input[nfiles].expos,GRN);
163 >                        colval(input[nfiles].coef,BLU) /=
164 >                                        colval(input[nfiles].expos,BLU);
165 >                        setcolor(input[nfiles].expos, 1.0, 1.0, 1.0);
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));
167                  nfiles++;
168 +                original = 0;
169          }
170 +        init();                         /* set constants */
171 +                                        /* go back and get expressions */
172 +        for (a = 1; a < argc; a++) {
173 +                if (argv[a][0] == '-')
174 +                        switch (argv[a][1]) {
175 +                        case 'x':
176 +                                varset(vxres, ':', eval(argv[++a]));
177 +                                continue;
178 +                        case 'y':
179 +                                varset(vyres, ':', eval(argv[++a]));
180 +                                continue;
181 +                        case 'w':
182 +                                continue;
183 +                        case 'f':
184 +                                fcompile(argv[++a]);
185 +                                continue;
186 +                        case 'e':
187 +                                scompile(argv[++a], NULL, 0);
188 +                                continue;
189 +                        }
190 +                break;
191 +        }
192 +                                                /* set/get output resolution */
193 +        if (!vardefined(vxres))
194 +                varset(vxres, ':', (double)xmax);
195 +        if (!vardefined(vyres))
196 +                varset(vyres, ':', (double)ymax);
197 +        xres = varvalue(vxres) + .5;
198 +        yres = varvalue(vyres) + .5;
199 +        if (xres <= 0 || yres <= 0) {
200 +                eputs(argv[0]);
201 +                eputs(": illegal output resolution\n");
202 +                quit(1);
203 +        }
204 +                                                /* complete header */
205          printargs(argc, argv, stdout);
206 <        fputformat(COLRFMT, stdout);
206 >        if (strcmp(ourfmt, PICFMT))
207 >                fputformat(ourfmt, stdout);     /* print format if known */
208          putchar('\n');
209 <        fputresolu(YMAJOR|YDECR, xres, yres, stdout);
209 >        fprtresolu(xres, yres, stdout);
210 >                                                /* combine pictures */
211          combine();
212          quit(0);
213   usage:
214          eputs("Usage: ");
215          eputs(argv[0]);
216          eputs(
217 < " [-w][-h][-x xr][-y yr][-e expr][-f file] [ [-s f][-c r g b] pic ..]\n");
217 > " [-w][-x xr][-y yr][-e expr][-f file] [ [-o][-s f][-c r g b] pic ..]\n");
218          quit(1);
219   }
220  
221  
222 + tabputs(s)                      /* put out string preceded by a tab */
223 + char    *s;
224 + {
225 +        char    fmt[32];
226 +        double  d;
227 +        COLOR   ctmp;
228 +
229 +        if (isheadid(s))                        /* header id */
230 +                return(0);      /* don't echo */
231 +        if (formatval(fmt, s)) {                /* check format */
232 +                if (globmatch(ourfmt, fmt)) {
233 +                        wrongformat = 0;
234 +                        strcpy(ourfmt, fmt);
235 +                } else
236 +                        wrongformat = globmatch(PICFMT, fmt) ? 1 : -1;
237 +                return(0);      /* don't echo */
238 +        }
239 +        if (isexpos(s)) {                       /* exposure */
240 +                d = exposval(s);
241 +                scalecolor(input[nfiles].expos, d);
242 +        } else if (iscolcor(s)) {               /* color correction */
243 +                colcorval(ctmp, s);
244 +                multcolor(input[nfiles].expos, ctmp);
245 +        } else if (isaspect(s))
246 +                input[nfiles].pa *= aspectval(s);
247 +        else if (isview(s) && sscanview(&input[nfiles].vw, s) > 0)
248 +                gotview++;
249 +                                                /* echo line */
250 +        putchar('\t');
251 +        return(fputs(s, stdout));
252 + }
253 +
254 +
255 + checkfile()                     /* ready a file */
256 + {
257 +        register int    i;
258 +                                        /* process header */
259 +        gotview = 0;
260 +        fputs(input[nfiles].name, stdout);
261 +        fputs(":\n", stdout);
262 +        getheader(input[nfiles].fp, tabputs, NULL);
263 +        if (wrongformat < 0) {
264 +                eputs(input[nfiles].name);
265 +                eputs(": not a Radiance picture\n");
266 +                quit(1);
267 +        }
268 +        if (wrongformat > 0) {
269 +                wputs(input[nfiles].name);
270 +                wputs(": warning -- incompatible picture format\n");
271 +        }
272 +        if (!gotview || setview(&input[nfiles].vw) != NULL)
273 +                input[nfiles].vw.type = 0;
274 +        if (!fgetsresolu(&input[nfiles].rs, input[nfiles].fp)) {
275 +                eputs(input[nfiles].name);
276 +                eputs(": bad picture size\n");
277 +                quit(1);
278 +        }
279 +        if (xmax == 0 && ymax == 0) {
280 +                xmax = scanlen(&input[nfiles].rs);
281 +                ymax = numscans(&input[nfiles].rs);
282 +        } else if (scanlen(&input[nfiles].rs) != xmax ||
283 +                        numscans(&input[nfiles].rs) != ymax) {
284 +                eputs(input[nfiles].name);
285 +                eputs(": resolution mismatch\n");
286 +                quit(1);
287 +        }
288 +                                        /* allocate scanlines */
289 +        for (i = 0; i < WINSIZ; i++)
290 +                input[nfiles].scan[i] = (COLOR *)emalloc(xmax*sizeof(COLOR));
291 + }
292 +
293 +
294 + double
295 + rgb_bright(clr)
296 + COLOR  clr;
297 + {
298 +        return(bright(clr));
299 + }
300 +
301 +
302 + double
303 + xyz_bright(clr)
304 + COLOR  clr;
305 + {
306 +        return(clr[CIEY]);
307 + }
308 +
309 +
310 + double  (*ourbright)() = rgb_bright;
311 +
312 +
313 + init()                                  /* perform final setup */
314 + {
315 +        double  l_colin(), l_expos(), l_pixaspect(), l_ray(), l_psize();
316 +        register int    i;
317 +                                                /* define constants */
318 +        varset("PI", ':', PI);
319 +        varset(vnfiles, ':', (double)nfiles);
320 +        varset(vxmax, ':', (double)xmax);
321 +        varset(vymax, ':', (double)ymax);
322 +                                                /* set functions */
323 +        for (i = 0; i < 3; i++) {
324 +                funset(vcolexp[i], 1, ':', l_expos);
325 +                funset(vcolin[i], 1, '=', l_colin);
326 +        }
327 +        funset(vbrtexp, 1, ':', l_expos);
328 +        funset(vbrtin, 1, '=', l_colin);
329 +        funset(vpixaspect, 1, ':', l_pixaspect);
330 +        for (i = 0; i < 7; i++)
331 +                funset(vray[i], 1, '=', l_ray);
332 +        funset(vpsize, 1, '=', l_psize);
333 +                                                /* set brightness function */
334 +        if (!strcmp(ourfmt, CIEFMT)) {
335 +                varset(vwhteff, ':', 1.0);
336 +                ourbright = xyz_bright;
337 +        } else
338 +                varset(vwhteff, ':', WHTEFFICACY);
339 + }
340 +
341 +
342   combine()                       /* combine pictures */
343   {
344          EPNODE  *coldef[3], *brtdef;
# Line 213 | Line 356 | combine()                      /* combine pictures */
356                  brtdef = eparse(vbrtout);
357          else
358                  brtdef = NULL;
216                                                /* predefine variables */
217        varset(vnfiles, (double)nfiles);
218        varset(vxres, (double)xres);
219        varset(vyres, (double)yres);
359                                                  /* allocate scanline */
360          scanout = (COLOR *)emalloc(xres*sizeof(COLOR));
361 +                                                /* set input position */
362 +        yscan = ymax+MIDSCN;
363                                                  /* combine files */
364          for (ypos = yres-1; ypos >= 0; ypos--) {
365 <            for (i = 0; i < nfiles; i++)
366 <                    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);
365 >            advance();
366 >            varset(vypos, '=', (double)ypos);
367              for (xpos = 0; xpos < xres; xpos++) {
368 <                for (i = 0; i < nfiles; i++)
369 <                        multcolor(input[i].scan[xpos],input[i].coef);
234 <                varset(vxpos, (double)xpos);
368 >                xscan = (long)xpos*xmax/xres;
369 >                varset(vxpos, '=', (double)xpos);
370                  eclock++;
371                  if (brtdef != NULL) {
372                      d = evalue(brtdef);
# Line 241 | Line 376 | combine()                      /* combine pictures */
376                  } else {
377                      for (j = 0; j < 3; j++) {
378                          if (coldef[j] != NULL) {
379 <                                colval(scanout[xpos],j) = evalue(coldef[j]);
379 >                                d = evalue(coldef[j]);
380                          } else {
381 <                            colval(scanout[xpos],j) = 0.0;
381 >                            d = 0.0;
382                              for (i = 0; i < nfiles; i++)
383 <                                colval(scanout[xpos],j) +=
249 <                                        colval(input[i].scan[xpos],j);
383 >                                d += colval(input[i].scan[MIDSCN][xscan],j);
384                          }
385 <                        if (colval(scanout[xpos],j) < 0.0)
386 <                            colval(scanout[xpos],j) = 0.0;
385 >                        if (d < 0.0)
386 >                            d = 0.0;
387 >                        colval(scanout[xpos],j) = d;
388                      }
389                  }
390              }
# Line 258 | Line 393 | combine()                      /* combine pictures */
393                      quit(1);
394              }
395          }
396 <        efree(scanout);
396 >        efree((char *)scanout);
397   }
398  
399  
400 + advance()                       /* read in data for next scanline */
401 + {
402 +        int     ytarget;
403 +        register COLOR  *st;
404 +        register int    i, j;
405 +
406 +        for (ytarget = (long)ypos*ymax/yres; yscan > ytarget; yscan--)
407 +                for (i = 0; i < nfiles; i++) {
408 +                        st = input[i].scan[WINSIZ-1];
409 +                        for (j = WINSIZ-1; j > 0; j--)  /* rotate window */
410 +                                input[i].scan[j] = input[i].scan[j-1];
411 +                        input[i].scan[0] = st;
412 +                        if (yscan <= MIDSCN)            /* hit bottom? */
413 +                                continue;
414 +                        if (freadscan(st, xmax, input[i].fp) < 0) {  /* read */
415 +                                eputs(input[i].name);
416 +                                eputs(": read error\n");
417 +                                quit(1);
418 +                        }
419 +                        if (fabs(colval(input[i].coef,RED)-1.0) > 1e-3 ||
420 +                                fabs(colval(input[i].coef,GRN)-1.0) > 1e-3 ||
421 +                                fabs(colval(input[i].coef,BLU)-1.0) > 1e-3)
422 +                                for (j = 0; j < xmax; j++)  /* adjust color */
423 +                                        multcolor(st[j], input[i].coef);
424 +                }
425 + }
426 +
427 +
428   double
429 < colin(fn, ci)                   /* return color value for picture */
430 < register int    fn, ci;
429 > l_expos(nam)                    /* return picture exposure */
430 > register char   *nam;
431   {
432 <        if (fn == 0)
433 <                return((double)nfiles);
434 <        if (fn < 1 || fn > nfiles) {
435 <                errno = EDOM;
436 <                return(0.0);
437 <        }
438 <        return(colval(input[fn-1].scan[xpos],ci));
432 >        register int    fn, n;
433 >
434 >        fn = argument(1) - .5;
435 >        if (fn < 0 || fn >= nfiles)
436 >                return(1.0);
437 >        if (nam == vbrtexp)
438 >                return((*ourbright)(input[fn].expos));
439 >        n = 3;
440 >        while (n--)
441 >                if (nam == vcolexp[n])
442 >                        return(colval(input[fn].expos,n));
443 >        eputs("Bad call to l_expos()!\n");
444 >        quit(1);
445   }
446  
447  
448   double
449 < l_redin()                       /* get red color */
449 > l_pixaspect()                   /* return pixel aspect ratio */
450   {
451 <        return(colin((int)(argument(1)+.5), RED));
451 >        register int    fn;
452 >
453 >        fn = argument(1) - .5;
454 >        if (fn < 0 || fn >= nfiles)
455 >                return(1.0);
456 >        return(input[fn].pa);
457   }
458  
459  
460   double
461 < l_grnin()                       /* get green color */
461 > l_colin(nam)                    /* return color value for picture */
462 > register char   *nam;
463   {
464 <        return(colin((int)(argument(1)+.5), GRN));
464 >        int     fn;
465 >        register int    n, xoff, yoff;
466 >        double  d;
467 >
468 >        fn = argument(1) - .5;
469 >        if (fn < 0 || fn >= nfiles) {
470 >                errno = EDOM;
471 >                return(0.0);
472 >        }
473 >        xoff = yoff = 0;
474 >        n = nargum();
475 >        if (n >= 2) {
476 >                d = argument(2);
477 >                if (d < 0.0) {
478 >                        xoff = d-.5;
479 >                        if (xscan+xoff < 0)
480 >                                xoff = -xscan;
481 >                } else {
482 >                        xoff = d+.5;
483 >                        if (xscan+xoff >= xmax)
484 >                                xoff = xmax-1-xscan;
485 >                }
486 >        }
487 >        if (n >= 3) {
488 >                d = argument(3);
489 >                if (d < 0.0) {
490 >                        yoff = d-.5;
491 >                        if (yoff+MIDSCN < 0)
492 >                                yoff = -MIDSCN;
493 >                        if (yscan+yoff < 0)
494 >                                yoff = -yscan;
495 >                } else {
496 >                        yoff = d+.5;
497 >                        if (yoff+MIDSCN >= WINSIZ)
498 >                                yoff = WINSIZ-1-MIDSCN;
499 >                        if (yscan+yoff >= ymax)
500 >                                yoff = ymax-1-yscan;
501 >                }
502 >        }
503 >        if (nam == vbrtin)
504 >                return((*ourbright)(input[fn].scan[MIDSCN+yoff][xscan+xoff]));
505 >        n = 3;
506 >        while (n--)
507 >            if (nam == vcolin[n])
508 >                return(colval(input[fn].scan[MIDSCN+yoff][xscan+xoff],n));
509 >        eputs("Bad call to l_colin()!\n");
510 >        quit(1);
511   }
512  
513  
514   double
515 < l_bluin()                       /* get blue color */
515 > l_ray(nam)              /* return ray origin or direction */
516 > register char   *nam;
517   {
518 <        return(colin((int)(argument(1)+.5), BLU));
518 >        static unsigned long    ltick[MAXINP];
519 >        static FVECT    lorg[MAXINP], ldir[MAXINP];
520 >        static double   ldist[MAXINP];
521 >        FLOAT   loc[2];
522 >        int     fn;
523 >        register int    i;
524 >
525 >        fn = argument(1) - .5;
526 >        if (fn < 0 || fn >= nfiles) {
527 >                errno = EDOM;
528 >                return(0.0);
529 >        }
530 >        if (ltick[fn] != eclock) {              /* need to compute? */
531 >                lorg[fn][0] = lorg[fn][1] = lorg[fn][2] = 0.0;
532 >                ldir[fn][0] = ldir[fn][1] = ldir[fn][2] = 0.0;
533 >                ldist[fn] = -1.0;
534 >                if (input[fn].vw.type == 0)
535 >                        errno = EDOM;
536 >                else {
537 >                        pix2loc(loc, &input[fn].rs, xscan, ymax-1-yscan);
538 >                        ldist[fn] = viewray(lorg[fn], ldir[fn],
539 >                                        &input[fn].vw, loc[0], loc[1]);
540 >                }
541 >                ltick[fn] = eclock;
542 >        }
543 >        if (nam == vray[i=6])
544 >                return(ldist[fn]);
545 >        while (i--)
546 >                if (nam == vray[i])
547 >                        return(i < 3 ? lorg[fn][i] : ldir[fn][i-3]);
548 >        eputs("Bad call to l_ray()!\n");
549 >        quit(1);
550   }
551  
552  
553   double
554 < l_brtin()                       /* get brightness value */
554 > l_psize()                       /* compute pixel size in steradians */
555   {
556 <        register int    fn;
556 >        static unsigned long    ltick[MAXINP];
557 >        static double   psize[MAXINP];
558 >        FVECT   dir0, org, dirx, diry;
559 >        FLOAT   locx[2], locy[2];
560 >        double  d;
561 >        int     fn;
562 >        register int    i;
563  
564 <        fn = argument(1)+.5;
565 <        if (fn == 0)
307 <                return((double)nfiles);
308 <        if (fn < 1 || fn > nfiles) {
564 >        d = argument(1);
565 >        if (d < .5 || d >= nfiles+.5) {
566                  errno = EDOM;
567                  return(0.0);
568          }
569 <        return(bright(input[fn-1].scan[xpos]));
569 >        fn = d - .5;
570 >        if (ltick[fn] != eclock) {              /* need to compute? */
571 >                psize[fn] = 0.0;
572 >                if (input[fn].vw.type == 0)
573 >                        errno = EDOM;
574 >                else if (input[fn].vw.type != VT_PAR &&
575 >                                funvalue(vray[6], 1, &d) >= 0) {
576 >                        for (i = 0; i < 3; i++)
577 >                                dir0[i] = funvalue(vray[3+i], 1, &d);
578 >                        pix2loc(locx, &input[fn].rs, xscan+1, ymax-1-yscan);
579 >                        pix2loc(locy, &input[fn].rs, xscan, ymax-yscan);
580 >                        if (viewray(org, dirx, &input[fn].vw,
581 >                                        locx[0], locx[1]) >= 0 &&
582 >                                        viewray(org, diry, &input[fn].vw,
583 >                                        locy[0], locy[1]) >= 0) {
584 >                                                /* approximate solid angle */
585 >                                for (i = 0; i < 3; i++) {
586 >                                        dirx[i] -= dir0[i];
587 >                                        diry[i] -= dir0[i];
588 >                                }
589 >                                fcross(dir0, dirx, diry);
590 >                                psize[fn] = sqrt(DOT(dir0,dir0));
591 >                        }
592 >                }
593 >                ltick[fn] = eclock;
594 >        }
595 >        return(psize[fn]);
596   }
597  
598  
599 + void
600   wputs(msg)
601   char    *msg;
602   {
# Line 321 | Line 605 | char   *msg;
605   }
606  
607  
608 + void
609   eputs(msg)
610   char    *msg;
611   {
# Line 328 | Line 613 | char   *msg;
613   }
614  
615  
616 < quit(code)
617 < int     code;
616 > void
617 > quit(code)              /* exit gracefully */
618 > int  code;
619   {
620 +        register int  i;
621 +                                /* close input files */
622 +        for (i = 0; i < nfiles; i++)
623 +                if (input[i].name == Command)
624 +                        pclose(input[i].fp);
625 +                else
626 +                        fclose(input[i].fp);
627          exit(code);
628   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines