% You may not use this file except in compliance with the License. You may %
% obtain a copy of the License at %
% %
-% http://www.imagemagick.org/script/license.php %
+% https://www.imagemagick.org/script/license.php %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
if ((unique_file == -1) || (file == (FILE *) NULL))
ThrowImageException(FileOpenError,"UnableToCreateTemporaryFile");
length=fwrite("\111\111\052\000\010\000\000\000\016\000",1,10,file);
+ if (length != 10)
+ ThrowReaderException(CorruptImageError,"UnexpectedEndOfFile");
length=fwrite("\376\000\003\000\001\000\000\000\000\000\000\000",1,12,file);
length=fwrite("\000\001\004\000\001\000\000\000",1,8,file);
length=WriteLSBLong(file,image->columns);
status=MagickFalse;
offset=(ssize_t) fseek(file,(ssize_t) offset,SEEK_SET);
length=WriteLSBLong(file,(unsigned int) length);
+ if (ferror(file) != 0)
+ {
+ (void) fclose(file);
+ ThrowImageException(FileOpenError,"UnableToCreateTemporaryFile");
+ }
(void) fclose(file);
(void) CloseBlob(image);
image=DestroyImage(image);
return((toff_t) GetBlobSize((Image *) image));
}
-static void TIFFGetProfiles(TIFF *tiff,Image *image,MagickBooleanType ping,
- ExceptionInfo *exception)
+static void TIFFGetProfiles(TIFF *tiff,Image *image,ExceptionInfo *exception)
{
uint32
length;
*profile;
length=0;
- if (ping == MagickFalse)
- {
#if defined(TIFFTAG_ICCPROFILE)
- if ((TIFFGetField(tiff,TIFFTAG_ICCPROFILE,&length,&profile) == 1) &&
- (profile != (unsigned char *) NULL))
- (void) ReadProfile(image,"icc",profile,(ssize_t) length,exception);
+ if ((TIFFGetField(tiff,TIFFTAG_ICCPROFILE,&length,&profile) == 1) &&
+ (profile != (unsigned char *) NULL))
+ (void) ReadProfile(image,"icc",profile,(ssize_t) length,exception);
#endif
#if defined(TIFFTAG_PHOTOSHOP)
- if ((TIFFGetField(tiff,TIFFTAG_PHOTOSHOP,&length,&profile) == 1) &&
- (profile != (unsigned char *) NULL))
- (void) ReadProfile(image,"8bim",profile,(ssize_t) length,exception);
+ if ((TIFFGetField(tiff,TIFFTAG_PHOTOSHOP,&length,&profile) == 1) &&
+ (profile != (unsigned char *) NULL))
+ (void) ReadProfile(image,"8bim",profile,(ssize_t) length,exception);
#endif
#if defined(TIFFTAG_RICHTIFFIPTC)
- if ((TIFFGetField(tiff,TIFFTAG_RICHTIFFIPTC,&length,&profile) == 1) &&
- (profile != (unsigned char *) NULL))
- {
- if (TIFFIsByteSwapped(tiff) != 0)
- TIFFSwabArrayOfLong((uint32 *) profile,(size_t) length);
- (void) ReadProfile(image,"iptc",profile,4L*length,exception);
- }
+ if ((TIFFGetField(tiff,TIFFTAG_RICHTIFFIPTC,&length,&profile) == 1) &&
+ (profile != (unsigned char *) NULL))
+ {
+ if (TIFFIsByteSwapped(tiff) != 0)
+ TIFFSwabArrayOfLong((uint32 *) profile,(size_t) length);
+ (void) ReadProfile(image,"iptc",profile,4L*length,exception);
+ }
#endif
#if defined(TIFFTAG_XMLPACKET)
- if ((TIFFGetField(tiff,TIFFTAG_XMLPACKET,&length,&profile) == 1) &&
- (profile != (unsigned char *) NULL))
- (void) ReadProfile(image,"xmp",profile,(ssize_t) length,exception);
+ if ((TIFFGetField(tiff,TIFFTAG_XMLPACKET,&length,&profile) == 1) &&
+ (profile != (unsigned char *) NULL))
+ (void) ReadProfile(image,"xmp",profile,(ssize_t) length,exception);
#endif
- if ((TIFFGetField(tiff,34118,&length,&profile) == 1) &&
- (profile != (unsigned char *) NULL))
- (void) ReadProfile(image,"tiff:34118",profile,(ssize_t) length,
- exception);
- }
+ if ((TIFFGetField(tiff,34118,&length,&profile) == 1) &&
+ (profile != (unsigned char *) NULL))
+ (void) ReadProfile(image,"tiff:34118",profile,(ssize_t) length,
+ exception);
if ((TIFFGetField(tiff,37724,&length,&profile) == 1) &&
(profile != (unsigned char *) NULL))
(void) ReadProfile(image,"tiff:37724",profile,(ssize_t) length,exception);
SetImageColorspace(image,CMYKColorspace,exception);
if (photometric == PHOTOMETRIC_CIELAB)
SetImageColorspace(image,LabColorspace,exception);
- TIFFGetProfiles(tiff,image,image_info->ping,exception);
+ TIFFGetProfiles(tiff,image,exception);
TIFFGetProperties(tiff,image,exception);
option=GetImageOption(image_info,"tiff:exif-properties");
if (IsStringFalse(option) == MagickFalse) /* enabled by default */
(void) SetImageProperty(image,"tiff:rows-per-strip",value,exception);
}
if ((samples_per_pixel >= 3) && (interlace == PLANARCONFIG_CONTIG))
- method=ReadRGBAMethod;
+ if ((image->alpha_trait == UndefinedPixelTrait) ||
+ (samples_per_pixel >= 4))
+ method=ReadRGBAMethod;
if ((samples_per_pixel >= 4) && (interlace == PLANARCONFIG_SEPARATE))
- method=ReadCMYKAMethod;
+ if ((image->alpha_trait == UndefinedPixelTrait) ||
+ (samples_per_pixel >= 5))
+ method=ReadCMYKAMethod;
if ((photometric != PHOTOMETRIC_RGB) &&
(photometric != PHOTOMETRIC_CIELAB) &&
(photometric != PHOTOMETRIC_SEPARATED))
method=ReadTileMethod;
quantum_info->endian=LSBEndian;
quantum_type=RGBQuantum;
- tiff_pixels=(unsigned char *) AcquireMagickMemory(TIFFScanlineSize(tiff)+
- sizeof(uint32));
+ tiff_pixels=(unsigned char *) AcquireMagickMemory(MagickMax(
+ TIFFScanlineSize(tiff),(ssize_t) (image->columns*samples_per_pixel*
+ pow(2.0,ceil(log(bits_per_sample)/log(2.0))))));
if (tiff_pixels == (unsigned char *) NULL)
{
TIFFClose(tiff);
#endif
entry->flags|=CoderRawSupportFlag;
entry->flags|=CoderEndianSupportFlag;
- entry->flags|=CoderSeekableStreamFlag;
+ entry->flags|=CoderDecoderSeekableStreamFlag;
+ entry->flags|=CoderEncoderSeekableStreamFlag;
entry->flags^=CoderAdjoinFlag;
entry->flags^=CoderUseExtensionFlag;
entry->format_type=ImplicitFormatType;
entry->encoder=(EncodeImageHandler *) WritePTIFImage;
#endif
entry->flags|=CoderEndianSupportFlag;
- entry->flags|=CoderSeekableStreamFlag;
+ entry->flags|=CoderDecoderSeekableStreamFlag;
+ entry->flags|=CoderEncoderSeekableStreamFlag;
entry->flags^=CoderUseExtensionFlag;
entry->mime_type=ConstantString("image/tiff");
(void) RegisterMagickInfo(entry);
entry->encoder=(EncodeImageHandler *) WriteTIFFImage;
#endif
entry->flags|=CoderEndianSupportFlag;
- entry->flags|=CoderSeekableStreamFlag;
+ entry->flags|=CoderDecoderSeekableStreamFlag;
+ entry->flags|=CoderEncoderSeekableStreamFlag;
entry->flags|=CoderStealthFlag;
entry->flags^=CoderUseExtensionFlag;
if (*version != '\0')
#endif
entry->magick=(IsImageFormatHandler *) IsTIFF;
entry->flags|=CoderEndianSupportFlag;
- entry->flags|=CoderSeekableStreamFlag;
+ entry->flags|=CoderDecoderSeekableStreamFlag;
+ entry->flags|=CoderEncoderSeekableStreamFlag;
entry->flags^=CoderUseExtensionFlag;
if (*version != '\0')
entry->version=ConstantString(version);
entry->encoder=(EncodeImageHandler *) WriteTIFFImage;
#endif
entry->flags|=CoderEndianSupportFlag;
- entry->flags|=CoderSeekableStreamFlag;
+ entry->flags|=CoderDecoderSeekableStreamFlag;
+ entry->flags|=CoderEncoderSeekableStreamFlag;
entry->flags^=CoderAdjoinFlag;
entry->flags^=CoderUseExtensionFlag;
if (*version != '\0')
AppendImageToList(&images,pyramid_image);
}
}
- images=GetFirstImageInList(images);
- /*
- Write pyramid-encoded TIFF image.
- */
- write_info=CloneImageInfo(image_info);
- write_info->adjoin=MagickTrue;
- (void) CopyMagickString(write_info->magick,"TIFF",MagickPathExtent);
- (void) CopyMagickString(images->magick,"TIFF",MagickPathExtent);
- status=WriteTIFFImage(write_info,images,exception);
- images=DestroyImageList(images);
- write_info=DestroyImageInfo(write_info);
+ status=MagickFalse;
+ if (images != (Image *) NULL)
+ {
+ /*
+ Write pyramid-encoded TIFF image.
+ */
+ images=GetFirstImageInList(images);
+ write_info=CloneImageInfo(image_info);
+ write_info->adjoin=MagickTrue;
+ (void) CopyMagickString(write_info->magick,"TIFF",MagickPathExtent);
+ (void) CopyMagickString(images->magick,"TIFF",MagickPathExtent);
+ status=WriteTIFFImage(write_info,images,exception);
+ images=DestroyImageList(images);
+ write_info=DestroyImageInfo(write_info);
+ }
return(status);
}
#endif