| AWARE [SYSTEMS] | Imaging expertise for the Delphi developer | |||||||
![]() |
TIFF and LibTiff Mailing List Archive | |||||||
LibTiff Mailing List
TIFF and LibTiff Mailing List Archive Contact
The TIFF Mailing List Homepage |
Thread2007.10.23 08:38 "universal build patch", by Kai-uwe BehrmannAttached is a patch for v3.9.0beta to run libtiff in a universal build on osX fro one configuration. It is just for testing libtiff, the tools are unchanged as it is not clear, whether this direction of handling the issue will be accepted. In tif_swab.c a function int _TIFFBigEndian() is added to do the runtime endianess check. kind regards Kai-Uwe Behrmann -- developing for colour management www.behrmann.name + www.oyranos.org + www.cinepaint.org diff -aur tiff-3.9.0beta_orig/libtiff/tif_open.c tiff-3.9.0beta/libtiff/tif_open.c --- tiff-3.9.0beta_orig/libtiff/tif_open.c 2006-06-08 16:27:17.000000000 +0200 +++ tiff-3.9.0beta/libtiff/tif_open.c 2007-10-22 23:18:54.000000000 +0200 @@ -102,14 +102,12 @@ tif->tif_typemask = typemask; if (magic == TIFF_BIGENDIAN) { tif->tif_typeshift = bigTypeshift; -#ifndef WORDS_BIGENDIAN + if (!_TIFFBigEndian()) tif->tif_flags |= TIFF_SWAB; -#endif } else { tif->tif_typeshift = litTypeshift; -#ifdef WORDS_BIGENDIAN + if (_TIFFBigEndian()) tif->tif_flags |= TIFF_SWAB; -#endif } } @@ -258,16 +256,14 @@ for (cp = mode; *cp; cp++) switch (*cp) { case 'b': -#ifndef WORDS_BIGENDIAN - if (m&O_CREAT) + if (!_TIFFBigEndian() && + m&O_CREAT) tif->tif_flags |= TIFF_SWAB; -#endif break; case 'l': -#ifdef WORDS_BIGENDIAN - if ((m&O_CREAT)) + if (_TIFFBigEndian() && + (m&O_CREAT)) tif->tif_flags |= TIFF_SWAB; -#endif break; case 'B': tif->tif_flags = (tif->tif_flags &~ TIFF_FILLORDER) | @@ -314,13 +310,13 @@ /* * Setup header and write. */ -#ifdef WORDS_BIGENDIAN - tif->tif_header.tiff_magic = tif->tif_flags & TIFF_SWAB + if (_TIFFBigEndian()) + tif->tif_header.tiff_magic = tif->tif_flags & TIFF_SWAB ? TIFF_LITTLEENDIAN : TIFF_BIGENDIAN; -#else - tif->tif_header.tiff_magic = tif->tif_flags & TIFF_SWAB + else + tif->tif_header.tiff_magic = tif->tif_flags & TIFF_SWAB ? TIFF_BIGENDIAN : TIFF_LITTLEENDIAN; -#endif + tif->tif_header.tiff_version = TIFF_VERSION; if (tif->tif_flags & TIFF_SWAB) TIFFSwabShort(&tif->tif_header.tiff_version); @@ -363,11 +359,10 @@ tif->tif_header.tiff_magic != TIFF_LITTLEENDIAN #if MDI_SUPPORT && -#if HOST_BIGENDIAN - tif->tif_header.tiff_magic != MDI_BIGENDIAN -#else - tif->tif_header.tiff_magic != MDI_LITTLEENDIAN -#endif + ((_TIFFBigEndian() && + tif->tif_header.tiff_magic != MDI_BIGENDIAN) || + (!_TIFFBigEndian() && + tif->tif_header.tiff_magic != MDI_LITTLEENDIAN)) ) { TIFFErrorExt(tif->tif_clientdata, name, "Not a TIFF or MDI file, bad magic number %d (0x%x)", diff -aur tiff-3.9.0beta_orig/libtiff/tif_predict.c tiff-3.9.0beta/libtiff/tif_predict.c --- tiff-3.9.0beta_orig/libtiff/tif_predict.c 2007-04-07 16:58:30.000000000 +0200 +++ tiff-3.9.0beta/libtiff/tif_predict.c 2007-10-22 23:25:47.000000000 +0200 @@ -317,12 +317,11 @@ for (count = 0; count < wc; count++) { uint32 byte; for (byte = 0; byte < bps; byte++) { -#if WORDS_BIGENDIAN - cp[bps * count + byte] = tmp[byte * wc + count]; -#else - cp[bps * count + byte] = + if (_TIFFBigEndian()) + cp[bps * count + byte] = tmp[byte * wc + count]; + else + cp[bps * count + byte] = tmp[(bps - byte - 1) * wc + count]; -#endif } } _TIFFfree(tmp); @@ -459,12 +458,11 @@ for (count = 0; count < wc; count++) { uint32 byte; for (byte = 0; byte < bps; byte++) { -#if WORDS_BIGENDIAN - cp[byte * wc + count] = tmp[bps * count + byte]; -#else - cp[(bps - byte - 1) * wc + count] = + if (_TIFFBigEndian()) + cp[byte * wc + count] = tmp[bps * count + byte]; + else + cp[(bps - byte - 1) * wc + count] = tmp[bps * count + byte]; -#endif } } _TIFFfree(tmp); diff -aur tiff-3.9.0beta_orig/libtiff/tif_swab.c tiff-3.9.0beta/libtiff/tif_swab.c --- tiff-3.9.0beta_orig/libtiff/tif_swab.c 2005-04-13 16:06:21.000000000 +0200 +++ tiff-3.9.0beta/libtiff/tif_swab.c 2007-10-22 22:22:14.000000000 +0200 @@ -31,6 +31,17 @@ */ #include "tiffiop.h" +int +_TIFFBigEndian(void) +{ + int big = 0; + char testc[2] = {0,0}; + uint16 *testu = (uint16*)testc; + *testu = 1; + big = testc[1]; + return big; +} + #ifndef TIFFSwabShort void TIFFSwabShort(uint16* wp) diff -aur tiff-3.9.0beta_orig/libtiff/tiffconf.h tiff-3.9.0beta/libtiff/tiffconf.h diff -aur tiff-3.9.0beta_orig/libtiff/tiffiop.h tiff-3.9.0beta/libtiff/tiffiop.h --- tiff-3.9.0beta_orig/libtiff/tiffiop.h 2007-04-18 10:23:07.000000000 +0200 +++ tiff-3.9.0beta/libtiff/tiffiop.h 2007-10-22 22:22:09.000000000 +0200 @@ -251,6 +251,7 @@ extern void _TIFFNoPostDecode(TIFF*, tidata_t, tsize_t); extern int _TIFFNoPreCode (TIFF*, tsample_t); extern int _TIFFNoSeek(TIFF*, uint32); +extern int _TIFFBigEndian(void); extern void _TIFFSwab16BitData(TIFF*, tidata_t, tsize_t); extern void _TIFFSwab24BitData(TIFF*, tidata_t, tsize_t); extern void _TIFFSwab32BitData(TIFF*, tidata_t, tsize_t); |
|||||||