--- ray/src/util/dctimestep.c 2014/02/08 01:28:06 2.30 +++ ray/src/util/dctimestep.c 2014/09/17 22:40:49 2.34 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: dctimestep.c,v 2.30 2014/02/08 01:28:06 greg Exp $"; +static const char RCSid[] = "$Id: dctimestep.c,v 2.34 2014/09/17 22:40:49 greg Exp $"; #endif /* * Compute time-step result using Daylight Coefficient method. @@ -26,25 +26,27 @@ sum_images(const char *fspec, const CMATRIX *cv, FILE int i, y; if (cv->ncols != 1) - error(INTERNAL, "expected vector in sum_images()"); + error(INTERNAL, "expected matrix in sum_images()"); for (i = 0; i < cv->nrows; i++) { const COLORV *scv = cv_lval(cv,i); char fname[1024]; FILE *fp; int dt, xr, yr; COLORV *psp; + char *err; /* check for zero */ if ((scv[RED] == 0) & (scv[GRN] == 0) & (scv[BLU] == 0) && (myDT != DTfromHeader) | (i < cv->nrows-1)) continue; /* open next picture */ sprintf(fname, fspec, i); - if ((fp = fopen(fname, "r")) == NULL) { + if ((fp = fopen(fname, "rb")) == NULL) { sprintf(errmsg, "cannot open picture '%s'", fname); error(SYSTEM, errmsg); } - SET_FILE_BINARY(fp); - dt = getDTfromHeader(fp); + dt = DTfromHeader; + if ((err = cm_getheader(&dt, NULL, NULL, fp)) != NULL) + error(USER, err); if ((dt != DTrgbe) & (dt != DTxyze) || !fscnresolu(&xr, &yr, fp)) { sprintf(errmsg, "file '%s' not a picture", fname); @@ -117,9 +119,10 @@ hasNumberFormat(const char *s) int main(int argc, char *argv[]) { - int skyfmt = DTascii; + int skyfmt = DTfromHeader; int outfmt = DTascii; - int nsteps = 1; + int headout = 1; + int nsteps = 0; char *ofspec = NULL; FILE *ofp = stdout; CMATRIX *cmtx; /* component vector/matrix result */ @@ -132,9 +135,13 @@ main(int argc, char *argv[]) switch (argv[a][1]) { case 'n': nsteps = atoi(argv[++a]); - if (nsteps <= 0) + if (nsteps < 0) goto userr; + skyfmt = nsteps ? DTascii : DTfromHeader; break; + case 'h': + headout = !headout; + break; case 'i': switch (argv[a][2]) { case 'f': @@ -258,6 +265,19 @@ main(int argc, char *argv[]) progname, fnbuf); return(1); } +#ifdef getc_unlocked + flockfile(ofp); +#endif + if (headout) { /* header output */ + newheader("RADIANCE", ofp); + printargs(argc, argv, ofp); + fputnow(ofp); + fprintf(ofp, "FRAME=%d\n", i+1); + fprintf(ofp, "NROWS=%d\n", rvec->nrows); + fputs("NCOLS=1\nNCOMP=3\n", ofp); + fputformat((char *)cm_fmt_id[outfmt], ofp); + fputc('\n', ofp); + } cm_write(rvec, outfmt, ofp); if (fclose(ofp) == EOF) { fprintf(stderr, @@ -269,12 +289,18 @@ main(int argc, char *argv[]) cm_free(rvec); } } else { +#ifdef getc_unlocked + flockfile(ofp); +#endif if (outfmt != DTascii) SET_FILE_BINARY(ofp); - if (rmtx->ncols > 1) { /* header if actual matrix */ + if (headout) { /* header output */ newheader("RADIANCE", ofp); printargs(argc, argv, ofp); fputnow(ofp); + fprintf(ofp, "NROWS=%d\n", rmtx->nrows); + fprintf(ofp, "NCOLS=%d\n", rmtx->ncols); + fputs("NCOMP=3\n", ofp); fputformat((char *)cm_fmt_id[outfmt], ofp); fputc('\n', ofp); } @@ -289,9 +315,9 @@ main(int argc, char *argv[]) cm_free(cmtx); return(0); userr: - fprintf(stderr, "Usage: %s [-n nsteps][-o ospec][-i{f|d}][-o{f|d}] DCspec [skyf]\n", + fprintf(stderr, "Usage: %s [-n nsteps][-o ospec][-i{f|d|h}][-o{f|d}] DCspec [skyf]\n", progname); - fprintf(stderr, " or: %s [-n nsteps][-o ospec][-i{f|d}][-o{f|d}] Vspec Tbsdf.xml Dmat.dat [skyf]\n", + fprintf(stderr, " or: %s [-n nsteps][-o ospec][-i{f|d|h}][-o{f|d}] Vspec Tbsdf.xml Dmat.dat [skyf]\n", progname); return(1); }