2008.06.06 21:47 "[Tiff] Mac OS X universal binary PowerPC endian issues", by Ryan Schmidt

2008.06.06 21:47 "[Tiff] Mac OS X universal binary PowerPC endian issues", by Ryan Schmidt

Hello. I use MacPorts [1] to install tiff 3.8.2. There is no problem when building for only the native architecture. But a ticket was filed in the MacPorts issue tracker [2] for a problem when a universal binary of tiff is built using the usual Apple-recommended procedure [3] (configure and build once using "-arch i386 -arch ppc"). The problem is that the configure-time macros tiff uses to determine the endianness always detect Intel endianness in this case, so the PowerPC binaries don't function correctly:

$ tiffinfo file.tiff
file.tiff:
file.tiff: Not a TIFF file, bad version number 10752 (0x2a00).
$

There was a discussion about this problem on this list in October 2007 [4] with various fixes suggested but it appears nothing came of it as I've also tested version 4.0.0beta2 released in May 2008 and it still has the problem, though the error is different:

$ tiffinfo file.tiff
file.tiff:
tif_open.c:112: failed assertion `n.a16==1'
Abort trap
$

I committed a fix for this bug to the MacPorts repository [5] which works by patching the headers after ./configure is run to change the endianness definitions based on the __BIG_ENDIAN__ constant, as per instructions posted by Dominik Leonhardt [6]. Now it seems to work correctly (3.8.2):

$ tiffinfo file.tiff
file.tiff:
TIFF Directory at offset 0x36e8 (14056)
   Image Width: 136 Image Length: 231
   Bits/Sample: 8
   Sample Format: unsigned integer
   Compression Scheme: LZW
   Photometric Interpretation: RGB color
   Orientation: row 0 top, col 0 lhs
   Samples/Pixel: 3
   Rows/Strip: 321
   Planar Configuration: single image plane
   ICC Profile: <present>, 0 bytes
   Predictor: horizontal differencing 2 (0x2)
$

Output with 4.0.0beta2 and our patch is the same except for this line:

   ICC Profile: <present>, 1320 bytes

Our patch works for MacPorts, but I'm sure you'd want a cleaner fix for inclusion in your sources (e.g. one which doesn't involve patching after running configure). Also, there was a concern in the prior thread that the __BIG_ENDIAN__ constant would not exist on some other platforms. If that's so, then the use of __BIG_ENDIAN__ could be restricted to Mac OS X only, and other platforms could continue to use your configure-time checks. An example of this was posted to the list in another thread in October 2007 [7], using the __APPLE__ constant to check for Mac OS X.

Finally, a concern was voiced in our ticket that tiff's "make check" didn't catch this problem.

[1] http://www.macports.org/

[2] http://trac.macports.org/ticket/13946

[3] http://developer.apple.com/technotes/tn2005/tn2137.html

[4] http://www.asmail.be/msg0055159178.html

[5] http://trac.macports.org/changeset/37397

[6] http://www.dleo.de/howto/compile_imagemagick_on_os_x

[7] http://www.asmail.be/msg0055158922.html