| 7 | 
  | 
 *      1/4/89 | 
| 8 | 
  | 
 */ | 
| 9 | 
  | 
 | 
| 10 | 
– | 
#include "standard.h" | 
| 10 | 
  | 
#include "platform.h" | 
| 11 | 
+ | 
#include "standard.h" | 
| 12 | 
+ | 
#include "rtprocess.h" | 
| 13 | 
  | 
#include "color.h" | 
| 14 | 
  | 
#include "calcomp.h" | 
| 15 | 
  | 
#include "view.h" | 
| 16 | 
  | 
 | 
| 17 | 
< | 
#define MAXINP          32              /* maximum number of input files */ | 
| 17 | 
> | 
#define MAXINP          512             /* maximum number of input files */ | 
| 18 | 
  | 
#define WINSIZ          64              /* scanline window size */ | 
| 19 | 
  | 
#define MIDSCN          ((WINSIZ-1)/2+1) | 
| 20 | 
  | 
 | 
| 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"}; | 
| 68 | 
  | 
 | 
| 69 | 
  | 
char    *progname;                      /* global argv[0] */ | 
| 70 | 
  | 
 | 
| 71 | 
+ | 
int     echoheader = 1; | 
| 72 | 
  | 
int     wrongformat = 0; | 
| 73 | 
  | 
int     gotview; | 
| 74 | 
  | 
 | 
| 72 | 
– | 
FILE    *popen(); | 
| 75 | 
  | 
 | 
| 76 | 
< | 
extern char     *emalloc(); | 
| 76 | 
> | 
static gethfunc headline; | 
| 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; | 
| 98 | 
> | 
        int     a; | 
| 99 | 
  | 
        SET_DEFAULT_BINARY(); | 
| 100 | 
  | 
        SET_FILE_BINARY(stdin); | 
| 101 | 
  | 
        SET_FILE_BINARY(stdout); | 
| 111 | 
  | 
                        case 'w': | 
| 112 | 
  | 
                                nowarn = !nowarn; | 
| 113 | 
  | 
                                continue; | 
| 114 | 
+ | 
                        case 'h': | 
| 115 | 
+ | 
                                echoheader = !echoheader; | 
| 116 | 
+ | 
                                continue; | 
| 117 | 
  | 
                        case 'f': | 
| 118 | 
  | 
                        case 'e': | 
| 119 | 
  | 
                                a++; | 
| 127 | 
  | 
        for (nfiles = 0; nfiles < MAXINP; nfiles++) { | 
| 128 | 
  | 
                setcolor(input[nfiles].coef, 1.0, 1.0, 1.0); | 
| 129 | 
  | 
                setcolor(input[nfiles].expos, 1.0, 1.0, 1.0); | 
| 130 | 
< | 
                copystruct(&input[nfiles].vw, &stdview); | 
| 130 | 
> | 
                input[nfiles].vw = stdview; | 
| 131 | 
  | 
                input[nfiles].pa = 1.0; | 
| 132 | 
  | 
        } | 
| 133 | 
  | 
        nfiles = 0; | 
| 141 | 
  | 
                if (argv[a][0] == '-') | 
| 142 | 
  | 
                        switch (argv[a][1]) { | 
| 143 | 
  | 
                        case '\0': | 
| 144 | 
< | 
                                input[nfiles].name = "<stdin>"; | 
| 144 | 
> | 
                                input[nfiles].name = StandardInput; | 
| 145 | 
  | 
                                input[nfiles].fp = stdin; | 
| 146 | 
  | 
                                break; | 
| 147 | 
  | 
                        case 'o': | 
| 198 | 
  | 
                                continue; | 
| 199 | 
  | 
                        case 'w': | 
| 200 | 
  | 
                                continue; | 
| 201 | 
+ | 
                        case 'h': | 
| 202 | 
+ | 
                                continue; | 
| 203 | 
  | 
                        case 'f': | 
| 204 | 
  | 
                                fcompile(argv[++a]); | 
| 205 | 
  | 
                                continue; | 
| 234 | 
  | 
        eputs("Usage: "); | 
| 235 | 
  | 
        eputs(argv[0]); | 
| 236 | 
  | 
        eputs( | 
| 237 | 
< | 
" [-w][-x xr][-y yr][-e expr][-f file] [ [-o][-s f][-c r g b] pic ..]\n"); | 
| 237 | 
> | 
" [-w][-h][-x xr][-y yr][-e expr][-f file] [ [-o][-s f][-c r g b] pic ..]\n"); | 
| 238 | 
  | 
        quit(1); | 
| 239 | 
+ | 
        return 1; /* pro forma return */ | 
| 240 | 
  | 
} | 
| 241 | 
  | 
 | 
| 242 | 
  | 
 | 
| 243 | 
< | 
tabputs(s)                      /* put out string preceded by a tab */ | 
| 244 | 
< | 
char    *s; | 
| 243 | 
> | 
static int | 
| 244 | 
> | 
headline(                       /* check header line & echo if requested */ | 
| 245 | 
> | 
        char    *s, | 
| 246 | 
> | 
        void    *p | 
| 247 | 
> | 
) | 
| 248 | 
  | 
{ | 
| 249 | 
  | 
        char    fmt[32]; | 
| 250 | 
  | 
        double  d; | 
| 270 | 
  | 
                input[nfiles].pa *= aspectval(s); | 
| 271 | 
  | 
        else if (isview(s) && sscanview(&input[nfiles].vw, s) > 0) | 
| 272 | 
  | 
                gotview++; | 
| 273 | 
< | 
                                                /* echo line */ | 
| 274 | 
< | 
        putchar('\t'); | 
| 275 | 
< | 
        return(fputs(s, stdout)); | 
| 273 | 
> | 
 | 
| 274 | 
> | 
        if (echoheader) {                       /* echo line */ | 
| 275 | 
> | 
                putchar('\t'); | 
| 276 | 
> | 
                return(fputs(s, stdout)); | 
| 277 | 
> | 
        } | 
| 278 | 
> | 
        return(0); | 
| 279 | 
  | 
} | 
| 280 | 
  | 
 | 
| 281 | 
  | 
 | 
| 282 | 
< | 
checkfile()                     /* ready a file */ | 
| 282 | 
> | 
static void | 
| 283 | 
> | 
checkfile(void)                 /* ready a file */ | 
| 284 | 
  | 
{ | 
| 285 | 
  | 
        register int    i; | 
| 286 | 
  | 
                                        /* process header */ | 
| 287 | 
  | 
        gotview = 0; | 
| 288 | 
< | 
        fputs(input[nfiles].name, stdout); | 
| 289 | 
< | 
        fputs(":\n", stdout); | 
| 290 | 
< | 
        getheader(input[nfiles].fp, tabputs, NULL); | 
| 288 | 
> | 
        if (echoheader) { | 
| 289 | 
> | 
                fputs(input[nfiles].name, stdout); | 
| 290 | 
> | 
                fputs(":\n", stdout); | 
| 291 | 
> | 
        } | 
| 292 | 
> | 
        getheader(input[nfiles].fp, headline, NULL); | 
| 293 | 
  | 
        if (wrongformat < 0) { | 
| 294 | 
  | 
                eputs(input[nfiles].name); | 
| 295 | 
  | 
                eputs(": not a Radiance picture\n"); | 
| 321 | 
  | 
} | 
| 322 | 
  | 
 | 
| 323 | 
  | 
 | 
| 324 | 
< | 
double | 
| 325 | 
< | 
rgb_bright(clr) | 
| 326 | 
< | 
COLOR  clr; | 
| 324 | 
> | 
static double | 
| 325 | 
> | 
rgb_bright( | 
| 326 | 
> | 
        COLOR  clr | 
| 327 | 
> | 
) | 
| 328 | 
  | 
{ | 
| 329 | 
  | 
        return(bright(clr)); | 
| 330 | 
  | 
} | 
| 331 | 
  | 
 | 
| 332 | 
  | 
 | 
| 333 | 
< | 
double | 
| 334 | 
< | 
xyz_bright(clr) | 
| 335 | 
< | 
COLOR  clr; | 
| 333 | 
> | 
static double | 
| 334 | 
> | 
xyz_bright( | 
| 335 | 
> | 
        COLOR  clr | 
| 336 | 
> | 
) | 
| 337 | 
  | 
{ | 
| 338 | 
  | 
        return(clr[CIEY]); | 
| 339 | 
  | 
} | 
| 342 | 
  | 
double  (*ourbright)() = rgb_bright; | 
| 343 | 
  | 
 | 
| 344 | 
  | 
 | 
| 345 | 
< | 
init()                                  /* perform final setup */ | 
| 345 | 
> | 
static void | 
| 346 | 
> | 
init(void)                                      /* perform final setup */ | 
| 347 | 
  | 
{ | 
| 315 | 
– | 
        double  l_colin(), l_expos(), l_pixaspect(), l_ray(), l_psize(); | 
| 348 | 
  | 
        register int    i; | 
| 349 | 
  | 
                                                /* define constants */ | 
| 350 | 
  | 
        varset("PI", ':', PI); | 
| 371 | 
  | 
} | 
| 372 | 
  | 
 | 
| 373 | 
  | 
 | 
| 374 | 
< | 
combine()                       /* combine pictures */ | 
| 374 | 
> | 
static void | 
| 375 | 
> | 
combine(void)                   /* combine pictures */ | 
| 376 | 
  | 
{ | 
| 377 | 
  | 
        EPNODE  *coldef[3], *brtdef; | 
| 378 | 
  | 
        COLOR   *scanout; | 
| 430 | 
  | 
} | 
| 431 | 
  | 
 | 
| 432 | 
  | 
 | 
| 433 | 
< | 
advance()                       /* read in data for next scanline */ | 
| 433 | 
> | 
static void | 
| 434 | 
> | 
advance(void)                   /* read in data for next scanline */ | 
| 435 | 
  | 
{ | 
| 436 | 
  | 
        int     ytarget; | 
| 437 | 
  | 
        register COLOR  *st; | 
| 450 | 
  | 
                                eputs(": read error\n"); | 
| 451 | 
  | 
                                quit(1); | 
| 452 | 
  | 
                        } | 
| 453 | 
< | 
                        if (fabs(colval(input[i].coef,RED)-1.0) > 1e-3 || | 
| 454 | 
< | 
                                fabs(colval(input[i].coef,GRN)-1.0) > 1e-3 || | 
| 421 | 
< | 
                                fabs(colval(input[i].coef,BLU)-1.0) > 1e-3) | 
| 422 | 
< | 
                                for (j = 0; j < xmax; j++)  /* adjust color */ | 
| 423 | 
< | 
                                        multcolor(st[j], input[i].coef); | 
| 453 | 
> | 
                        for (j = 0; j < xmax; j++)      /* adjust color */ | 
| 454 | 
> | 
                                multcolor(st[j], input[i].coef); | 
| 455 | 
  | 
                } | 
| 456 | 
  | 
} | 
| 457 | 
  | 
 | 
| 458 | 
  | 
 | 
| 459 | 
< | 
double | 
| 460 | 
< | 
l_expos(nam)                    /* return picture exposure */ | 
| 461 | 
< | 
register char   *nam; | 
| 459 | 
> | 
static double | 
| 460 | 
> | 
l_expos(                        /* return picture exposure */ | 
| 461 | 
> | 
        register char   *nam | 
| 462 | 
> | 
) | 
| 463 | 
  | 
{ | 
| 464 | 
  | 
        register int    fn, n; | 
| 465 | 
  | 
 | 
| 474 | 
  | 
                        return(colval(input[fn].expos,n)); | 
| 475 | 
  | 
        eputs("Bad call to l_expos()!\n"); | 
| 476 | 
  | 
        quit(1); | 
| 477 | 
+ | 
        return 1; /* pro forma return */ | 
| 478 | 
  | 
} | 
| 479 | 
  | 
 | 
| 480 | 
  | 
 | 
| 481 | 
< | 
double | 
| 482 | 
< | 
l_pixaspect()                   /* return pixel aspect ratio */ | 
| 481 | 
> | 
static double | 
| 482 | 
> | 
l_pixaspect(char *nm)           /* return pixel aspect ratio */ | 
| 483 | 
  | 
{ | 
| 484 | 
  | 
        register int    fn; | 
| 485 | 
  | 
 | 
| 490 | 
  | 
} | 
| 491 | 
  | 
 | 
| 492 | 
  | 
 | 
| 493 | 
< | 
double | 
| 494 | 
< | 
l_colin(nam)                    /* return color value for picture */ | 
| 495 | 
< | 
register char   *nam; | 
| 493 | 
> | 
static double | 
| 494 | 
> | 
l_colin(                        /* return color value for picture */ | 
| 495 | 
> | 
        register char   *nam | 
| 496 | 
> | 
) | 
| 497 | 
  | 
{ | 
| 498 | 
  | 
        int     fn; | 
| 499 | 
  | 
        register int    n, xoff, yoff; | 
| 542 | 
  | 
                return(colval(input[fn].scan[MIDSCN+yoff][xscan+xoff],n)); | 
| 543 | 
  | 
        eputs("Bad call to l_colin()!\n"); | 
| 544 | 
  | 
        quit(1); | 
| 545 | 
+ | 
        return 1; /* pro forma return */ | 
| 546 | 
  | 
} | 
| 547 | 
  | 
 | 
| 548 | 
  | 
 | 
| 549 | 
< | 
double | 
| 550 | 
< | 
l_ray(nam)              /* return ray origin or direction */ | 
| 551 | 
< | 
register char   *nam; | 
| 549 | 
> | 
static double | 
| 550 | 
> | 
l_ray(          /* return ray origin or direction */ | 
| 551 | 
> | 
        register char   *nam | 
| 552 | 
> | 
) | 
| 553 | 
  | 
{ | 
| 554 | 
  | 
        static unsigned long    ltick[MAXINP]; | 
| 555 | 
  | 
        static FVECT    lorg[MAXINP], ldir[MAXINP]; | 
| 583 | 
  | 
                        return(i < 3 ? lorg[fn][i] : ldir[fn][i-3]); | 
| 584 | 
  | 
        eputs("Bad call to l_ray()!\n"); | 
| 585 | 
  | 
        quit(1); | 
| 586 | 
+ | 
        return 1; /* pro forma return */ | 
| 587 | 
  | 
} | 
| 588 | 
  | 
 | 
| 589 | 
  | 
 | 
| 590 | 
< | 
double | 
| 591 | 
< | 
l_psize()                       /* compute pixel size in steradians */ | 
| 590 | 
> | 
static double | 
| 591 | 
> | 
l_psize(char *nm)               /* compute pixel size in steradians */ | 
| 592 | 
  | 
{ | 
| 593 | 
  | 
        static unsigned long    ltick[MAXINP]; | 
| 594 | 
  | 
        static double   psize[MAXINP]; | 
| 609 | 
  | 
                if (input[fn].vw.type == 0) | 
| 610 | 
  | 
                        errno = EDOM; | 
| 611 | 
  | 
                else if (input[fn].vw.type != VT_PAR && | 
| 612 | 
< | 
                                funvalue(vray[6], 1, &d) >= 0) { | 
| 612 | 
> | 
                                funvalue(vray[6], 1, &d) >= -FTINY) { | 
| 613 | 
  | 
                        for (i = 0; i < 3; i++) | 
| 614 | 
  | 
                                dir0[i] = funvalue(vray[3+i], 1, &d); | 
| 615 | 
  | 
                        pix2loc(locx, &input[fn].rs, xscan+1, ymax-1-yscan); | 
| 616 | 
  | 
                        pix2loc(locy, &input[fn].rs, xscan, ymax-yscan); | 
| 617 | 
  | 
                        if (viewray(org, dirx, &input[fn].vw, | 
| 618 | 
< | 
                                        locx[0], locx[1]) >= 0 && | 
| 618 | 
> | 
                                        locx[0], locx[1]) >= -FTINY && | 
| 619 | 
  | 
                                        viewray(org, diry, &input[fn].vw, | 
| 620 | 
< | 
                                        locy[0], locy[1]) >= 0) { | 
| 620 | 
> | 
                                        locy[0], locy[1]) >= -FTINY) { | 
| 621 | 
  | 
                                                /* approximate solid angle */ | 
| 622 | 
  | 
                                for (i = 0; i < 3; i++) { | 
| 623 | 
  | 
                                        dirx[i] -= dir0[i]; | 
| 624 | 
  | 
                                        diry[i] -= dir0[i]; | 
| 625 | 
  | 
                                } | 
| 626 | 
  | 
                                fcross(dir0, dirx, diry); | 
| 627 | 
< | 
                                psize[fn] = sqrt(DOT(dir0,dir0)); | 
| 627 | 
> | 
                                psize[fn] = VLEN(dir0); | 
| 628 | 
  | 
                        } | 
| 629 | 
  | 
                } | 
| 630 | 
  | 
                ltick[fn] = eclock; | 
| 633 | 
  | 
} | 
| 634 | 
  | 
 | 
| 635 | 
  | 
 | 
| 636 | 
< | 
void | 
| 637 | 
< | 
wputs(msg) | 
| 601 | 
< | 
char    *msg; | 
| 636 | 
> | 
extern void | 
| 637 | 
> | 
wputs(char      *msg) | 
| 638 | 
  | 
{ | 
| 639 | 
  | 
        if (!nowarn) | 
| 640 | 
  | 
                eputs(msg); | 
| 641 | 
  | 
} | 
| 642 | 
  | 
 | 
| 643 | 
  | 
 | 
| 644 | 
< | 
void | 
| 645 | 
< | 
eputs(msg) | 
| 610 | 
< | 
char    *msg; | 
| 644 | 
> | 
extern void | 
| 645 | 
> | 
eputs(char *msg) | 
| 646 | 
  | 
{ | 
| 647 | 
  | 
        fputs(msg, stderr); | 
| 648 | 
  | 
} | 
| 649 | 
  | 
 | 
| 650 | 
  | 
 | 
| 651 | 
< | 
void | 
| 652 | 
< | 
quit(code)              /* exit gracefully */ | 
| 618 | 
< | 
int  code; | 
| 651 | 
> | 
extern void | 
| 652 | 
> | 
quit(int code)          /* exit gracefully */ | 
| 653 | 
  | 
{ | 
| 654 | 
  | 
        register int  i; | 
| 655 | 
  | 
                                /* close input files */ |