2013.10.08 10:01 "[Tiff] Problem with reading tiff exported from GDAL in C", by Josef Olah

2013.10.08 11:12 "Re: [Tiff] Problem with reading tiff exported from GDAL in C", by Jürgen_Buchmüller

Am Dienstag, den 08.10.2013, 12:01 +0200 schrieb Josef Olah: > Now I’d like to read this tiff file using methods from libtiff webpage

I used tiffinfo on the file, here's the output:

TIFF Directory at offset 0x14e588a (21911690)
    Image Width: 477 Image Length: 7643
    Bits/Sample: 16

  Sample Format: unsigned integer
  Compression Scheme: None
  Photometric Interpretation: min-is-black
  Extra Samples: 2<unspecified, unspecified>
  Samples/Pixel: 3
  Rows/Strip: 8
  Planar Configuration: separate image planes

I would guess that the number of extra samples == 2 is what causes TIFFReadRGBAImage to fail. What kind of extra samples is this? An alpha channel would be one extra sample per RGB triplet, not two.

Your best bet would probably be to directly read scanlines with TIFFReadScanline in the format you already know: it is 5 image planes (R, G, B, extra1, extra2) with 16 bits each and 477 samples per scanline (width). The buffer would thus be have to be 5 times 477 times sizeof(uint16) and the R, G, B values should be 477 uint16s apart.

  uint16 r = buff[0*width+x];
  uint16 g = buff[1*width+x];
  uint16 b = buff[2*width+x];

I believe TIFFScanlineSize should return the required size, so you could just do:

  buff = (uint16*) _TIFFMalloc(TIFFScanlineSize(tif));

Then you'd have to scale the range of the RGB values to whatever your display can handle and perhaps do whatever is required to make use of the extra1 and extra2 values...

HTH

Jürgen