59 |
|
pmat = cm_alloc(myYR, myXR); |
60 |
|
memset(pmat->cmem, 0, sizeof(COLOR)*myXR*myYR); |
61 |
|
/* finish header */ |
62 |
< |
fputformat(myDT==DTrgbe ? COLRFMT : CIEFMT, fout); |
62 |
> |
fputformat((char *)cm_fmt_id[myDT], fout); |
63 |
|
fputc('\n', fout); |
64 |
– |
fprtresolu(myXR, myYR, fout); |
64 |
|
fflush(fout); |
65 |
|
} else if ((dt != myDT) | (xr != myXR) | (yr != myYR)) { |
66 |
|
sprintf(errmsg, "picture '%s' format/size mismatch", |
84 |
|
fclose(fp); /* done this picture */ |
85 |
|
} |
86 |
|
free(scanline); |
87 |
< |
/* write scanlines */ |
88 |
< |
for (y = 0; y < myYR; y++) |
89 |
< |
if (fwritescan((COLOR *)cm_lval(pmat, y, 0), myXR, fout) < 0) |
91 |
< |
return(0); |
92 |
< |
cm_free(pmat); /* all done */ |
93 |
< |
return(fflush(fout) == 0); |
87 |
> |
i = cm_write(pmat, myDT, fout); /* write picture */ |
88 |
> |
cm_free(pmat); /* free data */ |
89 |
> |
return(i); |
90 |
|
} |
91 |
|
|
92 |
|
/* check to see if a string contains a %d or %o specification */ |
118 |
|
main(int argc, char *argv[]) |
119 |
|
{ |
120 |
|
int skyfmt = DTascii; |
121 |
+ |
int outfmt = DTascii; |
122 |
|
int nsteps = 1; |
123 |
|
char *ofspec = NULL; |
124 |
|
FILE *ofp = stdout; |
135 |
|
if (nsteps <= 0) |
136 |
|
goto userr; |
137 |
|
break; |
141 |
– |
case 'o': |
142 |
– |
ofspec = argv[++a]; |
143 |
– |
break; |
138 |
|
case 'i': |
139 |
|
switch (argv[a][2]) { |
140 |
|
case 'f': |
150 |
|
goto userr; |
151 |
|
} |
152 |
|
break; |
153 |
+ |
case 'o': |
154 |
+ |
switch (argv[a][2]) { |
155 |
+ |
case '\0': /* output specification (not format) */ |
156 |
+ |
ofspec = argv[++a]; |
157 |
+ |
break; |
158 |
+ |
case 'f': |
159 |
+ |
outfmt = DTfloat; |
160 |
+ |
break; |
161 |
+ |
case 'd': |
162 |
+ |
outfmt = DTdouble; |
163 |
+ |
break; |
164 |
+ |
case 'a': |
165 |
+ |
outfmt = DTascii; |
166 |
+ |
break; |
167 |
+ |
default: |
168 |
+ |
goto userr; |
169 |
+ |
} |
170 |
+ |
break; |
171 |
|
default: |
172 |
|
goto userr; |
173 |
|
} |
176 |
|
|
177 |
|
if (argc-a > 2) { /* VTDs expression */ |
178 |
|
CMATRIX *smtx, *Dmat, *Tmat, *imtx; |
167 |
– |
COLOR tLamb; |
179 |
|
/* get sky vector/matrix */ |
180 |
|
smtx = cm_load(argv[a+3], 0, nsteps, skyfmt); |
181 |
|
/* load BSDF */ |
182 |
< |
Tmat = cm_loadBSDF(argv[a+1], tLamb); |
182 |
> |
Tmat = cm_loadBTDF(argv[a+1]); |
183 |
|
/* load Daylight matrix */ |
184 |
|
Dmat = cm_load(argv[a+2], Tmat==NULL ? 0 : Tmat->ncols, |
185 |
|
smtx->nrows, DTfromHeader); |
186 |
|
/* multiply vector through */ |
187 |
|
imtx = cm_multiply(Dmat, smtx); |
188 |
|
cm_free(Dmat); cm_free(smtx); |
189 |
< |
if (Tmat == NULL) { /* diffuse only */ |
190 |
< |
cmtx = cm_scale(imtx, tLamb); |
180 |
< |
} else { /* else apply BTDF matrix */ |
181 |
< |
cmtx = cm_multiply(Tmat, imtx); |
182 |
< |
cm_free(Tmat); |
183 |
< |
} |
189 |
> |
cmtx = cm_multiply(Tmat, imtx); |
190 |
> |
cm_free(Tmat); |
191 |
|
cm_free(imtx); |
192 |
|
} else { /* sky vector/matrix only */ |
193 |
|
cmtx = cm_load(argv[a+1], 0, nsteps, skyfmt); |
247 |
|
CMATRIX *Vmat = cm_load(argv[a], 0, cmtx->nrows, DTfromHeader); |
248 |
|
CMATRIX *rmtx = cm_multiply(Vmat, cmtx); |
249 |
|
cm_free(Vmat); |
250 |
< |
if (ofspec != NULL) /* multiple vector files? */ |
250 |
> |
if (ofspec != NULL) { /* multiple vector files? */ |
251 |
> |
const char *wtype = (outfmt==DTascii) ? "w" : "wb"; |
252 |
|
for (i = 0; i < nsteps; i++) { |
253 |
|
CMATRIX *rvec = cm_column(rmtx, i); |
254 |
|
sprintf(fnbuf, ofspec, i+1); |
255 |
< |
if ((ofp = fopen(fnbuf, "w")) == NULL) { |
255 |
> |
if ((ofp = fopen(fnbuf, wtype)) == NULL) { |
256 |
|
fprintf(stderr, |
257 |
|
"%s: cannot open '%s' for output\n", |
258 |
|
progname, fnbuf); |
259 |
|
return(1); |
260 |
|
} |
261 |
< |
cm_print(rvec, ofp); |
261 |
> |
cm_write(rvec, outfmt, ofp); |
262 |
|
if (fclose(ofp) == EOF) { |
263 |
|
fprintf(stderr, |
264 |
|
"%s: error writing to '%s'\n", |
268 |
|
ofp = stdout; |
269 |
|
cm_free(rvec); |
270 |
|
} |
271 |
< |
else |
272 |
< |
cm_print(rmtx, ofp); |
271 |
> |
} else { |
272 |
> |
if (outfmt != DTascii) |
273 |
> |
SET_FILE_BINARY(ofp); |
274 |
> |
if (rmtx->ncols > 1) { /* header if actual matrix */ |
275 |
> |
newheader("RADIANCE", ofp); |
276 |
> |
printargs(argc, argv, ofp); |
277 |
> |
fputnow(ofp); |
278 |
> |
fputformat((char *)cm_fmt_id[outfmt], ofp); |
279 |
> |
fputc('\n', ofp); |
280 |
> |
} |
281 |
> |
cm_write(rmtx, outfmt, ofp); |
282 |
> |
} |
283 |
|
cm_free(rmtx); |
284 |
|
} |
285 |
|
if (fflush(ofp) == EOF) { /* final clean-up */ |
289 |
|
cm_free(cmtx); |
290 |
|
return(0); |
291 |
|
userr: |
292 |
< |
fprintf(stderr, "Usage: %s [-n nsteps][-o ospec][-i{f|d}] DCspec [skyf]\n", |
292 |
> |
fprintf(stderr, "Usage: %s [-n nsteps][-o ospec][-i{f|d}][-o{f|d}] DCspec [skyf]\n", |
293 |
|
progname); |
294 |
< |
fprintf(stderr, " or: %s [-n nsteps][-o ospec][-i{f|d}] Vspec Tbsdf.xml Dmat.dat [skyf]\n", |
294 |
> |
fprintf(stderr, " or: %s [-n nsteps][-o ospec][-i{f|d}][-o{f|d}] Vspec Tbsdf.xml Dmat.dat [skyf]\n", |
295 |
|
progname); |
296 |
|
return(1); |
297 |
|
} |