| 47 |
|
sprintf(errmsg, "cannot open picture '%s'", fname); |
| 48 |
|
error(SYSTEM, errmsg); |
| 49 |
|
} |
| 50 |
+ |
#ifdef getc_unlocked |
| 51 |
+ |
flockfile(fp); |
| 52 |
+ |
#endif |
| 53 |
|
dt = DTfromHeader; |
| 54 |
< |
if ((err = cm_getheader(&dt, NULL, NULL, fp)) != NULL) |
| 54 |
> |
if ((err = cm_getheader(&dt, NULL, NULL, NULL, NULL, fp)) != NULL) |
| 55 |
|
error(USER, err); |
| 56 |
|
if ((dt != DTrgbe) & (dt != DTxyze) || |
| 57 |
|
!fscnresolu(&xr, &yr, fp)) { |
| 67 |
|
pmat = cm_alloc(myYR, myXR); |
| 68 |
|
memset(pmat->cmem, 0, sizeof(COLOR)*myXR*myYR); |
| 69 |
|
/* finish header */ |
| 70 |
< |
fputformat((char *)cm_fmt_id[myDT], fout); |
| 70 |
> |
fputformat(cm_fmt_id[myDT], fout); |
| 71 |
|
fputc('\n', fout); |
| 72 |
|
fflush(fout); |
| 73 |
|
} else if ((dt != myDT) | (xr != myXR) | (yr != myYR)) { |
| 110 |
|
return(i); |
| 111 |
|
} |
| 112 |
|
|
| 113 |
+ |
/* adjust matrix dimensions according to user size(s) */ |
| 114 |
+ |
static int |
| 115 |
+ |
alt_dim(CMATRIX *cm, int nr, int nc) |
| 116 |
+ |
{ |
| 117 |
+ |
if ((nr <= 0) & (nc <= 0)) |
| 118 |
+ |
return(0); |
| 119 |
+ |
if ((nr == cm->nrows) & (nc == cm->ncols)) |
| 120 |
+ |
return(0); |
| 121 |
+ |
if (nr > 0) { |
| 122 |
+ |
if (nc <= 0) |
| 123 |
+ |
nc = cm->nrows*cm->ncols/nr; |
| 124 |
+ |
if (nr*nc != cm->nrows*cm->ncols) { |
| 125 |
+ |
fprintf(stderr, "Bad dimensions: %dx%d != %dx%d\n", |
| 126 |
+ |
nr, nc, cm->nrows, cm->ncols); |
| 127 |
+ |
return(-1); |
| 128 |
+ |
} |
| 129 |
+ |
} else /* nc > 0 */ { |
| 130 |
+ |
nr = cm->nrows*cm->ncols/nc; |
| 131 |
+ |
if (nc*nr != cm->nrows*cm->ncols) { |
| 132 |
+ |
fprintf(stderr, "Bad dimensions: %d does not divide %dx%d evenly\n", |
| 133 |
+ |
nc, cm->nrows, cm->ncols); |
| 134 |
+ |
return(-1); |
| 135 |
+ |
} |
| 136 |
+ |
} |
| 137 |
+ |
cm->nrows = nr; |
| 138 |
+ |
cm->ncols = nc; |
| 139 |
+ |
return(1); |
| 140 |
+ |
} |
| 141 |
+ |
|
| 142 |
|
/* check to see if a string contains a %d or %o specification */ |
| 143 |
|
static int |
| 144 |
|
hasNumberFormat(const char *s) |
| 173 |
|
int nsteps = 0; |
| 174 |
|
char *ofspec = NULL; |
| 175 |
|
FILE *ofp = stdout; |
| 176 |
+ |
int xres=0, yres=0; |
| 177 |
|
CMATRIX *cmtx; /* component vector/matrix result */ |
| 178 |
|
char fnbuf[256]; |
| 179 |
|
int a, i; |
| 220 |
|
case 'a': |
| 221 |
|
outfmt = DTascii; |
| 222 |
|
break; |
| 223 |
+ |
case 'c': |
| 224 |
+ |
outfmt = DTrgbe; |
| 225 |
+ |
break; |
| 226 |
|
default: |
| 227 |
|
goto userr; |
| 228 |
|
} |
| 229 |
|
break; |
| 230 |
+ |
case 'x': |
| 231 |
+ |
xres = atoi(argv[++a]); |
| 232 |
+ |
break; |
| 233 |
+ |
case 'y': |
| 234 |
+ |
yres = atoi(argv[++a]); |
| 235 |
+ |
break; |
| 236 |
|
default: |
| 237 |
|
goto userr; |
| 238 |
|
} |
| 279 |
|
ofspec = NULL; /* only need to open once */ |
| 280 |
|
} |
| 281 |
|
if (hasNumberFormat(argv[a])) { /* generating image(s) */ |
| 282 |
+ |
if (outfmt != DTrgbe) { |
| 283 |
+ |
error(WARNING, "changing output type to -oc"); |
| 284 |
+ |
outfmt = DTrgbe; |
| 285 |
+ |
} |
| 286 |
|
if (ofspec == NULL) { |
| 287 |
|
SET_FILE_BINARY(ofp); |
| 288 |
|
newheader("RADIANCE", ofp); |
| 328 |
|
const char *wtype = (outfmt==DTascii) ? "w" : "wb"; |
| 329 |
|
for (i = 0; i < nsteps; i++) { |
| 330 |
|
CMATRIX *rvec = cm_column(rmtx, i); |
| 331 |
+ |
if (alt_dim(rvec, yres, xres) < 0) |
| 332 |
+ |
return(1); |
| 333 |
|
sprintf(fnbuf, ofspec, i); |
| 334 |
|
if ((ofp = fopen(fnbuf, wtype)) == NULL) { |
| 335 |
|
fprintf(stderr, |
| 345 |
|
printargs(argc, argv, ofp); |
| 346 |
|
fputnow(ofp); |
| 347 |
|
fprintf(ofp, "FRAME=%d\n", i); |
| 348 |
< |
fprintf(ofp, "NROWS=%d\n", rvec->nrows); |
| 349 |
< |
fputs("NCOLS=1\nNCOMP=3\n", ofp); |
| 350 |
< |
fputformat((char *)cm_fmt_id[outfmt], ofp); |
| 348 |
> |
if ((outfmt != DTrgbe) & (outfmt != DTxyze)) { |
| 349 |
> |
fprintf(ofp, "NROWS=%d\n", rvec->nrows); |
| 350 |
> |
fprintf(ofp, "NCOLS=%d\n", rvec->ncols); |
| 351 |
> |
fputs("NCOMP=3\n", ofp); |
| 352 |
> |
} |
| 353 |
> |
if ((outfmt == DTfloat) | (outfmt == DTdouble)) |
| 354 |
> |
fputendian(ofp); |
| 355 |
> |
fputformat(cm_fmt_id[outfmt], ofp); |
| 356 |
|
fputc('\n', ofp); |
| 357 |
|
} |
| 358 |
|
cm_write(rvec, outfmt, ofp); |
| 371 |
|
#endif |
| 372 |
|
if (outfmt != DTascii) |
| 373 |
|
SET_FILE_BINARY(ofp); |
| 374 |
+ |
if (alt_dim(rmtx, yres, xres) < 0) |
| 375 |
+ |
return(1); |
| 376 |
|
if (headout) { /* header output */ |
| 377 |
|
newheader("RADIANCE", ofp); |
| 378 |
|
printargs(argc, argv, ofp); |
| 379 |
|
fputnow(ofp); |
| 380 |
< |
fprintf(ofp, "NROWS=%d\n", rmtx->nrows); |
| 381 |
< |
fprintf(ofp, "NCOLS=%d\n", rmtx->ncols); |
| 382 |
< |
fputs("NCOMP=3\n", ofp); |
| 383 |
< |
fputformat((char *)cm_fmt_id[outfmt], ofp); |
| 380 |
> |
if ((outfmt != DTrgbe) & (outfmt != DTxyze)) { |
| 381 |
> |
fprintf(ofp, "NROWS=%d\n", rmtx->nrows); |
| 382 |
> |
fprintf(ofp, "NCOLS=%d\n", rmtx->ncols); |
| 383 |
> |
fputs("NCOMP=3\n", ofp); |
| 384 |
> |
} |
| 385 |
> |
if ((outfmt == DTfloat) | (outfmt == DTdouble)) |
| 386 |
> |
fputendian(ofp); |
| 387 |
> |
fputformat(cm_fmt_id[outfmt], ofp); |
| 388 |
|
fputc('\n', ofp); |
| 389 |
|
} |
| 390 |
|
cm_write(rmtx, outfmt, ofp); |
| 398 |
|
cm_free(cmtx); |
| 399 |
|
return(0); |
| 400 |
|
userr: |
| 401 |
< |
fprintf(stderr, "Usage: %s [-n nsteps][-o ospec][-i{f|d|h}][-o{f|d}] DCspec [skyf]\n", |
| 401 |
> |
fprintf(stderr, "Usage: %s [-n nsteps][-o ospec][-x xr][-y yr][-i{f|d|h}][-o{f|d|c}] DCspec [skyf]\n", |
| 402 |
|
progname); |
| 403 |
< |
fprintf(stderr, " or: %s [-n nsteps][-o ospec][-i{f|d|h}][-o{f|d}] Vspec Tbsdf Dmat.dat [skyf]\n", |
| 403 |
> |
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", |
| 404 |
|
progname); |
| 405 |
|
return(1); |
| 406 |
|
} |