--- ray/src/util/dctimestep.c 2019/08/14 18:20:02 2.41 +++ ray/src/util/dctimestep.c 2022/03/11 02:27:02 2.47 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: dctimestep.c,v 2.41 2019/08/14 18:20:02 greg Exp $"; +static const char RCSid[] = "$Id: dctimestep.c,v 2.47 2022/03/11 02:27:02 greg Exp $"; #endif /* * Compute time-step result using Daylight Coefficient method. @@ -48,7 +48,7 @@ sum_images(const char *fspec, const CMATRIX *cv, FILE error(SYSTEM, errmsg); } dt = DTfromHeader; - if ((err = cm_getheader(&dt, NULL, NULL, NULL, fp)) != NULL) + if ((err = cm_getheader(&dt, NULL, NULL, NULL, NULL, fp)) != NULL) error(USER, err); if ((dt != DTrgbe) & (dt != DTxyze) || !fscnresolu(&xr, &yr, fp)) { @@ -64,7 +64,7 @@ sum_images(const char *fspec, const CMATRIX *cv, FILE pmat = cm_alloc(myYR, myXR); memset(pmat->cmem, 0, sizeof(COLOR)*myXR*myYR); /* finish header */ - fputformat((char *)cm_fmt_id[myDT], fout); + fputformat(cm_fmt_id[myDT], fout); fputc('\n', fout); fflush(fout); } else if ((dt != myDT) | (xr != myXR) | (yr != myYR)) { @@ -141,6 +141,7 @@ main(int argc, char *argv[]) int nsteps = 0; char *ofspec = NULL; FILE *ofp = stdout; + int xres=0, yres=0; CMATRIX *cmtx; /* component vector/matrix result */ char fnbuf[256]; int a, i; @@ -187,10 +188,19 @@ main(int argc, char *argv[]) case 'a': outfmt = DTascii; break; + case 'c': + outfmt = DTrgbe; + break; default: goto userr; } break; + case 'x': + xres = atoi(argv[++a]); + break; + case 'y': + yres = atoi(argv[++a]); + break; default: goto userr; } @@ -237,6 +247,10 @@ main(int argc, char *argv[]) ofspec = NULL; /* only need to open once */ } if (hasNumberFormat(argv[a])) { /* generating image(s) */ + if (outfmt != DTrgbe) { + error(WARNING, "changing output type to -oc"); + outfmt = DTrgbe; + } if (ofspec == NULL) { SET_FILE_BINARY(ofp); newheader("RADIANCE", ofp); @@ -282,6 +296,27 @@ main(int argc, char *argv[]) const char *wtype = (outfmt==DTascii) ? "w" : "wb"; for (i = 0; i < nsteps; i++) { CMATRIX *rvec = cm_column(rmtx, i); + if (yres > 0) { + if (xres <= 0) + xres = rvec->nrows/yres; + if (xres*yres != rvec->nrows) { + fprintf(stderr, "Bad resolution: %d != %dx%d\n", + rvec->nrows, xres, yres); + return(1); + } + rvec->nrows = yres; + rvec->ncols = xres; + } else if (xres > 0) { + yres = rvec->nrows/xres; + if (xres*yres != rvec->nrows) { + fprintf(stderr, + "Bad resolution: %d does not divide %d evenly\n", + xres, rvec->nrows); + return(1); + } + rvec->nrows = yres; + rvec->ncols = xres; + } sprintf(fnbuf, ofspec, i); if ((ofp = fopen(fnbuf, wtype)) == NULL) { fprintf(stderr, @@ -297,9 +332,14 @@ main(int argc, char *argv[]) printargs(argc, argv, ofp); fputnow(ofp); fprintf(ofp, "FRAME=%d\n", i); - fprintf(ofp, "NROWS=%d\n", rvec->nrows); - fputs("NCOLS=1\nNCOMP=3\n", ofp); - fputformat((char *)cm_fmt_id[outfmt], ofp); + if ((outfmt != DTrgbe) & (outfmt != DTxyze)) { + fprintf(ofp, "NROWS=%d\n", rvec->nrows); + fprintf(ofp, "NCOLS=%d\n", rvec->ncols); + fputs("NCOMP=3\n", ofp); + } + if ((outfmt == DTfloat) | (outfmt == DTdouble)) + fputendian(ofp); + fputformat(cm_fmt_id[outfmt], ofp); fputc('\n', ofp); } cm_write(rvec, outfmt, ofp); @@ -322,10 +362,14 @@ main(int argc, char *argv[]) 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); + if ((outfmt != DTrgbe) & (outfmt != DTxyze)) { + fprintf(ofp, "NROWS=%d\n", rmtx->nrows); + fprintf(ofp, "NCOLS=%d\n", rmtx->ncols); + fputs("NCOMP=3\n", ofp); + } + if ((outfmt == DTfloat) | (outfmt == DTdouble)) + fputendian(ofp); + fputformat(cm_fmt_id[outfmt], ofp); fputc('\n', ofp); } cm_write(rmtx, outfmt, ofp); @@ -339,9 +383,9 @@ main(int argc, char *argv[]) cm_free(cmtx); return(0); userr: - fprintf(stderr, "Usage: %s [-n nsteps][-o ospec][-i{f|d|h}][-o{f|d}] DCspec [skyf]\n", + fprintf(stderr, "Usage: %s [-n nsteps][-o ospec][-i{f|d|h}][-o{f|d|c}] DCspec [skyf]\n", progname); - fprintf(stderr, " or: %s [-n nsteps][-o ospec][-i{f|d|h}][-o{f|d}] Vspec Tbsdf Dmat.dat [skyf]\n", + fprintf(stderr, " or: %s [-n nsteps][-o ospec][-i{f|d|h}][-o{f|d|c}] Vspec Tbsdf Dmat.dat [skyf]\n", progname); return(1); }