108 |
|
CMATRIX *cm; |
109 |
|
FILE *fp = stdin; |
110 |
|
|
111 |
+ |
if (ncols <= 0) |
112 |
+ |
error(USER, "Non-positive number of columns"); |
113 |
|
if (fname == NULL) |
114 |
|
fname = "<stdin>"; |
115 |
|
else if ((fp = fopen(fname, "r")) == NULL) { |
334 |
|
|
335 |
|
/* Sum together a set of images and write result to stdout */ |
336 |
|
static int |
337 |
< |
sum_images(const char *fspec, const CMATRIX *cv) |
337 |
> |
sum_images(const char *fspec, const CMATRIX *cv, FILE *fout) |
338 |
|
{ |
339 |
|
int myDT = DTfromHeader; |
340 |
|
CMATRIX *pmat; |
350 |
|
FILE *fp; |
351 |
|
int dt, xr, yr; |
352 |
|
COLORV *psp; |
353 |
+ |
/* check for zero */ |
354 |
+ |
if ((scv[RED] == .0) & (scv[GRN] == .0) & (scv[BLU] == .0)) |
355 |
+ |
continue; |
356 |
|
/* open next picture */ |
357 |
|
sprintf(fname, fspec, i); |
358 |
|
if ((fp = fopen(fname, "r")) == NULL) { |
375 |
|
pmat = cm_alloc(myYR, myXR); |
376 |
|
memset(pmat->cmem, 0, sizeof(COLOR)*myXR*myYR); |
377 |
|
/* finish header */ |
378 |
< |
fputformat(myDT==DTrgbe ? COLRFMT : CIEFMT, stdout); |
379 |
< |
fputc('\n', stdout); |
380 |
< |
fprtresolu(myXR, myYR, stdout); |
381 |
< |
fflush(stdout); |
378 |
> |
fputformat(myDT==DTrgbe ? COLRFMT : CIEFMT, fout); |
379 |
> |
fputc('\n', fout); |
380 |
> |
fprtresolu(myXR, myYR, fout); |
381 |
> |
fflush(fout); |
382 |
|
} else if ((dt != myDT) | (xr != myXR) | (yr != myYR)) { |
383 |
|
sprintf(errmsg, "picture '%s' format/size mismatch", |
384 |
|
fname); |
403 |
|
free(scanline); |
404 |
|
/* write scanlines */ |
405 |
|
for (y = 0; y < myYR; y++) |
406 |
< |
if (fwritescan((COLOR *)cm_lval(pmat, y, 0), myXR, stdout) < 0) |
406 |
> |
if (fwritescan((COLOR *)cm_lval(pmat, y, 0), myXR, fout) < 0) |
407 |
|
return(0); |
408 |
|
cm_free(pmat); /* all done */ |
409 |
< |
return(fflush(stdout) == 0); |
409 |
> |
return(fflush(fout) == 0); |
410 |
|
} |
411 |
|
|
412 |
|
/* check to see if a string contains a %d or %o specification */ |
427 |
|
int |
428 |
|
main(int argc, char *argv[]) |
429 |
|
{ |
430 |
< |
CMATRIX *tvec, *Dmat, *Tmat, *ivec, *cvec; |
426 |
< |
struct BSDF_data *btdf; |
430 |
> |
CMATRIX *cvec; |
431 |
|
|
432 |
|
progname = argv[0]; |
433 |
|
|
434 |
< |
if ((argc < 4) | (argc > 5)) { |
435 |
< |
fprintf(stderr, "Usage: %s Vspec Tbsdf.xml Dmat.dat [tregvec]\n", |
436 |
< |
progname); |
434 |
> |
if ((argc < 2) | (argc > 5)) { |
435 |
> |
fprintf(stderr, "Usage: %s DCspec [tregvec]\n", progname); |
436 |
> |
fprintf(stderr, " or: %s Vspec Tbsdf.xml Dmat.dat [tregvec]\n", |
437 |
> |
progname); |
438 |
|
return(1); |
439 |
|
} |
440 |
< |
/* load Tregenza vector */ |
441 |
< |
tvec = cm_load(argv[4], 0, 1, DTascii); /* argv[4]==NULL iff argc==4 */ |
442 |
< |
/* load BTDF */ |
443 |
< |
btdf = load_BSDF(argv[2]); |
444 |
< |
if (btdf == NULL) |
445 |
< |
return(1); |
440 |
> |
|
441 |
> |
if (argc > 3) { /* VTDs expression */ |
442 |
> |
CMATRIX *svec, *Dmat, *Tmat, *ivec; |
443 |
> |
struct BSDF_data *btdf; |
444 |
> |
/* get sky vector */ |
445 |
> |
svec = cm_load(argv[4], 0, 1, DTascii); |
446 |
> |
/* load BSDF */ |
447 |
> |
btdf = load_BSDF(argv[2]); |
448 |
> |
if (btdf == NULL) |
449 |
> |
return(1); |
450 |
|
/* load Daylight matrix */ |
451 |
< |
Dmat = cm_load(argv[3], btdf->ninc, tvec->nrows, DTfromHeader); |
451 |
> |
Dmat = cm_load(argv[3], btdf->ninc, svec->nrows, DTfromHeader); |
452 |
|
/* multiply vector through */ |
453 |
< |
ivec = cm_multiply(Dmat, tvec); |
454 |
< |
cm_free(Dmat); cm_free(tvec); |
455 |
< |
Tmat = cm_bsdf(btdf); /* convert BTDF to matrix */ |
456 |
< |
free_BSDF(btdf); |
457 |
< |
cvec = cm_multiply(Tmat, ivec); /* cvec = component vector */ |
458 |
< |
cm_free(Tmat); cm_free(ivec); |
453 |
> |
ivec = cm_multiply(Dmat, svec); |
454 |
> |
cm_free(Dmat); cm_free(svec); |
455 |
> |
Tmat = cm_bsdf(btdf); /* convert BTDF to matrix */ |
456 |
> |
free_BSDF(btdf); |
457 |
> |
cvec = cm_multiply(Tmat, ivec); /* cvec = component vector */ |
458 |
> |
cm_free(Tmat); cm_free(ivec); |
459 |
> |
} else { /* else just use sky vector */ |
460 |
> |
cvec = cm_load(argv[2], 0, 1, DTascii); |
461 |
> |
} |
462 |
> |
|
463 |
|
if (hasNumberFormat(argv[1])) { /* generating image */ |
464 |
|
SET_FILE_BINARY(stdout); |
465 |
|
newheader("RADIANCE", stdout); |
466 |
|
printargs(argc, argv, stdout); |
467 |
|
fputnow(stdout); |
468 |
< |
if (!sum_images(argv[1], cvec)) |
468 |
> |
if (!sum_images(argv[1], cvec, stdout)) |
469 |
|
return(1); |
470 |
|
} else { /* generating vector */ |
471 |
|
CMATRIX *Vmat = cm_load(argv[1], 0, cvec->nrows, DTfromHeader); |