--- ray/src/px/ra_tiff.c 2004/03/28 20:33:14 2.28 +++ ray/src/px/ra_tiff.c 2005/08/19 02:31:32 2.32 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: ra_tiff.c,v 2.28 2004/03/28 20:33:14 schorsch Exp $"; +static const char RCSid[] = "$Id: ra_tiff.c,v 2.32 2005/08/19 02:31:32 greg Exp $"; #endif /* * Program to convert between RADIANCE and TIFF files. @@ -275,7 +275,7 @@ initfromtif(void) /* initialize conversion from TIFF cpcolormat(cvts.cmat, xyz2rgbmat); SET(C_CXFM|C_GAMUT); } else if (cvts.comp == COMPRESSION_SGILOG) - SET(C_GAMUT); + SET(C_GAMUT); /* may be outside XYZ gamut */ if (cvts.pconf != PLANARCONFIG_CONTIG) quiterr("cannot handle separate Luv planes"); TIFFSetField(cvts.tif, TIFFTAG_SGILOGDATAFMT, @@ -362,7 +362,7 @@ initfromtif(void) /* initialize conversion from TIFF quiterr("unknown input image resolution"); if (!TIFFGetField(cvts.tif, TIFFTAG_STONITS, &cvts.stonits)) - cvts.stonits = 1.; + cvts.stonits = -1.; if (!TIFFGetField(cvts.tif, TIFFTAG_DATETIME, &cp)) cvts.capdate[0] = '\0'; @@ -380,13 +380,15 @@ initfromtif(void) /* initialize conversion from TIFF if (cvts.pixrat < .99 || cvts.pixrat > 1.01) fputaspect(cvts.pixrat, cvts.rfp); if (CHK(C_XYZE)) { - fputexpos(pow(2.,(double)cvts.bradj)/cvts.stonits, cvts.rfp); + if (cvts.stonits > .0) + fputexpos(pow(2.,(double)cvts.bradj)/cvts.stonits, cvts.rfp); fputformat(CIEFMT, cvts.rfp); } else { if (CHK(C_PRIM)) fputprims(cvts.prims, cvts.rfp); - fputexpos(WHTEFFICACY*pow(2.,(double)cvts.bradj)/cvts.stonits, - cvts.rfp); + if (cvts.stonits > .0) + fputexpos(WHTEFFICACY*pow(2.,(double)cvts.bradj)/cvts.stonits, + cvts.rfp); fputformat(COLRFMT, cvts.rfp); } if (cvts.capdate[0]) @@ -569,6 +571,7 @@ initfromrad(void) /* initialize input from a Radianc SAMPLEFORMAT_IEEEFP); cvts.tf = Color2RfGfBf; SET(C_RFLT); + CLR(C_GAMUT); } else cvts.tf = Colr2RGB; break; @@ -655,6 +658,9 @@ Luv2Color( /* read/convert/write Luv->COLOR scanline if (CHK(C_RFLT|C_TWRD|C_TFLT|C_GRY) != (C_RFLT|C_TFLT)) quiterr("internal error 1 in Luv2Color"); + if (cvts.pconf != PLANARCONFIG_CONTIG) + quiterr("cannot handle separate 32-bit color planes"); + if (TIFFReadScanline(cvts.tif, cvts.t.p, y, 0) < 0) quiterr("error reading TIFF input"); /* also works for float RGB */ @@ -693,6 +699,9 @@ RRGGBB2Color( /* read/convert/write RGB16->COLOR sca if (CHK(C_RFLT|C_TWRD|C_TFLT|C_GRY) != (C_TWRD|C_RFLT)) quiterr("internal error 1 in RRGGBB2Color"); + if (cvts.pconf != PLANARCONFIG_CONTIG) + quiterr("cannot handle separate 16-bit color planes"); + if (TIFFReadScanline(cvts.tif, cvts.t.p, y, 0) < 0) quiterr("error reading TIFF input"); @@ -709,9 +718,6 @@ RRGGBB2Color( /* read/convert/write RGB16->COLOR sca if (CHK(C_CXFM)) colortrans(cvts.r.colors[x], cvts.cmat, cvts.r.colors[x]); - if (CHK(C_GAMUT)) - clipgamut(cvts.r.colors[x], cvts.t.fp[3*x + 1], - CGAMUT_LOWER, cblack, cwhite); } if (cvts.bradj) { d = pow(2.,(double)cvts.bradj); @@ -970,7 +976,14 @@ Color2RRGGBB( /* read/convert/write COLOR->RGB16 sca if (freadscan(cvts.r.colors, cvts.xmax, cvts.rfp) < 0) quiterr("error reading Radiance picture"); - for (x = cvts.xmax; x--; ) + for (x = cvts.xmax; x--; ) { + if (CHK(C_CXFM)) { + colortrans(cvts.r.colors[x], cvts.cmat, + cvts.r.colors[x]); + if (CHK(C_GAMUT)) + clipgamut(cvts.r.colors[x], bright(cvts.r.colors[x]), + CGAMUT_LOWER, cblack, cwhite); + } for (i = 3; i--; ) { register float f = m*colval(cvts.r.colors[x],i); if (f <= 0) @@ -983,6 +996,7 @@ Color2RRGGBB( /* read/convert/write COLOR->RGB16 sca else cvts.t.wp[3*x + i] = (int)((float)(1L<<16)*f); } + } if (TIFFWriteScanline(cvts.tif, cvts.t.p, y, 0) < 0) quiterr("error writing TIFF output");