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 "rtmisc.h" |
14 |
|
#include "color.h" |
16 |
– |
|
17 |
– |
#include "resolu.h" |
18 |
– |
|
15 |
|
#include "calcomp.h" |
20 |
– |
|
16 |
|
#include "view.h" |
17 |
|
|
18 |
|
#define MAXINP 32 /* maximum number of input files */ |
19 |
< |
#define WINSIZ 17 /* scanline window size */ |
19 |
> |
#define WINSIZ 64 /* scanline window size */ |
20 |
|
#define MIDSCN ((WINSIZ-1)/2+1) |
21 |
|
|
22 |
|
struct { |
34 |
|
|
35 |
|
char ourfmt[LPICFMT+1] = PICFMT; /* input picture format */ |
36 |
|
|
37 |
+ |
char StandardInput[] = "<stdin>"; |
38 |
|
char Command[] = "<Command>"; |
39 |
|
char vcolin[3][4] = {"ri", "gi", "bi"}; |
40 |
|
char vcolout[3][4] = {"ro", "go", "bo"}; |
72 |
|
int wrongformat = 0; |
73 |
|
int gotview; |
74 |
|
|
79 |
– |
FILE *popen(); |
75 |
|
|
76 |
< |
extern char *emalloc(); |
76 |
> |
static gethfunc tabputs; |
77 |
> |
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 |
< |
main(argc, argv) |
91 |
< |
int argc; |
92 |
< |
char *argv[]; |
90 |
> |
int |
91 |
> |
main( |
92 |
> |
int argc, |
93 |
> |
char *argv[] |
94 |
> |
) |
95 |
|
{ |
96 |
|
int original; |
97 |
|
double f; |
98 |
< |
int a, i; |
99 |
< |
#ifdef MSDOS |
100 |
< |
extern int _fmode; |
101 |
< |
_fmode = O_BINARY; |
94 |
< |
setmode(fileno(stdin), O_BINARY); |
95 |
< |
setmode(fileno(stdout), O_BINARY); |
96 |
< |
#endif |
98 |
> |
int a; |
99 |
> |
SET_DEFAULT_BINARY(); |
100 |
> |
SET_FILE_BINARY(stdin); |
101 |
> |
SET_FILE_BINARY(stdout); |
102 |
|
progname = argv[0]; |
103 |
|
/* scan options */ |
104 |
|
for (a = 1; a < argc; a++) { |
119 |
|
break; |
120 |
|
} |
121 |
|
newheader("RADIANCE", stdout); /* start header */ |
122 |
+ |
fputnow(stdout); |
123 |
|
/* process files */ |
124 |
|
for (nfiles = 0; nfiles < MAXINP; nfiles++) { |
125 |
|
setcolor(input[nfiles].coef, 1.0, 1.0, 1.0); |
126 |
|
setcolor(input[nfiles].expos, 1.0, 1.0, 1.0); |
127 |
< |
copystruct(&input[nfiles].vw, &stdview); |
127 |
> |
input[nfiles].vw = stdview; |
128 |
|
input[nfiles].pa = 1.0; |
129 |
|
} |
130 |
|
nfiles = 0; |
138 |
|
if (argv[a][0] == '-') |
139 |
|
switch (argv[a][1]) { |
140 |
|
case '\0': |
141 |
< |
input[nfiles].name = "<stdin>"; |
141 |
> |
input[nfiles].name = StandardInput; |
142 |
|
input[nfiles].fp = stdin; |
143 |
|
break; |
144 |
|
case 'o': |
177 |
|
colval(input[nfiles].expos,GRN); |
178 |
|
colval(input[nfiles].coef,BLU) /= |
179 |
|
colval(input[nfiles].expos,BLU); |
180 |
+ |
setcolor(input[nfiles].expos, 1.0, 1.0, 1.0); |
181 |
|
} |
182 |
|
nfiles++; |
183 |
|
original = 0; |
231 |
|
eputs( |
232 |
|
" [-w][-x xr][-y yr][-e expr][-f file] [ [-o][-s f][-c r g b] pic ..]\n"); |
233 |
|
quit(1); |
234 |
+ |
return 1; /* pro forma return */ |
235 |
|
} |
236 |
|
|
237 |
|
|
238 |
< |
tputs(s) /* put out string preceded by a tab */ |
239 |
< |
char *s; |
238 |
> |
static int |
239 |
> |
tabputs( /* put out string preceded by a tab */ |
240 |
> |
char *s, |
241 |
> |
void *p |
242 |
> |
) |
243 |
|
{ |
244 |
|
char fmt[32]; |
245 |
|
double d; |
246 |
|
COLOR ctmp; |
247 |
|
|
248 |
|
if (isheadid(s)) /* header id */ |
249 |
< |
return; /* don't echo */ |
249 |
> |
return(0); /* don't echo */ |
250 |
|
if (formatval(fmt, s)) { /* check format */ |
251 |
|
if (globmatch(ourfmt, fmt)) { |
252 |
|
wrongformat = 0; |
253 |
|
strcpy(ourfmt, fmt); |
254 |
|
} else |
255 |
< |
wrongformat = 1; |
256 |
< |
return; /* don't echo */ |
255 |
> |
wrongformat = globmatch(PICFMT, fmt) ? 1 : -1; |
256 |
> |
return(0); /* don't echo */ |
257 |
|
} |
258 |
|
if (isexpos(s)) { /* exposure */ |
259 |
|
d = exposval(s); |
267 |
|
gotview++; |
268 |
|
/* echo line */ |
269 |
|
putchar('\t'); |
270 |
< |
fputs(s, stdout); |
270 |
> |
return(fputs(s, stdout)); |
271 |
|
} |
272 |
|
|
273 |
|
|
274 |
< |
checkfile() /* ready a file */ |
274 |
> |
static void |
275 |
> |
checkfile(void) /* ready a file */ |
276 |
|
{ |
277 |
|
register int i; |
278 |
|
/* process header */ |
279 |
|
gotview = 0; |
280 |
|
fputs(input[nfiles].name, stdout); |
281 |
|
fputs(":\n", stdout); |
282 |
< |
getheader(input[nfiles].fp, tputs, NULL); |
283 |
< |
if (wrongformat) { |
282 |
> |
getheader(input[nfiles].fp, tabputs, NULL); |
283 |
> |
if (wrongformat < 0) { |
284 |
|
eputs(input[nfiles].name); |
285 |
< |
eputs(": not in Radiance picture format\n"); |
285 |
> |
eputs(": not a Radiance picture\n"); |
286 |
|
quit(1); |
287 |
|
} |
288 |
+ |
if (wrongformat > 0) { |
289 |
+ |
wputs(input[nfiles].name); |
290 |
+ |
wputs(": warning -- incompatible picture format\n"); |
291 |
+ |
} |
292 |
|
if (!gotview || setview(&input[nfiles].vw) != NULL) |
293 |
|
input[nfiles].vw.type = 0; |
294 |
|
if (!fgetsresolu(&input[nfiles].rs, input[nfiles].fp)) { |
311 |
|
} |
312 |
|
|
313 |
|
|
314 |
< |
double |
315 |
< |
rgb_bright(clr) |
316 |
< |
COLOR clr; |
314 |
> |
static double |
315 |
> |
rgb_bright( |
316 |
> |
COLOR clr |
317 |
> |
) |
318 |
|
{ |
319 |
|
return(bright(clr)); |
320 |
|
} |
321 |
|
|
322 |
|
|
323 |
< |
double |
324 |
< |
xyz_bright(clr) |
325 |
< |
COLOR clr; |
323 |
> |
static double |
324 |
> |
xyz_bright( |
325 |
> |
COLOR clr |
326 |
> |
) |
327 |
|
{ |
328 |
|
return(clr[CIEY]); |
329 |
|
} |
332 |
|
double (*ourbright)() = rgb_bright; |
333 |
|
|
334 |
|
|
335 |
< |
init() /* perform final setup */ |
335 |
> |
static void |
336 |
> |
init(void) /* perform final setup */ |
337 |
|
{ |
338 |
< |
double l_colin(), l_expos(), l_pixaspect(), l_ray(), l_psize(); |
338 |
> |
double l_colin(char *), l_expos(char *), l_pixaspect(char *), |
339 |
> |
l_ray(char *), l_psize(char *); |
340 |
|
register int i; |
341 |
|
/* define constants */ |
342 |
+ |
varset("PI", ':', PI); |
343 |
|
varset(vnfiles, ':', (double)nfiles); |
344 |
|
varset(vxmax, ':', (double)xmax); |
345 |
|
varset(vymax, ':', (double)ymax); |
363 |
|
} |
364 |
|
|
365 |
|
|
366 |
< |
combine() /* combine pictures */ |
366 |
> |
static void |
367 |
> |
combine(void) /* combine pictures */ |
368 |
|
{ |
369 |
|
EPNODE *coldef[3], *brtdef; |
370 |
|
COLOR *scanout; |
418 |
|
quit(1); |
419 |
|
} |
420 |
|
} |
421 |
< |
efree(scanout); |
421 |
> |
efree((char *)scanout); |
422 |
|
} |
423 |
|
|
424 |
|
|
425 |
< |
advance() /* read in data for next scanline */ |
425 |
> |
static void |
426 |
> |
advance(void) /* read in data for next scanline */ |
427 |
|
{ |
428 |
|
int ytarget; |
429 |
|
register COLOR *st; |
451 |
|
} |
452 |
|
|
453 |
|
|
454 |
< |
double |
455 |
< |
l_expos(nam) /* return picture exposure */ |
456 |
< |
register char *nam; |
454 |
> |
static double |
455 |
> |
l_expos( /* return picture exposure */ |
456 |
> |
register char *nam |
457 |
> |
) |
458 |
|
{ |
459 |
|
register int fn, n; |
460 |
|
|
469 |
|
return(colval(input[fn].expos,n)); |
470 |
|
eputs("Bad call to l_expos()!\n"); |
471 |
|
quit(1); |
472 |
+ |
return 1; /* pro forma return */ |
473 |
|
} |
474 |
|
|
475 |
|
|
476 |
< |
double |
477 |
< |
l_pixaspect() /* return pixel aspect ratio */ |
476 |
> |
static double |
477 |
> |
l_pixaspect(char *nm) /* return pixel aspect ratio */ |
478 |
|
{ |
479 |
|
register int fn; |
480 |
|
|
485 |
|
} |
486 |
|
|
487 |
|
|
488 |
< |
double |
489 |
< |
l_colin(nam) /* return color value for picture */ |
490 |
< |
register char *nam; |
488 |
> |
static double |
489 |
> |
l_colin( /* return color value for picture */ |
490 |
> |
register char *nam |
491 |
> |
) |
492 |
|
{ |
493 |
|
int fn; |
494 |
|
register int n, xoff, yoff; |
537 |
|
return(colval(input[fn].scan[MIDSCN+yoff][xscan+xoff],n)); |
538 |
|
eputs("Bad call to l_colin()!\n"); |
539 |
|
quit(1); |
540 |
+ |
return 1; /* pro forma return */ |
541 |
|
} |
542 |
|
|
543 |
|
|
544 |
< |
double |
545 |
< |
l_ray(nam) /* return ray origin or direction */ |
546 |
< |
register char *nam; |
544 |
> |
static double |
545 |
> |
l_ray( /* return ray origin or direction */ |
546 |
> |
register char *nam |
547 |
> |
) |
548 |
|
{ |
549 |
|
static unsigned long ltick[MAXINP]; |
550 |
|
static FVECT lorg[MAXINP], ldir[MAXINP]; |
551 |
|
static double ldist[MAXINP]; |
552 |
< |
FLOAT loc[2]; |
552 |
> |
RREAL loc[2]; |
553 |
|
int fn; |
554 |
|
register int i; |
555 |
|
|
558 |
|
errno = EDOM; |
559 |
|
return(0.0); |
560 |
|
} |
561 |
< |
if (ltick[fn] < eclock) { /* need to compute? */ |
561 |
> |
if (ltick[fn] != eclock) { /* need to compute? */ |
562 |
|
lorg[fn][0] = lorg[fn][1] = lorg[fn][2] = 0.0; |
563 |
|
ldir[fn][0] = ldir[fn][1] = ldir[fn][2] = 0.0; |
564 |
+ |
ldist[fn] = -1.0; |
565 |
|
if (input[fn].vw.type == 0) |
566 |
|
errno = EDOM; |
567 |
|
else { |
578 |
|
return(i < 3 ? lorg[fn][i] : ldir[fn][i-3]); |
579 |
|
eputs("Bad call to l_ray()!\n"); |
580 |
|
quit(1); |
581 |
+ |
return 1; /* pro forma return */ |
582 |
|
} |
583 |
|
|
584 |
|
|
585 |
< |
double |
586 |
< |
l_psize() /* compute pixel size in steradians */ |
585 |
> |
static double |
586 |
> |
l_psize(char *nm) /* compute pixel size in steradians */ |
587 |
|
{ |
588 |
|
static unsigned long ltick[MAXINP]; |
589 |
|
static double psize[MAXINP]; |
590 |
|
FVECT dir0, org, dirx, diry; |
591 |
< |
FLOAT locx[2], locy[2]; |
591 |
> |
RREAL locx[2], locy[2]; |
592 |
|
double d; |
593 |
|
int fn; |
594 |
|
register int i; |
599 |
|
return(0.0); |
600 |
|
} |
601 |
|
fn = d - .5; |
602 |
< |
if (ltick[fn] < eclock) { /* need to compute? */ |
602 |
> |
if (ltick[fn] != eclock) { /* need to compute? */ |
603 |
|
psize[fn] = 0.0; |
604 |
|
if (input[fn].vw.type == 0) |
605 |
|
errno = EDOM; |
619 |
|
diry[i] -= dir0[i]; |
620 |
|
} |
621 |
|
fcross(dir0, dirx, diry); |
622 |
< |
psize[fn] = 0.5 * sqrt(DOT(dir0,dir0)); |
622 |
> |
psize[fn] = sqrt(DOT(dir0,dir0)); |
623 |
|
} |
624 |
|
} |
625 |
|
ltick[fn] = eclock; |
628 |
|
} |
629 |
|
|
630 |
|
|
631 |
< |
wputs(msg) |
632 |
< |
char *msg; |
631 |
> |
extern void |
632 |
> |
wputs(char *msg) |
633 |
|
{ |
634 |
|
if (!nowarn) |
635 |
|
eputs(msg); |
636 |
|
} |
637 |
|
|
638 |
|
|
639 |
< |
eputs(msg) |
640 |
< |
char *msg; |
639 |
> |
extern void |
640 |
> |
eputs(char *msg) |
641 |
|
{ |
642 |
|
fputs(msg, stderr); |
643 |
|
} |
644 |
|
|
645 |
|
|
646 |
< |
quit(code) /* exit gracefully */ |
647 |
< |
int code; |
646 |
> |
extern void |
647 |
> |
quit(int code) /* exit gracefully */ |
648 |
|
{ |
649 |
|
register int i; |
650 |
|
/* close input files */ |