--- ray/src/px/pcomb.c 1989/02/02 10:49:22 1.1 +++ ray/src/px/pcomb.c 1991/04/18 08:05:57 1.8 @@ -1,4 +1,4 @@ -/* Copyright (c) 1989 Regents of the University of California */ +/* Copyright (c) 1991 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -18,19 +18,25 @@ static char SCCSid[] = "$SunId$ LBL"; #include "calcomp.h" -#define MAXINP 16 /* maximum number of input files */ +#define MAXINP 32 /* maximum number of input files */ struct { char *name; /* file name */ FILE *fp; /* stream pointer */ COLOR *scan; /* input scanline */ + COLOR coef; /* coefficient */ } input[MAXINP]; /* input pictures */ int nfiles; /* number of input files */ char *vcolin[3] = {"ri", "gi", "bi"}; char *vcolout[3] = {"ro", "go", "bo"}; +#define vbrtin "li" +#define vbrtout "lo" +#define vnfiles "nfiles" +#define vxres "xres" +#define vyres "yres" #define vxpos "x" #define vypos "y" @@ -53,17 +59,21 @@ main(argc, argv) int argc; char *argv[]; { - extern double l_redin(), l_grnin(), l_bluin(); + extern double l_redin(), l_grnin(), l_bluin(), l_brtin(), atof(); + double f; int a; funset(vcolin[RED], 1, l_redin); funset(vcolin[GRN], 1, l_grnin); funset(vcolin[BLU], 1, l_bluin); + funset(vbrtin, 1, l_brtin); for (a = 1; a < argc; a++) if (argv[a][0] == '-') switch (argv[a][1]) { case '\0': + case 's': + case 'c': goto getfiles; case 'x': xres = atoi(argv[++a]); @@ -78,17 +88,16 @@ char *argv[]; fcompile(argv[++a]); break; case 'e': - scompile(NULL, argv[++a]); + scompile(argv[++a], NULL, 0); break; default: - eputs("Usage: "); - eputs(argv[0]); - eputs(" [-w][-x xres][-y yres][-e expr][-f file] [picture ..]\n"); - quit(1); + goto usage; } else break; getfiles: + for (nfiles = 0; nfiles < MAXINP; nfiles++) + setcolor(input[nfiles].coef, 1.0, 1.0, 1.0); nfiles = 0; for ( ; a < argc; a++) { if (nfiles >= MAXINP) { @@ -96,22 +105,37 @@ getfiles: eputs(": too many picture files\n"); quit(1); } - if (argv[a][0] == '-') { - input[nfiles].name = ""; - input[nfiles].fp = stdin; - } else { + if (argv[a][0] == '-') + switch (argv[a][1]) { + case '\0': + input[nfiles].name = ""; + input[nfiles].fp = stdin; + break; + case 's': + f = atof(argv[++a]); + scalecolor(input[nfiles].coef, f); + continue; + case 'c': + colval(input[nfiles].coef,RED)*=atof(argv[++a]); + colval(input[nfiles].coef,GRN)*=atof(argv[++a]); + colval(input[nfiles].coef,BLU)*=atof(argv[++a]); + continue; + default: + goto usage; + } + else { input[nfiles].name = argv[a]; input[nfiles].fp = fopen(argv[a], "r"); if (input[nfiles].fp == NULL) { - eputs(argv[a]); - eputs(": cannot open\n"); + perror(argv[a]); quit(1); } } fputs(input[nfiles].name, stdout); fputs(":\n", stdout); getheader(input[nfiles].fp, tputs); - if (fscanf(input[nfiles].fp, "-Y %d +X %d\n", &ypos, &xpos) != 2) { + if (fgetresolu(&xpos, &ypos, input[nfiles].fp) != + (YMAJOR|YDECR)) { eputs(input[nfiles].name); eputs(": bad picture size\n"); quit(1); @@ -129,50 +153,77 @@ getfiles: } printargs(argc, argv, stdout); putchar('\n'); - printf("-Y %d +X %d\n", yres, xres); + fputresolu(YMAJOR|YDECR, xres, yres, stdout); combine(); quit(0); +usage: + eputs("Usage: "); + eputs(argv[0]); +eputs(" [-w][-x xr][-y yr][-e expr][-f file] [ [-s f][-c r g b] picture ..]\n"); + quit(1); } combine() /* combine pictures */ { - int coldef[3]; + EPNODE *coldef[3], *brtdef; COLOR *scanout; + double d; register int i, j; /* check defined variables */ - for (j = 0; j < 3; j++) - coldef[j] = vardefined(vcolout[j]); + for (j = 0; j < 3; j++) { + if (vardefined(vcolout[j])) + coldef[j] = eparse(vcolout[j]); + else + coldef[j] = NULL; + } + if (vardefined(vbrtout)) + brtdef = eparse(vbrtout); + else + brtdef = NULL; + /* predefine variables */ + varset(vnfiles, (double)nfiles); + varset(vxres, (double)xres); + varset(vyres, (double)yres); /* allocate scanline */ scanout = (COLOR *)emalloc(xres*sizeof(COLOR)); /* combine files */ for (ypos = yres-1; ypos >= 0; ypos--) { - for (i = 0; i < nfiles; i++) - if (freadscan(input[i].scan, xres, input[i].fp) < 0) { - eputs(input[i].name); - eputs(": read error\n"); - quit(1); + for (i = 0; i < nfiles; i++) + if (freadscan(input[i].scan, xres, input[i].fp) < 0) { + eputs(input[i].name); + eputs(": read error\n"); + quit(1); + } + varset(vypos, (double)ypos); + for (xpos = 0; xpos < xres; xpos++) { + varset(vxpos, (double)xpos); + eclock++; + if (brtdef != NULL) { + d = evalue(brtdef); + if (d < 0.0) + d = 0.0; + setcolor(scanout[xpos], d, d, d); + } else { + for (j = 0; j < 3; j++) { + if (coldef[j] != NULL) { + colval(scanout[xpos],j) = evalue(coldef[j]); + } else { + colval(scanout[xpos],j) = 0.0; + for (i = 0; i < nfiles; i++) + colval(scanout[xpos],j) += + colval(input[i].coef,j) * + colval(input[i].scan[xpos],j); } - varset(vypos, (double)ypos); - for (xpos = 0; xpos < xres; xpos++) { - varset(vxpos, (double)xpos); - eclock++; - for (j = 0; j < 3; j++) - if (coldef[j]) { - colval(scanout[xpos],j) = varvalue(vcolout[j]); - if (colval(scanout[xpos],j) < 0.0) - colval(scanout[xpos],j) = 0.0; - } else { - colval(scanout[xpos],j) = 0.0; - for (i = 0; i < nfiles; i++) - colval(scanout[xpos],j) += colval(input[i].scan[xpos],j); - colval(scanout[xpos],j) /= (double)nfiles; - } + if (colval(scanout[xpos],j) < 0.0) + colval(scanout[xpos],j) = 0.0; + } } - if (fwritescan(scanout, xres, stdout) < 0) { - eputs("write error\n"); - quit(1); - } + } + if (fwritescan(scanout, xres, stdout) < 0) { + perror("write error"); + quit(1); + } } efree(scanout); } @@ -210,6 +261,22 @@ double l_bluin() /* get blue color */ { return(colin((int)(argument(1)+.5), BLU)); +} + + +double +l_brtin() /* get brightness value */ +{ + register int fn; + + fn = argument(1)+.5; + if (fn == 0) + return((double)nfiles); + if (fn < 1 || fn > nfiles) { + errno = EDOM; + return(0.0); + } + return(bright(input[fn-1].scan[xpos])); }