--- ray/src/px/pcomb.c 1991/05/30 09:47:14 1.19 +++ ray/src/px/pcomb.c 1992/09/21 12:13:48 2.7 @@ -1,4 +1,4 @@ -/* Copyright (c) 1991 Regents of the University of California */ +/* Copyright (c) 1992 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -12,18 +12,22 @@ static char SCCSid[] = "$SunId$ LBL"; #include +#ifdef MSDOS +#include +#endif + #include #include "color.h" +#include "resolu.h" + #include "calcomp.h" #define MAXINP 32 /* maximum number of input files */ #define WINSIZ 9 /* scanline window size */ #define MIDSCN 4 /* current scan position */ -#define BRT (-1) /* special index for brightness */ - struct { char *name; /* file or command name */ FILE *fp; /* stream pointer */ @@ -34,11 +38,12 @@ struct { int nfiles; /* number of input files */ -char *vcolin[3] = {"ri", "gi", "bi"}; -char *vcolout[3] = {"ro", "go", "bo"}; +char Command[] = ""; +char vcolin[3][4] = {"ri", "gi", "bi"}; +char vcolout[3][4] = {"ro", "go", "bo"}; char vbrtin[] = "li"; char vbrtout[] = "lo"; -char *vcolexp[3] = {"re", "ge", "be"}; +char vcolexp[3][4] = {"re", "ge", "be"}; char vbrtexp[] = "le"; char vnfiles[] = "nfiles"; @@ -63,15 +68,22 @@ int wrongformat = 0; FILE *popen(); +extern char *emalloc(); + main(argc, argv) int argc; char *argv[]; { - char buf[128]; int original; double f; int a, i; +#ifdef MSDOS + extern int _fmode; + _fmode = O_BINARY; + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); +#endif /* scan options */ for (a = 1; a < argc; a++) { if (argv[a][0] == '-') @@ -111,7 +123,7 @@ char *argv[]; break; case 'o': original++; - break; + continue; case 's': f = atof(argv[++a]); scalecolor(input[nfiles].coef, f); @@ -125,10 +137,13 @@ char *argv[]; goto usage; } else { - input[nfiles].name = argv[a]; - input[nfiles].fp = argv[a][0]=='!' ? - popen(argv[a]+1, "r") : - fopen(argv[a], "r"); + if (argv[a][0] == '!') { + input[nfiles].name = Command; + input[nfiles].fp = popen(argv[a]+1, "r"); + } else { + input[nfiles].name = argv[a]; + input[nfiles].fp = fopen(argv[a], "r"); + } if (input[nfiles].fp == NULL) { perror(argv[a]); quit(1); @@ -152,16 +167,10 @@ char *argv[]; if (argv[a][0] == '-') switch (argv[a][1]) { case 'x': - strcpy(buf, vxres); - strcat(buf, ":"); - strcat(buf, argv[++a]); - scompile(buf, NULL, 0); + varset(vxres, ':', eval(argv[++a])); continue; case 'y': - strcpy(buf, vyres); - strcat(buf, ":"); - strcat(buf, argv[++a]); - scompile(buf, NULL, 0); + varset(vyres, ':', eval(argv[++a])); continue; case 'w': continue; @@ -190,7 +199,7 @@ char *argv[]; printargs(argc, argv, stdout); fputformat(COLRFMT, stdout); putchar('\n'); - fputresolu(YMAJOR|YDECR, xres, yres, stdout); + fprtresolu(xres, yres, stdout); /* combine pictures */ combine(); quit(0); @@ -198,7 +207,7 @@ usage: eputs("Usage: "); eputs(argv[0]); eputs( -" [-w][-h][-x xr][-y yr][-e expr][-f file] [ [-s f][-c r g b] pic ..]\n"); +" [-w][-x xr][-y yr][-e expr][-f file] [ [-s f][-c r g b] pic ..]\n"); quit(1); } @@ -241,7 +250,7 @@ checkfile() /* ready a file */ eputs(": not in Radiance picture format\n"); quit(1); } - if (fgetresolu(&xinp, &yinp, input[nfiles].fp) != (YMAJOR|YDECR)) { + if (fgetresolu(&xinp, &yinp, input[nfiles].fp) < 0) { eputs(input[nfiles].name); eputs(": bad picture size\n"); quit(1); @@ -338,6 +347,7 @@ combine() /* combine pictures */ advance() /* read in data for next scanline */ { + extern double fabs(); int ytarget; register COLOR *st; register int i, j; @@ -350,13 +360,16 @@ advance() /* read in data for next scanline */ input[i].scan[0] = st; if (yscan <= MIDSCN) /* hit bottom? */ continue; - if (freadscan(st, xmax, input[i].fp) < 0) { /* read */ + if (freadscan(st, xmax, input[i].fp) < 0) { /* read */ eputs(input[i].name); eputs(": read error\n"); quit(1); } - for (j = 0; j < xmax; j++) /* adjust color */ - multcolor(st[j], input[i].coef); + if (fabs(colval(input[i].coef,RED)-1.0) > 1e-3 || + fabs(colval(input[i].coef,GRN)-1.0) > 1e-3 || + fabs(colval(input[i].coef,BLU)-1.0) > 1e-3) + for (j = 0; j < xmax; j++) /* adjust color */ + multcolor(st[j], input[i].coef); } } @@ -453,8 +466,15 @@ char *msg; } -quit(code) -int code; +quit(code) /* exit gracefully */ +int code; { + register int i; + /* close input files */ + for (i = 0; i < nfiles; i++) + if (input[i].name == Command) + pclose(input[i].fp); + else + fclose(input[i].fp); exit(code); }