113 |
|
printargs(gargc-1, gargv, fout); /* add our command */ |
114 |
|
fprintf(fout, "SOFTWARE= %s\n", VersionID); |
115 |
|
fputnow(fout); |
116 |
< |
fputs("NCOMP=3\n", fout); /* always RGB */ |
116 |
> |
fputncomp(NCSAMP, fout); |
117 |
|
if (info != NULL) /* add extra info if given */ |
118 |
|
fputs(info, fout); |
119 |
|
if ((outfmt == 'f') | (outfmt == 'd')) |
143 |
|
LUENT *lep; |
144 |
|
STREAMOUT *sop; |
145 |
|
char *cp; |
146 |
< |
|
146 |
> |
|
147 |
> |
info[0] = '\0'; |
148 |
|
if (ospec == NULL) { /* use stdout? */ |
149 |
|
if (!noopen & !using_stdout) { |
150 |
|
if (outfmt != 'a') |
271 |
|
} |
272 |
|
break; |
273 |
|
case 'f': /* binary float */ |
274 |
< |
if (getbinary((char *)vf, sizeof(float), 3, stdin) != 3) |
274 |
> |
if (getbinary(vf, sizeof(float), 3, stdin) != 3) |
275 |
|
return(-1); |
276 |
|
VCOPY(vec, vf); |
277 |
|
break; |
278 |
|
case 'd': /* binary double */ |
279 |
< |
if (getbinary((char *)vd, sizeof(double), 3, stdin) != 3) |
279 |
> |
if (getbinary(vd, sizeof(double), 3, stdin) != 3) |
280 |
|
return(-1); |
281 |
|
VCOPY(vec, vd); |
282 |
|
break; |
289 |
|
|
290 |
|
/* Put out ray contribution to file */ |
291 |
|
static void |
292 |
< |
put_contrib(const DCOLOR cnt, FILE *fout) |
292 |
> |
put_contrib(const DCOLORV *cnt, FILE *fout) |
293 |
|
{ |
294 |
|
double sf = 1; |
295 |
< |
COLOR fv; |
296 |
< |
COLR cv; |
295 |
> |
SCOLOR fv; |
296 |
> |
SCOLR cv; |
297 |
> |
int i; |
298 |
|
|
299 |
|
if (accumulate > 1) |
300 |
|
sf = 1./(double)accumulate; |
301 |
|
switch (outfmt) { |
302 |
|
case 'a': |
303 |
< |
if (accumulate > 1) |
304 |
< |
fprintf(fout, "%.6e\t%.6e\t%.6e\t", |
303 |
< |
sf*cnt[0], sf*cnt[1], sf*cnt[2]); |
304 |
< |
else |
305 |
< |
fprintf(fout, "%.6e\t%.6e\t%.6e\t", |
306 |
< |
cnt[0], cnt[1], cnt[2]); |
303 |
> |
for (i = 0; i < NCSAMP; i++) |
304 |
> |
fprintf(fout, "%.6e\t", sf*cnt[i]); |
305 |
|
break; |
306 |
|
case 'f': |
307 |
< |
if (accumulate > 1) { |
308 |
< |
copycolor(fv, cnt); |
309 |
< |
scalecolor(fv, sf); |
310 |
< |
} else |
311 |
< |
copycolor(fv, cnt); |
314 |
< |
putbinary(fv, sizeof(float), 3, fout); |
307 |
> |
for (i = NCSAMP; i-- > 0; ) |
308 |
> |
fv[i] = cnt[i]; |
309 |
> |
if (accumulate > 1) |
310 |
> |
scalescolor(fv, sf); |
311 |
> |
putbinary(fv, sizeof(COLORV), NCSAMP, fout); |
312 |
|
break; |
313 |
|
case 'd': |
314 |
|
if (accumulate > 1) { |
315 |
< |
DCOLOR dv; |
316 |
< |
copycolor(dv, cnt); |
317 |
< |
scalecolor(dv, sf); |
318 |
< |
putbinary(dv, sizeof(double), 3, fout); |
315 |
> |
DCOLORV dv[MAXCSAMP]; |
316 |
> |
for (i = NCSAMP; i-- > 0; ) |
317 |
> |
dv[i] = sf*cnt[i]; |
318 |
> |
putbinary(dv, sizeof(DCOLORV), NCSAMP, fout); |
319 |
|
} else |
320 |
< |
putbinary(cnt, sizeof(double), 3, fout); |
320 |
> |
putbinary(cnt, sizeof(DCOLORV), NCSAMP, fout); |
321 |
|
break; |
322 |
|
case 'c': |
323 |
+ |
for (i = NCSAMP; i-- > 0; ) |
324 |
+ |
fv[i] = cnt[i]; |
325 |
|
if (accumulate > 1) |
326 |
< |
setcolr(cv, sf*cnt[0], sf*cnt[1], sf*cnt[2]); |
327 |
< |
else |
328 |
< |
setcolr(cv, cnt[0], cnt[1], cnt[2]); |
330 |
< |
putbinary(cv, sizeof(cv), 1, fout); |
326 |
> |
scalescolor(fv, sf); |
327 |
> |
scolor_scolr(cv, fv); |
328 |
> |
putbinary(cv, 1, LSCOLR, fout); |
329 |
|
break; |
330 |
|
default: |
331 |
|
error(INTERNAL, "botched output format"); |
340 |
|
STREAMOUT *sop = getostream(mp->outspec, mp->modname, mp->bin0, 0); |
341 |
|
int j; |
342 |
|
|
343 |
< |
put_contrib(mp->cbin[0], sop->ofp); |
343 |
> |
put_contrib(mp->cbin, sop->ofp); |
344 |
|
if (mp->nbins > 3 && /* minor optimization */ |
345 |
|
sop == getostream(mp->outspec, mp->modname, mp->bin0+1, 0)) { |
346 |
|
for (j = 1; j < mp->nbins; j++) |
347 |
< |
put_contrib(mp->cbin[j], sop->ofp); |
347 |
> |
put_contrib(mcbin(mp,j), sop->ofp); |
348 |
|
} else { |
349 |
|
for (j = 1; j < mp->nbins; j++) { |
350 |
|
sop = getostream(mp->outspec, mp->modname, mp->bin0+j, 0); |
351 |
< |
put_contrib(mp->cbin[j], sop->ofp); |
351 |
> |
put_contrib(mcbin(mp,j), sop->ofp); |
352 |
|
} |
353 |
|
} |
354 |
|
} |
391 |
|
|
392 |
|
/* Get ray contribution from previous file */ |
393 |
|
static int |
394 |
< |
get_contrib(DCOLOR cnt, FILE *finp) |
394 |
> |
get_contrib(DCOLORV *cnt, FILE *finp) |
395 |
|
{ |
396 |
< |
COLOR fv; |
397 |
< |
COLR cv; |
396 |
> |
SCOLOR fv; |
397 |
> |
SCOLR cv; |
398 |
> |
int i; |
399 |
|
|
400 |
|
switch (outfmt) { |
401 |
|
case 'a': |
402 |
< |
return(fscanf(finp,"%lf %lf %lf",&cnt[0],&cnt[1],&cnt[2]) == 3); |
403 |
< |
case 'f': |
404 |
< |
if (getbinary(fv, sizeof(fv[0]), 3, finp) != 3) |
406 |
< |
return(0); |
407 |
< |
copycolor(cnt, fv); |
402 |
> |
for (i = 0; i < NCSAMP; i++) |
403 |
> |
if (fscanf(finp, "%lf", &cnt[i]) != 1) |
404 |
> |
return(0); |
405 |
|
return(1); |
406 |
|
case 'd': |
407 |
< |
return(getbinary(cnt, sizeof(cnt[0]), 3, finp) == 3); |
407 |
> |
return(getbinary(cnt, sizeof(DCOLORV), NCSAMP, finp) == NCSAMP); |
408 |
> |
case 'f': |
409 |
> |
if (getbinary(fv, sizeof(COLORV), NCSAMP, finp) != NCSAMP) |
410 |
> |
return(0); |
411 |
> |
break; |
412 |
|
case 'c': |
413 |
< |
if (getbinary(cv, sizeof(cv), 1, finp) != 1) |
413 |
> |
if (getbinary(cv, 1, LSCOLR, finp) != LSCOLR) |
414 |
|
return(0); |
415 |
< |
colr_color(fv, cv); |
416 |
< |
copycolor(cnt, fv); |
416 |
< |
return(1); |
415 |
> |
scolr_scolor(fv, cv); |
416 |
> |
break; |
417 |
|
default: |
418 |
|
error(INTERNAL, "botched output format"); |
419 |
|
} |
420 |
< |
return(0); /* pro forma return */ |
420 |
> |
/* copy result from SCOLOR */ |
421 |
> |
for (i = NCSAMP; i-- > 0; ) |
422 |
> |
cnt[i] = fv[i]; |
423 |
> |
return(1); |
424 |
|
} |
425 |
|
|
426 |
|
|
451 |
|
LUENT *oent; |
452 |
|
int xr, yr; |
453 |
|
STREAMOUT *sop; |
454 |
< |
DCOLOR rgbv; |
454 |
> |
DCOLORV contr[MAXCSAMP]; |
455 |
|
|
456 |
|
if (outfmt == 'a') |
457 |
|
fmode = "r"; |
458 |
< |
outvfmt = formstr(outfmt); |
458 |
> |
outvfmt = (char *)formstr(outfmt); |
459 |
|
/* reload modifier values */ |
460 |
|
for (i = 0; i < nmods; i++) { |
461 |
|
mp = (MODCONT *)lu_find(&modconttab,modname[i])->data; |
496 |
|
error(USER, errmsg); |
497 |
|
} |
498 |
|
} |
499 |
< |
/* read in RGB value */ |
500 |
< |
if (!get_contrib(rgbv, sop->ofp)) { |
499 |
> |
/* read in spectral value */ |
500 |
> |
if (!get_contrib(contr, sop->ofp)) { |
501 |
|
if (!j) { |
502 |
|
fclose(sop->ofp); |
503 |
|
break; /* ignore empty file */ |
508 |
|
error(USER, errmsg); |
509 |
|
} |
510 |
|
break; |
511 |
< |
} |
512 |
< |
copycolor(mp->cbin[j], rgbv); |
511 |
> |
} |
512 |
> |
memcpy(mcbin(mp,j), contr, DCOLORSIZ); |
513 |
|
} |
514 |
|
} |
515 |
|
lu_doall(&ofiletab, &myclose, NULL); /* close all files */ |
554 |
|
error(USER, "cannot recover ASCII output"); |
555 |
|
return; |
556 |
|
case 'f': |
557 |
< |
outvsiz = sizeof(float)*3; |
557 |
> |
outvsiz = sizeof(float)*NCSAMP; |
558 |
|
break; |
559 |
|
case 'd': |
560 |
< |
outvsiz = sizeof(double)*3; |
560 |
> |
outvsiz = sizeof(double)*NCSAMP; |
561 |
|
break; |
562 |
|
case 'c': |
563 |
< |
outvsiz = sizeof(COLR); |
563 |
> |
outvsiz = LSCOLR; |
564 |
|
break; |
565 |
|
default: |
566 |
|
error(INTERNAL, "botched output format"); |
567 |
|
return; |
568 |
|
} |
569 |
< |
outvfmt = formstr(outfmt); |
569 |
> |
outvfmt = (char *)formstr(outfmt); |
570 |
|
/* check modifier outputs */ |
571 |
|
for (i = 0; i < nmods; i++) { |
572 |
|
mp = (MODCONT *)lu_find(&modconttab,modname[i])->data; |