13 |
|
#include <time.h> |
14 |
|
#include <string.h> |
15 |
|
|
16 |
+ |
#include "platform.h" |
17 |
|
#include "tiffio.h" |
18 |
|
#include "color.h" |
19 |
|
#include "resolu.h" |
192 |
|
exit(0); |
193 |
|
userr: |
194 |
|
fprintf(stderr, |
195 |
< |
"Usage: %s [-z|-L|-l|-f|-w][-b][-e +/-stops][-g gamma] {in.pic|-} out.tif\n", |
195 |
> |
"Usage: %s [-z|-L|-l|-f|-w][-b][-e +/-stops][-g gamma] {in.hdr|-} out.tif\n", |
196 |
|
progname); |
197 |
|
fprintf(stderr, |
198 |
< |
" Or: %s -r [-x][-e +/-stops][-g gamma] in.tif [out.pic|-]\n", |
198 |
> |
" Or: %s -r [-x][-e +/-stops][-g gamma] in.tif [out.hdr|-]\n", |
199 |
|
progname); |
200 |
|
exit(1); |
201 |
|
} |
276 |
|
cpcolormat(cvts.cmat, xyz2rgbmat); |
277 |
|
SET(C_CXFM|C_GAMUT); |
278 |
|
} else if (cvts.comp == COMPRESSION_SGILOG) |
279 |
< |
SET(C_GAMUT); |
279 |
> |
SET(C_GAMUT); /* may be outside XYZ gamut */ |
280 |
|
if (cvts.pconf != PLANARCONFIG_CONTIG) |
281 |
|
quiterr("cannot handle separate Luv planes"); |
282 |
|
TIFFSetField(cvts.tif, TIFFTAG_SGILOGDATAFMT, |
363 |
|
quiterr("unknown input image resolution"); |
364 |
|
|
365 |
|
if (!TIFFGetField(cvts.tif, TIFFTAG_STONITS, &cvts.stonits)) |
366 |
< |
cvts.stonits = 1.; |
366 |
> |
cvts.stonits = -1.; |
367 |
|
|
368 |
|
if (!TIFFGetField(cvts.tif, TIFFTAG_DATETIME, &cp)) |
369 |
|
cvts.capdate[0] = '\0'; |
381 |
|
if (cvts.pixrat < .99 || cvts.pixrat > 1.01) |
382 |
|
fputaspect(cvts.pixrat, cvts.rfp); |
383 |
|
if (CHK(C_XYZE)) { |
384 |
< |
fputexpos(pow(2.,(double)cvts.bradj)/cvts.stonits, cvts.rfp); |
384 |
> |
if (cvts.stonits > .0) |
385 |
> |
fputexpos(pow(2.,(double)cvts.bradj)/cvts.stonits, cvts.rfp); |
386 |
|
fputformat(CIEFMT, cvts.rfp); |
387 |
|
} else { |
388 |
|
if (CHK(C_PRIM)) |
389 |
|
fputprims(cvts.prims, cvts.rfp); |
390 |
< |
fputexpos(WHTEFFICACY*pow(2.,(double)cvts.bradj)/cvts.stonits, |
391 |
< |
cvts.rfp); |
390 |
> |
if (cvts.stonits > .0) |
391 |
> |
fputexpos(WHTEFFICACY*pow(2.,(double)cvts.bradj)/cvts.stonits, |
392 |
> |
cvts.rfp); |
393 |
|
fputformat(COLRFMT, cvts.rfp); |
394 |
|
} |
395 |
|
if (cvts.capdate[0]) |
416 |
|
cvts.rfp = stdout; |
417 |
|
else if ((cvts.rfp = fopen(av[ac+1], "w")) == NULL) |
418 |
|
quiterr("cannot open Radiance output picture"); |
419 |
+ |
SET_FILE_BINARY(cvts.rfp); |
420 |
|
/* start output header */ |
421 |
|
newheader("RADIANCE", cvts.rfp); |
422 |
|
printargs(ac, av, cvts.rfp); |
573 |
|
SAMPLEFORMAT_IEEEFP); |
574 |
|
cvts.tf = Color2RfGfBf; |
575 |
|
SET(C_RFLT); |
576 |
+ |
CLR(C_GAMUT); |
577 |
|
} else |
578 |
|
cvts.tf = Colr2RGB; |
579 |
|
break; |
636 |
|
cvts.rfp = stdin; |
637 |
|
else if ((cvts.rfp = fopen(av[ac], "r")) == NULL) |
638 |
|
quiterr("cannot open Radiance input picture"); |
639 |
+ |
SET_FILE_BINARY(cvts.rfp); |
640 |
|
/* open TIFF file */ |
641 |
|
if ((cvts.tif = TIFFOpen(av[ac+1], "w")) == NULL) |
642 |
|
quiterr("cannot open TIFF output"); |
661 |
|
if (CHK(C_RFLT|C_TWRD|C_TFLT|C_GRY) != (C_RFLT|C_TFLT)) |
662 |
|
quiterr("internal error 1 in Luv2Color"); |
663 |
|
|
664 |
+ |
if (cvts.pconf != PLANARCONFIG_CONTIG) |
665 |
+ |
quiterr("cannot handle separate 32-bit color planes"); |
666 |
+ |
|
667 |
|
if (TIFFReadScanline(cvts.tif, cvts.t.p, y, 0) < 0) |
668 |
|
quiterr("error reading TIFF input"); |
669 |
|
/* also works for float RGB */ |
702 |
|
if (CHK(C_RFLT|C_TWRD|C_TFLT|C_GRY) != (C_TWRD|C_RFLT)) |
703 |
|
quiterr("internal error 1 in RRGGBB2Color"); |
704 |
|
|
705 |
+ |
if (cvts.pconf != PLANARCONFIG_CONTIG) |
706 |
+ |
quiterr("cannot handle separate 16-bit color planes"); |
707 |
+ |
|
708 |
|
if (TIFFReadScanline(cvts.tif, cvts.t.p, y, 0) < 0) |
709 |
|
quiterr("error reading TIFF input"); |
710 |
|
|
721 |
|
if (CHK(C_CXFM)) |
722 |
|
colortrans(cvts.r.colors[x], cvts.cmat, |
723 |
|
cvts.r.colors[x]); |
712 |
– |
if (CHK(C_GAMUT)) |
713 |
– |
clipgamut(cvts.r.colors[x], cvts.t.fp[3*x + 1], |
714 |
– |
CGAMUT_LOWER, cblack, cwhite); |
724 |
|
} |
725 |
|
if (cvts.bradj) { |
726 |
|
d = pow(2.,(double)cvts.bradj); |
979 |
|
if (freadscan(cvts.r.colors, cvts.xmax, cvts.rfp) < 0) |
980 |
|
quiterr("error reading Radiance picture"); |
981 |
|
|
982 |
< |
for (x = cvts.xmax; x--; ) |
982 |
> |
for (x = cvts.xmax; x--; ) { |
983 |
> |
if (CHK(C_CXFM)) { |
984 |
> |
colortrans(cvts.r.colors[x], cvts.cmat, |
985 |
> |
cvts.r.colors[x]); |
986 |
> |
if (CHK(C_GAMUT)) |
987 |
> |
clipgamut(cvts.r.colors[x], bright(cvts.r.colors[x]), |
988 |
> |
CGAMUT_LOWER, cblack, cwhite); |
989 |
> |
} |
990 |
|
for (i = 3; i--; ) { |
991 |
|
register float f = m*colval(cvts.r.colors[x],i); |
992 |
|
if (f <= 0) |
999 |
|
else |
1000 |
|
cvts.t.wp[3*x + i] = (int)((float)(1L<<16)*f); |
1001 |
|
} |
1002 |
+ |
} |
1003 |
|
|
1004 |
|
if (TIFFWriteScanline(cvts.tif, cvts.t.p, y, 0) < 0) |
1005 |
|
quiterr("error writing TIFF output"); |