X-Git-Url: https://granicus.if.org/sourcecode?a=blobdiff_plain;f=coders%2Ftiff.c;h=79ddc535491ef05f1160c4ad51f29c740f6c390d;hb=9c47c73fa67a9301cf2205c741aa12af3c6fe6c3;hp=3c89fa6ca6a82f64e34e74bb38f2a711228421c1;hpb=3a37efd7ece979e9c63dc8f2f2d3816bab8b1156;p=imagemagick diff --git a/coders/tiff.c b/coders/tiff.c index 3c89fa6ca..79ddc5354 100644 --- a/coders/tiff.c +++ b/coders/tiff.c @@ -91,6 +91,12 @@ # if !defined(PREDICTOR_HORIZONTAL) # define PREDICTOR_HORIZONTAL 2 # endif +# if !defined(TIFFTAG_COPYRIGHT) +# define TIFFTAG_COPYRIGHT 33432 +# endif +# if !defined(TIFFTAG_OPIIMAGEID) +# define TIFF_OPIIMAGEID 32781 +# endif /* Typedef declarations. @@ -113,11 +119,11 @@ static const ExifInfo { EXIFTAG_EXPOSUREPROGRAM, TIFF_SHORT, "exif:ExposureProgram" }, { EXIFTAG_SPECTRALSENSITIVITY, TIFF_ASCII, "exif:SpectralSensitivity" }, { EXIFTAG_ISOSPEEDRATINGS, TIFF_SHORT, "exif:ISOSpeedRatings" }, - { EXIFTAG_OECF, TIFF_UNDEFINED, "exif:OptoelectricConversionFactor" }, - { EXIFTAG_EXIFVERSION, TIFF_UNDEFINED, "exif:ExifVersion" }, + { EXIFTAG_OECF, TIFF_NOTYPE, "exif:OptoelectricConversionFactor" }, + { EXIFTAG_EXIFVERSION, TIFF_NOTYPE, "exif:ExifVersion" }, { EXIFTAG_DATETIMEORIGINAL, TIFF_ASCII, "exif:DateTimeOriginal" }, { EXIFTAG_DATETIMEDIGITIZED, TIFF_ASCII, "exif:DateTimeDigitized" }, - { EXIFTAG_COMPONENTSCONFIGURATION, TIFF_UNDEFINED, "exif:ComponentsConfiguration" }, + { EXIFTAG_COMPONENTSCONFIGURATION, TIFF_NOTYPE, "exif:ComponentsConfiguration" }, { EXIFTAG_COMPRESSEDBITSPERPIXEL, TIFF_RATIONAL, "exif:CompressedBitsPerPixel" }, { EXIFTAG_SHUTTERSPEEDVALUE, TIFF_SRATIONAL, "exif:ShutterSpeedValue" }, { EXIFTAG_APERTUREVALUE, TIFF_RATIONAL, "exif:ApertureValue" }, @@ -129,29 +135,29 @@ static const ExifInfo { EXIFTAG_LIGHTSOURCE, TIFF_SHORT, "exif:LightSource" }, { EXIFTAG_FLASH, TIFF_SHORT, "exif:Flash" }, { EXIFTAG_FOCALLENGTH, TIFF_RATIONAL, "exif:FocalLength" }, - /* { EXIFTAG_SUBJECTAREA, TIFF_SHORT, "exif:SubjectArea" }, */ - { EXIFTAG_MAKERNOTE, TIFF_UNDEFINED, "exif:MakerNote" }, - { EXIFTAG_USERCOMMENT, TIFF_UNDEFINED, "exif:UserComment" }, + { EXIFTAG_SUBJECTAREA, TIFF_NOTYPE, "exif:SubjectArea" }, + { EXIFTAG_MAKERNOTE, TIFF_NOTYPE, "exif:MakerNote" }, + { EXIFTAG_USERCOMMENT, TIFF_NOTYPE, "exif:UserComment" }, { EXIFTAG_SUBSECTIME, TIFF_ASCII, "exif:SubSecTime" }, { EXIFTAG_SUBSECTIMEORIGINAL, TIFF_ASCII, "exif:SubSecTimeOriginal" }, { EXIFTAG_SUBSECTIMEDIGITIZED, TIFF_ASCII, "exif:SubSecTimeDigitized" }, - { EXIFTAG_FLASHPIXVERSION, TIFF_UNDEFINED, "exif:FlashpixVersion" }, + { EXIFTAG_FLASHPIXVERSION, TIFF_NOTYPE, "exif:FlashpixVersion" }, { EXIFTAG_PIXELXDIMENSION, TIFF_LONG, "exif:PixelXDimension" }, { EXIFTAG_PIXELXDIMENSION, TIFF_SHORT, "exif:PixelXDimension" }, { EXIFTAG_PIXELYDIMENSION, TIFF_LONG, "exif:PixelYDimension" }, { EXIFTAG_PIXELYDIMENSION, TIFF_SHORT, "exif:PixelYDimension" }, { EXIFTAG_RELATEDSOUNDFILE, TIFF_ASCII, "exif:RelatedSoundFile" }, { EXIFTAG_FLASHENERGY, TIFF_RATIONAL, "exif:FlashEnergy" }, - { EXIFTAG_SPATIALFREQUENCYRESPONSE, TIFF_UNDEFINED, "exif:SpatialFrequencyResponse" }, + { EXIFTAG_SPATIALFREQUENCYRESPONSE, TIFF_NOTYPE, "exif:SpatialFrequencyResponse" }, { EXIFTAG_FOCALPLANEXRESOLUTION, TIFF_RATIONAL, "exif:FocalPlaneXResolution" }, { EXIFTAG_FOCALPLANEYRESOLUTION, TIFF_RATIONAL, "exif:FocalPlaneYResolution" }, { EXIFTAG_FOCALPLANERESOLUTIONUNIT, TIFF_SHORT, "exif:FocalPlaneResolutionUnit" }, { EXIFTAG_SUBJECTLOCATION, TIFF_SHORT, "exif:SubjectLocation" }, { EXIFTAG_EXPOSUREINDEX, TIFF_RATIONAL, "exif:ExposureIndex" }, { EXIFTAG_SENSINGMETHOD, TIFF_SHORT, "exif:SensingMethod" }, - { EXIFTAG_FILESOURCE, TIFF_UNDEFINED, "exif:FileSource" }, - { EXIFTAG_SCENETYPE, TIFF_UNDEFINED, "exif:SceneType" }, - { EXIFTAG_CFAPATTERN, TIFF_UNDEFINED, "exif:CFAPattern" }, + { EXIFTAG_FILESOURCE, TIFF_NOTYPE, "exif:FileSource" }, + { EXIFTAG_SCENETYPE, TIFF_NOTYPE, "exif:SceneType" }, + { EXIFTAG_CFAPATTERN, TIFF_NOTYPE, "exif:CFAPattern" }, { EXIFTAG_CUSTOMRENDERED, TIFF_SHORT, "exif:CustomRendered" }, { EXIFTAG_EXPOSUREMODE, TIFF_SHORT, "exif:ExposureMode" }, { EXIFTAG_WHITEBALANCE, TIFF_SHORT, "exif:WhiteBalance" }, @@ -162,7 +168,7 @@ static const ExifInfo { EXIFTAG_CONTRAST, TIFF_SHORT, "exif:Contrast" }, { EXIFTAG_SATURATION, TIFF_SHORT, "exif:Saturation" }, { EXIFTAG_SHARPNESS, TIFF_SHORT, "exif:Sharpness" }, - { EXIFTAG_DEVICESETTINGDESCRIPTION, TIFF_UNDEFINED, "exif:DeviceSettingDescription" }, + { EXIFTAG_DEVICESETTINGDESCRIPTION, TIFF_NOTYPE, "exif:DeviceSettingDescription" }, { EXIFTAG_SUBJECTDISTANCERANGE, TIFF_SHORT, "exif:SubjectDistanceRange" }, { EXIFTAG_IMAGEUNIQUEID, TIFF_ASCII, "exif:ImageUniqueID" }, { 0, 0, (char *) NULL } @@ -319,7 +325,7 @@ static Image *ReadGROUP4Image(const ImageInfo *image_info, image_info->filename); assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); - image=AcquireImage(image_info); + image=AcquireImage(image_info,exception); status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); if (status == MagickFalse) { @@ -360,7 +366,7 @@ static Image *ReadGROUP4Image(const ImageInfo *image_info, length=WriteLSBLong(file,(size_t) (strip_offset-8)); length=fwrite("\050\001\003\000\001\000\000\000\002\000\000\000",1,12,file); length=fwrite("\000\000\000\000",1,4,file); - length=WriteLSBLong(file,image->x_resolution); + length=WriteLSBLong(file,(long) image->resolution.x); length=WriteLSBLong(file,1); for (length=0; (c=ReadBlobByte(image)) != EOF; length++) (void) fputc(c,file); @@ -433,7 +439,7 @@ static inline ssize_t MagickMin(const ssize_t x,const ssize_t y) } static MagickBooleanType ReadProfile(Image *image,const char *name, - unsigned char *datum,ssize_t length) + unsigned char *datum,ssize_t length,ExceptionInfo *exception) { MagickBooleanType status; @@ -459,9 +465,11 @@ static MagickBooleanType ReadProfile(Image *image,const char *name, if (length < 4) return(MagickFalse); } - profile=AcquireStringInfo((size_t) length); - SetStringInfoDatum(profile,datum+i); - status=SetImageProfile(image,name,profile); + profile=BlobToStringInfo(datum+i,(size_t) length); + if (profile == (StringInfo *) NULL) + ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed", + image->filename); + status=SetImageProfile(image,name,profile,exception); profile=DestroyStringInfo(profile); if (status == MagickFalse) ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed", @@ -499,7 +507,12 @@ static void TIFFErrors(const char *module,const char *format,va_list error) "`%s'",module); } -static void TIFFGetProfiles(TIFF *tiff,Image *image) +static toff_t TIFFGetBlobSize(thandle_t image) +{ + return((toff_t) GetBlobSize((Image *) image)); +} + +static void TIFFGetProfiles(TIFF *tiff,Image *image,ExceptionInfo *exception) { uint32 length; @@ -510,12 +523,12 @@ static void TIFFGetProfiles(TIFF *tiff,Image *image) #if defined(TIFFTAG_ICCPROFILE) length=0; if (TIFFGetField(tiff,TIFFTAG_ICCPROFILE,&length,&profile) == 1) - (void) ReadProfile(image,"icc",profile,(ssize_t) length); + (void) ReadProfile(image,"icc",profile,(ssize_t) length,exception); #endif #if defined(TIFFTAG_PHOTOSHOP) length=0; if (TIFFGetField(tiff,TIFFTAG_PHOTOSHOP,&length,&profile) == 1) - (void) ReadProfile(image,"8bim",profile,(ssize_t) length); + (void) ReadProfile(image,"8bim",profile,(ssize_t) length,exception); #endif #if defined(TIFFTAG_RICHTIFFIPTC) length=0; @@ -523,47 +536,73 @@ static void TIFFGetProfiles(TIFF *tiff,Image *image) { if (TIFFIsByteSwapped(tiff) != 0) TIFFSwabArrayOfLong((uint32 *) profile,(size_t) length); - (void) ReadProfile(image,"iptc",profile,4L*length); + (void) ReadProfile(image,"iptc",profile,4L*length,exception); } #endif #if defined(TIFFTAG_XMLPACKET) length=0; if (TIFFGetField(tiff,TIFFTAG_XMLPACKET,&length,&profile) == 1) - (void) ReadProfile(image,"xmp",profile,(ssize_t) length); + (void) ReadProfile(image,"xmp",profile,(ssize_t) length,exception); #endif length=0; if (TIFFGetField(tiff,37724,&length,&profile) == 1) - (void) ReadProfile(image,"tiff:37724",profile,(ssize_t) length); + (void) ReadProfile(image,"tiff:37724",profile,(ssize_t) length,exception); } -static void TIFFGetProperties(TIFF *tiff,Image *image) +static void TIFFGetProperties(TIFF *tiff,Image *image,ExceptionInfo *exception) { char + message[MaxTextExtent], *text; + uint32 + count; + if (TIFFGetField(tiff,TIFFTAG_ARTIST,&text) == 1) - (void) SetImageProperty(image,"tiff:artist",text); + (void) SetImageProperty(image,"tiff:artist",text,exception); + if (TIFFGetField(tiff,TIFFTAG_COPYRIGHT,&text) == 1) + (void) SetImageProperty(image,"tiff:copyright",text,exception); if (TIFFGetField(tiff,TIFFTAG_DATETIME,&text) == 1) - (void) SetImageProperty(image,"tiff:timestamp",text); - if (TIFFGetField(tiff,TIFFTAG_SOFTWARE,&text) == 1) - (void) SetImageProperty(image,"tiff:software",text); - if (TIFFGetField(tiff,TIFFTAG_HOSTCOMPUTER,&text) == 1) - (void) SetImageProperty(image,"tiff:hostcomputer",text); + (void) SetImageProperty(image,"tiff:timestamp",text,exception); if (TIFFGetField(tiff,TIFFTAG_DOCUMENTNAME,&text) == 1) - (void) SetImageProperty(image,"tiff:document",text); + (void) SetImageProperty(image,"tiff:document",text,exception); + if (TIFFGetField(tiff,TIFFTAG_HOSTCOMPUTER,&text) == 1) + (void) SetImageProperty(image,"tiff:hostcomputer",text,exception); + if (TIFFGetField(tiff,TIFFTAG_IMAGEDESCRIPTION,&text) == 1) + (void) SetImageProperty(image,"comment",text,exception); if (TIFFGetField(tiff,TIFFTAG_MAKE,&text) == 1) - (void) SetImageProperty(image,"tiff:make",text); + (void) SetImageProperty(image,"tiff:make",text,exception); if (TIFFGetField(tiff,TIFFTAG_MODEL,&text) == 1) - (void) SetImageProperty(image,"tiff:model",text); - if (TIFFGetField(tiff,33432,&text) == 1) - (void) SetImageProperty(image,"tiff:copyright",text); + (void) SetImageProperty(image,"tiff:model",text,exception); + if (TIFFGetField(tiff,TIFFTAG_OPIIMAGEID,&count,&text) == 1) + { + if (count >= MaxTextExtent) + count=MaxTextExtent-1; + (void) CopyMagickString(message,text,count+1); + (void) SetImageProperty(image,"tiff:image-id",message,exception); + } if (TIFFGetField(tiff,TIFFTAG_PAGENAME,&text) == 1) - (void) SetImageProperty(image,"label",text); - if (TIFFGetField(tiff,TIFFTAG_IMAGEDESCRIPTION,&text) == 1) - (void) SetImageProperty(image,"comment",text); + (void) SetImageProperty(image,"label",text,exception); + if (TIFFGetField(tiff,TIFFTAG_SOFTWARE,&text) == 1) + (void) SetImageProperty(image,"tiff:software",text,exception); + if (TIFFGetField(tiff,33423,&count,&text) == 1) + { + if (count >= MaxTextExtent) + count=MaxTextExtent-1; + (void) CopyMagickString(message,text,count+1); + (void) SetImageProperty(image,"tiff:kodak-33423",message,exception); + } + if (TIFFGetField(tiff,36867,&count,&text) == 1) + { + if (count >= MaxTextExtent) + count=MaxTextExtent-1; + (void) CopyMagickString(message,text,count+1); + (void) SetImageProperty(image,"tiff:kodak-36867",message,exception); + } } -static void TIFFGetEXIFProperties(TIFF *tiff,Image *image) +static void TIFFGetEXIFProperties(TIFF *tiff,Image *image, + ExceptionInfo *exception) { #if defined(MAGICKCORE_HAVE_TIFFREADEXIFDIRECTORY) char @@ -575,9 +614,16 @@ static void TIFFGetEXIFProperties(TIFF *tiff,Image *image) tdir_t directory; +#if defined(TIFF_VERSION_BIG) + uint64 +#else uint32 +#endif offset; + void + *sans; + /* Read EXIF properties. */ @@ -586,6 +632,7 @@ static void TIFFGetEXIFProperties(TIFF *tiff,Image *image) directory=TIFFCurrentDirectory(tiff); if (TIFFReadEXIFDirectory(tiff,offset) == 0) return; + sans=NULL; for (i=0; exif_info[i].tag != 0; i++) { *value='\0'; @@ -596,43 +643,58 @@ static void TIFFGetEXIFProperties(TIFF *tiff,Image *image) char *ascii; - if (TIFFGetField(tiff,exif_info[i].tag,&ascii) != 0) + ascii=(char *) NULL; + if ((TIFFGetField(tiff,exif_info[i].tag,&ascii,&sans) != 0) && + (ascii != (char *) NULL) && (*ascii != '\0')) (void) CopyMagickMemory(value,ascii,MaxTextExtent); break; } case TIFF_SHORT: { uint16 - shorty; + shorty[2] = { 0, 0}; - if (TIFFGetField(tiff,exif_info[i].tag,&shorty) != 0) - (void) FormatLocaleString(value,MaxTextExtent,"%d",shorty); + if (TIFFGetField(tiff,exif_info[i].tag,&shorty,&sans) != 0) + (void) FormatLocaleString(value,MaxTextExtent,"%d",(int) shorty[0]); break; } case TIFF_LONG: { uint32 - ssize_ty; + longy; - if (TIFFGetField(tiff,exif_info[i].tag,&ssize_ty) != 0) - (void) FormatLocaleString(value,MaxTextExtent,"%d",ssize_ty); + if (TIFFGetField(tiff,exif_info[i].tag,&longy,&sans) != 0) + (void) FormatLocaleString(value,MaxTextExtent,"%d",longy); break; } +#if defined(TIFF_VERSION_BIG) + case TIFF_LONG8: + { + uint64 + longy; + + if (TIFFGetField(tiff,exif_info[i].tag,&longy,&sans) != 0) + (void) FormatLocaleString(value,MaxTextExtent,"%ld",longy); + break; + } +#endif case TIFF_RATIONAL: case TIFF_SRATIONAL: + case TIFF_FLOAT: + case TIFF_DOUBLE: { float - rational; + rational[16]; - if (TIFFGetField(tiff,exif_info[i].tag,&rational) != 0) - (void) FormatLocaleString(value,MaxTextExtent,"%g",rational); + if (TIFFGetField(tiff,exif_info[i].tag,&rational,&sans) != 0) + (void) FormatLocaleString(value,MaxTextExtent,"%g",rational[0]); break; } default: break; } if (*value != '\0') - (void) SetImageProperty(image,exif_info[i].property,value); + (void) SetImageProperty(image,exif_info[i].property,value,exception); } TIFFSetDirectory(tiff,directory); #else @@ -677,10 +739,24 @@ static toff_t TIFFSeekBlob(thandle_t image,toff_t offset,int whence) return((toff_t) SeekBlob((Image *) image,(MagickOffsetType) offset,whence)); } -static toff_t TIFFGetBlobSize(thandle_t image) +#if defined(MAGICKCORE_HAVE_TIFFMERGEFIELDINFO) && defined(MAGICKCORE_HAVE_TIFFSETTAGEXTENDER) +static TIFFExtendProc + tiff_extensions = (TIFFExtendProc) NULL; + +static void TIFFTagExtender(TIFF *tiff) { - return((toff_t) GetBlobSize((Image *) image)); + static const TIFFFieldInfo + TIFFExtensions[] = + { + { 37724, -3, -3, TIFF_UNDEFINED, FIELD_CUSTOM, 1, 1, "PhotoshopLayerData" } + }; + + TIFFMergeFieldInfo(tiff,TIFFExtensions,sizeof(TIFFExtensions)/ + sizeof(*TIFFExtensions)); + if (tiff_extensions != (TIFFExtendProc) NULL) + (*tiff_extensions)(tiff); } +#endif static void TIFFUnmapBlob(thandle_t image,tdata_t base,toff_t size) { @@ -819,7 +895,11 @@ static Image *ReadTIFFImage(const ImageInfo *image_info, image_info->filename); assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); - image=AcquireImage(image_info); +#if defined(MAGICKCORE_HAVE_TIFFMERGEFIELDINFO) && defined(MAGICKCORE_HAVE_TIFFSETTAGEXTENDER) + if (tiff_extensions == (TIFFExtendProc) NULL) + tiff_extensions=TIFFSetTagExtender(TIFFTagExtender); +#endif + image=AcquireImage(image_info,exception); status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); if (status == MagickFalse) { @@ -849,7 +929,7 @@ static Image *ReadTIFFImage(const ImageInfo *image_info, for (i=0; i < (ssize_t) image_info->scene; i++) { (void) TIFFReadDirectory(tiff); - AcquireNextImage(image_info,image); + AcquireNextImage(image_info,image,exception); if (GetNextImageInList(image) == (Image *) NULL) { image=DestroyImageList(image); @@ -862,8 +942,11 @@ static Image *ReadTIFFImage(const ImageInfo *image_info, { if (0 && (image_info->verbose != MagickFalse)) TIFFPrintDirectory(tiff,stdout,MagickFalse); + TIFFGetEXIFProperties(tiff,image,exception); + TIFFGetProfiles(tiff,image,exception); + TIFFGetProperties(tiff,image,exception); (void) SetImageProperty(image,"tiff:endian",TIFFIsBigEndian(tiff) == 0 ? - "lsb" : "msb"); + "lsb" : "msb",exception); (void) TIFFGetFieldDefaulted(tiff,TIFFTAG_COMPRESSION,&compress_tag); (void) TIFFGetFieldDefaulted(tiff,TIFFTAG_ORIENTATION,&orientation); (void) TIFFGetFieldDefaulted(tiff,TIFFTAG_IMAGEWIDTH,&width); @@ -873,7 +956,8 @@ static Image *ReadTIFFImage(const ImageInfo *image_info, (void) TIFFGetFieldDefaulted(tiff,TIFFTAG_BITSPERSAMPLE,&bits_per_sample); (void) TIFFGetFieldDefaulted(tiff,TIFFTAG_SAMPLEFORMAT,&sample_format); if (sample_format == SAMPLEFORMAT_IEEEFP) - (void) SetImageProperty(image,"quantum:format","floating-point"); + (void) SetImageProperty(image,"quantum:format","floating-point", + exception); (void) TIFFGetFieldDefaulted(tiff,TIFFTAG_MINSAMPLEVALUE,&min_sample_value); (void) TIFFGetFieldDefaulted(tiff,TIFFTAG_MAXSAMPLEVALUE,&max_sample_value); (void) TIFFGetFieldDefaulted(tiff,TIFFTAG_PHOTOMETRIC,&photometric); @@ -881,42 +965,44 @@ static Image *ReadTIFFImage(const ImageInfo *image_info, { case PHOTOMETRIC_MINISBLACK: { - (void) SetImageProperty(image,"tiff:photometric","min-is-black"); + (void) SetImageProperty(image,"tiff:photometric","min-is-black", + exception); break; } case PHOTOMETRIC_MINISWHITE: { - (void) SetImageProperty(image,"tiff:photometric","min-is-white"); + (void) SetImageProperty(image,"tiff:photometric","min-is-white", + exception); break; } case PHOTOMETRIC_PALETTE: { - (void) SetImageProperty(image,"tiff:photometric","palette"); + (void) SetImageProperty(image,"tiff:photometric","palette",exception); break; } case PHOTOMETRIC_RGB: { - (void) SetImageProperty(image,"tiff:photometric","RGB"); + (void) SetImageProperty(image,"tiff:photometric","RGB",exception); break; } case PHOTOMETRIC_CIELAB: { - (void) SetImageProperty(image,"tiff:photometric","CIELAB"); + (void) SetImageProperty(image,"tiff:photometric","CIELAB",exception); break; } case PHOTOMETRIC_SEPARATED: { - (void) SetImageProperty(image,"tiff:photometric","separated"); + (void) SetImageProperty(image,"tiff:photometric","separated",exception); break; } case PHOTOMETRIC_YCBCR: { - (void) SetImageProperty(image,"tiff:photometric","YCBCR"); + (void) SetImageProperty(image,"tiff:photometric","YCBCR",exception); break; } default: { - (void) SetImageProperty(image,"tiff:photometric","unknown"); + (void) SetImageProperty(image,"tiff:photometric","unknown",exception); break; } } @@ -933,7 +1019,8 @@ static Image *ReadTIFFImage(const ImageInfo *image_info, (void) LogMagickEvent(CoderEvent,GetMagickModule(), "Max sample value: %u",max_sample_value); (void) LogMagickEvent(CoderEvent,GetMagickModule(),"Photometric " - "interpretation: %s",GetImageProperty(image,"tiff:photometric")); + "interpretation: %s",GetImageProperty(image,"tiff:photometric", + exception)); } image->columns=(size_t) width; image->rows=(size_t) height; @@ -952,12 +1039,12 @@ static Image *ReadTIFFImage(const ImageInfo *image_info, (void) TIFFGetFieldDefaulted(tiff,TIFFTAG_SAMPLESPERPIXEL, &samples_per_pixel); (void) TIFFGetFieldDefaulted(tiff,TIFFTAG_RESOLUTIONUNIT,&units); - x_resolution=(float) image->x_resolution; - y_resolution=(float) image->y_resolution; + x_resolution=(float) image->resolution.x; + y_resolution=(float) image->resolution.y; (void) TIFFGetFieldDefaulted(tiff,TIFFTAG_XRESOLUTION,&x_resolution); (void) TIFFGetFieldDefaulted(tiff,TIFFTAG_YRESOLUTION,&y_resolution); - image->x_resolution=x_resolution; - image->y_resolution=y_resolution; + image->resolution.x=x_resolution; + image->resolution.y=y_resolution; x_position=(float) image->page.x/x_resolution; y_position=(float) image->page.y/y_resolution; (void) TIFFGetFieldDefaulted(tiff,TIFFTAG_XPOSITION,&x_position); @@ -983,12 +1070,6 @@ static Image *ReadTIFFImage(const ImageInfo *image_info, image->chromaticity.blue_primary.x=chromaticity[4]; image->chromaticity.blue_primary.y=chromaticity[5]; } - TIFFGetProperties(tiff,image); - option=GetImageOption(image_info,"tiff:exif"); - if ((option != (const char *) NULL) && - (IsMagickTrue(option) != MagickFalse)) - TIFFGetEXIFProperties(tiff,image); - TIFFGetProfiles(tiff,image); /* Allocate memory for the image and pixel buffer. */ @@ -1022,7 +1103,7 @@ static Image *ReadTIFFImage(const ImageInfo *image_info, (void) FormatLocaleString(sampling_factor,MaxTextExtent,"%dx%d", horizontal,vertical); (void) SetImageProperty(image,"jpeg:sampling-factor", - sampling_factor); + sampling_factor,exception); (void) LogMagickEvent(CoderEvent,GetMagickModule(), "Sampling Factors: %s",sampling_factor); if ((samples_per_pixel > 1) && (photometric == PHOTOMETRIC_YCBCR)) @@ -1058,6 +1139,7 @@ static Image *ReadTIFFImage(const ImageInfo *image_info, status=SetQuantumFormat(image,quantum_info,FloatingPointQuantumFormat); if (status == MagickFalse) { + quantum_info=DestroyQuantumInfo(quantum_info); TIFFClose(tiff); ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); } @@ -1099,7 +1181,8 @@ static Image *ReadTIFFImage(const ImageInfo *image_info, MagickFalse; if (image->matte != MagickFalse) (void) SetImageProperty(image,"tiff:alpha", - associated_alpha != MagickFalse ? "associated" : "unassociated"); + associated_alpha != MagickFalse ? "associated" : "unassociated", + exception); if ((photometric == PHOTOMETRIC_PALETTE) && (pow(2.0,1.0*bits_per_sample) <= MaxColormapSize)) { @@ -1107,7 +1190,7 @@ static Image *ReadTIFFImage(const ImageInfo *image_info, colors; colors=(size_t) GetQuantumRange(bits_per_sample)+1; - if (AcquireImageColormap(image,colors) == MagickFalse) + if (AcquireImageColormap(image,colors,exception) == MagickFalse) { TIFFClose(tiff); ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); @@ -1136,7 +1219,7 @@ static Image *ReadTIFFImage(const ImageInfo *image_info, method=ReadStripMethod; (void) FormatLocaleString(value,MaxTextExtent,"%u", (unsigned int) rows_per_strip); - (void) SetImageProperty(image,"tiff:rows-per-strip",value); + (void) SetImageProperty(image,"tiff:rows-per-strip",value,exception); } if ((samples_per_pixel >= 2) && (interlace == PLANARCONFIG_CONTIG)) method=ReadRGBAMethod; @@ -1242,7 +1325,7 @@ static Image *ReadTIFFImage(const ImageInfo *image_info, if (status == -1) break; q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); - if (q == (const Quantum *) NULL) + if (q == (Quantum *) NULL) break; length=ImportQuantumPixels(image,(CacheView *) NULL,quantum_info, quantum_type,pixels,exception); @@ -1300,7 +1383,7 @@ static Image *ReadTIFFImage(const ImageInfo *image_info, if (status == -1) break; q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); - if (q == (const Quantum *) NULL) + if (q == (Quantum *) NULL) break; length=ImportQuantumPixels(image,(CacheView *) NULL,quantum_info, quantum_type,pixels,exception); @@ -1336,7 +1419,7 @@ static Image *ReadTIFFImage(const ImageInfo *image_info, if (status == -1) break; q=GetAuthenticPixels(image,0,y,image->columns,1,exception); - if (q == (const Quantum *) NULL) + if (q == (Quantum *) NULL) break; if (image->colorspace != CMYKColorspace) switch (i) @@ -1391,7 +1474,7 @@ static Image *ReadTIFFImage(const ImageInfo *image_info, *restrict q; q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); - if (q == (const Quantum *) NULL) + if (q == (Quantum *) NULL) break; if (i == 0) { @@ -1450,7 +1533,7 @@ static Image *ReadTIFFImage(const ImageInfo *image_info, TIFFClose(tiff); ThrowReaderException(CoderError,"ImageIsNotTiled"); } - (void) SetImageStorageClass(image,DirectClass,&image->exception); + (void) SetImageStorageClass(image,DirectClass,exception); number_pixels=columns*rows; tile_pixels=(uint32 *) AcquireQuantumMemory(number_pixels, sizeof(*tile_pixels)); @@ -1579,7 +1662,7 @@ static Image *ReadTIFFImage(const ImageInfo *image_info, *restrict q; q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); - if (q == (const Quantum *) NULL) + if (q == (Quantum *) NULL) break; q+=GetPixelChannels(image)*(image->columns-1); for (x=0; x < (ssize_t) image->columns; x++) @@ -1612,6 +1695,7 @@ static Image *ReadTIFFImage(const ImageInfo *image_info, } SetQuantumImageType(image,quantum_type); next_tiff_frame: + quantum_info=DestroyQuantumInfo(quantum_info); if ((photometric == PHOTOMETRIC_LOGL) || (photometric == PHOTOMETRIC_MINISBLACK) || (photometric == PHOTOMETRIC_MINISWHITE)) @@ -1645,7 +1729,7 @@ static Image *ReadTIFFImage(const ImageInfo *image_info, /* Allocate next image structure. */ - AcquireNextImage(image_info,image); + AcquireNextImage(image_info,image,exception); if (GetNextImageInList(image) == (Image *) NULL) { image=DestroyImageList(image); @@ -1657,7 +1741,6 @@ static Image *ReadTIFFImage(const ImageInfo *image_info, if (status == MagickFalse) break; } - quantum_info=DestroyQuantumInfo(quantum_info); } while (status == MagickTrue); (void) TIFFSetWarningHandler(warning_handler); (void) TIFFSetErrorHandler(error_handler); @@ -1933,7 +2016,7 @@ static MagickBooleanType WriteGROUP4Image(const ImageInfo *image_info, } (void) FormatLocaleString(huffman_image->filename,MaxTextExtent,"tiff:%s", filename); - (void) SetImageType(huffman_image,BilevelType); + (void) SetImageType(huffman_image,BilevelType,exception); write_info=CloneImageInfo((ImageInfo *) NULL); SetImageInfoFile(write_info,file); write_info->compression=Group4Compression; @@ -2064,7 +2147,7 @@ static MagickBooleanType WritePTIFImage(const ImageInfo *image_info, { columns/=2; rows/=2; - pyramid_image=ResizeImage(next,columns,rows,UndefinedFilter,image->blur, + pyramid_image=ResizeImage(next,columns,rows,image->filter,image->blur, exception); AppendImageToList(&images,pyramid_image); } @@ -2297,54 +2380,55 @@ static void TIFFSetProfiles(TIFF *tiff,Image *image) GetStringInfoLength(profile),GetStringInfoDatum(profile)); #endif if (LocaleCompare(name,"tiff:37724") == 0) - (void) TIFFSetField(tiff,37724,(uint32)GetStringInfoLength(profile), + (void) TIFFSetField(tiff,37724,(uint32) GetStringInfoLength(profile), GetStringInfoDatum(profile)); name=GetNextImageProfile(image); } } -static void TIFFSetProperties(TIFF *tiff,Image *image) +static void TIFFSetProperties(TIFF *tiff,Image *image,ExceptionInfo *exception) { const char *value; (void) TIFFSetField(tiff,TIFFTAG_DOCUMENTNAME,image->filename); - value=GetImageProperty(image,"tiff:hostcomputer"); + value=GetImageProperty(image,"tiff:hostcomputer",exception); if (value != (const char *) NULL) (void) TIFFSetField(tiff,TIFFTAG_HOSTCOMPUTER,value); - value=GetImageProperty(image,"tiff:artist"); + value=GetImageProperty(image,"tiff:artist",exception); if (value != (const char *) NULL) (void) TIFFSetField(tiff,TIFFTAG_ARTIST,value); - value=GetImageProperty(image,"tiff:timestamp"); + value=GetImageProperty(image,"tiff:timestamp",exception); if (value != (const char *) NULL) (void) TIFFSetField(tiff,TIFFTAG_DATETIME,value); - value=GetImageProperty(image,"tiff:make"); + value=GetImageProperty(image,"tiff:make",exception); if (value != (const char *) NULL) (void) TIFFSetField(tiff,TIFFTAG_MAKE,value); - value=GetImageProperty(image,"tiff:model"); + value=GetImageProperty(image,"tiff:model",exception); if (value != (const char *) NULL) (void) TIFFSetField(tiff,TIFFTAG_MODEL,value); - value=GetImageProperty(image,"tiff:software"); + value=GetImageProperty(image,"tiff:software",exception); if (value != (const char *) NULL) (void) TIFFSetField(tiff,TIFFTAG_SOFTWARE,value); - value=GetImageProperty(image,"tiff:copyright"); + value=GetImageProperty(image,"tiff:copyright",exception); if (value != (const char *) NULL) - (void) TIFFSetField(tiff,33432,value); - value=GetImageProperty(image,"kodak-33423"); + (void) TIFFSetField(tiff,TIFFTAG_COPYRIGHT,value); + value=GetImageProperty(image,"kodak-33423",exception); if (value != (const char *) NULL) (void) TIFFSetField(tiff,33423,value); - value=GetImageProperty(image,"kodak-36867"); + value=GetImageProperty(image,"kodak-36867",exception); if (value != (const char *) NULL) (void) TIFFSetField(tiff,36867,value); - value=GetImageProperty(image,"label"); + value=GetImageProperty(image,"label",exception); if (value != (const char *) NULL) (void) TIFFSetField(tiff,TIFFTAG_PAGENAME,value); - value=GetImageProperty(image,"comment"); + value=GetImageProperty(image,"comment",exception); if (value != (const char *) NULL) (void) TIFFSetField(tiff,TIFFTAG_IMAGEDESCRIPTION,value); } -static void TIFFSetEXIFProperties(TIFF *tiff,Image *image) +static void TIFFSetEXIFProperties(TIFF *tiff,Image *image, + ExceptionInfo *exception) { #if defined(MAGICKCORE_HAVE_TIFFREADEXIFDIRECTORY) const char @@ -2363,7 +2447,7 @@ static void TIFFSetEXIFProperties(TIFF *tiff,Image *image) (void) TIFFSetField(tiff,TIFFTAG_SUBIFD,1,&offset); for (i=0; exif_info[i].tag != 0; i++) { - value=GetImageProperty(image,exif_info[i].property); + value=GetImageProperty(image,exif_info[i].property,exception); if (value == (const char *) NULL) continue; switch (exif_info[i].type) @@ -2397,7 +2481,7 @@ static void TIFFSetEXIFProperties(TIFF *tiff,Image *image) float rational; - rational=InterpretLocaleValue(value,(char **) NULL); + rational=StringToDouble(value,(char **) NULL); (void) TIFFSetField(tiff,exif_info[i].tag,rational); break; } @@ -2536,7 +2620,7 @@ static MagickBooleanType WriteTIFFImage(const ImageInfo *image_info, */ if ((image_info->type != UndefinedType) && (image_info->type != OptimizeType)) - (void) SetImageType(image,image_info->type); + (void) SetImageType(image,image_info->type,exception); quantum_info=AcquireQuantumInfo(image_info,image); if (quantum_info == (QuantumInfo *) NULL) ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); @@ -2664,13 +2748,13 @@ static MagickBooleanType WriteTIFFImage(const ImageInfo *image_info, case FaxCompression: case Group4Compression: { - (void) SetImageType(image,BilevelType); + (void) SetImageType(image,BilevelType,exception); break; } case JPEGCompression: { (void) SetImageStorageClass(image,DirectClass,exception); - (void) SetImageDepth(image,8); + (void) SetImageDepth(image,8,exception); break; } default: @@ -2695,12 +2779,12 @@ static MagickBooleanType WriteTIFFImage(const ImageInfo *image_info, photometric=PHOTOMETRIC_YCBCR; (void) TIFFSetField(tiff,TIFFTAG_YCBCRSUBSAMPLING,1,1); (void) SetImageStorageClass(image,DirectClass,exception); - (void) SetImageDepth(image,8); + (void) SetImageDepth(image,8,exception); } else { if (IsRGBColorspace(image->colorspace) == MagickFalse) - (void) TransformImageColorspace(image,RGBColorspace); + (void) TransformImageColorspace(image,RGBColorspace,exception); photometric=PHOTOMETRIC_RGB; } (void) TIFFSetField(tiff,TIFFTAG_SAMPLESPERPIXEL,3); @@ -2780,7 +2864,7 @@ static MagickBooleanType WriteTIFFImage(const ImageInfo *image_info, compress_tag=COMPRESSION_NONE; endian=FILLORDER_MSB2LSB; } - option=GetImageProperty(image,"tiff:fill-order"); + option=GetImageProperty(image,"tiff:fill-order",exception); if (option != (const char *) NULL) { if (LocaleNCompare(option,"msb",3) == 0) @@ -2803,7 +2887,7 @@ static MagickBooleanType WriteTIFFImage(const ImageInfo *image_info, */ extra_samples=1; sample_info[0]=EXTRASAMPLE_UNASSALPHA; - option=GetImageProperty(image,"tiff:alpha"); + option=GetImageProperty(image,"tiff:alpha",exception); if ((option != (const char *) NULL) && (LocaleCompare(option,"associated") == 0)) sample_info[0]=EXTRASAMPLE_ASSOCALPHA; @@ -2878,7 +2962,7 @@ static MagickBooleanType WriteTIFFImage(const ImageInfo *image_info, (void) TIFFSetField(tiff,TIFFTAG_JPEGCOLORMODE,JPEGCOLORMODE_RGB); sampling_factor=(const char *) NULL; - value=GetImageProperty(image,"jpeg:sampling-factor"); + value=GetImageProperty(image,"jpeg:sampling-factor",exception); if (value != (char *) NULL) { sampling_factor=value; @@ -2960,7 +3044,7 @@ static MagickBooleanType WriteTIFFImage(const ImageInfo *image_info, option=GetImageOption(image_info,"tiff:tile-geometry"); if (option == (const char *) NULL) (void) TIFFSetField(tiff,TIFFTAG_ROWSPERSTRIP,rows_per_strip); - if ((image->x_resolution != 0.0) && (image->y_resolution != 0.0)) + if ((image->resolution.x != 0.0) && (image->resolution.y != 0.0)) { unsigned short units; @@ -2974,17 +3058,17 @@ static MagickBooleanType WriteTIFFImage(const ImageInfo *image_info, if (image->units == PixelsPerCentimeterResolution) units=RESUNIT_CENTIMETER; (void) TIFFSetField(tiff,TIFFTAG_RESOLUTIONUNIT,(uint16) units); - (void) TIFFSetField(tiff,TIFFTAG_XRESOLUTION,image->x_resolution); - (void) TIFFSetField(tiff,TIFFTAG_YRESOLUTION,image->y_resolution); + (void) TIFFSetField(tiff,TIFFTAG_XRESOLUTION,image->resolution.x); + (void) TIFFSetField(tiff,TIFFTAG_YRESOLUTION,image->resolution.y); if ((image->page.x != 0) || (image->page.y != 0)) { /* Set image position. */ (void) TIFFSetField(tiff,TIFFTAG_XPOSITION,(float) image->page.x/ - image->x_resolution); + image->resolution.x); (void) TIFFSetField(tiff,TIFFTAG_YPOSITION,(float) image->page.y/ - image->y_resolution); + image->resolution.y); } } if (image->chromaticity.white_point.x != 0.0) @@ -3027,9 +3111,9 @@ static MagickBooleanType WriteTIFFImage(const ImageInfo *image_info, (void) TIFFSetField(tiff,TIFFTAG_SUBFILETYPE,FILETYPE_PAGE); (void) TIFFSetField(tiff,TIFFTAG_PAGENUMBER,page,pages); } - (void) TIFFSetProperties(tiff,image); + (void) TIFFSetProperties(tiff,image,exception); if (0) - (void) TIFFSetEXIFProperties(tiff,image); + (void) TIFFSetEXIFProperties(tiff,image,exception); /* Write image scanlines. */ @@ -3174,7 +3258,7 @@ static MagickBooleanType WriteTIFFImage(const ImageInfo *image_info, if (image->matte != MagickFalse) quantum_type=CMYKAQuantum; if (image->colorspace != CMYKColorspace) - (void) TransformImageColorspace(image,CMYKColorspace); + (void) TransformImageColorspace(image,CMYKColorspace,exception); for (y=0; y < (ssize_t) image->rows; y++) { register const Quantum