--- ray/src/px/pcomb.c 1989/05/09 10:07:04 1.2 +++ ray/src/px/pcomb.c 1989/09/12 13:04:22 1.5 @@ -24,6 +24,7 @@ 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 */ @@ -53,7 +54,8 @@ main(argc, argv) int argc; char *argv[]; { - extern double l_redin(), l_grnin(), l_bluin(); + extern double l_redin(), l_grnin(), l_bluin(), atof(); + double f; int a; funset(vcolin[RED], 1, l_redin); @@ -64,6 +66,8 @@ char *argv[]; if (argv[a][0] == '-') switch (argv[a][1]) { case '\0': + case 's': + case 'c': goto getfiles; case 'x': xres = atoi(argv[++a]); @@ -81,14 +85,13 @@ char *argv[]; scompile(NULL, argv[++a]); 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,10 +99,25 @@ 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) { @@ -111,7 +129,8 @@ getfiles: 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,20 +148,29 @@ 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]; COLOR *scanout; 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; + } /* allocate scanline */ scanout = (COLOR *)emalloc(xres*sizeof(COLOR)); /* combine files */ @@ -157,16 +185,20 @@ combine() /* combine pictures */ 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; + 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].scan[xpos],j); + colval(scanout[xpos],j) += + colval(input[i].coef,j) * + colval(input[i].scan[xpos],j); } + if (colval(scanout[xpos],j) < 0.0) + colval(scanout[xpos],j) = 0.0; + } } if (fwritescan(scanout, xres, stdout) < 0) { eputs("write error\n");