Pyramidal TIFF doesn't correctly set TIFFTAG_SUBFILETYPE

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
bgilbert
Posts: 1
Joined: 2011-11-22T20:58:51-07:00
Authentication code: 8675308

Pyramidal TIFF doesn't correctly set TIFFTAG_SUBFILETYPE

Post by bgilbert »

Version: 6.7.3, svn r6051
OS: Linux

Writing a PTIF with convert sets the FILETYPE_PAGE flag on every image within the file, as though the TIFF is a multi-page image. It should be setting no flags on the first (full-sized) image, and FILETYPE_REDUCEDIMAGE on subsequent images.

Code: Select all

$ convert ~/small.ppm -define tiff:tile-geometry=256x256 ~/small.ptif
$ tiffinfo small.ptif
TIFF Directory at offset 0x300008 (3145736)
  Subfile Type: multi-page document (2 = 0x2)
  Image Width: 1000 Image Length: 1000
  Tile Width: 256 Tile Length: 256
[...]

TIFF Directory at offset 0x3c021a (3932698)
  Subfile Type: multi-page document (2 = 0x2)
  Image Width: 500 Image Length: 500
  Tile Width: 256 Tile Length: 256
[...]

TIFF Directory at offset 0x3f03cc (4129740)
  Subfile Type: multi-page document (2 = 0x2)
  Image Width: 250 Image Length: 250
  Tile Width: 256 Tile Length: 256
[...]
This patch fixes the problem for me:

Code: Select all

Index: coders/tiff.c
===================================================================
--- coders/tiff.c	(revision 6051)
+++ coders/tiff.c	(working copy)
@@ -2154,7 +2154,6 @@
     Write pyramid-encoded TIFF image.
   */
   write_info=CloneImageInfo(image_info);
-  *write_info->magick='\0';
   write_info->adjoin=MagickTrue;
   status=WriteTIFFImage(write_info,GetFirstImageInList(images));
   images=DestroyImageList(images);
@@ -3081,7 +3080,8 @@
         chromaticity[1]=(float) image->chromaticity.white_point.y;
         (void) TIFFSetField(tiff,TIFFTAG_WHITEPOINT,chromaticity);
       }
-    if ((image_info->adjoin != MagickFalse) && (GetImageListLength(image) > 1))
+    if ((LocaleCompare(image_info->magick,"PTIF") != 0) &&
+        (image_info->adjoin != MagickFalse) && (GetImageListLength(image) > 1))
       {
         (void) TIFFSetField(tiff,TIFFTAG_SUBFILETYPE,FILETYPE_PAGE);
         if (image->scene != 0)
@@ -3098,7 +3098,8 @@
 
       page=(uint16) scene;
       pages=(uint16) GetImageListLength(image);
-      if ((image_info->adjoin != MagickFalse) && (pages > 1))
+      if ((LocaleCompare(image_info->magick,"PTIF") != 0) &&
+          (image_info->adjoin != MagickFalse) && (pages > 1))
         (void) TIFFSetField(tiff,TIFFTAG_SUBFILETYPE,FILETYPE_PAGE);
       (void) TIFFSetField(tiff,TIFFTAG_PAGENUMBER,page,pages);
     }
Result:

Code: Select all

TIFF Directory at offset 0x300008 (3145736)
  Image Width: 1000 Image Length: 1000
  Tile Width: 256 Tile Length: 256
[...]

TIFF Directory at offset 0x3c01b8 (3932600)
  Subfile Type: reduced-resolution image (1 = 0x1)
  Image Width: 500 Image Length: 500
  Tile Width: 256 Tile Length: 256
[...]

TIFF Directory at offset 0x3f0314 (4129556)
  Subfile Type: reduced-resolution image (1 = 0x1)
  Image Width: 250 Image Length: 250
  Tile Width: 256 Tile Length: 256
[...]
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Pyramidal TIFF doesn't correctly set TIFFTAG_SUBFILETYPE

Post by magick »

Thanks for the problem report and patch. We'll get your patch into the Subversion trunk by sometime tomorrow.
Post Reply