1 |
– |
/* Copyright (c) 1992 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 |
< |
|
12 |
< |
#include <errno.h> |
16 |
< |
|
10 |
> |
#include "platform.h" |
11 |
> |
#include "standard.h" |
12 |
> |
#include "rtprocess.h" |
13 |
|
#include "color.h" |
18 |
– |
|
19 |
– |
#include "resolu.h" |
20 |
– |
|
14 |
|
#include "calcomp.h" |
15 |
+ |
#include "view.h" |
16 |
|
|
17 |
|
#define MAXINP 32 /* maximum number of input files */ |
18 |
< |
#define WINSIZ 9 /* scanline window size */ |
19 |
< |
#define MIDSCN 4 /* current scan position */ |
18 |
> |
#define WINSIZ 64 /* scanline window size */ |
19 |
> |
#define MIDSCN ((WINSIZ-1)/2+1) |
20 |
|
|
21 |
|
struct { |
22 |
|
char *name; /* file or command name */ |
23 |
|
FILE *fp; /* stream pointer */ |
24 |
+ |
VIEW vw; /* view for picture */ |
25 |
+ |
RESOLU rs; /* image resolution and orientation */ |
26 |
+ |
float pa; /* pixel aspect ratio */ |
27 |
|
COLOR *scan[WINSIZ]; /* input scanline window */ |
28 |
|
COLOR coef; /* coefficient */ |
29 |
|
COLOR expos; /* recorded exposure */ |
31 |
|
|
32 |
|
int nfiles; /* number of input files */ |
33 |
|
|
34 |
+ |
char ourfmt[LPICFMT+1] = PICFMT; /* input picture format */ |
35 |
+ |
|
36 |
+ |
char StandardInput[] = "<stdin>"; |
37 |
|
char Command[] = "<Command>"; |
38 |
|
char vcolin[3][4] = {"ri", "gi", "bi"}; |
39 |
|
char vcolout[3][4] = {"ro", "go", "bo"}; |
41 |
|
char vbrtout[] = "lo"; |
42 |
|
char vcolexp[3][4] = {"re", "ge", "be"}; |
43 |
|
char vbrtexp[] = "le"; |
44 |
+ |
char vpixaspect[] = "pa"; |
45 |
|
|
46 |
+ |
char vray[7][4] = {"Ox", "Oy", "Oz", "Dx", "Dy", "Dz", "T"}; |
47 |
+ |
|
48 |
+ |
char vpsize[] = "S"; |
49 |
+ |
|
50 |
|
char vnfiles[] = "nfiles"; |
51 |
+ |
char vwhteff[] = "WE"; |
52 |
|
char vxmax[] = "xmax"; |
53 |
|
char vymax[] = "ymax"; |
54 |
|
char vxres[] = "xres"; |
66 |
|
|
67 |
|
int xpos, ypos; /* output position */ |
68 |
|
|
69 |
+ |
char *progname; /* global argv[0] */ |
70 |
+ |
|
71 |
|
int wrongformat = 0; |
72 |
+ |
int gotview; |
73 |
|
|
65 |
– |
FILE *popen(); |
74 |
|
|
75 |
+ |
static gethfunc tabputs; |
76 |
+ |
static void checkfile(void); |
77 |
+ |
static double rgb_bright(COLOR clr); |
78 |
+ |
static double xyz_bright(COLOR clr); |
79 |
+ |
static void init(void); |
80 |
+ |
static void combine(void); |
81 |
+ |
static void advance(void); |
82 |
+ |
static double l_expos(char *nam); |
83 |
+ |
static double l_pixaspect(char *nm); |
84 |
+ |
static double l_colin(char *nam); |
85 |
+ |
static double l_ray(char *nam); |
86 |
+ |
static double l_psize(char *nm); |
87 |
|
|
88 |
< |
main(argc, argv) |
89 |
< |
int argc; |
90 |
< |
char *argv[]; |
88 |
> |
|
89 |
> |
int |
90 |
> |
main( |
91 |
> |
int argc, |
92 |
> |
char *argv[] |
93 |
> |
) |
94 |
|
{ |
95 |
|
int original; |
96 |
|
double f; |
97 |
< |
int a, i; |
97 |
> |
int a; |
98 |
> |
SET_DEFAULT_BINARY(); |
99 |
> |
SET_FILE_BINARY(stdin); |
100 |
> |
SET_FILE_BINARY(stdout); |
101 |
> |
progname = argv[0]; |
102 |
|
/* scan options */ |
103 |
|
for (a = 1; a < argc; a++) { |
104 |
|
if (argv[a][0] == '-') |
117 |
|
} |
118 |
|
break; |
119 |
|
} |
120 |
+ |
newheader("RADIANCE", stdout); /* start header */ |
121 |
+ |
fputnow(stdout); |
122 |
|
/* process files */ |
123 |
|
for (nfiles = 0; nfiles < MAXINP; nfiles++) { |
124 |
|
setcolor(input[nfiles].coef, 1.0, 1.0, 1.0); |
125 |
|
setcolor(input[nfiles].expos, 1.0, 1.0, 1.0); |
126 |
+ |
input[nfiles].vw = stdview; |
127 |
+ |
input[nfiles].pa = 1.0; |
128 |
|
} |
129 |
|
nfiles = 0; |
130 |
|
original = 0; |
137 |
|
if (argv[a][0] == '-') |
138 |
|
switch (argv[a][1]) { |
139 |
|
case '\0': |
140 |
< |
input[nfiles].name = "<stdin>"; |
140 |
> |
input[nfiles].name = StandardInput; |
141 |
|
input[nfiles].fp = stdin; |
142 |
|
break; |
143 |
|
case 'o': |
176 |
|
colval(input[nfiles].expos,GRN); |
177 |
|
colval(input[nfiles].coef,BLU) /= |
178 |
|
colval(input[nfiles].expos,BLU); |
179 |
+ |
setcolor(input[nfiles].expos, 1.0, 1.0, 1.0); |
180 |
|
} |
181 |
|
nfiles++; |
182 |
|
original = 0; |
217 |
|
} |
218 |
|
/* complete header */ |
219 |
|
printargs(argc, argv, stdout); |
220 |
< |
fputformat(COLRFMT, stdout); |
220 |
> |
if (strcmp(ourfmt, PICFMT)) |
221 |
> |
fputformat(ourfmt, stdout); /* print format if known */ |
222 |
|
putchar('\n'); |
223 |
|
fprtresolu(xres, yres, stdout); |
224 |
|
/* combine pictures */ |
228 |
|
eputs("Usage: "); |
229 |
|
eputs(argv[0]); |
230 |
|
eputs( |
231 |
< |
" [-w][-x xr][-y yr][-e expr][-f file] [ [-s f][-c r g b] pic ..]\n"); |
231 |
> |
" [-w][-x xr][-y yr][-e expr][-f file] [ [-o][-s f][-c r g b] pic ..]\n"); |
232 |
|
quit(1); |
233 |
+ |
return 1; /* pro forma return */ |
234 |
|
} |
235 |
|
|
236 |
|
|
237 |
< |
tputs(s) /* put out string preceded by a tab */ |
238 |
< |
char *s; |
237 |
> |
static int |
238 |
> |
tabputs( /* put out string preceded by a tab */ |
239 |
> |
char *s, |
240 |
> |
void *p |
241 |
> |
) |
242 |
|
{ |
243 |
|
char fmt[32]; |
244 |
|
double d; |
245 |
|
COLOR ctmp; |
246 |
|
|
247 |
< |
if (isformat(s)) { /* check format */ |
248 |
< |
formatval(fmt, s); |
249 |
< |
wrongformat = strcmp(fmt, COLRFMT); |
250 |
< |
return; /* don't echo */ |
247 |
> |
if (isheadid(s)) /* header id */ |
248 |
> |
return(0); /* don't echo */ |
249 |
> |
if (formatval(fmt, s)) { /* check format */ |
250 |
> |
if (globmatch(ourfmt, fmt)) { |
251 |
> |
wrongformat = 0; |
252 |
> |
strcpy(ourfmt, fmt); |
253 |
> |
} else |
254 |
> |
wrongformat = globmatch(PICFMT, fmt) ? 1 : -1; |
255 |
> |
return(0); /* don't echo */ |
256 |
|
} |
257 |
|
if (isexpos(s)) { /* exposure */ |
258 |
|
d = exposval(s); |
260 |
|
} else if (iscolcor(s)) { /* color correction */ |
261 |
|
colcorval(ctmp, s); |
262 |
|
multcolor(input[nfiles].expos, ctmp); |
263 |
< |
} |
263 |
> |
} else if (isaspect(s)) |
264 |
> |
input[nfiles].pa *= aspectval(s); |
265 |
> |
else if (isview(s) && sscanview(&input[nfiles].vw, s) > 0) |
266 |
> |
gotview++; |
267 |
|
/* echo line */ |
268 |
|
putchar('\t'); |
269 |
< |
fputs(s, stdout); |
269 |
> |
return(fputs(s, stdout)); |
270 |
|
} |
271 |
|
|
272 |
|
|
273 |
< |
checkfile() /* ready a file */ |
273 |
> |
static void |
274 |
> |
checkfile(void) /* ready a file */ |
275 |
|
{ |
230 |
– |
int xinp, yinp; |
276 |
|
register int i; |
277 |
|
/* process header */ |
278 |
+ |
gotview = 0; |
279 |
|
fputs(input[nfiles].name, stdout); |
280 |
|
fputs(":\n", stdout); |
281 |
< |
getheader(input[nfiles].fp, tputs, NULL); |
282 |
< |
if (wrongformat) { |
281 |
> |
getheader(input[nfiles].fp, tabputs, NULL); |
282 |
> |
if (wrongformat < 0) { |
283 |
|
eputs(input[nfiles].name); |
284 |
< |
eputs(": not in Radiance picture format\n"); |
284 |
> |
eputs(": not a Radiance picture\n"); |
285 |
|
quit(1); |
286 |
|
} |
287 |
< |
if (fgetresolu(&xinp, &yinp, input[nfiles].fp) < 0) { |
287 |
> |
if (wrongformat > 0) { |
288 |
> |
wputs(input[nfiles].name); |
289 |
> |
wputs(": warning -- incompatible picture format\n"); |
290 |
> |
} |
291 |
> |
if (!gotview || setview(&input[nfiles].vw) != NULL) |
292 |
> |
input[nfiles].vw.type = 0; |
293 |
> |
if (!fgetsresolu(&input[nfiles].rs, input[nfiles].fp)) { |
294 |
|
eputs(input[nfiles].name); |
295 |
|
eputs(": bad picture size\n"); |
296 |
|
quit(1); |
297 |
|
} |
298 |
|
if (xmax == 0 && ymax == 0) { |
299 |
< |
xmax = xinp; |
300 |
< |
ymax = yinp; |
301 |
< |
} else if (xinp != xmax || yinp != ymax) { |
299 |
> |
xmax = scanlen(&input[nfiles].rs); |
300 |
> |
ymax = numscans(&input[nfiles].rs); |
301 |
> |
} else if (scanlen(&input[nfiles].rs) != xmax || |
302 |
> |
numscans(&input[nfiles].rs) != ymax) { |
303 |
|
eputs(input[nfiles].name); |
304 |
|
eputs(": resolution mismatch\n"); |
305 |
|
quit(1); |
310 |
|
} |
311 |
|
|
312 |
|
|
313 |
< |
init() /* perform final setup */ |
313 |
> |
static double |
314 |
> |
rgb_bright( |
315 |
> |
COLOR clr |
316 |
> |
) |
317 |
|
{ |
318 |
< |
double l_colin(), l_expos(); |
318 |
> |
return(bright(clr)); |
319 |
> |
} |
320 |
> |
|
321 |
> |
|
322 |
> |
static double |
323 |
> |
xyz_bright( |
324 |
> |
COLOR clr |
325 |
> |
) |
326 |
> |
{ |
327 |
> |
return(clr[CIEY]); |
328 |
> |
} |
329 |
> |
|
330 |
> |
|
331 |
> |
double (*ourbright)() = rgb_bright; |
332 |
> |
|
333 |
> |
|
334 |
> |
static void |
335 |
> |
init(void) /* perform final setup */ |
336 |
> |
{ |
337 |
|
register int i; |
338 |
|
/* define constants */ |
339 |
+ |
varset("PI", ':', PI); |
340 |
|
varset(vnfiles, ':', (double)nfiles); |
341 |
|
varset(vxmax, ':', (double)xmax); |
342 |
|
varset(vymax, ':', (double)ymax); |
347 |
|
} |
348 |
|
funset(vbrtexp, 1, ':', l_expos); |
349 |
|
funset(vbrtin, 1, '=', l_colin); |
350 |
+ |
funset(vpixaspect, 1, ':', l_pixaspect); |
351 |
+ |
for (i = 0; i < 7; i++) |
352 |
+ |
funset(vray[i], 1, '=', l_ray); |
353 |
+ |
funset(vpsize, 1, '=', l_psize); |
354 |
+ |
/* set brightness function */ |
355 |
+ |
if (!strcmp(ourfmt, CIEFMT)) { |
356 |
+ |
varset(vwhteff, ':', 1.0); |
357 |
+ |
ourbright = xyz_bright; |
358 |
+ |
} else |
359 |
+ |
varset(vwhteff, ':', WHTEFFICACY); |
360 |
|
} |
361 |
|
|
362 |
|
|
363 |
< |
combine() /* combine pictures */ |
363 |
> |
static void |
364 |
> |
combine(void) /* combine pictures */ |
365 |
|
{ |
366 |
|
EPNODE *coldef[3], *brtdef; |
367 |
|
COLOR *scanout; |
415 |
|
quit(1); |
416 |
|
} |
417 |
|
} |
418 |
< |
efree(scanout); |
418 |
> |
efree((char *)scanout); |
419 |
|
} |
420 |
|
|
421 |
|
|
422 |
< |
advance() /* read in data for next scanline */ |
422 |
> |
static void |
423 |
> |
advance(void) /* read in data for next scanline */ |
424 |
|
{ |
338 |
– |
extern double fabs(); |
425 |
|
int ytarget; |
426 |
|
register COLOR *st; |
427 |
|
register int i, j; |
448 |
|
} |
449 |
|
|
450 |
|
|
451 |
< |
double |
452 |
< |
l_expos(nam) /* return picture exposure */ |
453 |
< |
register char *nam; |
451 |
> |
static double |
452 |
> |
l_expos( /* return picture exposure */ |
453 |
> |
register char *nam |
454 |
> |
) |
455 |
|
{ |
456 |
|
register int fn, n; |
457 |
|
|
459 |
|
if (fn < 0 || fn >= nfiles) |
460 |
|
return(1.0); |
461 |
|
if (nam == vbrtexp) |
462 |
< |
return(bright(input[fn].expos)); |
462 |
> |
return((*ourbright)(input[fn].expos)); |
463 |
|
n = 3; |
464 |
|
while (n--) |
465 |
|
if (nam == vcolexp[n]) |
466 |
|
return(colval(input[fn].expos,n)); |
467 |
|
eputs("Bad call to l_expos()!\n"); |
468 |
|
quit(1); |
469 |
+ |
return 1; /* pro forma return */ |
470 |
|
} |
471 |
|
|
472 |
|
|
473 |
< |
double |
474 |
< |
l_colin(nam) /* return color value for picture */ |
387 |
< |
register char *nam; |
473 |
> |
static double |
474 |
> |
l_pixaspect(char *nm) /* return pixel aspect ratio */ |
475 |
|
{ |
476 |
+ |
register int fn; |
477 |
+ |
|
478 |
+ |
fn = argument(1) - .5; |
479 |
+ |
if (fn < 0 || fn >= nfiles) |
480 |
+ |
return(1.0); |
481 |
+ |
return(input[fn].pa); |
482 |
+ |
} |
483 |
+ |
|
484 |
+ |
|
485 |
+ |
static double |
486 |
+ |
l_colin( /* return color value for picture */ |
487 |
+ |
register char *nam |
488 |
+ |
) |
489 |
+ |
{ |
490 |
|
int fn; |
491 |
|
register int n, xoff, yoff; |
492 |
|
double d; |
493 |
|
|
494 |
< |
d = argument(1); |
394 |
< |
if (d > -.5 && d < .5) |
395 |
< |
return((double)nfiles); |
396 |
< |
fn = d - .5; |
494 |
> |
fn = argument(1) - .5; |
495 |
|
if (fn < 0 || fn >= nfiles) { |
496 |
|
errno = EDOM; |
497 |
|
return(0.0); |
527 |
|
} |
528 |
|
} |
529 |
|
if (nam == vbrtin) |
530 |
< |
return(bright(input[fn].scan[MIDSCN+yoff][xscan+xoff])); |
530 |
> |
return((*ourbright)(input[fn].scan[MIDSCN+yoff][xscan+xoff])); |
531 |
|
n = 3; |
532 |
|
while (n--) |
533 |
|
if (nam == vcolin[n]) |
534 |
|
return(colval(input[fn].scan[MIDSCN+yoff][xscan+xoff],n)); |
535 |
|
eputs("Bad call to l_colin()!\n"); |
536 |
|
quit(1); |
537 |
+ |
return 1; /* pro forma return */ |
538 |
|
} |
539 |
|
|
540 |
|
|
541 |
< |
wputs(msg) |
542 |
< |
char *msg; |
541 |
> |
static double |
542 |
> |
l_ray( /* return ray origin or direction */ |
543 |
> |
register char *nam |
544 |
> |
) |
545 |
|
{ |
546 |
+ |
static unsigned long ltick[MAXINP]; |
547 |
+ |
static FVECT lorg[MAXINP], ldir[MAXINP]; |
548 |
+ |
static double ldist[MAXINP]; |
549 |
+ |
RREAL loc[2]; |
550 |
+ |
int fn; |
551 |
+ |
register int i; |
552 |
+ |
|
553 |
+ |
fn = argument(1) - .5; |
554 |
+ |
if (fn < 0 || fn >= nfiles) { |
555 |
+ |
errno = EDOM; |
556 |
+ |
return(0.0); |
557 |
+ |
} |
558 |
+ |
if (ltick[fn] != eclock) { /* need to compute? */ |
559 |
+ |
lorg[fn][0] = lorg[fn][1] = lorg[fn][2] = 0.0; |
560 |
+ |
ldir[fn][0] = ldir[fn][1] = ldir[fn][2] = 0.0; |
561 |
+ |
ldist[fn] = -1.0; |
562 |
+ |
if (input[fn].vw.type == 0) |
563 |
+ |
errno = EDOM; |
564 |
+ |
else { |
565 |
+ |
pix2loc(loc, &input[fn].rs, xscan, ymax-1-yscan); |
566 |
+ |
ldist[fn] = viewray(lorg[fn], ldir[fn], |
567 |
+ |
&input[fn].vw, loc[0], loc[1]); |
568 |
+ |
} |
569 |
+ |
ltick[fn] = eclock; |
570 |
+ |
} |
571 |
+ |
if (nam == vray[i=6]) |
572 |
+ |
return(ldist[fn]); |
573 |
+ |
while (i--) |
574 |
+ |
if (nam == vray[i]) |
575 |
+ |
return(i < 3 ? lorg[fn][i] : ldir[fn][i-3]); |
576 |
+ |
eputs("Bad call to l_ray()!\n"); |
577 |
+ |
quit(1); |
578 |
+ |
return 1; /* pro forma return */ |
579 |
+ |
} |
580 |
+ |
|
581 |
+ |
|
582 |
+ |
static double |
583 |
+ |
l_psize(char *nm) /* compute pixel size in steradians */ |
584 |
+ |
{ |
585 |
+ |
static unsigned long ltick[MAXINP]; |
586 |
+ |
static double psize[MAXINP]; |
587 |
+ |
FVECT dir0, org, dirx, diry; |
588 |
+ |
RREAL locx[2], locy[2]; |
589 |
+ |
double d; |
590 |
+ |
int fn; |
591 |
+ |
register int i; |
592 |
+ |
|
593 |
+ |
d = argument(1); |
594 |
+ |
if (d < .5 || d >= nfiles+.5) { |
595 |
+ |
errno = EDOM; |
596 |
+ |
return(0.0); |
597 |
+ |
} |
598 |
+ |
fn = d - .5; |
599 |
+ |
if (ltick[fn] != eclock) { /* need to compute? */ |
600 |
+ |
psize[fn] = 0.0; |
601 |
+ |
if (input[fn].vw.type == 0) |
602 |
+ |
errno = EDOM; |
603 |
+ |
else if (input[fn].vw.type != VT_PAR && |
604 |
+ |
funvalue(vray[6], 1, &d) >= 0) { |
605 |
+ |
for (i = 0; i < 3; i++) |
606 |
+ |
dir0[i] = funvalue(vray[3+i], 1, &d); |
607 |
+ |
pix2loc(locx, &input[fn].rs, xscan+1, ymax-1-yscan); |
608 |
+ |
pix2loc(locy, &input[fn].rs, xscan, ymax-yscan); |
609 |
+ |
if (viewray(org, dirx, &input[fn].vw, |
610 |
+ |
locx[0], locx[1]) >= 0 && |
611 |
+ |
viewray(org, diry, &input[fn].vw, |
612 |
+ |
locy[0], locy[1]) >= 0) { |
613 |
+ |
/* approximate solid angle */ |
614 |
+ |
for (i = 0; i < 3; i++) { |
615 |
+ |
dirx[i] -= dir0[i]; |
616 |
+ |
diry[i] -= dir0[i]; |
617 |
+ |
} |
618 |
+ |
fcross(dir0, dirx, diry); |
619 |
+ |
psize[fn] = sqrt(DOT(dir0,dir0)); |
620 |
+ |
} |
621 |
+ |
} |
622 |
+ |
ltick[fn] = eclock; |
623 |
+ |
} |
624 |
+ |
return(psize[fn]); |
625 |
+ |
} |
626 |
+ |
|
627 |
+ |
|
628 |
+ |
extern void |
629 |
+ |
wputs(char *msg) |
630 |
+ |
{ |
631 |
|
if (!nowarn) |
632 |
|
eputs(msg); |
633 |
|
} |
634 |
|
|
635 |
|
|
636 |
< |
eputs(msg) |
637 |
< |
char *msg; |
636 |
> |
extern void |
637 |
> |
eputs(char *msg) |
638 |
|
{ |
639 |
|
fputs(msg, stderr); |
640 |
|
} |
641 |
|
|
642 |
|
|
643 |
< |
quit(code) /* exit gracefully */ |
644 |
< |
int code; |
643 |
> |
extern void |
644 |
> |
quit(int code) /* exit gracefully */ |
645 |
|
{ |
646 |
|
register int i; |
647 |
|
/* close input files */ |