AWARE SYSTEMS
TIFF and LibTiff Mail List Archive

Thread

1999.11.24 14:42 "byte order of >8bpp data", by Frank Warmerdam
1999.11.24 16:31 "Re: byte order of >8bpp data", by Tom Lane
1999.11.24 17:09 "Re: byte order of >8bpp data", by Frank Warmerdam
1999.11.25 06:01 "Re: byte order of >8bpp data", by Tom Lane

1999.11.24 17:09 "Re: byte order of >8bpp data", by Frank Warmerdam

I am trying to read a big-endian 16 bits per sample image on a little endian system, and it seems that libtiff isn't swapping the data into little endian order for me in TIFFReadTile() (or presumably TIFFReadStrip()).

My questions are:

  • Am I wrong? Is libtiff swapping it, but I am missing it somehow?

It should be doing so. Look through the library code at the uses of the tif_postdecode filter. Perhaps you have found a bug wherein that function pointer isn't set up correctly in a particular situation.

  • An alternate form of this question is, do decompressors return image data in local system byte order or the byte order of the underlying tiff file?

Either; but in the former case the decompressor has to override tif_postdecode to prevent an extra swap from happening. The JPEG decompressor actually does this, and I think a couple others do too.

Folks,

Tom is correct, and the library's postdecode functions were in fact performing the byte swapping as required. It turns out the data provider was writing the image data in little endian format in bigendian (MM) TIFF files. I am contacting the vendor about the problem.

In summary, libtiff will take care of returning image data in the local systems byte order, swapping if necessary when you use the TIFFReadScanline(), TIFFReadStrip() or TIFFReadTile() functions.

Note that the TIFFIsByteSwapped() documentation in the TIFFquery.3t man page say:

>TIFFIsByteSwapped returns a non-zero value if the image data was in a >different byte-order than the host machine. Zero is returned if the image >data and local host byte-orders are the same. Data samples that are more >than 8 bits wide must be byte-swapped by the application.

The statement that "data samples that are more than 8 bits wide must be byte-swapped by the application" appears to be wrong, and I will correct the man page unless someone can explain why it shouldn't be changed.

Best regards,

---------------------------------------+--------------------------------------
I set the clouds in motion - turned up | Frank Warmerdam, warmerda@home.com
light and sound - activate the windows | http://members.home.com/warmerda
and watch the world go round - Rush    | Geospatial Programmer for Rent