--- ray/src/rt/rc2.c 2016/03/01 00:58:31 2.16 +++ ray/src/rt/rc2.c 2016/09/12 20:31:34 2.19 @@ -1,14 +1,15 @@ #ifndef lint -static const char RCSid[] = "$Id: rc2.c,v 2.16 2016/03/01 00:58:31 greg Exp $"; +static const char RCSid[] = "$Id: rc2.c,v 2.19 2016/09/12 20:31:34 greg Exp $"; #endif /* * Accumulate ray contributions for a set of materials * File i/o and recovery */ +#include +#include "platform.h" #include "rcontrib.h" #include "resolu.h" -#include /* Close output stream and free record */ static void @@ -183,7 +184,7 @@ getostream(const char *ospec, const char *mname, int b sop = (STREAMOUT *)malloc(sizeof(STREAMOUT)); if (sop == NULL) error(SYSTEM, "out of memory in getostream"); - sop->outpipe = oname[0] == '!'; + sop->outpipe = (oname[0] == '!'); sop->reclen = 0; sop->ofp = NULL; /* open iff noopen==0 */ sop->xr = xres; sop->yr = yres; @@ -193,6 +194,12 @@ getostream(const char *ospec, const char *mname, int b errno = EEXIST; /* file exists */ goto openerr; } + } else if (noopen && outfmt == 'c' && /* stream exists to picture? */ + (sop->xr > 0) & (sop->yr > 0)) { + if (ofl & OF_BIN) + return(NULL); /* let caller offset bins */ + sprintf(errmsg, "output '%s' not a valid picture", oname); + error(WARNING, errmsg); } if (!noopen && sop->ofp == NULL) { /* open output stream */ if (oname[0] == '!') /* output to command */ @@ -261,12 +268,12 @@ getvec(FVECT vec) } break; case 'f': /* binary float */ - if (fread((char *)vf, sizeof(float), 3, stdin) != 3) + if (getbinary((char *)vf, sizeof(float), 3, stdin) != 3) return(-1); VCOPY(vec, vf); break; case 'd': /* binary double */ - if (fread((char *)vd, sizeof(double), 3, stdin) != 3) + if (getbinary((char *)vd, sizeof(double), 3, stdin) != 3) return(-1); VCOPY(vec, vd); break; @@ -302,23 +309,23 @@ put_contrib(const DCOLOR cnt, FILE *fout) scalecolor(fv, sf); } else copycolor(fv, cnt); - fwrite(fv, sizeof(float), 3, fout); + putbinary(fv, sizeof(float), 3, fout); break; case 'd': if (accumulate > 1) { DCOLOR dv; copycolor(dv, cnt); scalecolor(dv, sf); - fwrite(dv, sizeof(double), 3, fout); + putbinary(dv, sizeof(double), 3, fout); } else - fwrite(cnt, sizeof(double), 3, fout); + putbinary(cnt, sizeof(double), 3, fout); break; case 'c': if (accumulate > 1) setcolr(cv, sf*cnt[0], sf*cnt[1], sf*cnt[2]); else setcolr(cv, cnt[0], cnt[1], cnt[2]); - fwrite(cv, sizeof(cv), 1, fout); + putbinary(cv, sizeof(cv), 1, fout); break; default: error(INTERNAL, "botched output format"); @@ -330,17 +337,17 @@ put_contrib(const DCOLOR cnt, FILE *fout) void mod_output(MODCONT *mp) { - STREAMOUT *sop = getostream(mp->outspec, mp->modname, 0, 0); + STREAMOUT *sop = getostream(mp->outspec, mp->modname, mp->bin0, 0); int j; put_contrib(mp->cbin[0], sop->ofp); if (mp->nbins > 3 && /* minor optimization */ - sop == getostream(mp->outspec, mp->modname, 1, 0)) { + sop == getostream(mp->outspec, mp->modname, mp->bin0+1, 0)) { for (j = 1; j < mp->nbins; j++) put_contrib(mp->cbin[j], sop->ofp); } else { for (j = 1; j < mp->nbins; j++) { - sop = getostream(mp->outspec, mp->modname, j, 0); + sop = getostream(mp->outspec, mp->modname, mp->bin0+j, 0); put_contrib(mp->cbin[j], sop->ofp); } } @@ -393,14 +400,14 @@ get_contrib(DCOLOR cnt, FILE *finp) case 'a': return(fscanf(finp,"%lf %lf %lf",&cnt[0],&cnt[1],&cnt[2]) == 3); case 'f': - if (fread(fv, sizeof(fv[0]), 3, finp) != 3) + if (getbinary(fv, sizeof(fv[0]), 3, finp) != 3) return(0); copycolor(cnt, fv); return(1); case 'd': - return(fread(cnt, sizeof(cnt[0]), 3, finp) == 3); + return(getbinary(cnt, sizeof(cnt[0]), 3, finp) == 3); case 'c': - if (fread(cv, sizeof(cv), 1, finp) != 1) + if (getbinary(cv, sizeof(cv), 1, finp) != 1) return(0); colr_color(fv, cv); copycolor(cnt, fv);