]> git.imager.perl.org - imager.git/commitdiff
work around limits of older libtiffs
authorTony Cook <tony@develop=help.com>
Wed, 28 Nov 2007 04:18:47 +0000 (04:18 +0000)
committerTony Cook <tony@develop=help.com>
Wed, 28 Nov 2007 04:18:47 +0000 (04:18 +0000)
t/t106tiff.t
testimg/pengtile.tif
tiff.c

index 08727499607a2704ffc3f2b367c3073149cbf012..36bacd1e6a97538ee81cd8a24805bdca4ece1d22 100644 (file)
@@ -34,7 +34,7 @@ SKIP:
     cmp_ok($im->errstr, '=~', "format 'tiff' not supported", "check no tiff message");
     ok(!grep($_ eq 'tiff', Imager->read_types), "check tiff not in read types");
     ok(!grep($_ eq 'tiff', Imager->write_types), "check tiff not in write types");
-    skip("no tiff support", 209);
+    skip("no tiff support", 207);
   }
 
   my $ver_string = Imager::i_tiff_libversion();
@@ -486,7 +486,8 @@ SKIP:
 
   { # reading tile based images
     my $im = Imager->new;
-    ok($im->read(file => 'testimg/pengtile.tif'), "read tiled image");
+    ok($im->read(file => 'testimg/pengtile.tif'), "read tiled image")
+      or print "# ", $im->errstr, "\n";
     # compare it
     my $comp = Imager->new;
     ok($comp->read(file => 'testimg/penguin-base.ppm'), 'read comparison image');
@@ -499,13 +500,13 @@ SKIP:
     ok(open(TIFF, '< testimg/pengtile.tif'), 'open pengtile.tif')
       or skip 'cannot open testimg/pengtile.tif', 4;
 
-    $cmp_ver ge '0030057'
+    $cmp_ver ge '003005007'
       or skip("Your ancient tifflib has bad error handling", 4);
     binmode TIFF;
     my $data = do { local $/; <TIFF>; };
     
     # patch a tile offset
-    substr($data, 0x5AFE, 4) = pack("H*", "1F5C0000");
+    substr($data, 0x1AFA0, 4) = pack("H*", "00000200");
 
     #open PIPE, "| bytedump -a | less" or die;
     #print PIPE $data;
@@ -671,7 +672,8 @@ SKIP:
     my $data;
     ok($orig->write(data => \$data, type => 'tiff',
                    tiff_compression=> $compress),
-       "write 8 bit");
+       "write 8 bit")
+      or print "# ", $orig->errstr, "\n";
     my $im = Imager->new;
     ok($im->read(data => $data), "read it back");
     is_image($im, $orig, "check read data matches");
index dd4229f67b5838142e9f8a9e87a853f18b638fd4..de7c5a247de1ba28637fee7e36b378acbf7d04ba 100644 (file)
Binary files a/testimg/pengtile.tif and b/testimg/pengtile.tif differ
diff --git a/tiff.c b/tiff.c
index 7c5548e84bc6bf70a5921fa6f3b6dd2ec75d9c19..7f9f618d9ba908ae9e6608ad5ea16e57fa513dbf 100644 (file)
--- a/tiff.c
+++ b/tiff.c
@@ -5,7 +5,6 @@
 
 /* needed to implement our substitute TIFFIsCODECConfigured */
 #if TIFFLIB_VERSION < 20031121
-#include "tiffconf.h"
 static int TIFFIsCODECConfigured(uint16 scheme);
 #endif
 
@@ -86,6 +85,9 @@ compress_values[] =
 static const int compress_value_count = 
   sizeof(compress_values) / sizeof(*compress_values);
 
+static int 
+myTIFFIsCODECConfigured(uint16 scheme);
+
 typedef struct read_state_tag read_state_t;
 /* the setup function creates the image object, allocates the line buffer */
 typedef int (*read_setup_t)(read_state_t *state);
@@ -740,12 +742,12 @@ get_compression(i_img *im, uint16 def_compress) {
       && im->tags.tags[entry].data) {
     uint16 compress;
     if (find_compression(im->tags.tags[entry].data, &compress)
-       && TIFFIsCODECConfigured(compress))
+       && myTIFFIsCODECConfigured(compress))
       return compress;
   }
   if (i_tags_get_int(&im->tags, "tiff_compression", 0, &value)) {
     if ((uint16)value == value
-       && TIFFIsCODECConfigured((uint16)value))
+       && myTIFFIsCODECConfigured((uint16)value))
       return (uint16)value;
   }
 
@@ -759,7 +761,7 @@ i_tiff_has_compression(const char *name) {
   if (!find_compression(name, &compress))
     return 0;
 
-  return TIFFIsCODECConfigured(compress);
+  return myTIFFIsCODECConfigured(compress);
 }
 
 static int
@@ -2507,44 +2509,46 @@ putter_cmyk16(read_state_t *state, int x, int y, int width, int height,
   Older versions of tifflib we support don't define this, so define it
   ourselves.
 
+  If you want this detection to do anything useful, use a newer
+  release of tifflib.
+
  */
 #if TIFFLIB_VERSION < 20031121
 
-int TIFFIsCODECConfigured(uint16 scheme) {
+int 
+TIFFIsCODECConfigured(uint16 scheme) {
   switch (scheme) {
+    /* these schemes are all shipped with tifflib */
  case COMPRESSION_NONE:
-#if PACKBITS_SUPPORT
  case COMPRESSION_PACKBITS:
-#endif
-
-#if CCITT_SUPPORT
  case COMPRESSION_CCITTRLE:
  case COMPRESSION_CCITTRLEW:
  case COMPRESSION_CCITTFAX3:
  case COMPRESSION_CCITTFAX4:
-#endif
+    return 1;
 
-#if JPEG_SUPPORT
+    /* these require external library support */
+  default:
  case COMPRESSION_JPEG:
-#endif
-
-#if LZW_SUPPORT
  case COMPRESSION_LZW:
-#endif
-
-#if ZIP_SUPPORT
  case COMPRESSION_DEFLATE:
  case COMPRESSION_ADOBE_DEFLATE:
-#endif
-    return 1;
-
-  default:
     return 0;
   }
 }
 
 #endif
 
+static int 
+myTIFFIsCODECConfigured(uint16 scheme) {
+#if TIFFLIB_VERSION < 20040724
+  if (scheme == COMPRESSION_LZW)
+    return 0;
+#endif
+
+  return TIFFIsCODECConfigured(scheme);
+}
+
 /*
 =back