ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/pcomb.c
Revision: 2.48
Committed: Sat Jan 13 00:35:55 2018 UTC (6 years, 4 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.47: +5 -6 lines
Log Message:
Fixed issue introduced with xres and yres definitions

File Contents

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