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 |
|
* |
8 |
|
*/ |
9 |
|
|
10 |
|
#include "standard.h" |
14 |
– |
|
11 |
|
#include "color.h" |
16 |
– |
|
17 |
– |
#include "resolu.h" |
18 |
– |
|
12 |
|
#include "calcomp.h" |
20 |
– |
|
13 |
|
#include "view.h" |
14 |
|
|
15 |
|
#define MAXINP 32 /* maximum number of input files */ |
16 |
< |
#define WINSIZ 17 /* scanline window size */ |
16 |
> |
#define WINSIZ 64 /* scanline window size */ |
17 |
|
#define MIDSCN ((WINSIZ-1)/2+1) |
18 |
|
|
19 |
|
struct { |
38 |
|
char vbrtout[] = "lo"; |
39 |
|
char vcolexp[3][4] = {"re", "ge", "be"}; |
40 |
|
char vbrtexp[] = "le"; |
41 |
+ |
char vpixaspect[] = "pa"; |
42 |
|
|
43 |
< |
char vray[6][4] = {"Ox", "Oy", "Oz", "Dx", "Dy", "Dz"}; |
43 |
> |
char vray[7][4] = {"Ox", "Oy", "Oz", "Dx", "Dy", "Dz", "T"}; |
44 |
|
|
45 |
|
char vpsize[] = "S"; |
46 |
|
|
47 |
|
char vnfiles[] = "nfiles"; |
48 |
+ |
char vwhteff[] = "WE"; |
49 |
|
char vxmax[] = "xmax"; |
50 |
|
char vymax[] = "ymax"; |
51 |
|
char vxres[] = "xres"; |
80 |
|
int original; |
81 |
|
double f; |
82 |
|
int a, i; |
83 |
< |
#ifdef MSDOS |
84 |
< |
extern int _fmode; |
85 |
< |
_fmode = O_BINARY; |
92 |
< |
setmode(fileno(stdin), O_BINARY); |
93 |
< |
setmode(fileno(stdout), O_BINARY); |
94 |
< |
#endif |
83 |
> |
SET_DEFAULT_BINARY(); |
84 |
> |
SET_FILE_BINARY(stdin); |
85 |
> |
SET_FILE_BINARY(stdout); |
86 |
|
progname = argv[0]; |
87 |
|
/* scan options */ |
88 |
|
for (a = 1; a < argc; a++) { |
103 |
|
break; |
104 |
|
} |
105 |
|
newheader("RADIANCE", stdout); /* start header */ |
106 |
+ |
fputnow(stdout); |
107 |
|
/* process files */ |
108 |
|
for (nfiles = 0; nfiles < MAXINP; nfiles++) { |
109 |
|
setcolor(input[nfiles].coef, 1.0, 1.0, 1.0); |
161 |
|
colval(input[nfiles].expos,GRN); |
162 |
|
colval(input[nfiles].coef,BLU) /= |
163 |
|
colval(input[nfiles].expos,BLU); |
164 |
+ |
setcolor(input[nfiles].expos, 1.0, 1.0, 1.0); |
165 |
|
} |
166 |
|
nfiles++; |
167 |
|
original = 0; |
218 |
|
} |
219 |
|
|
220 |
|
|
221 |
< |
tputs(s) /* put out string preceded by a tab */ |
221 |
> |
tabputs(s) /* put out string preceded by a tab */ |
222 |
|
char *s; |
223 |
|
{ |
224 |
|
char fmt[32]; |
226 |
|
COLOR ctmp; |
227 |
|
|
228 |
|
if (isheadid(s)) /* header id */ |
229 |
< |
return; /* don't echo */ |
229 |
> |
return(0); /* don't echo */ |
230 |
|
if (formatval(fmt, s)) { /* check format */ |
231 |
|
if (globmatch(ourfmt, fmt)) { |
232 |
|
wrongformat = 0; |
233 |
|
strcpy(ourfmt, fmt); |
234 |
|
} else |
235 |
< |
wrongformat = 1; |
236 |
< |
return; /* don't echo */ |
235 |
> |
wrongformat = globmatch(PICFMT, fmt) ? 1 : -1; |
236 |
> |
return(0); /* don't echo */ |
237 |
|
} |
238 |
|
if (isexpos(s)) { /* exposure */ |
239 |
|
d = exposval(s); |
241 |
|
} else if (iscolcor(s)) { /* color correction */ |
242 |
|
colcorval(ctmp, s); |
243 |
|
multcolor(input[nfiles].expos, ctmp); |
244 |
< |
} else if (isaspect(s)) { |
244 |
> |
} else if (isaspect(s)) |
245 |
|
input[nfiles].pa *= aspectval(s); |
246 |
< |
} else if (isview(s) && sscanview(&input[nfiles].vw, s) > 0) |
246 |
> |
else if (isview(s) && sscanview(&input[nfiles].vw, s) > 0) |
247 |
|
gotview++; |
248 |
|
/* echo line */ |
249 |
|
putchar('\t'); |
250 |
< |
fputs(s, stdout); |
250 |
> |
return(fputs(s, stdout)); |
251 |
|
} |
252 |
|
|
253 |
|
|
258 |
|
gotview = 0; |
259 |
|
fputs(input[nfiles].name, stdout); |
260 |
|
fputs(":\n", stdout); |
261 |
< |
getheader(input[nfiles].fp, tputs, NULL); |
262 |
< |
if (wrongformat) { |
261 |
> |
getheader(input[nfiles].fp, tabputs, NULL); |
262 |
> |
if (wrongformat < 0) { |
263 |
|
eputs(input[nfiles].name); |
264 |
< |
eputs(": not in Radiance picture format\n"); |
264 |
> |
eputs(": not a Radiance picture\n"); |
265 |
|
quit(1); |
266 |
|
} |
267 |
+ |
if (wrongformat > 0) { |
268 |
+ |
wputs(input[nfiles].name); |
269 |
+ |
wputs(": warning -- incompatible picture format\n"); |
270 |
+ |
} |
271 |
|
if (!gotview || setview(&input[nfiles].vw) != NULL) |
272 |
|
input[nfiles].vw.type = 0; |
273 |
|
if (!fgetsresolu(&input[nfiles].rs, input[nfiles].fp)) { |
311 |
|
|
312 |
|
init() /* perform final setup */ |
313 |
|
{ |
314 |
< |
double l_colin(), l_expos(), l_ray(), l_psize(); |
314 |
> |
double l_colin(), l_expos(), l_pixaspect(), l_ray(), l_psize(); |
315 |
|
register int i; |
316 |
|
/* define constants */ |
317 |
+ |
varset("PI", ':', PI); |
318 |
|
varset(vnfiles, ':', (double)nfiles); |
319 |
|
varset(vxmax, ':', (double)xmax); |
320 |
|
varset(vymax, ':', (double)ymax); |
325 |
|
} |
326 |
|
funset(vbrtexp, 1, ':', l_expos); |
327 |
|
funset(vbrtin, 1, '=', l_colin); |
328 |
< |
for (i = 0; i < 6; i++) |
328 |
> |
funset(vpixaspect, 1, ':', l_pixaspect); |
329 |
> |
for (i = 0; i < 7; i++) |
330 |
|
funset(vray[i], 1, '=', l_ray); |
331 |
|
funset(vpsize, 1, '=', l_psize); |
332 |
|
/* set brightness function */ |
333 |
< |
if (!strcmp(ourfmt, CIEFMT)) |
333 |
> |
if (!strcmp(ourfmt, CIEFMT)) { |
334 |
> |
varset(vwhteff, ':', 1.0); |
335 |
|
ourbright = xyz_bright; |
336 |
+ |
} else |
337 |
+ |
varset(vwhteff, ':', WHTEFFICACY); |
338 |
|
} |
339 |
|
|
340 |
|
|
392 |
|
quit(1); |
393 |
|
} |
394 |
|
} |
395 |
< |
efree(scanout); |
395 |
> |
efree((char *)scanout); |
396 |
|
} |
397 |
|
|
398 |
|
|
445 |
|
|
446 |
|
|
447 |
|
double |
448 |
+ |
l_pixaspect() /* return pixel aspect ratio */ |
449 |
+ |
{ |
450 |
+ |
register int fn; |
451 |
+ |
|
452 |
+ |
fn = argument(1) - .5; |
453 |
+ |
if (fn < 0 || fn >= nfiles) |
454 |
+ |
return(1.0); |
455 |
+ |
return(input[fn].pa); |
456 |
+ |
} |
457 |
+ |
|
458 |
+ |
|
459 |
+ |
double |
460 |
|
l_colin(nam) /* return color value for picture */ |
461 |
|
register char *nam; |
462 |
|
{ |
464 |
|
register int n, xoff, yoff; |
465 |
|
double d; |
466 |
|
|
467 |
< |
d = argument(1); |
454 |
< |
if (d > -.5 && d < .5) |
455 |
< |
return((double)nfiles); |
456 |
< |
fn = d - .5; |
467 |
> |
fn = argument(1) - .5; |
468 |
|
if (fn < 0 || fn >= nfiles) { |
469 |
|
errno = EDOM; |
470 |
|
return(0.0); |
516 |
|
{ |
517 |
|
static unsigned long ltick[MAXINP]; |
518 |
|
static FVECT lorg[MAXINP], ldir[MAXINP]; |
519 |
+ |
static double ldist[MAXINP]; |
520 |
|
FLOAT loc[2]; |
509 |
– |
double d; |
521 |
|
int fn; |
522 |
|
register int i; |
523 |
|
|
524 |
< |
d = argument(1); |
514 |
< |
if (d > -.5 && d < .5) |
515 |
< |
return((double)nfiles); |
516 |
< |
fn = d - .5; |
524 |
> |
fn = argument(1) - .5; |
525 |
|
if (fn < 0 || fn >= nfiles) { |
526 |
|
errno = EDOM; |
527 |
|
return(0.0); |
528 |
|
} |
529 |
< |
if (ltick[fn] < eclock) { /* need to compute? */ |
529 |
> |
if (ltick[fn] != eclock) { /* need to compute? */ |
530 |
|
lorg[fn][0] = lorg[fn][1] = lorg[fn][2] = 0.0; |
531 |
|
ldir[fn][0] = ldir[fn][1] = ldir[fn][2] = 0.0; |
532 |
+ |
ldist[fn] = -1.0; |
533 |
|
if (input[fn].vw.type == 0) |
534 |
|
errno = EDOM; |
535 |
|
else { |
536 |
|
pix2loc(loc, &input[fn].rs, xscan, ymax-1-yscan); |
537 |
< |
if (viewray(lorg[fn], ldir[fn], |
538 |
< |
&input[fn].vw, loc[0], loc[1]) < 0) |
530 |
< |
errno = ERANGE; |
531 |
< |
ltick[fn] = eclock; |
537 |
> |
ldist[fn] = viewray(lorg[fn], ldir[fn], |
538 |
> |
&input[fn].vw, loc[0], loc[1]); |
539 |
|
} |
540 |
+ |
ltick[fn] = eclock; |
541 |
|
} |
542 |
< |
i = 6; |
542 |
> |
if (nam == vray[i=6]) |
543 |
> |
return(ldist[fn]); |
544 |
|
while (i--) |
545 |
|
if (nam == vray[i]) |
546 |
|
return(i < 3 ? lorg[fn][i] : ldir[fn][i-3]); |
554 |
|
{ |
555 |
|
static unsigned long ltick[MAXINP]; |
556 |
|
static double psize[MAXINP]; |
557 |
< |
FVECT dir0, org1, dir1; |
558 |
< |
FLOAT loc[2]; |
557 |
> |
FVECT dir0, org, dirx, diry; |
558 |
> |
FLOAT locx[2], locy[2]; |
559 |
|
double d; |
560 |
|
int fn; |
561 |
+ |
register int i; |
562 |
|
|
563 |
|
d = argument(1); |
564 |
< |
if (d > -.5 && d < .5) |
555 |
< |
return((double)nfiles); |
556 |
< |
fn = d - .5; |
557 |
< |
if (fn < 0 || fn >= nfiles) { |
564 |
> |
if (d < .5 || d >= nfiles+.5) { |
565 |
|
errno = EDOM; |
566 |
|
return(0.0); |
567 |
|
} |
568 |
< |
if (ltick[fn] < eclock) /* need to compute? */ |
569 |
< |
if (input[fn].vw.type == 0 || input[fn].vw.type == VT_PAR) |
568 |
> |
fn = d - .5; |
569 |
> |
if (ltick[fn] != eclock) { /* need to compute? */ |
570 |
> |
psize[fn] = 0.0; |
571 |
> |
if (input[fn].vw.type == 0) |
572 |
|
errno = EDOM; |
573 |
< |
else { |
574 |
< |
errno = 0; |
575 |
< |
dir0[0] = funvalue(vray[3], 1, &d); |
576 |
< |
if (errno) |
577 |
< |
return(0.0); |
578 |
< |
dir0[1] = funvalue(vray[4], 1, &d); |
579 |
< |
if (errno) |
580 |
< |
return(0.0); |
581 |
< |
dir0[2] = funvalue(vray[5], 1, &d); |
582 |
< |
if (errno) |
574 |
< |
return(0.0); |
575 |
< |
pix2loc(loc, &input[fn].rs, xscan+1, ymax-yscan); |
576 |
< |
psize[fn] = 0.0; |
577 |
< |
if (viewray(org1, dir1, |
578 |
< |
&input[fn].vw, loc[0], loc[1]) < 0) |
579 |
< |
errno = ERANGE; |
580 |
< |
else { |
573 |
> |
else if (input[fn].vw.type != VT_PAR && |
574 |
> |
funvalue(vray[6], 1, &d) >= 0) { |
575 |
> |
for (i = 0; i < 3; i++) |
576 |
> |
dir0[i] = funvalue(vray[3+i], 1, &d); |
577 |
> |
pix2loc(locx, &input[fn].rs, xscan+1, ymax-1-yscan); |
578 |
> |
pix2loc(locy, &input[fn].rs, xscan, ymax-yscan); |
579 |
> |
if (viewray(org, dirx, &input[fn].vw, |
580 |
> |
locx[0], locx[1]) >= 0 && |
581 |
> |
viewray(org, diry, &input[fn].vw, |
582 |
> |
locy[0], locy[1]) >= 0) { |
583 |
|
/* approximate solid angle */ |
584 |
< |
psize[fn] = dist2(dir0, dir1) * input[fn].pa / |
585 |
< |
(1.0 + input[fn].pa*input[fn].pa); |
586 |
< |
ltick[fn] = eclock; |
584 |
> |
for (i = 0; i < 3; i++) { |
585 |
> |
dirx[i] -= dir0[i]; |
586 |
> |
diry[i] -= dir0[i]; |
587 |
> |
} |
588 |
> |
fcross(dir0, dirx, diry); |
589 |
> |
psize[fn] = sqrt(DOT(dir0,dir0)); |
590 |
|
} |
591 |
|
} |
592 |
+ |
ltick[fn] = eclock; |
593 |
+ |
} |
594 |
|
return(psize[fn]); |
595 |
|
} |
596 |
|
|
597 |
|
|
598 |
+ |
void |
599 |
|
wputs(msg) |
600 |
|
char *msg; |
601 |
|
{ |
604 |
|
} |
605 |
|
|
606 |
|
|
607 |
+ |
void |
608 |
|
eputs(msg) |
609 |
|
char *msg; |
610 |
|
{ |
612 |
|
} |
613 |
|
|
614 |
|
|
615 |
+ |
void |
616 |
|
quit(code) /* exit gracefully */ |
617 |
|
int code; |
618 |
|
{ |