16 |
|
|
17 |
|
char *progname; /* global argv[0] */ |
18 |
|
|
19 |
< |
/* Data types for matrix loading */ |
19 |
> |
/* Data types for file loading */ |
20 |
|
enum {DTfromHeader, DTascii, DTfloat, DTdouble, DTrgbe, DTxyze}; |
21 |
|
|
22 |
|
/* A color coefficient matrix -- vectors have ncols==1 */ |
125 |
|
break; |
126 |
|
default: |
127 |
|
error(USER, "unexpected data type in cm_load()"); |
128 |
– |
return(NULL); |
128 |
|
} |
129 |
|
if (nrows <= 0) { /* don't know length? */ |
130 |
|
int guessrows = 147; /* usually big enough */ |
134 |
|
long endpos = ftell(fp); |
135 |
|
long elemsiz = 3*(dtype==DTfloat ? |
136 |
|
sizeof(float) : sizeof(double)); |
137 |
< |
guessrows = (endpos - startpos)/elemsiz; |
137 |
> |
|
138 |
> |
if ((endpos - startpos) % (ncols*elemsiz)) { |
139 |
> |
sprintf(errmsg, |
140 |
> |
"improper length for binary file '%s'", |
141 |
> |
fname); |
142 |
> |
error(USER, errmsg); |
143 |
> |
} |
144 |
> |
guessrows = (endpos - startpos)/(ncols*elemsiz); |
145 |
|
if (fseek(fp, startpos, SEEK_SET) < 0) { |
146 |
|
sprintf(errmsg, |
147 |
|
"fseek() error on file '%s'", |
148 |
|
fname); |
149 |
|
error(SYSTEM, errmsg); |
150 |
|
} |
151 |
< |
if ((endpos - startpos) % elemsiz == 0) |
146 |
< |
nrows = guessrows; /* confident */ |
151 |
> |
nrows = guessrows; /* we're confident */ |
152 |
|
} |
153 |
|
} |
154 |
|
cm = cm_alloc(guessrows, ncols); |
215 |
|
copycolor(cvp, dc); |
216 |
|
cvp += 3; |
217 |
|
} |
213 |
– |
|
218 |
|
} else /* dtype == DTfloat */ { |
219 |
|
float fc[3]; /* load from float */ |
220 |
|
COLORV *cvp = cm->cmem; |
342 |
|
error(SYSTEM, "out of memory in sum_images()"); |
343 |
|
pmat = cm_alloc(myYR, myXR); |
344 |
|
memset(pmat->cmem, 0, sizeof(COLOR)*myXR*myYR); |
345 |
+ |
/* finish header */ |
346 |
+ |
fputformat(myDT==DTrgbe ? COLRFMT : CIEFMT, stdout); |
347 |
+ |
fputc('\n', stdout); |
348 |
+ |
fprtresolu(myXR, myYR, stdout); |
349 |
+ |
fflush(stdout); |
350 |
|
} else if ((dt != myDT) | (xr != myXR) | (yr != myYR)) { |
351 |
|
sprintf(errmsg, "picture '%s' format/size mismatch", |
352 |
|
fname); |
369 |
|
fclose(fp); /* done this picture */ |
370 |
|
} |
371 |
|
free(scanline); |
363 |
– |
/* finish header */ |
364 |
– |
fputformat(myDT==DTrgbe ? COLRFMT : CIEFMT, stdout); |
365 |
– |
fputc('\n', stdout); |
366 |
– |
fprtresolu(myXR, myYR, stdout); |
372 |
|
/* write scanlines */ |
373 |
|
for (y = 0; y < myYR; y++) |
374 |
|
if (fwritescan((COLOR *)cm_lval(pmat, y, 0), myXR, stdout) < 0) |
395 |
|
int |
396 |
|
main(int argc, char *argv[]) |
397 |
|
{ |
398 |
< |
CMATRIX *tvec, *Dmat, *Tmat, *vtmp, *cvec; |
398 |
> |
CMATRIX *tvec, *Dmat, *Tmat, *ivec, *cvec; |
399 |
|
struct BSDF_data *btdf; |
400 |
|
|
401 |
|
progname = argv[0]; |
416 |
|
error(USER, errmsg); |
417 |
|
} |
418 |
|
/* multiply vector through */ |
419 |
< |
vtmp = cm_multiply(Dmat, tvec); |
419 |
> |
ivec = cm_multiply(Dmat, tvec); |
420 |
|
cm_free(Dmat); cm_free(tvec); |
421 |
|
Tmat = cm_bsdf(btdf); /* convert BTDF to matrix */ |
422 |
|
free_BSDF(btdf); |
423 |
< |
cvec = cm_multiply(Tmat, vtmp); /* cvec = component vector */ |
424 |
< |
cm_free(Tmat); cm_free(vtmp); |
423 |
> |
cvec = cm_multiply(Tmat, ivec); /* cvec = component vector */ |
424 |
> |
cm_free(Tmat); cm_free(ivec); |
425 |
|
if (hasDecimalSpec(argv[1])) { /* generating image */ |
426 |
|
SET_FILE_BINARY(stdout); |
427 |
|
newheader("RADIANCE", stdout); |