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 "standard.h" |
11 |
< |
|
10 |
> |
#include "platform.h" |
11 |
> |
#include "rtprocess.h" |
12 |
> |
#include "rterror.h" |
13 |
|
#include "color.h" |
16 |
– |
|
17 |
– |
#include "resolu.h" |
18 |
– |
|
14 |
|
#include "calcomp.h" |
20 |
– |
|
15 |
|
#include "view.h" |
16 |
|
|
17 |
|
#define MAXINP 32 /* maximum number of input files */ |
18 |
< |
#define WINSIZ 17 /* scanline window size */ |
18 |
> |
#define WINSIZ 64 /* scanline window size */ |
19 |
|
#define MIDSCN ((WINSIZ-1)/2+1) |
20 |
|
|
21 |
|
struct { |
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 Command[] = "<Command>"; |
37 |
|
char vcolin[3][4] = {"ri", "gi", "bi"}; |
38 |
|
char vcolout[3][4] = {"ro", "go", "bo"}; |
40 |
|
char vbrtout[] = "lo"; |
41 |
|
char vcolexp[3][4] = {"re", "ge", "be"}; |
42 |
|
char vbrtexp[] = "le"; |
43 |
+ |
char vpixaspect[] = "pa"; |
44 |
|
|
45 |
< |
char vray[6][4] = {"Ox", "Oy", "Oz", "Dx", "Dy", "Dz"}; |
45 |
> |
char vray[7][4] = {"Ox", "Oy", "Oz", "Dx", "Dy", "Dz", "T"}; |
46 |
|
|
47 |
+ |
char vpsize[] = "S"; |
48 |
+ |
|
49 |
|
char vnfiles[] = "nfiles"; |
50 |
+ |
char vwhteff[] = "WE"; |
51 |
|
char vxmax[] = "xmax"; |
52 |
|
char vymax[] = "ymax"; |
53 |
|
char vxres[] = "xres"; |
70 |
|
int wrongformat = 0; |
71 |
|
int gotview; |
72 |
|
|
72 |
– |
FILE *popen(); |
73 |
|
|
74 |
|
extern char *emalloc(); |
75 |
|
|
81 |
|
int original; |
82 |
|
double f; |
83 |
|
int a, i; |
84 |
< |
#ifdef MSDOS |
85 |
< |
extern int _fmode; |
86 |
< |
_fmode = O_BINARY; |
87 |
< |
setmode(fileno(stdin), O_BINARY); |
88 |
< |
setmode(fileno(stdout), O_BINARY); |
89 |
< |
#endif |
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++) { |
103 |
|
} |
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); |
112 |
> |
input[nfiles].vw = stdview; |
113 |
> |
input[nfiles].pa = 1.0; |
114 |
|
} |
115 |
|
nfiles = 0; |
116 |
|
original = 0; |
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 |
|
nfiles++; |
168 |
|
original = 0; |
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 |
|
fprtresolu(xres, yres, stdout); |
210 |
|
/* combine pictures */ |
219 |
|
} |
220 |
|
|
221 |
|
|
222 |
< |
tputs(s) /* put out string preceded by a tab */ |
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 (isformat(s)) { /* check format */ |
230 |
< |
formatval(fmt, s); |
231 |
< |
wrongformat = strcmp(fmt, COLRFMT); |
232 |
< |
return; /* don't echo */ |
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); |
242 |
|
} else if (iscolcor(s)) { /* color correction */ |
243 |
|
colcorval(ctmp, s); |
244 |
|
multcolor(input[nfiles].expos, ctmp); |
245 |
< |
} else if (isview(s) && sscanview(&input[nfiles].vw, s) > 0) |
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 |
< |
fputs(s, stdout); |
251 |
> |
return(fputs(s, stdout)); |
252 |
|
} |
253 |
|
|
254 |
|
|
259 |
|
gotview = 0; |
260 |
|
fputs(input[nfiles].name, stdout); |
261 |
|
fputs(":\n", stdout); |
262 |
< |
getheader(input[nfiles].fp, tputs, NULL); |
263 |
< |
if (wrongformat) { |
262 |
> |
getheader(input[nfiles].fp, tabputs, NULL); |
263 |
> |
if (wrongformat < 0) { |
264 |
|
eputs(input[nfiles].name); |
265 |
< |
eputs(": not in Radiance picture format\n"); |
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)) { |
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_ray(); |
315 |
> |
double l_colin(char *), l_expos(char *), l_pixaspect(char *), |
316 |
> |
l_ray(char *), l_psize(char *); |
317 |
|
register int i; |
318 |
|
/* define constants */ |
319 |
+ |
varset("PI", ':', PI); |
320 |
|
varset(vnfiles, ':', (double)nfiles); |
321 |
|
varset(vxmax, ':', (double)xmax); |
322 |
|
varset(vymax, ':', (double)ymax); |
327 |
|
} |
328 |
|
funset(vbrtexp, 1, ':', l_expos); |
329 |
|
funset(vbrtin, 1, '=', l_colin); |
330 |
< |
for (i = 0; i < 6; i++) |
330 |
> |
funset(vpixaspect, 1, ':', l_pixaspect); |
331 |
> |
for (i = 0; i < 7; i++) |
332 |
|
funset(vray[i], 1, '=', l_ray); |
333 |
+ |
funset(vpsize, 1, '=', l_psize); |
334 |
+ |
/* set brightness function */ |
335 |
+ |
if (!strcmp(ourfmt, CIEFMT)) { |
336 |
+ |
varset(vwhteff, ':', 1.0); |
337 |
+ |
ourbright = xyz_bright; |
338 |
+ |
} else |
339 |
+ |
varset(vwhteff, ':', WHTEFFICACY); |
340 |
|
} |
341 |
|
|
342 |
|
|
394 |
|
quit(1); |
395 |
|
} |
396 |
|
} |
397 |
< |
efree(scanout); |
397 |
> |
efree((char *)scanout); |
398 |
|
} |
399 |
|
|
400 |
|
|
436 |
|
if (fn < 0 || fn >= nfiles) |
437 |
|
return(1.0); |
438 |
|
if (nam == vbrtexp) |
439 |
< |
return(bright(input[fn].expos)); |
439 |
> |
return((*ourbright)(input[fn].expos)); |
440 |
|
n = 3; |
441 |
|
while (n--) |
442 |
|
if (nam == vcolexp[n]) |
447 |
|
|
448 |
|
|
449 |
|
double |
450 |
+ |
l_pixaspect(char *nm) /* return pixel aspect ratio */ |
451 |
+ |
{ |
452 |
+ |
register int fn; |
453 |
+ |
|
454 |
+ |
fn = argument(1) - .5; |
455 |
+ |
if (fn < 0 || fn >= nfiles) |
456 |
+ |
return(1.0); |
457 |
+ |
return(input[fn].pa); |
458 |
+ |
} |
459 |
+ |
|
460 |
+ |
|
461 |
+ |
double |
462 |
|
l_colin(nam) /* return color value for picture */ |
463 |
|
register char *nam; |
464 |
|
{ |
466 |
|
register int n, xoff, yoff; |
467 |
|
double d; |
468 |
|
|
469 |
< |
d = argument(1); |
416 |
< |
if (d > -.5 && d < .5) |
417 |
< |
return((double)nfiles); |
418 |
< |
fn = d - .5; |
469 |
> |
fn = argument(1) - .5; |
470 |
|
if (fn < 0 || fn >= nfiles) { |
471 |
|
errno = EDOM; |
472 |
|
return(0.0); |
502 |
|
} |
503 |
|
} |
504 |
|
if (nam == vbrtin) |
505 |
< |
return(bright(input[fn].scan[MIDSCN+yoff][xscan+xoff])); |
505 |
> |
return((*ourbright)(input[fn].scan[MIDSCN+yoff][xscan+xoff])); |
506 |
|
n = 3; |
507 |
|
while (n--) |
508 |
|
if (nam == vcolin[n]) |
516 |
|
l_ray(nam) /* return ray origin or direction */ |
517 |
|
register char *nam; |
518 |
|
{ |
519 |
< |
static long ltick[MAXINP]; |
519 |
> |
static unsigned long ltick[MAXINP]; |
520 |
|
static FVECT lorg[MAXINP], ldir[MAXINP]; |
521 |
< |
FLOAT loc[2]; |
522 |
< |
double d; |
521 |
> |
static double ldist[MAXINP]; |
522 |
> |
RREAL loc[2]; |
523 |
|
int fn; |
524 |
|
register int i; |
525 |
|
|
526 |
< |
d = argument(1); |
476 |
< |
if (d > -.5 && d < .5) |
477 |
< |
return((double)nfiles); |
478 |
< |
fn = d - .5; |
526 |
> |
fn = argument(1) - .5; |
527 |
|
if (fn < 0 || fn >= nfiles) { |
528 |
|
errno = EDOM; |
529 |
|
return(0.0); |
530 |
|
} |
531 |
< |
if (ltick[fn] < eclock) { /* need to compute? */ |
531 |
> |
if (ltick[fn] != eclock) { /* need to compute? */ |
532 |
|
lorg[fn][0] = lorg[fn][1] = lorg[fn][2] = 0.0; |
533 |
|
ldir[fn][0] = ldir[fn][1] = ldir[fn][2] = 0.0; |
534 |
+ |
ldist[fn] = -1.0; |
535 |
|
if (input[fn].vw.type == 0) |
536 |
|
errno = EDOM; |
537 |
|
else { |
538 |
|
pix2loc(loc, &input[fn].rs, xscan, ymax-1-yscan); |
539 |
< |
if (viewray(lorg[fn], ldir[fn], |
540 |
< |
&input[fn].vw, loc[0], loc[1]) < 0) |
492 |
< |
errno = ERANGE; |
539 |
> |
ldist[fn] = viewray(lorg[fn], ldir[fn], |
540 |
> |
&input[fn].vw, loc[0], loc[1]); |
541 |
|
} |
542 |
|
ltick[fn] = eclock; |
543 |
|
} |
544 |
< |
i = 6; |
544 |
> |
if (nam == vray[i=6]) |
545 |
> |
return(ldist[fn]); |
546 |
|
while (i--) |
547 |
|
if (nam == vray[i]) |
548 |
|
return(i < 3 ? lorg[fn][i] : ldir[fn][i-3]); |
551 |
|
} |
552 |
|
|
553 |
|
|
554 |
< |
wputs(msg) |
555 |
< |
char *msg; |
554 |
> |
double |
555 |
> |
l_psize(char *nm) /* compute pixel size in steradians */ |
556 |
|
{ |
557 |
+ |
static unsigned long ltick[MAXINP]; |
558 |
+ |
static double psize[MAXINP]; |
559 |
+ |
FVECT dir0, org, dirx, diry; |
560 |
+ |
RREAL locx[2], locy[2]; |
561 |
+ |
double d; |
562 |
+ |
int fn; |
563 |
+ |
register int i; |
564 |
+ |
|
565 |
+ |
d = argument(1); |
566 |
+ |
if (d < .5 || d >= nfiles+.5) { |
567 |
+ |
errno = EDOM; |
568 |
+ |
return(0.0); |
569 |
+ |
} |
570 |
+ |
fn = d - .5; |
571 |
+ |
if (ltick[fn] != eclock) { /* need to compute? */ |
572 |
+ |
psize[fn] = 0.0; |
573 |
+ |
if (input[fn].vw.type == 0) |
574 |
+ |
errno = EDOM; |
575 |
+ |
else if (input[fn].vw.type != VT_PAR && |
576 |
+ |
funvalue(vray[6], 1, &d) >= 0) { |
577 |
+ |
for (i = 0; i < 3; i++) |
578 |
+ |
dir0[i] = funvalue(vray[3+i], 1, &d); |
579 |
+ |
pix2loc(locx, &input[fn].rs, xscan+1, ymax-1-yscan); |
580 |
+ |
pix2loc(locy, &input[fn].rs, xscan, ymax-yscan); |
581 |
+ |
if (viewray(org, dirx, &input[fn].vw, |
582 |
+ |
locx[0], locx[1]) >= 0 && |
583 |
+ |
viewray(org, diry, &input[fn].vw, |
584 |
+ |
locy[0], locy[1]) >= 0) { |
585 |
+ |
/* approximate solid angle */ |
586 |
+ |
for (i = 0; i < 3; i++) { |
587 |
+ |
dirx[i] -= dir0[i]; |
588 |
+ |
diry[i] -= dir0[i]; |
589 |
+ |
} |
590 |
+ |
fcross(dir0, dirx, diry); |
591 |
+ |
psize[fn] = sqrt(DOT(dir0,dir0)); |
592 |
+ |
} |
593 |
+ |
} |
594 |
+ |
ltick[fn] = eclock; |
595 |
+ |
} |
596 |
+ |
return(psize[fn]); |
597 |
+ |
} |
598 |
+ |
|
599 |
+ |
|
600 |
+ |
extern void |
601 |
+ |
wputs(char *msg) |
602 |
+ |
{ |
603 |
|
if (!nowarn) |
604 |
|
eputs(msg); |
605 |
|
} |
606 |
|
|
607 |
|
|
608 |
< |
eputs(msg) |
609 |
< |
char *msg; |
608 |
> |
extern void |
609 |
> |
eputs(char *msg) |
610 |
|
{ |
611 |
|
fputs(msg, stderr); |
612 |
|
} |
613 |
|
|
614 |
|
|
615 |
< |
quit(code) /* exit gracefully */ |
616 |
< |
int code; |
615 |
> |
extern void |
616 |
> |
quit(int code) /* exit gracefully */ |
617 |
|
{ |
618 |
|
register int i; |
619 |
|
/* close input files */ |