AWARE SYSTEMS
TIFF and LibTiff Mail List Archive

1998.02.18 10:25 "tiff lib question / bug (?)", by Raymond Walsh

Hello

Heres my setup:

Version 3.4
OS: Win NT ( 4.0 servicepak 3 in case you're interested )
Compiler: VC++ 5.0
Target: Win32 ( debug )

I created the *.lib by using the *.mak file I found in the \contrib\WinNT folder. I know thats not a supported version, but the Windows specific aspect doesnt seem to be my trouble... Please read on :)

i'm dabbling with this wonderful tiff library. I have TIFFs created in Photoshop 4.0 Macintosh, saved as PC & Mac tiffs with and without LZW ( all 4 cases )

I open the tiff,
tif = TIFFOpen( (*path), "ru" ); //read, un-memory mapped ( the
memory-mapped version crashes my machine but thats another story )

...get the height & width...
TIFFGetField( tif, TIFFTAG_IMAGEWIDTH, &w );
TIFFGetField( tif, TIFFTAG_IMAGELENGTH, &h );

....get my memory buffer....
...

....and read the bits....
TIFFReadRGBAImage( tif, w, h, raster, 0 );

...and close the file

TIFFReadRGBAImage has the alpha channel as all 0xff. Every darn pixel! I know for a fact that there are other alpha values in there.... so i step into code. :)

I follow it down into:

pickTileContigCase(TIFFRGBAImage* img)
...
switch (img->photometric)
...
case PHOTOMETRIC_RGB:
switch (img->bitspersample)
{
case 8:
//ok so I have a 8 bit per sample, RGB, photometric TIFF...
if (!img->Map)    //map == 0, and my ->alpha == 0, so i get the "ignore
alpha" "put" routine... but wait darn it, the Alpha shouldnt be 0
    {
     if (img->alpha == EXTRASAMPLE_ASSOCALPHA)
     put = putRGBAAcontig8bittile;
     else if (img->alpha == EXTRASAMPLE_UNASSALPHA)
     put = putRGBUAcontig8bittile;
     else
     put = putRGBcontig8bittile;    <--------------------------- im getting
this one, but I want one of the other 2...
    }

//so if I add a line ( or two ) to:
"int TIFFRGBAImageBegin(TIFFRGBAImage* img, TIFF* tif, int stop, char
emsg[1024])"...I can make the image appear the way I want it to.

in "TIFFRGBAImageBegin" ( tif_getimage.c )
theres one "switch" right away. then the following code:

    img->alpha = 0;
    TIFFGetFieldDefaulted(tif, TIFFTAG_SAMPLESPERPIXEL,
&img->samplesperpixel);
    TIFFGetFieldDefaulted(tif, TIFFTAG_EXTRASAMPLES,&extrasamples,
&sampleinfo);
    if (extrasamples == 1)
{    //i've added a bracket here cuz of the line(s) i'm adding
   switch (sampleinfo[0])
  {
  case EXTRASAMPLE_ASSOCALPHA: /* data is pre-multiplied */
  case EXTRASAMPLE_UNASSALPHA: /* data is not pre-multiplied */
   img->alpha = sampleinfo[0];
   break;
  }
.........................AFTER THAT CODE I'M
ADDING..............................................
 //if the alpha is still empty, but there are 4 channels, then one of those
channels is the alpha, damnit
 //so we're gunna make it one of the 2 types of alphachannels
 //photoshop4.0 Macintosh seems to make sampleinfo[0] == 0
  if( img->alpha == 0 )
   {
   if( img->samplesperpixel == 4 )
   {
   //this is arbitrary, take your pick...
   // EXTRASAMPLE_UNASSALPHA | EXTRASAMPLE_ASSOCALPHA
    img->alpha = EXTRASAMPLE_UNASSALPHA ;
   }
  }
 }

Am I messing up your awesome library? or have I found some obscure alphachannel related quirk? or does photoshop generate substandard TIFF images? Or am I an idiot who should just learn to live with it? :)

Did you get all that? If you want or need more information I can probably explain that in more detail.

thanks for your attention
ray