ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/pcomb.c
Revision: 2.55
Committed: Mon Feb 6 22:40:21 2023 UTC (15 months, 1 week ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad5R4
Changes since 2.54: +3 -3 lines
Log Message:
refactor: Changed some char* args to const char* to avoid warnings

File Contents

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