| 48 |
|
error(SYSTEM, errmsg); |
| 49 |
|
} |
| 50 |
|
dt = DTfromHeader; |
| 51 |
< |
if ((err = cm_getheader(&dt, NULL, NULL, NULL, fp)) != NULL) |
| 51 |
> |
if ((err = cm_getheader(&dt, NULL, NULL, NULL, NULL, fp)) != NULL) |
| 52 |
|
error(USER, err); |
| 53 |
|
if ((dt != DTrgbe) & (dt != DTxyze) || |
| 54 |
|
!fscnresolu(&xr, &yr, fp)) { |
| 64 |
|
pmat = cm_alloc(myYR, myXR); |
| 65 |
|
memset(pmat->cmem, 0, sizeof(COLOR)*myXR*myYR); |
| 66 |
|
/* finish header */ |
| 67 |
< |
fputformat((char *)cm_fmt_id[myDT], fout); |
| 67 |
> |
fputformat(cm_fmt_id[myDT], fout); |
| 68 |
|
fputc('\n', fout); |
| 69 |
|
fflush(fout); |
| 70 |
|
} else if ((dt != myDT) | (xr != myXR) | (yr != myYR)) { |
| 141 |
|
int nsteps = 0; |
| 142 |
|
char *ofspec = NULL; |
| 143 |
|
FILE *ofp = stdout; |
| 144 |
+ |
int xres=0, yres=0; |
| 145 |
|
CMATRIX *cmtx; /* component vector/matrix result */ |
| 146 |
|
char fnbuf[256]; |
| 147 |
|
int a, i; |
| 188 |
|
case 'a': |
| 189 |
|
outfmt = DTascii; |
| 190 |
|
break; |
| 191 |
+ |
case 'c': |
| 192 |
+ |
outfmt = DTrgbe; |
| 193 |
+ |
break; |
| 194 |
|
default: |
| 195 |
|
goto userr; |
| 196 |
|
} |
| 197 |
|
break; |
| 198 |
+ |
case 'x': |
| 199 |
+ |
xres = atoi(argv[++a]); |
| 200 |
+ |
break; |
| 201 |
+ |
case 'y': |
| 202 |
+ |
yres = atoi(argv[++a]); |
| 203 |
+ |
break; |
| 204 |
|
default: |
| 205 |
|
goto userr; |
| 206 |
|
} |
| 247 |
|
ofspec = NULL; /* only need to open once */ |
| 248 |
|
} |
| 249 |
|
if (hasNumberFormat(argv[a])) { /* generating image(s) */ |
| 250 |
+ |
if (outfmt != DTrgbe) { |
| 251 |
+ |
error(WARNING, "changing output type to -oc"); |
| 252 |
+ |
outfmt = DTrgbe; |
| 253 |
+ |
} |
| 254 |
|
if (ofspec == NULL) { |
| 255 |
|
SET_FILE_BINARY(ofp); |
| 256 |
|
newheader("RADIANCE", ofp); |
| 296 |
|
const char *wtype = (outfmt==DTascii) ? "w" : "wb"; |
| 297 |
|
for (i = 0; i < nsteps; i++) { |
| 298 |
|
CMATRIX *rvec = cm_column(rmtx, i); |
| 299 |
+ |
if (yres > 0) { |
| 300 |
+ |
if (xres <= 0) |
| 301 |
+ |
xres = rvec->nrows/yres; |
| 302 |
+ |
if (xres*yres != rvec->nrows) { |
| 303 |
+ |
fprintf(stderr, "Bad resolution: %d != %dx%d\n", |
| 304 |
+ |
rvec->nrows, xres, yres); |
| 305 |
+ |
return(1); |
| 306 |
+ |
} |
| 307 |
+ |
rvec->nrows = yres; |
| 308 |
+ |
rvec->ncols = xres; |
| 309 |
+ |
} else if (xres > 0) { |
| 310 |
+ |
yres = rvec->nrows/xres; |
| 311 |
+ |
if (xres*yres != rvec->nrows) { |
| 312 |
+ |
fprintf(stderr, |
| 313 |
+ |
"Bad resolution: %d does not divide %d evenly\n", |
| 314 |
+ |
xres, rvec->nrows); |
| 315 |
+ |
return(1); |
| 316 |
+ |
} |
| 317 |
+ |
rvec->nrows = yres; |
| 318 |
+ |
rvec->ncols = xres; |
| 319 |
+ |
} |
| 320 |
|
sprintf(fnbuf, ofspec, i); |
| 321 |
|
if ((ofp = fopen(fnbuf, wtype)) == NULL) { |
| 322 |
|
fprintf(stderr, |
| 332 |
|
printargs(argc, argv, ofp); |
| 333 |
|
fputnow(ofp); |
| 334 |
|
fprintf(ofp, "FRAME=%d\n", i); |
| 335 |
< |
fprintf(ofp, "NROWS=%d\n", rvec->nrows); |
| 336 |
< |
fputs("NCOLS=1\nNCOMP=3\n", ofp); |
| 337 |
< |
if ((outfmt == 'f') | (outfmt == 'd')) |
| 335 |
> |
if ((outfmt != DTrgbe) & (outfmt != DTxyze)) { |
| 336 |
> |
fprintf(ofp, "NROWS=%d\n", rvec->nrows); |
| 337 |
> |
fprintf(ofp, "NCOLS=%d\n", rvec->ncols); |
| 338 |
> |
fputs("NCOMP=3\n", ofp); |
| 339 |
> |
} |
| 340 |
> |
if ((outfmt == DTfloat) | (outfmt == DTdouble)) |
| 341 |
|
fputendian(ofp); |
| 342 |
< |
fputformat((char *)cm_fmt_id[outfmt], ofp); |
| 342 |
> |
fputformat(cm_fmt_id[outfmt], ofp); |
| 343 |
|
fputc('\n', ofp); |
| 344 |
|
} |
| 345 |
|
cm_write(rvec, outfmt, ofp); |
| 362 |
|
newheader("RADIANCE", ofp); |
| 363 |
|
printargs(argc, argv, ofp); |
| 364 |
|
fputnow(ofp); |
| 365 |
< |
fprintf(ofp, "NROWS=%d\n", rmtx->nrows); |
| 366 |
< |
fprintf(ofp, "NCOLS=%d\n", rmtx->ncols); |
| 367 |
< |
fputs("NCOMP=3\n", ofp); |
| 368 |
< |
if ((outfmt == 'f') | (outfmt == 'd')) |
| 365 |
> |
if ((outfmt != DTrgbe) & (outfmt != DTxyze)) { |
| 366 |
> |
fprintf(ofp, "NROWS=%d\n", rmtx->nrows); |
| 367 |
> |
fprintf(ofp, "NCOLS=%d\n", rmtx->ncols); |
| 368 |
> |
fputs("NCOMP=3\n", ofp); |
| 369 |
> |
} |
| 370 |
> |
if ((outfmt == DTfloat) | (outfmt == DTdouble)) |
| 371 |
|
fputendian(ofp); |
| 372 |
< |
fputformat((char *)cm_fmt_id[outfmt], ofp); |
| 372 |
> |
fputformat(cm_fmt_id[outfmt], ofp); |
| 373 |
|
fputc('\n', ofp); |
| 374 |
|
} |
| 375 |
|
cm_write(rmtx, outfmt, ofp); |
| 383 |
|
cm_free(cmtx); |
| 384 |
|
return(0); |
| 385 |
|
userr: |
| 386 |
< |
fprintf(stderr, "Usage: %s [-n nsteps][-o ospec][-i{f|d|h}][-o{f|d}] DCspec [skyf]\n", |
| 386 |
> |
fprintf(stderr, "Usage: %s [-n nsteps][-o ospec][-x xr][-y yr][-i{f|d|h}][-o{f|d|c}] DCspec [skyf]\n", |
| 387 |
|
progname); |
| 388 |
< |
fprintf(stderr, " or: %s [-n nsteps][-o ospec][-i{f|d|h}][-o{f|d}] Vspec Tbsdf Dmat.dat [skyf]\n", |
| 388 |
> |
fprintf(stderr, " or: %s [-n nsteps][-o ospec][-x xr][-y yr][-i{f|d|h}][-o{f|d|c}] Vspec Tbsdf Dmat.dat [skyf]\n", |
| 389 |
|
progname); |
| 390 |
|
return(1); |
| 391 |
|
} |