static void combine(void) /* combine pictures */ { EPNODE *coldef[3], *brtdef; COLOR *scanout; double d; register int i, j; /* check defined variables */ 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; /* allocate scanline */ scanout = (COLOR *)emalloc(xres*sizeof(COLOR)); /* set input position */ yscan = ymax+MIDSCN; /* combine files */ for (ypos = yres-1; ypos >= 0; ypos--) { advance(); varset(vypos, '=', (double)ypos); for (xpos = 0; xpos < xres; xpos++) { xscan = (xpos+.5)*xmax/xres; 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) { d = evalue(coldef[j]); } else { d = 0.0; for (i = 0; i < nfiles; i++) d += colval(input[i].scan[MIDSCN][xscan],j); } if (d < 0.0) d = 0.0; colval(scanout[xpos],j) = d; } } } if (fwritescan(scanout, xres, stdout) < 0) { perror("write error"); quit(1); } } efree((char *)scanout); }
static void execute( /* process a file */ char *file ) { int conditional = vardefined("cond"); long nrecs = 0; long nout = 0; FILE *fp; if (file == NULL) fp = stdin; else if ((fp = fopen(file, "r")) == NULL) { eputs(file); eputs(": cannot open\n"); quit(1); } if (inpfmt != NULL) initinp(fp); while (getinputrec(fp)) { varset("recno", '=', (double)++nrecs); varset("outno", '=', (double)(nout+1)); colflg = 0; eclock++; if (!conditional || varvalue("cond") > 0.0) { putout(); ++nout; } } fclose(fp); }
static int getfield( /* get next field */ register struct field *f ) { static char buf[RMAXWORD+1]; /* no recursion! */ int delim, inword; double d; char *np; register char *cp; switch (f->type & F_TYP) { case T_LIT: cp = f->f.sl; do { if (blnkeq && isblnk(*cp)) { if (!isblnk(ipb.chr)) return(-1); do cp++; while (isblnk(*cp)); do scaninp(); while (isblnk(ipb.chr)); } else if (*cp == ipb.chr) { cp++; scaninp(); } else return(-1); } while (*cp); return(0); case T_STR: if (f->next == NULL || (f->next->type & F_TYP) != T_LIT) delim = EOF; else delim = f->next->f.sl[0]; cp = buf; do { if (ipb.chr == EOF || ipb.chr == '\n') inword = 0; else if (blnkeq && delim != EOF) inword = isblnk(delim) ? !isblnk(ipb.chr) : ipb.chr != delim; else inword = cp-buf < (f->type & F_WID); if (inword) { *cp++ = ipb.chr; scaninp(); } } while (inword && cp < &buf[RMAXWORD]); *cp = '\0'; if (f->f.sv->val == NULL) f->f.sv->val = savqstr(buf); /* first setting */ else if (strcmp(f->f.sv->val, buf)) return(-1); /* doesn't match! */ return(0); case T_NUM: if (f->next == NULL || (f->next->type & F_TYP) != T_LIT) delim = EOF; else delim = f->next->f.sl[0]; np = NULL; cp = buf; do { if (!((np==NULL&&isblnk(ipb.chr)) || isnum(ipb.chr))) inword = 0; else if (blnkeq && delim != EOF) inword = isblnk(delim) ? !isblnk(ipb.chr) : ipb.chr != delim; else inword = cp-buf < (f->type & F_WID); if (inword) { if (np==NULL && !isblnk(ipb.chr)) np = cp; *cp++ = ipb.chr; scaninp(); } } while (inword && cp < &buf[RMAXWORD]); *cp = '\0'; d = np==NULL ? 0. : atof(np); if (!vardefined(f->f.nv)) varset(f->f.nv, '=', d); /* first setting */ else if ((d = (varvalue(f->f.nv)-d)/(d==0.?1.:d)) > .001 || d < -.001) return(-1); /* doesn't match! */ return(0); } return -1; /* pro forma return */ }
int main( int argc, char *argv[] ) { int original; double f; int a; SET_DEFAULT_BINARY(); SET_FILE_BINARY(stdin); SET_FILE_BINARY(stdout); progname = argv[0]; /* scan options */ for (a = 1; a < argc; a++) { if (argv[a][0] == '-') switch (argv[a][1]) { case 'x': case 'y': a++; continue; case 'w': nowarn = !nowarn; continue; case 'h': echoheader = !echoheader; continue; case 'f': case 'e': a++; continue; } break; } newheader("RADIANCE", stdout); /* start header */ fputnow(stdout); /* process files */ for (nfiles = 0; nfiles < MAXINP; nfiles++) { setcolor(input[nfiles].coef, 1.0, 1.0, 1.0); setcolor(input[nfiles].expos, 1.0, 1.0, 1.0); input[nfiles].vw = stdview; input[nfiles].pa = 1.0; } nfiles = 0; original = 0; for ( ; a < argc; a++) { if (nfiles >= MAXINP) { eputs(argv[0]); eputs(": too many picture files\n"); quit(1); } if (argv[a][0] == '-') switch (argv[a][1]) { case '\0': input[nfiles].name = StandardInput; input[nfiles].fp = stdin; break; case 'o': original++; continue; 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 { 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); } } checkfile(); if (original) { colval(input[nfiles].coef,RED) /= colval(input[nfiles].expos,RED); colval(input[nfiles].coef,GRN) /= colval(input[nfiles].expos,GRN); colval(input[nfiles].coef,BLU) /= colval(input[nfiles].expos,BLU); setcolor(input[nfiles].expos, 1.0, 1.0, 1.0); } nfiles++; original = 0; } init(); /* set constants */ /* go back and get expressions */ for (a = 1; a < argc; a++) { if (argv[a][0] == '-') switch (argv[a][1]) { case 'x': varset(vxres, ':', eval(argv[++a])); continue; case 'y': varset(vyres, ':', eval(argv[++a])); continue; case 'w': continue; case 'h': continue; case 'f': fcompile(argv[++a]); continue; case 'e': scompile(argv[++a], NULL, 0); continue; } break; } /* set/get output resolution */ if (!vardefined(vxres)) varset(vxres, ':', (double)xmax); if (!vardefined(vyres)) varset(vyres, ':', (double)ymax); xres = varvalue(vxres) + .5; yres = varvalue(vyres) + .5; if (xres <= 0 || yres <= 0) { eputs(argv[0]); eputs(": illegal output resolution\n"); quit(1); } /* complete header */ printargs(argc, argv, stdout); if (strcmp(ourfmt, PICFMT)) fputformat(ourfmt, stdout); /* print format if known */ putchar('\n'); fprtresolu(xres, yres, stdout); /* combine pictures */ combine(); quit(0); usage: eputs("Usage: "); eputs(argv[0]); eputs( " [-w][-h][-x xr][-y yr][-e expr][-f file] [ [-o][-s f][-c r g b] hdr ..]\n"); quit(1); return 1; /* pro forma return */ }