static int headline( /* process header line */ char *s, void *p ) { static RGBPRIMS inprimS; char fmt[32]; if (formatval(fmt, s)) { /* check if format string */ if (!strcmp(fmt,COLRFMT)) lumf = rgblum; else if (!strcmp(fmt,CIEFMT)) lumf = cielum; else lumf = NULL; return(0); /* don't echo */ } if (isprims(s)) { /* get input primaries */ primsval(inprimS, s); inprims= inprimS; return(0); /* don't echo */ } if (isexpos(s)) { /* picture exposure */ inpexp *= exposval(s); return(0); /* don't echo */ } if (isaspect(s)) /* pixel aspect ratio */ pixaspect *= aspectval(s); if (isview(s)) /* image view */ gotview += sscanview(&ourview, s); return(fputs(s, stdout)); }
static int picheadline( /* process picture header line */ char *s, void *vph ) { char fmt[32]; struct phead *ph = vph; if (formatval(fmt, s)) { ph->badfmt = strcmp(fmt, COLRFMT); return(0); } if (isprims(s)) { ph->altprims++; /* don't want to deal with this */ return(0); } if (isexpos(s)) { ph->expos *= exposval(s); return(0); } if (isview(s)) { ph->gotview += sscanview(&ph->vw, s); return(0); } return(0); }
static int gethview( /* get view from header */ char *s, void *v ) { if (isview(s) && sscanview(((struct myview*)v)->hv, s) > 0) ((struct myview*)v)->ok++; return(0); }
static int headline( /* check header line & echo if requested */ char *s, void *p ) { char fmt[32]; double d; COLOR ctmp; if (isheadid(s)) /* header id */ return(0); /* don't echo */ if (formatval(fmt, s)) { /* check format */ if (globmatch(ourfmt, fmt)) { wrongformat = 0; strcpy(ourfmt, fmt); } else wrongformat = globmatch(PICFMT, fmt) ? 1 : -1; return(0); /* don't echo */ } if (isexpos(s)) { /* exposure */ d = exposval(s); scalecolor(input[nfiles].expos, d); } else if (iscolcor(s)) { /* color correction */ colcorval(ctmp, s); multcolor(input[nfiles].expos, ctmp); } else if (isaspect(s)) input[nfiles].pa *= aspectval(s); else if (isview(s) && sscanview(&input[nfiles].vw, s) > 0) gotview++; if (echoheader) { /* echo line */ putchar('\t'); return(fputs(s, stdout)); } return(0); }
static void runrad( /* run rad and load variables */ int ac, char **av ) { static char optfile[] = TEMPLATE; int nvn = 0, nvv = 0; FILE *fp; register char *cp; char radcomm[256], buf[128], nam[32]; /* set rad commmand */ strcpy(radcomm, "rad -w -v 0 "); /* look out below! */ cp = radcomm + 19; if (silent) { strcpy(cp, "-s "); cp += 3; } while (ac--) { strcpy(cp, *av++); while (*cp) cp++; *cp++ = ' '; } strcpy(cp, "OPTFILE="); /* create temporary options file */ strcpy(cp+8, mktemp(optfile)); if (system(radcomm)) /* update octree */ error(USER, "error executing rad command"); /* replace "-v 0" with "-n -e -s -V" */ strcpy(radcomm+7, "-n -e -s -V"); radcomm[18] = ' '; if ((fp = popen(radcomm, "r")) == NULL) error(SYSTEM, "cannot start rad command"); buf[0] = '\0'; /* read variables alphabetically */ /* get exposure */ if ((cp = scan4var(buf, sizeof(buf), "EXPOSURE", fp)) != NULL) { expval = atof(cp); if ((*cp == '-') | (*cp == '+')) expval = pow(2., expval); expval *= 0.5; /* compensate for local shading */ } /* look for eye separation */ if ((cp = scan4var(buf, sizeof(buf), "EYESEP", fp)) != NULL) eyedist = atof(cp); /* look for materials */ while ((cp = scan4var(buf, sizeof(buf), "materials", fp)) != NULL) { nscenef += wordstring(scene+nscenef, cp); buf[0] = '\0'; } /* look for octree */ if ((cp = scan4var(buf, sizeof(buf), "OCTREE", fp)) != NULL) octree = savqstr(cp); /* look for scene files */ while ((cp = scan4var(buf, sizeof(buf), "scene", fp)) != NULL) { nscenef += wordstring(scene+nscenef, cp); buf[0] = '\0'; } /* load view names */ while ((cp = scan4var(buf, sizeof(buf), "view", fp)) != NULL) { if (nvn >= MAXVIEW) error(INTERNAL, "too many views in rad file"); vwl[nvn++].nam = *cp == '-' ? (char *)NULL : savqstr(atos(nam, sizeof(nam), cp)); buf[0] = '\0'; } /* load actual views */ do if (isview(buf)) { vwl[nvv].v = (VIEW *)bmalloc(sizeof(VIEW)); *(vwl[nvv].v) = stdview; sscanview(vwl[nvv].v, buf); if ((cp = setview(vwl[nvv++].v)) != NULL) { fprintf(stderr, "%s: bad view %d - %s\n", progname, nvv, cp); quit(1); } } while (fgets(buf, sizeof(buf), fp) != NULL); if (nvv != nvn) error(INTERNAL, "view miscount in runrad"); pclose(fp); /* open options file */ if ((fp = fopen(optfile, "r")) == NULL) error(SYSTEM, "cannot open options file"); /* get relevant options */ while (fgets(buf, sizeof(buf), fp) != NULL) if (!strncmp(buf, "-av ", 4)) setcolor(ambval, atof(buf+4), atof(sskip2(buf+4,1)), atof(sskip2(buf+4,2))); else if (backvis && !strncmp(buf, "-bv", 3) && (!buf[3] || strchr("0-FfNn \n",buf[3])!=NULL)) backvis = 0; fclose(fp); unlink(optfile); /* delete options file */ }