ReadYCCKMethod,
ReadStripMethod,
ReadTileMethod,
+ ReadRGBATileMethod,
ReadGenericMethod
} TIFFMethodType;
if (compress_tag == COMPRESSION_JBIG)
method=ReadStripMethod;
if (TIFFIsTiled(tiff) != MagickFalse)
- method=ReadTileMethod;
+ {
+ method=ReadRGBATileMethod;
+ if (bits_per_sample > 16)
+ method=ReadTileMethod;
+ }
quantum_info->endian=LSBEndian;
quantum_type=RGBQuantum;
if (TIFFScanlineSize(tiff) <= 0)
break;
}
case ReadTileMethod:
+ {
+ register unsigned char
+ *p;
+
+ uint32
+ columns,
+ rows;
+
+ unsigned char
+ *tile_pixels;
+
+ /*
+ Convert tiled TIFF image to DirectClass MIFF image.
+ */
+ quantum_type=IndexQuantum;
+ pad=(size_t) MagickMax((ssize_t) samples_per_pixel-1,0);
+ if (image->alpha_trait != UndefinedPixelTrait)
+ {
+ if (image->storage_class != PseudoClass)
+ {
+ quantum_type=samples_per_pixel == 1 ? AlphaQuantum :
+ GrayAlphaQuantum;
+ pad=(size_t) MagickMax((ssize_t) samples_per_pixel-2,0);
+ }
+ else
+ {
+ quantum_type=IndexAlphaQuantum;
+ pad=(size_t) MagickMax((ssize_t) samples_per_pixel-2,0);
+ }
+ }
+ else
+ if (image->storage_class != PseudoClass)
+ {
+ quantum_type=GrayQuantum;
+ pad=(size_t) MagickMax((ssize_t) samples_per_pixel-1,0);
+ }
+ status=SetQuantumPad(image,quantum_info,pad*pow(2,ceil(log(
+ bits_per_sample)/log(2))));
+ if (status == MagickFalse)
+ ThrowTIFFException(ResourceLimitError,"MemoryAllocationFailed");
+ if ((TIFFGetField(tiff,TIFFTAG_TILEWIDTH,&columns) != 1) ||
+ (TIFFGetField(tiff,TIFFTAG_TILELENGTH,&rows) != 1))
+ ThrowTIFFException(CoderError,"ImageIsNotTiled");
+ if ((AcquireMagickResource(WidthResource,columns) == MagickFalse) ||
+ (AcquireMagickResource(HeightResource,rows) == MagickFalse))
+ ThrowTIFFException(ImageError,"WidthOrHeightExceedsLimit");
+ (void) SetImageStorageClass(image,DirectClass,exception);
+ number_pixels=(MagickSizeType) columns*rows;
+ if (HeapOverflowSanityCheck(rows,sizeof(*tile_pixels)) != MagickFalse)
+ ThrowTIFFException(ResourceLimitError,"MemoryAllocationFailed");
+ tile_pixels=(unsigned char *) AcquireQuantumMemory(TIFFTileSize(tiff)+
+ sizeof(uint32),sizeof(*tile_pixels));
+ if (tile_pixels == (unsigned char *) NULL)
+ ThrowTIFFException(ResourceLimitError,"MemoryAllocationFailed");
+ for (y=0; y < (ssize_t) image->rows; y+=rows)
+ {
+ register ssize_t
+ x;
+
+ size_t
+ rows_remaining;
+
+ rows_remaining=image->rows-y;
+ if ((ssize_t) (y+rows) < (ssize_t) image->rows)
+ rows_remaining=rows;
+ for (x=0; x < (ssize_t) image->columns; x+=columns)
+ {
+ size_t
+ columns_remaining,
+ row;
+
+ columns_remaining=image->columns-x;
+ if ((ssize_t) (x+columns) < (ssize_t) image->columns)
+ columns_remaining=columns;
+ if (TIFFReadTile(tiff,tile_pixels,(uint32) x,(uint32) y,0,0) == 0)
+ break;
+ p=tile_pixels;
+ for (row=0; row < rows_remaining; row++)
+ {
+ register Quantum
+ *magick_restrict q;
+
+ q=GetAuthenticPixels(image,x,y+row,columns_remaining,1,exception);
+ if (q == (Quantum *) NULL)
+ break;
+ (void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
+ quantum_type,p,exception);
+ p+=TIFFTileRowSize(tiff);
+ if (SyncAuthenticPixels(image,exception) == MagickFalse)
+ break;
+ }
+ }
+ if (image->previous == (Image *) NULL)
+ {
+ status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
+ image->rows);
+ if (status == MagickFalse)
+ break;
+ }
+ }
+ tile_pixels=(unsigned char *) RelinquishMagickMemory(tile_pixels);
+ break;
+ }
+ case ReadRGBATileMethod:
{
register uint32
*p;