2016.02.04 07:16 "[Tiff] Image data layout", by Maximilian Heinzler

2016.02.04 07:16 "[Tiff] Image data layout", by Maximilian Heinzler

Hi everyone,

I'm currently implementing TIFF write support in my image library. While testing some larger values for the bits per sample field, I noticed that LibTIFF does some internal swapping of the image data for some of these values. But I’m not sure if it uses the correct method for the 128 bits per sample case. Is this supposed to be correct? Shouldn’t it use a real 128 bit swap here?

Here is the part of the code I’m talking about (from tif_dir.c):

if (tif->tif_flags & TIFF_SWAB) {
     if (td->td_bitspersample == 8)

          tif->tif_postdecode = _TIFFNoPostDecode;
     else if (td->td_bitspersample == 16)
          tif->tif_postdecode = _TIFFSwab16BitData;
     else if (td->td_bitspersample == 24)
          tif->tif_postdecode = _TIFFSwab24BitData;
     else if (td->td_bitspersample == 32)
          tif->tif_postdecode = _TIFFSwab32BitData;
     else if (td->td_bitspersample == 64)
          tif->tif_postdecode = _TIFFSwab64BitData;
     else if (td->td_bitspersample == 128) /* two 64's */
          tif->tif_postdecode = _TIFFSwab64BitData; // Is this correct?


By the way, is there any definition of how the layout of the image data looks like for odd bit depths (like 7)? I can’t find anything in the specification about this and it looks like that in most cases a big endian layout is used regardless of the file’s endianness. For example, if I use ImageMagick to create a TIFF file with 48 bits per sample, the image data is exactly the same for both little and big endian files.

I would appreciate any hints on this subject.