33 |
|
FILE *fp; |
34 |
|
int dt, xr, yr; |
35 |
|
COLORV *psp; |
36 |
+ |
char *err; |
37 |
|
/* check for zero */ |
38 |
|
if ((scv[RED] == 0) & (scv[GRN] == 0) & (scv[BLU] == 0) && |
39 |
|
(myDT != DTfromHeader) | (i < cv->nrows-1)) |
40 |
|
continue; |
41 |
|
/* open next picture */ |
42 |
|
sprintf(fname, fspec, i); |
43 |
< |
if ((fp = fopen(fname, "r")) == NULL) { |
43 |
> |
if ((fp = fopen(fname, "rb")) == NULL) { |
44 |
|
sprintf(errmsg, "cannot open picture '%s'", fname); |
45 |
|
error(SYSTEM, errmsg); |
46 |
|
} |
47 |
< |
SET_FILE_BINARY(fp); |
48 |
< |
dt = getDTfromHeader(fp); |
47 |
> |
dt = DTfromHeader; |
48 |
> |
if ((err = cm_getheader(&dt, NULL, NULL, fp)) != NULL) |
49 |
> |
error(USER, err); |
50 |
|
if ((dt != DTrgbe) & (dt != DTxyze) || |
51 |
|
!fscnresolu(&xr, &yr, fp)) { |
52 |
|
sprintf(errmsg, "file '%s' not a picture", fname); |
119 |
|
int |
120 |
|
main(int argc, char *argv[]) |
121 |
|
{ |
122 |
< |
int skyfmt = DTascii; |
122 |
> |
int skyfmt = DTfromHeader; |
123 |
|
int outfmt = DTascii; |
124 |
< |
int nsteps = 1; |
124 |
> |
int headout = 1; |
125 |
> |
int nsteps = 0; |
126 |
|
char *ofspec = NULL; |
127 |
|
FILE *ofp = stdout; |
128 |
|
CMATRIX *cmtx; /* component vector/matrix result */ |
135 |
|
switch (argv[a][1]) { |
136 |
|
case 'n': |
137 |
|
nsteps = atoi(argv[++a]); |
138 |
< |
if (nsteps <= 0) |
138 |
> |
if (nsteps < 0) |
139 |
|
goto userr; |
140 |
+ |
skyfmt = nsteps ? DTascii : DTfromHeader; |
141 |
|
break; |
142 |
+ |
case 'h': |
143 |
+ |
headout = !headout; |
144 |
+ |
break; |
145 |
|
case 'i': |
146 |
|
switch (argv[a][2]) { |
147 |
|
case 'f': |
185 |
|
CMATRIX *smtx, *Dmat, *Tmat, *imtx; |
186 |
|
/* get sky vector/matrix */ |
187 |
|
smtx = cm_load(argv[a+3], 0, nsteps, skyfmt); |
188 |
+ |
nsteps = smtx->ncols; |
189 |
|
/* load BSDF */ |
190 |
|
Tmat = cm_loadBTDF(argv[a+1]); |
191 |
|
/* load Daylight matrix */ |
199 |
|
cm_free(imtx); |
200 |
|
} else { /* sky vector/matrix only */ |
201 |
|
cmtx = cm_load(argv[a+1], 0, nsteps, skyfmt); |
202 |
+ |
nsteps = cmtx->ncols; |
203 |
|
} |
204 |
|
/* prepare output stream */ |
205 |
|
if ((ofspec != NULL) & (nsteps == 1) && hasNumberFormat(ofspec)) { |
267 |
|
progname, fnbuf); |
268 |
|
return(1); |
269 |
|
} |
270 |
+ |
#ifdef getc_unlocked |
271 |
+ |
flockfile(ofp); |
272 |
+ |
#endif |
273 |
+ |
if (headout) { /* header output */ |
274 |
+ |
newheader("RADIANCE", ofp); |
275 |
+ |
printargs(argc, argv, ofp); |
276 |
+ |
fputnow(ofp); |
277 |
+ |
fprintf(ofp, "FRAME=%d\n", i+1); |
278 |
+ |
fprintf(ofp, "NROWS=%d\n", rvec->nrows); |
279 |
+ |
fputs("NCOLS=1\nNCOMP=3\n", ofp); |
280 |
+ |
fputformat((char *)cm_fmt_id[outfmt], ofp); |
281 |
+ |
fputc('\n', ofp); |
282 |
+ |
} |
283 |
|
cm_write(rvec, outfmt, ofp); |
284 |
|
if (fclose(ofp) == EOF) { |
285 |
|
fprintf(stderr, |
291 |
|
cm_free(rvec); |
292 |
|
} |
293 |
|
} else { |
294 |
+ |
#ifdef getc_unlocked |
295 |
+ |
flockfile(ofp); |
296 |
+ |
#endif |
297 |
|
if (outfmt != DTascii) |
298 |
|
SET_FILE_BINARY(ofp); |
299 |
< |
if (rmtx->ncols > 1) { /* header if actual matrix */ |
299 |
> |
if (headout) { /* header output */ |
300 |
|
newheader("RADIANCE", ofp); |
301 |
|
printargs(argc, argv, ofp); |
302 |
|
fputnow(ofp); |
303 |
+ |
fprintf(ofp, "NROWS=%d\n", rmtx->nrows); |
304 |
+ |
fprintf(ofp, "NCOLS=%d\n", rmtx->ncols); |
305 |
+ |
fputs("NCOMP=3\n", ofp); |
306 |
|
fputformat((char *)cm_fmt_id[outfmt], ofp); |
307 |
|
fputc('\n', ofp); |
308 |
|
} |
317 |
|
cm_free(cmtx); |
318 |
|
return(0); |
319 |
|
userr: |
320 |
< |
fprintf(stderr, "Usage: %s [-n nsteps][-o ospec][-i{f|d}][-o{f|d}] DCspec [skyf]\n", |
320 |
> |
fprintf(stderr, "Usage: %s [-n nsteps][-o ospec][-i{f|d|h}][-o{f|d}] DCspec [skyf]\n", |
321 |
|
progname); |
322 |
< |
fprintf(stderr, " or: %s [-n nsteps][-o ospec][-i{f|d}][-o{f|d}] Vspec Tbsdf.xml Dmat.dat [skyf]\n", |
322 |
> |
fprintf(stderr, " or: %s [-n nsteps][-o ospec][-i{f|d|h}][-o{f|d}] Vspec Tbsdf.xml Dmat.dat [skyf]\n", |
323 |
|
progname); |
324 |
|
return(1); |
325 |
|
} |