]> granicus.if.org Git - imagemagick/commitdiff
https://github.com/ImageMagick/ImageMagick/issues/262
authorCristy <urban-warrior@imagemagick.org>
Sun, 4 Sep 2016 15:30:32 +0000 (11:30 -0400)
committerCristy <urban-warrior@imagemagick.org>
Sun, 4 Sep 2016 15:30:32 +0000 (11:30 -0400)
coders/tiff.c

index 4d0334b6259c70944d9ebf7af47a6f4e75a6c702..b2be73665c324360ae776984bf10c651bdeec8b6 100644 (file)
@@ -3002,7 +3002,7 @@ static void TIFFSetProperties(TIFF *tiff,const ImageInfo *image_info,
       uint16
         page,
         pages;
-      
+
       page=(uint16) image->scene;
       pages=(uint16) GetImageListLength(image);
       if ((image_info->adjoin != MagickFalse) && (pages > 1))
@@ -3499,7 +3499,7 @@ static MagickBooleanType WriteTIFFImage(const ImageInfo *image_info,
         MagickStatusType
           flags;
 
-        rows_per_strip+=(16-(rows_per_strip % 16));
+        rows_per_strip=16*(((rows_per_strip < 16 ? 16 : rows_per_strip)+1)/16);
         if (image_info->quality != UndefinedCompressionQuality)
           (void) TIFFSetField(tiff,TIFFTAG_JPEGQUALITY,image_info->quality);
         (void) TIFFSetField(tiff,TIFFTAG_JPEGCOLORMODE,JPEGCOLORMODE_RAW);
@@ -3539,7 +3539,8 @@ static MagickBooleanType WriteTIFFImage(const ImageInfo *image_info,
       }
       case COMPRESSION_ADOBE_DEFLATE:
       {
-        rows_per_strip=(uint32) image->rows;
+        if (((32*1024)/MagickMax(TIFFScanlineSize(tiff),1)) > rows_per_strip)
+          rows_per_strip=((32*1024)/MagickMax(TIFFScanlineSize(tiff),1));
         (void) TIFFGetFieldDefaulted(tiff,TIFFTAG_BITSPERSAMPLE,
           &bits_per_sample);
         if (((photometric == PHOTOMETRIC_RGB) ||
@@ -3556,18 +3557,31 @@ static MagickBooleanType WriteTIFFImage(const ImageInfo *image_info,
         /*
           Byte-aligned EOL.
         */
-        rows_per_strip=(uint32) image->rows;
+        rows_per_strip=(16*1024*1024UL)/image->columns;
+        if (rows_per_strip < 1)
+          rows_per_strip=1;
+        if (rows_per_strip > image->rows)
+          rows_per_strip=(uint32) image->rows;
         (void) TIFFSetField(tiff,TIFFTAG_GROUP3OPTIONS,4);
         break;
       }
       case COMPRESSION_CCITTFAX4:
       {
-        rows_per_strip=(uint32) image->rows;
+        rows_per_strip=(16*1024*1024UL)/image->columns;
+        if (rows_per_strip < 1)
+          rows_per_strip=1;
+        if (rows_per_strip > image->rows)
+          rows_per_strip=(uint32) image->rows;
         break;
       }
 #if defined(LZMA_SUPPORT) && defined(COMPRESSION_LZMA)
       case COMPRESSION_LZMA:
       {
+        rows_per_strip=(16*1024*1024UL)/image->columns;
+        if (rows_per_strip < 1)
+          rows_per_strip=1;
+        if (rows_per_strip > image->rows)
+          rows_per_strip=(uint32) image->rows;
         if (((photometric == PHOTOMETRIC_RGB) ||
              (photometric == PHOTOMETRIC_MINISBLACK)) &&
             ((bits_per_sample == 8) || (bits_per_sample == 16)))