2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 % TTTTT IIIII FFFFF FFFFF %
13 % Read/Write TIFF Image Format %
20 % Copyright 1999-2015 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
28 % Unless required by applicable law or agreed to in writing, software %
29 % distributed under the License is distributed on an "AS IS" BASIS, %
30 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31 % See the License for the specific language governing permissions and %
32 % limitations under the License. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42 #include "MagickCore/studio.h"
43 #include "MagickCore/artifact.h"
44 #include "MagickCore/attribute.h"
45 #include "MagickCore/blob.h"
46 #include "MagickCore/blob-private.h"
47 #include "MagickCore/cache.h"
48 #include "MagickCore/color.h"
49 #include "MagickCore/color-private.h"
50 #include "MagickCore/colormap.h"
51 #include "MagickCore/colorspace.h"
52 #include "MagickCore/colorspace-private.h"
53 #include "MagickCore/constitute.h"
54 #include "MagickCore/enhance.h"
55 #include "MagickCore/exception.h"
56 #include "MagickCore/exception-private.h"
57 #include "MagickCore/geometry.h"
58 #include "MagickCore/image.h"
59 #include "MagickCore/image-private.h"
60 #include "MagickCore/list.h"
61 #include "MagickCore/log.h"
62 #include "MagickCore/magick.h"
63 #include "MagickCore/memory_.h"
64 #include "MagickCore/module.h"
65 #include "MagickCore/monitor.h"
66 #include "MagickCore/monitor-private.h"
67 #include "MagickCore/option.h"
68 #include "MagickCore/pixel-accessor.h"
69 #include "MagickCore/pixel-private.h"
70 #include "MagickCore/property.h"
71 #include "MagickCore/quantum.h"
72 #include "MagickCore/quantum-private.h"
73 #include "MagickCore/profile.h"
74 #include "MagickCore/resize.h"
75 #include "MagickCore/resource_.h"
76 #include "MagickCore/semaphore.h"
77 #include "MagickCore/splay-tree.h"
78 #include "MagickCore/static.h"
79 #include "MagickCore/statistic.h"
80 #include "MagickCore/string_.h"
81 #include "MagickCore/string-private.h"
82 #include "MagickCore/thread_.h"
83 #include "MagickCore/token.h"
84 #include "MagickCore/utility.h"
85 #if defined(MAGICKCORE_TIFF_DELEGATE)
86 # if defined(MAGICKCORE_HAVE_TIFFCONF_H)
87 # include "tiffconf.h"
91 # if !defined(COMPRESSION_ADOBE_DEFLATE)
92 # define COMPRESSION_ADOBE_DEFLATE 8
94 # if !defined(PREDICTOR_HORIZONTAL)
95 # define PREDICTOR_HORIZONTAL 2
97 # if !defined(TIFFTAG_COPYRIGHT)
98 # define TIFFTAG_COPYRIGHT 33432
100 # if !defined(TIFFTAG_OPIIMAGEID)
101 # define TIFFTAG_OPIIMAGEID 32781
105 Typedef declarations.
109 ReadSingleSampleMethod,
118 #if defined(MAGICKCORE_HAVE_TIFFREADEXIFDIRECTORY)
119 typedef struct _ExifInfo
130 static const ExifInfo
132 { EXIFTAG_EXPOSURETIME, TIFF_RATIONAL, 0, "exif:ExposureTime" },
133 { EXIFTAG_FNUMBER, TIFF_RATIONAL, 0, "exif:FNumber" },
134 { EXIFTAG_EXPOSUREPROGRAM, TIFF_SHORT, 0, "exif:ExposureProgram" },
135 { EXIFTAG_SPECTRALSENSITIVITY, TIFF_ASCII, 0, "exif:SpectralSensitivity" },
136 { EXIFTAG_ISOSPEEDRATINGS, TIFF_SHORT, 1, "exif:ISOSpeedRatings" },
137 { EXIFTAG_OECF, TIFF_NOTYPE, 0, "exif:OptoelectricConversionFactor" },
138 { EXIFTAG_EXIFVERSION, TIFF_NOTYPE, 0, "exif:ExifVersion" },
139 { EXIFTAG_DATETIMEORIGINAL, TIFF_ASCII, 0, "exif:DateTimeOriginal" },
140 { EXIFTAG_DATETIMEDIGITIZED, TIFF_ASCII, 0, "exif:DateTimeDigitized" },
141 { EXIFTAG_COMPONENTSCONFIGURATION, TIFF_NOTYPE, 0, "exif:ComponentsConfiguration" },
142 { EXIFTAG_COMPRESSEDBITSPERPIXEL, TIFF_RATIONAL, 0, "exif:CompressedBitsPerPixel" },
143 { EXIFTAG_SHUTTERSPEEDVALUE, TIFF_SRATIONAL, 0, "exif:ShutterSpeedValue" },
144 { EXIFTAG_APERTUREVALUE, TIFF_RATIONAL, 0, "exif:ApertureValue" },
145 { EXIFTAG_BRIGHTNESSVALUE, TIFF_SRATIONAL, 0, "exif:BrightnessValue" },
146 { EXIFTAG_EXPOSUREBIASVALUE, TIFF_SRATIONAL, 0, "exif:ExposureBiasValue" },
147 { EXIFTAG_MAXAPERTUREVALUE, TIFF_RATIONAL, 0, "exif:MaxApertureValue" },
148 { EXIFTAG_SUBJECTDISTANCE, TIFF_RATIONAL, 0, "exif:SubjectDistance" },
149 { EXIFTAG_METERINGMODE, TIFF_SHORT, 0, "exif:MeteringMode" },
150 { EXIFTAG_LIGHTSOURCE, TIFF_SHORT, 0, "exif:LightSource" },
151 { EXIFTAG_FLASH, TIFF_SHORT, 0, "exif:Flash" },
152 { EXIFTAG_FOCALLENGTH, TIFF_RATIONAL, 0, "exif:FocalLength" },
153 { EXIFTAG_SUBJECTAREA, TIFF_NOTYPE, 0, "exif:SubjectArea" },
154 { EXIFTAG_MAKERNOTE, TIFF_NOTYPE, 0, "exif:MakerNote" },
155 { EXIFTAG_USERCOMMENT, TIFF_NOTYPE, 0, "exif:UserComment" },
156 { EXIFTAG_SUBSECTIME, TIFF_ASCII, 0, "exif:SubSecTime" },
157 { EXIFTAG_SUBSECTIMEORIGINAL, TIFF_ASCII, 0, "exif:SubSecTimeOriginal" },
158 { EXIFTAG_SUBSECTIMEDIGITIZED, TIFF_ASCII, 0, "exif:SubSecTimeDigitized" },
159 { EXIFTAG_FLASHPIXVERSION, TIFF_NOTYPE, 0, "exif:FlashpixVersion" },
160 { EXIFTAG_PIXELXDIMENSION, TIFF_LONG, 0, "exif:PixelXDimension" },
161 { EXIFTAG_PIXELYDIMENSION, TIFF_LONG, 0, "exif:PixelYDimension" },
162 { EXIFTAG_RELATEDSOUNDFILE, TIFF_ASCII, 0, "exif:RelatedSoundFile" },
163 { EXIFTAG_FLASHENERGY, TIFF_RATIONAL, 0, "exif:FlashEnergy" },
164 { EXIFTAG_SPATIALFREQUENCYRESPONSE, TIFF_NOTYPE, 0, "exif:SpatialFrequencyResponse" },
165 { EXIFTAG_FOCALPLANEXRESOLUTION, TIFF_RATIONAL, 0, "exif:FocalPlaneXResolution" },
166 { EXIFTAG_FOCALPLANEYRESOLUTION, TIFF_RATIONAL, 0, "exif:FocalPlaneYResolution" },
167 { EXIFTAG_FOCALPLANERESOLUTIONUNIT, TIFF_SHORT, 0, "exif:FocalPlaneResolutionUnit" },
168 { EXIFTAG_SUBJECTLOCATION, TIFF_SHORT, 0, "exif:SubjectLocation" },
169 { EXIFTAG_EXPOSUREINDEX, TIFF_RATIONAL, 0, "exif:ExposureIndex" },
170 { EXIFTAG_SENSINGMETHOD, TIFF_SHORT, 0, "exif:SensingMethod" },
171 { EXIFTAG_FILESOURCE, TIFF_NOTYPE, 0, "exif:FileSource" },
172 { EXIFTAG_SCENETYPE, TIFF_NOTYPE, 0, "exif:SceneType" },
173 { EXIFTAG_CFAPATTERN, TIFF_NOTYPE, 0, "exif:CFAPattern" },
174 { EXIFTAG_CUSTOMRENDERED, TIFF_SHORT, 0, "exif:CustomRendered" },
175 { EXIFTAG_EXPOSUREMODE, TIFF_SHORT, 0, "exif:ExposureMode" },
176 { EXIFTAG_WHITEBALANCE, TIFF_SHORT, 0, "exif:WhiteBalance" },
177 { EXIFTAG_DIGITALZOOMRATIO, TIFF_RATIONAL, 0, "exif:DigitalZoomRatio" },
178 { EXIFTAG_FOCALLENGTHIN35MMFILM, TIFF_SHORT, 0, "exif:FocalLengthIn35mmFilm" },
179 { EXIFTAG_SCENECAPTURETYPE, TIFF_SHORT, 0, "exif:SceneCaptureType" },
180 { EXIFTAG_GAINCONTROL, TIFF_RATIONAL, 0, "exif:GainControl" },
181 { EXIFTAG_CONTRAST, TIFF_SHORT, 0, "exif:Contrast" },
182 { EXIFTAG_SATURATION, TIFF_SHORT, 0, "exif:Saturation" },
183 { EXIFTAG_SHARPNESS, TIFF_SHORT, 0, "exif:Sharpness" },
184 { EXIFTAG_DEVICESETTINGDESCRIPTION, TIFF_NOTYPE, 0, "exif:DeviceSettingDescription" },
185 { EXIFTAG_SUBJECTDISTANCERANGE, TIFF_SHORT, 0, "exif:SubjectDistanceRange" },
186 { EXIFTAG_IMAGEUNIQUEID, TIFF_ASCII, 0, "exif:ImageUniqueID" },
187 { 0, 0, 0, (char *) NULL }
190 #endif /* MAGICKCORE_TIFF_DELEGATE */
195 static MagickThreadKey
199 *tiff_semaphore = (SemaphoreInfo *) NULL;
201 static volatile MagickBooleanType
202 instantiate_key = MagickFalse;
205 Forward declarations.
207 #if defined(MAGICKCORE_TIFF_DELEGATE)
209 ReadTIFFImage(const ImageInfo *,ExceptionInfo *);
211 static MagickBooleanType
212 WriteGROUP4Image(const ImageInfo *,Image *,ExceptionInfo *),
213 WritePTIFImage(const ImageInfo *,Image *,ExceptionInfo *),
214 WriteTIFFImage(const ImageInfo *,Image *,ExceptionInfo *);
218 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
226 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
228 % IsTIFF() returns MagickTrue if the image format type, identified by the
229 % magick string, is TIFF.
231 % The format of the IsTIFF method is:
233 % MagickBooleanType IsTIFF(const unsigned char *magick,const size_t length)
235 % A description of each parameter follows:
237 % o magick: compare image format pattern against these bytes.
239 % o length: Specifies the length of the magick string.
242 static MagickBooleanType IsTIFF(const unsigned char *magick,const size_t length)
246 if (memcmp(magick,"\115\115\000\052",4) == 0)
248 if (memcmp(magick,"\111\111\052\000",4) == 0)
250 #if defined(TIFF_VERSION_BIG)
253 if (memcmp(magick,"\115\115\000\053\000\010\000\000",8) == 0)
255 if (memcmp(magick,"\111\111\053\000\010\000\000\000",8) == 0)
261 #if defined(MAGICKCORE_TIFF_DELEGATE)
263 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
267 % R e a d G R O U P 4 I m a g e %
271 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
273 % ReadGROUP4Image() reads a raw CCITT Group 4 image file and returns it. It
274 % allocates the memory necessary for the new Image structure and returns a
275 % pointer to the new image.
277 % The format of the ReadGROUP4Image method is:
279 % Image *ReadGROUP4Image(const ImageInfo *image_info,
280 % ExceptionInfo *exception)
282 % A description of each parameter follows:
284 % o image_info: the image info.
286 % o exception: return any errors or warnings in this structure.
290 static inline size_t WriteLSBLong(FILE *file,const size_t value)
295 buffer[0]=(unsigned char) value;
296 buffer[1]=(unsigned char) (value >> 8);
297 buffer[2]=(unsigned char) (value >> 16);
298 buffer[3]=(unsigned char) (value >> 24);
299 return(fwrite(buffer,1,4,file));
302 static Image *ReadGROUP4Image(const ImageInfo *image_info,
303 ExceptionInfo *exception)
306 filename[MaxTextExtent];
334 assert(image_info != (const ImageInfo *) NULL);
335 assert(image_info->signature == MagickSignature);
336 if (image_info->debug != MagickFalse)
337 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
338 image_info->filename);
339 assert(exception != (ExceptionInfo *) NULL);
340 assert(exception->signature == MagickSignature);
341 image=AcquireImage(image_info,exception);
342 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
343 if (status == MagickFalse)
345 image=DestroyImageList(image);
346 return((Image *) NULL);
349 Write raw CCITT Group 4 wrapped as a TIFF image file.
352 unique_file=AcquireUniqueFileResource(filename);
353 if (unique_file != -1)
354 file=fdopen(unique_file,"wb");
355 if ((unique_file == -1) || (file == (FILE *) NULL))
356 ThrowImageException(FileOpenError,"UnableToCreateTemporaryFile");
357 length=fwrite("\111\111\052\000\010\000\000\000\016\000",1,10,file);
358 length=fwrite("\376\000\003\000\001\000\000\000\000\000\000\000",1,12,file);
359 length=fwrite("\000\001\004\000\001\000\000\000",1,8,file);
360 length=WriteLSBLong(file,image->columns);
361 length=fwrite("\001\001\004\000\001\000\000\000",1,8,file);
362 length=WriteLSBLong(file,image->rows);
363 length=fwrite("\002\001\003\000\001\000\000\000\001\000\000\000",1,12,file);
364 length=fwrite("\003\001\003\000\001\000\000\000\004\000\000\000",1,12,file);
365 length=fwrite("\006\001\003\000\001\000\000\000\000\000\000\000",1,12,file);
366 length=fwrite("\021\001\003\000\001\000\000\000",1,8,file);
367 strip_offset=10+(12*14)+4+8;
368 length=WriteLSBLong(file,(size_t) strip_offset);
369 length=fwrite("\022\001\003\000\001\000\000\000",1,8,file);
370 length=WriteLSBLong(file,(size_t) image_info->orientation);
371 length=fwrite("\025\001\003\000\001\000\000\000\001\000\000\000",1,12,file);
372 length=fwrite("\026\001\004\000\001\000\000\000",1,8,file);
373 length=WriteLSBLong(file,image->rows);
374 length=fwrite("\027\001\004\000\001\000\000\000\000\000\000\000",1,12,file);
375 offset=(ssize_t) ftell(file)-4;
376 length=fwrite("\032\001\005\000\001\000\000\000",1,8,file);
377 length=WriteLSBLong(file,(size_t) (strip_offset-8));
378 length=fwrite("\033\001\005\000\001\000\000\000",1,8,file);
379 length=WriteLSBLong(file,(size_t) (strip_offset-8));
380 length=fwrite("\050\001\003\000\001\000\000\000\002\000\000\000",1,12,file);
381 length=fwrite("\000\000\000\000",1,4,file);
382 length=WriteLSBLong(file,(long) image->resolution.x);
383 length=WriteLSBLong(file,1);
384 for (length=0; (c=ReadBlobByte(image)) != EOF; length++)
385 (void) fputc(c,file);
386 offset=(ssize_t) fseek(file,(ssize_t) offset,SEEK_SET);
387 length=WriteLSBLong(file,(unsigned int) length);
389 (void) CloseBlob(image);
390 image=DestroyImage(image);
394 read_info=CloneImageInfo((ImageInfo *) NULL);
395 (void) FormatLocaleString(read_info->filename,MaxTextExtent,"%s",filename);
396 image=ReadTIFFImage(read_info,exception);
397 read_info=DestroyImageInfo(read_info);
398 if (image != (Image *) NULL)
400 (void) CopyMagickString(image->filename,image_info->filename,
402 (void) CopyMagickString(image->magick_filename,image_info->filename,
404 (void) CopyMagickString(image->magick,"GROUP4",MaxTextExtent);
406 (void) RelinquishUniqueFileResource(filename);
411 #if defined(MAGICKCORE_TIFF_DELEGATE)
413 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
417 % R e a d T I F F I m a g e %
421 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
423 % ReadTIFFImage() reads a Tagged image file and returns it. It allocates the
424 % memory necessary for the new Image structure and returns a pointer to the
427 % The format of the ReadTIFFImage method is:
429 % Image *ReadTIFFImage(const ImageInfo *image_info,
430 % ExceptionInfo *exception)
432 % A description of each parameter follows:
434 % o image_info: the image info.
436 % o exception: return any errors or warnings in this structure.
440 static inline unsigned char ClampYCC(double value)
444 return((unsigned char)0);
446 return((unsigned char)255);
447 return((unsigned char)(value));
450 static MagickBooleanType DecodeLabImage(Image *image,ExceptionInfo *exception)
462 image_view=AcquireAuthenticCacheView(image,exception);
463 for (y=0; y < (ssize_t) image->rows; y++)
471 if (status == MagickFalse)
473 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
474 if (q == (Quantum *) NULL)
479 for (x=0; x < (ssize_t) image->columns; x++)
485 a=QuantumScale*GetPixela(image,q)+0.5;
488 b=QuantumScale*GetPixelb(image,q)+0.5;
491 SetPixela(image,QuantumRange*a,q);
492 SetPixelb(image,QuantumRange*b,q);
493 q+=GetPixelChannels(image);
495 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
498 image_view=DestroyCacheView(image_view);
502 static MagickBooleanType ReadProfile(Image *image,const char *name,
503 unsigned char *datum,ssize_t length,ExceptionInfo *exception)
513 if ((LocaleCompare(name,"icc") != 0) && (LocaleCompare(name,"xmp") != 0))
515 if (strstr((char *) datum,"8BIM") == (char *) NULL)
518 profile=BlobToStringInfo(datum,(size_t) length);
519 if (profile == (StringInfo *) NULL)
520 ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
522 status=SetImageProfile(image,name,profile,exception);
523 profile=DestroyStringInfo(profile);
524 if (status == MagickFalse)
525 ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
530 #if defined(__cplusplus) || defined(c_plusplus)
534 static int TIFFCloseBlob(thandle_t image)
536 (void) CloseBlob((Image *) image);
540 static void TIFFErrors(const char *module,const char *format,va_list error)
543 message[MaxTextExtent];
548 #if defined(MAGICKCORE_HAVE_VSNPRINTF)
549 (void) vsnprintf(message,MaxTextExtent,format,error);
551 (void) vsprintf(message,format,error);
553 (void) ConcatenateMagickString(message,".",MaxTextExtent);
554 exception=(ExceptionInfo *) MagickGetThreadValue(tiff_exception);
555 if (exception != (ExceptionInfo *) NULL)
556 (void) ThrowMagickException(exception,GetMagickModule(),CoderError,message,
560 static toff_t TIFFGetBlobSize(thandle_t image)
562 return((toff_t) GetBlobSize((Image *) image));
565 static void TIFFGetProfiles(TIFF *tiff,Image *image,ExceptionInfo *exception)
574 #if defined(TIFFTAG_ICCPROFILE)
575 if ((TIFFGetField(tiff,TIFFTAG_ICCPROFILE,&length,&profile) == 1) &&
576 (profile != (unsigned char *) NULL))
577 (void) ReadProfile(image,"icc",profile,(ssize_t) length,exception);
579 #if defined(TIFFTAG_PHOTOSHOP)
580 if ((TIFFGetField(tiff,TIFFTAG_PHOTOSHOP,&length,&profile) == 1) &&
581 (profile != (unsigned char *) NULL))
582 (void) ReadProfile(image,"8bim",profile,(ssize_t) length,exception);
584 #if defined(TIFFTAG_RICHTIFFIPTC)
585 if ((TIFFGetField(tiff,TIFFTAG_RICHTIFFIPTC,&length,&profile) == 1) &&
586 (profile != (unsigned char *) NULL))
588 if (TIFFIsByteSwapped(tiff) != 0)
589 TIFFSwabArrayOfLong((uint32 *) profile,(size_t) length);
590 (void) ReadProfile(image,"iptc",profile,4L*length,exception);
593 #if defined(TIFFTAG_XMLPACKET)
594 if ((TIFFGetField(tiff,TIFFTAG_XMLPACKET,&length,&profile) == 1) &&
595 (profile != (unsigned char *) NULL))
596 (void) ReadProfile(image,"xmp",profile,(ssize_t) length,exception);
598 if ((TIFFGetField(tiff,37724,&length,&profile) == 1) &&
599 (profile != (unsigned char *) NULL))
600 (void) ReadProfile(image,"tiff:37724",profile,(ssize_t) length,exception);
601 if ((TIFFGetField(tiff,34118,&length,&profile) == 1) &&
602 (profile != (unsigned char *) NULL))
603 (void) ReadProfile(image,"tiff:34118",profile,(ssize_t) length,exception);
606 static void TIFFGetProperties(TIFF *tiff,Image *image,ExceptionInfo *exception)
609 message[MaxTextExtent],
615 if (TIFFGetField(tiff,TIFFTAG_ARTIST,&text) == 1)
616 (void) SetImageProperty(image,"tiff:artist",text,exception);
617 if (TIFFGetField(tiff,TIFFTAG_COPYRIGHT,&text) == 1)
618 (void) SetImageProperty(image,"tiff:copyright",text,exception);
619 if (TIFFGetField(tiff,TIFFTAG_DATETIME,&text) == 1)
620 (void) SetImageProperty(image,"tiff:timestamp",text,exception);
621 if (TIFFGetField(tiff,TIFFTAG_DOCUMENTNAME,&text) == 1)
622 (void) SetImageProperty(image,"tiff:document",text,exception);
623 if (TIFFGetField(tiff,TIFFTAG_HOSTCOMPUTER,&text) == 1)
624 (void) SetImageProperty(image,"tiff:hostcomputer",text,exception);
625 if (TIFFGetField(tiff,TIFFTAG_IMAGEDESCRIPTION,&text) == 1)
626 (void) SetImageProperty(image,"comment",text,exception);
627 if (TIFFGetField(tiff,TIFFTAG_MAKE,&text) == 1)
628 (void) SetImageProperty(image,"tiff:make",text,exception);
629 if (TIFFGetField(tiff,TIFFTAG_MODEL,&text) == 1)
630 (void) SetImageProperty(image,"tiff:model",text,exception);
631 if (TIFFGetField(tiff,TIFFTAG_OPIIMAGEID,&count,&text) == 1)
633 if (count >= MaxTextExtent)
634 count=MaxTextExtent-1;
635 (void) CopyMagickString(message,text,count+1);
636 (void) SetImageProperty(image,"tiff:image-id",message,exception);
638 if (TIFFGetField(tiff,TIFFTAG_PAGENAME,&text) == 1)
639 (void) SetImageProperty(image,"label",text,exception);
640 if (TIFFGetField(tiff,TIFFTAG_SOFTWARE,&text) == 1)
641 (void) SetImageProperty(image,"tiff:software",text,exception);
642 if (TIFFGetField(tiff,33423,&count,&text) == 1)
644 if (count >= MaxTextExtent)
645 count=MaxTextExtent-1;
646 (void) CopyMagickString(message,text,count+1);
647 (void) SetImageProperty(image,"tiff:kodak-33423",message,exception);
649 if (TIFFGetField(tiff,36867,&count,&text) == 1)
651 if (count >= MaxTextExtent)
652 count=MaxTextExtent-1;
653 (void) CopyMagickString(message,text,count+1);
654 (void) SetImageProperty(image,"tiff:kodak-36867",message,exception);
658 static void TIFFGetEXIFProperties(TIFF *tiff,Image *image,
659 ExceptionInfo *exception)
661 #if defined(MAGICKCORE_HAVE_TIFFREADEXIFDIRECTORY)
663 value[MaxTextExtent];
671 #if defined(TIFF_VERSION_BIG)
682 Read EXIF properties.
685 if (TIFFGetField(tiff,TIFFTAG_EXIFIFD,&offset) != 1)
687 directory=TIFFCurrentDirectory(tiff);
688 if (TIFFReadEXIFDirectory(tiff,offset) != 1)
690 directory=TIFFCurrentDirectory(tiff);
694 for (i=0; exif_info[i].tag != 0; i++)
697 switch (exif_info[i].type)
705 if ((TIFFGetField(tiff,exif_info[i].tag,&ascii,&sans,&sans) == 1) &&
706 (ascii != (char *) NULL) && (*ascii != '\0'))
707 (void) CopyMagickString(value,ascii,MaxTextExtent);
712 if (exif_info[i].variable_length == 0)
718 if (TIFFGetField(tiff,exif_info[i].tag,&shorty,&sans,&sans) == 1)
719 (void) FormatLocaleString(value,MaxTextExtent,"%d",shorty);
732 tiff_status=TIFFGetField(tiff,exif_info[i].tag,&shorty_num,&shorty,
734 if (tiff_status == 1)
735 (void) FormatLocaleString(value,MaxTextExtent,"%d",
736 shorty_num != 0 ? shorty[0] : 0);
746 if (TIFFGetField(tiff,exif_info[i].tag,&longy,&sans,&sans) == 1)
747 (void) FormatLocaleString(value,MaxTextExtent,"%d",longy);
750 #if defined(TIFF_VERSION_BIG)
757 if (TIFFGetField(tiff,exif_info[i].tag,&long8y,&sans,&sans) == 1)
758 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
759 ((MagickOffsetType) long8y));
771 if (TIFFGetField(tiff,exif_info[i].tag,&floaty,&sans,&sans) == 1)
772 (void) FormatLocaleString(value,MaxTextExtent,"%g",(double) floaty);
781 if (TIFFGetField(tiff,exif_info[i].tag,&doubley,&sans,&sans) == 1)
782 (void) FormatLocaleString(value,MaxTextExtent,"%g",doubley);
789 (void) SetImageProperty(image,exif_info[i].property,value,exception);
791 TIFFSetDirectory(tiff,directory);
798 static int TIFFMapBlob(thandle_t image,tdata_t *base,toff_t *size)
800 *base=(tdata_t *) GetBlobStreamData((Image *) image);
801 if (*base != (tdata_t *) NULL)
802 *size=(toff_t) GetBlobSize((Image *) image);
803 if (*base != (tdata_t *) NULL)
808 static tsize_t TIFFReadBlob(thandle_t image,tdata_t data,tsize_t size)
813 count=(tsize_t) ReadBlob((Image *) image,(size_t) size,
814 (unsigned char *) data);
818 static int32 TIFFReadPixels(TIFF *tiff,size_t bits_per_sample,
819 tsample_t sample,ssize_t row,tdata_t scanline)
824 (void) bits_per_sample;
825 status=TIFFReadScanline(tiff,scanline,(uint32) row,sample);
829 static toff_t TIFFSeekBlob(thandle_t image,toff_t offset,int whence)
831 return((toff_t) SeekBlob((Image *) image,(MagickOffsetType) offset,whence));
834 static void TIFFUnmapBlob(thandle_t image,tdata_t base,toff_t size)
841 static void TIFFWarnings(const char *module,const char *format,va_list warning)
844 message[MaxTextExtent];
849 #if defined(MAGICKCORE_HAVE_VSNPRINTF)
850 (void) vsnprintf(message,MaxTextExtent,format,warning);
852 (void) vsprintf(message,format,warning);
854 (void) ConcatenateMagickString(message,".",MaxTextExtent);
855 exception=(ExceptionInfo *) MagickGetThreadValue(tiff_exception);
856 if (exception != (ExceptionInfo *) NULL)
857 (void) ThrowMagickException(exception,GetMagickModule(),CoderWarning,
858 message,"`%s'",module);
861 static tsize_t TIFFWriteBlob(thandle_t image,tdata_t data,tsize_t size)
866 count=(tsize_t) WriteBlob((Image *) image,(size_t) size,
867 (unsigned char *) data);
871 static TIFFMethodType GetJPEGMethod(Image* image,TIFF *tiff,uint16 photometric,
872 uint16 bits_per_sample,uint16 samples_per_pixel)
874 #define BUFFER_SIZE 2048
886 #if defined(TIFF_VERSION_BIG)
894 buffer[BUFFER_SIZE+3];
899 /* only support 8 bit for now */
900 if ((photometric != PHOTOMETRIC_SEPARATED) || (bits_per_sample != 8) ||
901 (samples_per_pixel != 4))
902 return(ReadGenericMethod);
903 /* Search for Adobe APP14 JPEG Marker */
904 if (!TIFFGetField(tiff,TIFFTAG_STRIPOFFSETS,&value))
905 return(ReadRGBAMethod);
906 position=TellBlob(image);
907 offset=(MagickOffsetType) value[0];
908 if (SeekBlob(image,offset,SEEK_SET) != offset)
909 return(ReadRGBAMethod);
910 method=ReadRGBAMethod;
911 if (ReadBlob(image,BUFFER_SIZE,buffer) == BUFFER_SIZE)
913 for (i=0; i < BUFFER_SIZE; i++)
915 while (i < BUFFER_SIZE)
917 if (buffer[i++] == 255)
920 while (i < BUFFER_SIZE)
922 if (buffer[++i] != 255)
925 if (buffer[i++] == 216) /* JPEG_MARKER_SOI */
927 length=(unsigned short) (((unsigned int) (buffer[i] << 8) |
928 (unsigned int) buffer[i+1]) & 0xffff);
929 if (i+(size_t) length >= BUFFER_SIZE)
931 if (buffer[i-1] == 238) /* JPEG_MARKER_APP0+14 */
935 /* 0 == CMYK, 1 == YCbCr, 2 = YCCK */
936 if (buffer[i+13] == 2)
937 method=ReadYCCKMethod;
943 SeekBlob(image,position,SEEK_SET);
947 #if defined(__cplusplus) || defined(c_plusplus)
951 static Image *ReadTIFFImage(const ImageInfo *image_info,
952 ExceptionInfo *exception)
1030 assert(image_info != (const ImageInfo *) NULL);
1031 assert(image_info->signature == MagickSignature);
1032 if (image_info->debug != MagickFalse)
1033 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1034 image_info->filename);
1035 assert(exception != (ExceptionInfo *) NULL);
1036 assert(exception->signature == MagickSignature);
1037 image=AcquireImage(image_info,exception);
1038 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
1039 if (status == MagickFalse)
1041 image=DestroyImageList(image);
1042 return((Image *) NULL);
1044 (void) MagickSetThreadValue(tiff_exception,exception);
1045 error_handler=TIFFSetErrorHandler(TIFFErrors);
1046 warning_handler=TIFFSetWarningHandler(TIFFWarnings);
1047 tiff=TIFFClientOpen(image->filename,"rb",(thandle_t) image,TIFFReadBlob,
1048 TIFFWriteBlob,TIFFSeekBlob,TIFFCloseBlob,TIFFGetBlobSize,TIFFMapBlob,
1050 if (tiff == (TIFF *) NULL)
1052 (void) TIFFSetWarningHandler(warning_handler);
1053 (void) TIFFSetErrorHandler(error_handler);
1054 image=DestroyImageList(image);
1055 return((Image *) NULL);
1057 debug=IsEventLogging();
1059 if (image_info->number_scenes != 0)
1062 Generate blank images for subimage specification (e.g. image.tif[4].
1064 for (i=0; i < (ssize_t) image_info->scene; i++)
1066 status=TIFFReadDirectory(tiff) != 0 ? MagickTrue : MagickFalse;
1067 if (status == MagickFalse)
1070 image=DestroyImageList(image);
1071 return((Image *) NULL);
1073 AcquireNextImage(image_info,image,exception);
1074 if (GetNextImageInList(image) == (Image *) NULL)
1077 image=DestroyImageList(image);
1078 return((Image *) NULL);
1080 image=SyncNextImageInList(image);
1085 DisableMSCWarning(4127)
1086 if (0 && (image_info->verbose != MagickFalse))
1087 TIFFPrintDirectory(tiff,stdout,MagickFalse);
1089 if ((TIFFGetField(tiff,TIFFTAG_IMAGEWIDTH,&width) != 1) ||
1090 (TIFFGetField(tiff,TIFFTAG_IMAGELENGTH,&height) != 1) ||
1091 (TIFFGetFieldDefaulted(tiff,TIFFTAG_COMPRESSION,&compress_tag) != 1) ||
1092 (TIFFGetFieldDefaulted(tiff,TIFFTAG_FILLORDER,&endian) != 1) ||
1093 (TIFFGetFieldDefaulted(tiff,TIFFTAG_PLANARCONFIG,&interlace) != 1) ||
1094 (TIFFGetFieldDefaulted(tiff,TIFFTAG_SAMPLESPERPIXEL,&samples_per_pixel) != 1) ||
1095 (TIFFGetFieldDefaulted(tiff,TIFFTAG_BITSPERSAMPLE,&bits_per_sample) != 1) ||
1096 (TIFFGetFieldDefaulted(tiff,TIFFTAG_SAMPLEFORMAT,&sample_format) != 1) ||
1097 (TIFFGetFieldDefaulted(tiff,TIFFTAG_MINSAMPLEVALUE,&min_sample_value) != 1) ||
1098 (TIFFGetFieldDefaulted(tiff,TIFFTAG_MAXSAMPLEVALUE,&max_sample_value) != 1) ||
1099 (TIFFGetFieldDefaulted(tiff,TIFFTAG_PHOTOMETRIC,&photometric) != 1))
1102 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
1104 if (sample_format == SAMPLEFORMAT_IEEEFP)
1105 (void) SetImageProperty(image,"quantum:format","floating-point",
1107 switch (photometric)
1109 case PHOTOMETRIC_MINISBLACK:
1111 (void) SetImageProperty(image,"tiff:photometric","min-is-black",
1115 case PHOTOMETRIC_MINISWHITE:
1117 (void) SetImageProperty(image,"tiff:photometric","min-is-white",
1121 case PHOTOMETRIC_PALETTE:
1123 (void) SetImageProperty(image,"tiff:photometric","palette",exception);
1126 case PHOTOMETRIC_RGB:
1128 (void) SetImageProperty(image,"tiff:photometric","RGB",exception);
1131 case PHOTOMETRIC_CIELAB:
1133 (void) SetImageProperty(image,"tiff:photometric","CIELAB",exception);
1136 case PHOTOMETRIC_LOGL:
1137 case PHOTOMETRIC_LOGLUV:
1139 (void) TIFFSetField(tiff,TIFFTAG_SGILOGDATAFMT,SGILOGDATAFMT_FLOAT);
1142 case PHOTOMETRIC_SEPARATED:
1144 (void) SetImageProperty(image,"tiff:photometric","separated",exception);
1147 case PHOTOMETRIC_YCBCR:
1149 (void) SetImageProperty(image,"tiff:photometric","YCBCR",exception);
1154 (void) SetImageProperty(image,"tiff:photometric","unknown",exception);
1158 if (image->debug != MagickFalse)
1160 (void) LogMagickEvent(CoderEvent,GetMagickModule(),"Geometry: %ux%u",
1161 (unsigned int) width,(unsigned int) height);
1162 (void) LogMagickEvent(CoderEvent,GetMagickModule(),"Interlace: %u",
1164 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
1165 "Bits per sample: %u",bits_per_sample);
1166 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
1167 "Min sample value: %u",min_sample_value);
1168 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
1169 "Max sample value: %u",max_sample_value);
1170 (void) LogMagickEvent(CoderEvent,GetMagickModule(),"Photometric "
1171 "interpretation: %s",GetImageProperty(image,"tiff:photometric",
1174 image->columns=(size_t) width;
1175 image->rows=(size_t) height;
1176 image->depth=(size_t) bits_per_sample;
1177 status=SetImageExtent(image,image->columns,image->rows,exception);
1178 if (status == MagickFalse)
1179 return(DestroyImageList(image));
1180 if (image->debug != MagickFalse)
1181 (void) LogMagickEvent(CoderEvent,GetMagickModule(),"Image depth: %.20g",
1182 (double) image->depth);
1183 image->endian=MSBEndian;
1184 if (endian == FILLORDER_LSB2MSB)
1185 image->endian=LSBEndian;
1186 #if defined(MAGICKCORE_HAVE_TIFFISBIGENDIAN)
1187 if (TIFFIsBigEndian(tiff) == 0)
1189 (void) SetImageProperty(image,"tiff:endian","lsb",exception);
1190 image->endian=LSBEndian;
1194 (void) SetImageProperty(image,"tiff:endian","msb",exception);
1195 image->endian=MSBEndian;
1198 if ((photometric == PHOTOMETRIC_MINISBLACK) ||
1199 (photometric == PHOTOMETRIC_MINISWHITE))
1200 SetImageColorspace(image,GRAYColorspace,exception);
1201 if (photometric == PHOTOMETRIC_SEPARATED)
1202 SetImageColorspace(image,CMYKColorspace,exception);
1203 if (photometric == PHOTOMETRIC_CIELAB)
1204 SetImageColorspace(image,LabColorspace,exception);
1205 if (image_info->ping == MagickFalse)
1206 TIFFGetProfiles(tiff,image,exception);
1207 TIFFGetProperties(tiff,image,exception);
1208 option=GetImageOption(image_info,"tiff:exif-properties");
1209 if (IfMagickTrue(IsStringNotFalse(option))) /* enabled by default */
1210 TIFFGetEXIFProperties(tiff,image,exception);
1211 (void) TIFFGetFieldDefaulted(tiff,TIFFTAG_SAMPLESPERPIXEL,
1212 &samples_per_pixel);
1213 if ((TIFFGetFieldDefaulted(tiff,TIFFTAG_XRESOLUTION,&x_resolution) == 1) &&
1214 (TIFFGetFieldDefaulted(tiff,TIFFTAG_YRESOLUTION,&y_resolution) == 1))
1216 image->resolution.x=x_resolution;
1217 image->resolution.y=y_resolution;
1219 if (TIFFGetFieldDefaulted(tiff,TIFFTAG_RESOLUTIONUNIT,&units) == 1)
1221 if (units == RESUNIT_INCH)
1222 image->units=PixelsPerInchResolution;
1223 if (units == RESUNIT_CENTIMETER)
1224 image->units=PixelsPerCentimeterResolution;
1226 if ((TIFFGetFieldDefaulted(tiff,TIFFTAG_XPOSITION,&x_position) == 1) &&
1227 (TIFFGetFieldDefaulted(tiff,TIFFTAG_YPOSITION,&y_position) == 1))
1229 image->page.x=(ssize_t) ceil(x_position*image->resolution.x-0.5);
1230 image->page.y=(ssize_t) ceil(y_position*image->resolution.y-0.5);
1232 if (TIFFGetFieldDefaulted(tiff,TIFFTAG_ORIENTATION,&orientation) == 1)
1233 image->orientation=(OrientationType) orientation;
1234 if (TIFFGetField(tiff,TIFFTAG_WHITEPOINT,&chromaticity) == 1)
1236 if (chromaticity != (float *) NULL)
1238 image->chromaticity.white_point.x=chromaticity[0];
1239 image->chromaticity.white_point.y=chromaticity[1];
1242 if (TIFFGetField(tiff,TIFFTAG_PRIMARYCHROMATICITIES,&chromaticity) == 1)
1244 if (chromaticity != (float *) NULL)
1246 image->chromaticity.red_primary.x=chromaticity[0];
1247 image->chromaticity.red_primary.y=chromaticity[1];
1248 image->chromaticity.green_primary.x=chromaticity[2];
1249 image->chromaticity.green_primary.y=chromaticity[3];
1250 image->chromaticity.blue_primary.x=chromaticity[4];
1251 image->chromaticity.blue_primary.y=chromaticity[5];
1254 #if defined(MAGICKCORE_HAVE_TIFFISCODECCONFIGURED) || (TIFFLIB_VERSION > 20040919)
1255 if ((compress_tag != COMPRESSION_NONE) &&
1256 (TIFFIsCODECConfigured(compress_tag) == 0))
1259 ThrowReaderException(CoderError,"CompressNotSupported");
1262 switch (compress_tag)
1264 case COMPRESSION_NONE: image->compression=NoCompression; break;
1265 case COMPRESSION_CCITTFAX3: image->compression=FaxCompression; break;
1266 case COMPRESSION_CCITTFAX4: image->compression=Group4Compression; break;
1267 case COMPRESSION_JPEG:
1269 image->compression=JPEGCompression;
1270 #if defined(JPEG_SUPPORT)
1273 sampling_factor[MaxTextExtent];
1282 tiff_status=TIFFGetFieldDefaulted(tiff,TIFFTAG_YCBCRSUBSAMPLING,
1283 &horizontal,&vertical);
1284 if (tiff_status == 1)
1286 (void) FormatLocaleString(sampling_factor,MaxTextExtent,"%dx%d",
1287 horizontal,vertical);
1288 (void) SetImageProperty(image,"jpeg:sampling-factor",
1289 sampling_factor,exception);
1290 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
1291 "Sampling Factors: %s",sampling_factor);
1297 case COMPRESSION_OJPEG: image->compression=JPEGCompression; break;
1298 #if defined(COMPRESSION_LZMA)
1299 case COMPRESSION_LZMA: image->compression=LZMACompression; break;
1301 case COMPRESSION_LZW: image->compression=LZWCompression; break;
1302 case COMPRESSION_DEFLATE: image->compression=ZipCompression; break;
1303 case COMPRESSION_ADOBE_DEFLATE: image->compression=ZipCompression; break;
1304 default: image->compression=RLECompression; break;
1307 Allocate memory for the image and pixel buffer.
1309 quantum_info=AcquireQuantumInfo(image_info,image);
1310 if (quantum_info == (QuantumInfo *) NULL)
1313 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1315 if (sample_format == SAMPLEFORMAT_UINT)
1316 status=SetQuantumFormat(image,quantum_info,UnsignedQuantumFormat);
1317 if (sample_format == SAMPLEFORMAT_INT)
1318 status=SetQuantumFormat(image,quantum_info,SignedQuantumFormat);
1319 if (sample_format == SAMPLEFORMAT_IEEEFP)
1320 status=SetQuantumFormat(image,quantum_info,FloatingPointQuantumFormat);
1321 if (status == MagickFalse)
1323 quantum_info=DestroyQuantumInfo(quantum_info);
1325 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1328 switch (photometric)
1330 case PHOTOMETRIC_MINISBLACK:
1332 quantum_info->min_is_white=MagickFalse;
1335 case PHOTOMETRIC_MINISWHITE:
1337 quantum_info->min_is_white=MagickTrue;
1343 tiff_status=TIFFGetFieldDefaulted(tiff,TIFFTAG_EXTRASAMPLES,&extra_samples,
1345 if (tiff_status == 1)
1347 (void) SetImageProperty(image,"tiff:alpha","unspecified",exception);
1348 if (extra_samples == 0)
1350 if ((samples_per_pixel == 4) && (photometric == PHOTOMETRIC_RGB))
1351 image->alpha_trait=BlendPixelTrait;
1354 for (i=0; i < extra_samples; i++)
1356 image->alpha_trait=BlendPixelTrait;
1357 if (sample_info[i] == EXTRASAMPLE_ASSOCALPHA)
1359 SetQuantumAlphaType(quantum_info,DisassociatedQuantumAlpha);
1360 (void) SetImageProperty(image,"tiff:alpha","associated",
1364 if (sample_info[i] == EXTRASAMPLE_UNASSALPHA)
1365 (void) SetImageProperty(image,"tiff:alpha","unassociated",
1369 if ((photometric == PHOTOMETRIC_PALETTE) &&
1370 (pow(2.0,1.0*bits_per_sample) <= MaxColormapSize))
1375 colors=(size_t) GetQuantumRange(bits_per_sample)+1;
1376 if (AcquireImageColormap(image,colors,exception) == MagickFalse)
1379 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1382 value=(unsigned short) image->scene;
1383 if (TIFFGetFieldDefaulted(tiff,TIFFTAG_PAGENUMBER,&value,&pages) == 1)
1385 if (image_info->ping != MagickFalse)
1387 if (image_info->number_scenes != 0)
1388 if (image->scene >= (image_info->scene+image_info->number_scenes-1))
1390 quantum_info=DestroyQuantumInfo(quantum_info);
1393 goto next_tiff_frame;
1395 method=ReadGenericMethod;
1396 if (TIFFGetField(tiff,TIFFTAG_ROWSPERSTRIP,&rows_per_strip) == 1)
1399 value[MaxTextExtent];
1401 method=ReadStripMethod;
1402 (void) FormatLocaleString(value,MaxTextExtent,"%u",
1403 (unsigned int) rows_per_strip);
1404 (void) SetImageProperty(image,"tiff:rows-per-strip",value,exception);
1406 if ((samples_per_pixel >= 2) && (interlace == PLANARCONFIG_CONTIG))
1407 method=ReadRGBAMethod;
1408 if ((samples_per_pixel >= 2) && (interlace == PLANARCONFIG_SEPARATE))
1409 method=ReadCMYKAMethod;
1410 if ((photometric != PHOTOMETRIC_RGB) &&
1411 (photometric != PHOTOMETRIC_CIELAB) &&
1412 (photometric != PHOTOMETRIC_SEPARATED))
1413 method=ReadGenericMethod;
1414 if (image->storage_class == PseudoClass)
1415 method=ReadSingleSampleMethod;
1416 if ((photometric == PHOTOMETRIC_MINISBLACK) ||
1417 (photometric == PHOTOMETRIC_MINISWHITE))
1418 method=ReadSingleSampleMethod;
1419 if ((photometric != PHOTOMETRIC_SEPARATED) &&
1420 (interlace == PLANARCONFIG_SEPARATE) && (bits_per_sample < 64))
1421 method=ReadGenericMethod;
1422 if (image->compression == JPEGCompression)
1423 method=GetJPEGMethod(image,tiff,photometric,bits_per_sample,
1425 if (compress_tag == COMPRESSION_JBIG)
1426 method=ReadStripMethod;
1427 if (TIFFIsTiled(tiff) != MagickFalse)
1428 method=ReadTileMethod;
1429 quantum_info->endian=LSBEndian;
1430 quantum_type=RGBQuantum;
1431 pixels=GetQuantumPixels(quantum_info);
1434 case ReadSingleSampleMethod:
1437 Convert TIFF image to PseudoClass MIFF image.
1439 if ((image->storage_class == PseudoClass) &&
1440 (photometric == PHOTOMETRIC_PALETTE))
1454 Initialize colormap.
1456 tiff_status=TIFFGetField(tiff,TIFFTAG_COLORMAP,&red_colormap,
1457 &green_colormap,&blue_colormap);
1458 if (tiff_status == 1)
1460 if ((red_colormap != (uint16 *) NULL) &&
1461 (green_colormap != (uint16 *) NULL) &&
1462 (blue_colormap != (uint16 *) NULL))
1464 range=255; /* might be old style 8-bit colormap */
1465 for (i=0; i < (ssize_t) image->colors; i++)
1466 if ((red_colormap[i] >= 256) ||
1467 (green_colormap[i] >= 256) ||
1468 (blue_colormap[i] >= 256))
1473 for (i=0; i < (ssize_t) image->colors; i++)
1475 image->colormap[i].red=ClampToQuantum(((double)
1476 QuantumRange*red_colormap[i])/range);
1477 image->colormap[i].green=ClampToQuantum(((double)
1478 QuantumRange*green_colormap[i])/range);
1479 image->colormap[i].blue=ClampToQuantum(((double)
1480 QuantumRange*blue_colormap[i])/range);
1485 quantum_type=IndexQuantum;
1486 pad=(size_t) MagickMax((size_t) samples_per_pixel-1,0);
1487 if (image->alpha_trait != UndefinedPixelTrait)
1489 if (image->storage_class != PseudoClass)
1491 quantum_type=samples_per_pixel == 1 ? AlphaQuantum :
1493 pad=(size_t) MagickMax((size_t) samples_per_pixel-2,0);
1497 quantum_type=IndexAlphaQuantum;
1498 pad=(size_t) MagickMax((size_t) samples_per_pixel-2,0);
1502 if (image->storage_class != PseudoClass)
1504 quantum_type=GrayQuantum;
1505 pad=(size_t) MagickMax((size_t) samples_per_pixel-1,0);
1507 status=SetQuantumPad(image,quantum_info,pad*((bits_per_sample+7) >> 3));
1508 if (status == MagickFalse)
1511 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1513 pixels=GetQuantumPixels(quantum_info);
1514 for (y=0; y < (ssize_t) image->rows; y++)
1522 status=TIFFReadPixels(tiff,bits_per_sample,0,y,(char *) pixels);
1525 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
1526 if (q == (Quantum *) NULL)
1528 (void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1529 quantum_type,pixels,exception);
1530 if (SyncAuthenticPixels(image,exception) == MagickFalse)
1532 if (image->previous == (Image *) NULL)
1534 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
1536 if (status == MagickFalse)
1542 case ReadRGBAMethod:
1545 Convert TIFF image to DirectClass MIFF image.
1547 pad=(size_t) MagickMax((size_t) samples_per_pixel-3,0);
1548 quantum_type=RGBQuantum;
1549 if (image->alpha_trait != UndefinedPixelTrait)
1551 quantum_type=RGBAQuantum;
1552 pad=(size_t) MagickMax((size_t) samples_per_pixel-4,0);
1554 if (image->colorspace == CMYKColorspace)
1556 pad=(size_t) MagickMax((size_t) samples_per_pixel-4,0);
1557 quantum_type=CMYKQuantum;
1558 if (image->alpha_trait != UndefinedPixelTrait)
1560 quantum_type=CMYKAQuantum;
1561 pad=(size_t) MagickMax((size_t) samples_per_pixel-5,0);
1564 status=SetQuantumPad(image,quantum_info,pad*((bits_per_sample+7) >> 3));
1565 if (status == MagickFalse)
1568 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1570 pixels=GetQuantumPixels(quantum_info);
1571 for (y=0; y < (ssize_t) image->rows; y++)
1579 status=TIFFReadPixels(tiff,bits_per_sample,0,y,(char *) pixels);
1582 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
1583 if (q == (Quantum *) NULL)
1585 (void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1586 quantum_type,pixels,exception);
1587 if (SyncAuthenticPixels(image,exception) == MagickFalse)
1589 if (image->previous == (Image *) NULL)
1591 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
1593 if (status == MagickFalse)
1599 case ReadCMYKAMethod:
1602 Convert TIFF image to DirectClass MIFF image.
1604 for (i=0; i < (ssize_t) samples_per_pixel; i++)
1606 for (y=0; y < (ssize_t) image->rows; y++)
1614 status=TIFFReadPixels(tiff,bits_per_sample,(tsample_t) i,y,(char *)
1618 q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
1619 if (q == (Quantum *) NULL)
1621 if (image->colorspace != CMYKColorspace)
1624 case 0: quantum_type=RedQuantum; break;
1625 case 1: quantum_type=GreenQuantum; break;
1626 case 2: quantum_type=BlueQuantum; break;
1627 case 3: quantum_type=AlphaQuantum; break;
1628 default: quantum_type=UndefinedQuantum; break;
1633 case 0: quantum_type=CyanQuantum; break;
1634 case 1: quantum_type=MagentaQuantum; break;
1635 case 2: quantum_type=YellowQuantum; break;
1636 case 3: quantum_type=BlackQuantum; break;
1637 case 4: quantum_type=AlphaQuantum; break;
1638 default: quantum_type=UndefinedQuantum; break;
1640 (void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1641 quantum_type,pixels,exception);
1642 if (SyncAuthenticPixels(image,exception) == MagickFalse)
1645 if (image->previous == (Image *) NULL)
1647 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
1649 if (status == MagickFalse)
1655 case ReadYCCKMethod:
1657 pixels=GetQuantumPixels(quantum_info);
1658 for (y=0; y < (ssize_t) image->rows; y++)
1672 status=TIFFReadPixels(tiff,bits_per_sample,0,y,(char *) pixels);
1675 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
1676 if (q == (Quantum *) NULL)
1679 for (x=0; x < (ssize_t) image->columns; x++)
1681 SetPixelCyan(image,ScaleCharToQuantum(ClampYCC((double) *p+
1682 (1.402*(double) *(p+2))-179.456)),q);
1683 SetPixelMagenta(image,ScaleCharToQuantum(ClampYCC((double) *p-
1684 (0.34414*(double) *(p+1))-(0.71414*(double ) *(p+2))+
1686 SetPixelYellow(image,ScaleCharToQuantum(ClampYCC((double) *p+
1687 (1.772*(double) *(p+1))-226.816)),q);
1688 SetPixelBlack(image,ScaleCharToQuantum((unsigned char) *(p+3)),q);
1689 q+=GetPixelChannels(image);
1692 if (SyncAuthenticPixels(image,exception) == MagickFalse)
1694 if (image->previous == (Image *) NULL)
1696 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
1698 if (status == MagickFalse)
1704 case ReadStripMethod:
1710 Convert stripped TIFF image to DirectClass MIFF image.
1714 for (y=0; y < (ssize_t) image->rows; y++)
1722 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
1723 if (q == (Quantum *) NULL)
1727 if (TIFFReadRGBAStrip(tiff,(tstrip_t) y,(uint32 *) pixels) == 0)
1729 i=(ssize_t) MagickMin((ssize_t) rows_per_strip,(ssize_t)
1733 p=((uint32 *) pixels)+image->columns*i;
1734 for (x=0; x < (ssize_t) image->columns; x++)
1736 SetPixelRed(image,ScaleCharToQuantum((unsigned char)
1738 SetPixelGreen(image,ScaleCharToQuantum((unsigned char)
1740 SetPixelBlue(image,ScaleCharToQuantum((unsigned char)
1742 if (image->alpha_trait != UndefinedPixelTrait)
1743 SetPixelAlpha(image,ScaleCharToQuantum((unsigned char)
1746 q+=GetPixelChannels(image);
1748 if (SyncAuthenticPixels(image,exception) == MagickFalse)
1750 if (image->previous == (Image *) NULL)
1752 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
1754 if (status == MagickFalse)
1760 case ReadTileMethod:
1774 Convert tiled TIFF image to DirectClass MIFF image.
1776 if ((TIFFGetField(tiff,TIFFTAG_TILEWIDTH,&columns) != 1) ||
1777 (TIFFGetField(tiff,TIFFTAG_TILELENGTH,&rows) != 1))
1780 ThrowReaderException(CoderError,"ImageIsNotTiled");
1782 (void) SetImageStorageClass(image,DirectClass,exception);
1783 number_pixels=columns*rows;
1784 tile_pixels=(uint32 *) AcquireQuantumMemory(number_pixels,
1785 sizeof(*tile_pixels));
1786 if (tile_pixels == (uint32 *) NULL)
1789 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1791 for (y=0; y < (ssize_t) image->rows; y+=rows)
1804 rows_remaining=image->rows-y;
1805 if ((ssize_t) (y+rows) < (ssize_t) image->rows)
1806 rows_remaining=rows;
1807 tile=QueueAuthenticPixels(image,0,y,image->columns,rows_remaining,
1809 if (tile == (Quantum *) NULL)
1811 for (x=0; x < (ssize_t) image->columns; x+=columns)
1817 if (TIFFReadRGBATile(tiff,(uint32) x,(uint32) y,tile_pixels) == 0)
1819 columns_remaining=image->columns-x;
1820 if ((ssize_t) (x+columns) < (ssize_t) image->columns)
1821 columns_remaining=columns;
1822 p=tile_pixels+(rows-rows_remaining)*columns;
1823 q=tile+GetPixelChannels(image)*(image->columns*(rows_remaining-1)+
1825 for (row=rows_remaining; row > 0; row--)
1827 if (image->alpha_trait != UndefinedPixelTrait)
1828 for (column=columns_remaining; column > 0; column--)
1830 SetPixelRed(image,ScaleCharToQuantum((unsigned char)
1832 SetPixelGreen(image,ScaleCharToQuantum((unsigned char)
1834 SetPixelBlue(image,ScaleCharToQuantum((unsigned char)
1836 SetPixelAlpha(image,ScaleCharToQuantum((unsigned char)
1839 q+=GetPixelChannels(image);
1842 for (column=columns_remaining; column > 0; column--)
1844 SetPixelRed(image,ScaleCharToQuantum((unsigned char)
1846 SetPixelGreen(image,ScaleCharToQuantum((unsigned char)
1848 SetPixelBlue(image,ScaleCharToQuantum((unsigned char)
1851 q+=GetPixelChannels(image);
1853 p+=columns-columns_remaining;
1854 q-=GetPixelChannels(image)*(image->columns+columns_remaining);
1857 if (SyncAuthenticPixels(image,exception) == MagickFalse)
1859 if (image->previous == (Image *) NULL)
1861 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
1863 if (status == MagickFalse)
1867 tile_pixels=(uint32 *) RelinquishMagickMemory(tile_pixels);
1870 case ReadGenericMethod:
1883 Convert TIFF image to DirectClass MIFF image.
1885 number_pixels=(MagickSizeType) image->columns*image->rows;
1886 if ((number_pixels*sizeof(uint32)) != (MagickSizeType) ((size_t)
1887 (number_pixels*sizeof(uint32))))
1890 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1892 pixel_info=AcquireVirtualMemory(image->columns,image->rows*
1894 if (pixel_info == (MemoryInfo *) NULL)
1897 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1899 pixels=(uint32 *) GetVirtualMemoryBlob(pixel_info);
1900 (void) TIFFReadRGBAImage(tiff,(uint32) image->columns,
1901 (uint32) image->rows,(uint32 *) pixels,0);
1903 Convert image to DirectClass pixel packets.
1905 p=pixels+number_pixels-1;
1906 for (y=0; y < (ssize_t) image->rows; y++)
1914 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
1915 if (q == (Quantum *) NULL)
1917 q+=GetPixelChannels(image)*(image->columns-1);
1918 for (x=0; x < (ssize_t) image->columns; x++)
1920 SetPixelRed(image,ScaleCharToQuantum((unsigned char) TIFFGetR(*p)),q);
1921 SetPixelGreen(image,ScaleCharToQuantum((unsigned char)
1923 SetPixelBlue(image,ScaleCharToQuantum((unsigned char) TIFFGetB(*p)),
1925 if (image->alpha_trait != UndefinedPixelTrait)
1926 SetPixelAlpha(image,ScaleCharToQuantum((unsigned char)
1929 q-=GetPixelChannels(image);
1931 if (SyncAuthenticPixels(image,exception) == MagickFalse)
1933 if (image->previous == (Image *) NULL)
1935 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
1937 if (status == MagickFalse)
1941 pixel_info=RelinquishVirtualMemory(pixel_info);
1945 SetQuantumImageType(image,quantum_type);
1947 quantum_info=DestroyQuantumInfo(quantum_info);
1948 if (photometric == PHOTOMETRIC_CIELAB)
1949 DecodeLabImage(image,exception);
1950 if ((photometric == PHOTOMETRIC_LOGL) ||
1951 (photometric == PHOTOMETRIC_MINISBLACK) ||
1952 (photometric == PHOTOMETRIC_MINISWHITE))
1954 image->type=GrayscaleType;
1955 if (bits_per_sample == 1)
1956 image->type=BilevelType;
1958 if (image->storage_class == PseudoClass)
1959 image->depth=GetImageDepth(image,exception);
1961 Proceed to next image.
1963 if (image_info->number_scenes != 0)
1964 if (image->scene >= (image_info->scene+image_info->number_scenes-1))
1966 status=TIFFReadDirectory(tiff) != 0 ? MagickTrue : MagickFalse;
1967 if (status != MagickFalse)
1970 Allocate next image structure.
1972 AcquireNextImage(image_info,image,exception);
1973 if (GetNextImageInList(image) == (Image *) NULL)
1975 image=DestroyImageList(image);
1976 return((Image *) NULL);
1978 image=SyncNextImageInList(image);
1979 status=SetImageProgress(image,LoadImagesTag,image->scene-1,
1981 if (status == MagickFalse)
1984 } while (status != MagickFalse);
1985 (void) TIFFSetWarningHandler(warning_handler);
1986 (void) TIFFSetErrorHandler(error_handler);
1988 return(GetFirstImageInList(image));
1993 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1997 % R e g i s t e r T I F F I m a g e %
2001 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2003 % RegisterTIFFImage() adds properties for the TIFF image format to
2004 % the list of supported formats. The properties include the image format
2005 % tag, a method to read and/or write the format, whether the format
2006 % supports the saving of more than one frame to the same file or blob,
2007 % whether the format supports native in-memory I/O, and a brief
2008 % description of the format.
2010 % The format of the RegisterTIFFImage method is:
2012 % size_t RegisterTIFFImage(void)
2016 #if defined(MAGICKCORE_HAVE_TIFFMERGEFIELDINFO) && defined(MAGICKCORE_HAVE_TIFFSETTAGEXTENDER)
2017 static TIFFExtendProc
2018 tag_extender = (TIFFExtendProc) NULL;
2020 static void TIFFIgnoreTags(TIFF *tiff)
2041 if (TIFFGetReadProc(tiff) != TIFFReadBlob)
2043 image=(Image *)TIFFClientdata(tiff);
2044 tags=GetImageArtifact(image,"tiff:ignore-tags");
2045 if (tags == (const char *) NULL)
2051 while ((isspace((int) ((unsigned char) *p)) != 0))
2054 (void) strtol(p,&q,10);
2061 while ((isspace((int) ((unsigned char) *p)) != 0) || (*p == ','))
2068 ignore=(TIFFFieldInfo *) AcquireQuantumMemory(count,sizeof(*ignore));
2069 /* This also sets field_bit to 0 (FIELD_IGNORE) */
2070 ResetMagickMemory(ignore,0,count*sizeof(*ignore));
2073 while ((isspace((int) ((unsigned char) *p)) != 0))
2076 ignore[i].field_tag=(ttag_t) strtol(p,&q,10);
2081 while ((isspace((int) ((unsigned char) *p)) != 0) || (*p == ','))
2084 (void) TIFFMergeFieldInfo(tiff,ignore,(uint32) count);
2085 ignore=(TIFFFieldInfo *) RelinquishMagickMemory(ignore);
2088 static void TIFFTagExtender(TIFF *tiff)
2090 static const TIFFFieldInfo
2093 { 37724, -3, -3, TIFF_UNDEFINED, FIELD_CUSTOM, 1, 1,
2094 (char *) "PhotoshopLayerData" },
2095 { 34118, -3, -3, TIFF_UNDEFINED, FIELD_CUSTOM, 1, 1,
2096 (char *) "Microscope" }
2099 TIFFMergeFieldInfo(tiff,TIFFExtensions,sizeof(TIFFExtensions)/
2100 sizeof(*TIFFExtensions));
2101 if (tag_extender != (TIFFExtendProc) NULL)
2102 (*tag_extender)(tiff);
2103 TIFFIgnoreTags(tiff);
2107 ModuleExport size_t RegisterTIFFImage(void)
2109 #define TIFFDescription "Tagged Image File Format"
2112 version[MaxTextExtent];
2117 if (tiff_semaphore == (SemaphoreInfo *) NULL)
2118 ActivateSemaphoreInfo(&tiff_semaphore);
2119 LockSemaphoreInfo(tiff_semaphore);
2120 if (instantiate_key == MagickFalse)
2122 if (MagickCreateThreadKey(&tiff_exception) == MagickFalse)
2123 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
2124 #if defined(MAGICKCORE_HAVE_TIFFMERGEFIELDINFO) && defined(MAGICKCORE_HAVE_TIFFSETTAGEXTENDER)
2125 if (tag_extender == (TIFFExtendProc) NULL)
2126 tag_extender=TIFFSetTagExtender(TIFFTagExtender);
2128 instantiate_key=MagickTrue;
2130 UnlockSemaphoreInfo(tiff_semaphore);
2132 #if defined(TIFF_VERSION)
2133 (void) FormatLocaleString(version,MaxTextExtent,"%d",TIFF_VERSION);
2135 #if defined(MAGICKCORE_TIFF_DELEGATE)
2144 for (i=0; (i < (MaxTextExtent-1)) && (*p != 0) && (*p != '\n'); i++)
2150 entry=SetMagickInfo("GROUP4");
2151 #if defined(MAGICKCORE_TIFF_DELEGATE)
2152 entry->decoder=(DecodeImageHandler *) ReadGROUP4Image;
2153 entry->encoder=(EncodeImageHandler *) WriteGROUP4Image;
2155 entry->raw=MagickTrue;
2156 entry->endian_support=MagickTrue;
2157 entry->adjoin=MagickFalse;
2158 entry->format_type=ImplicitFormatType;
2159 entry->seekable_stream=MagickTrue;
2160 entry->description=ConstantString("Raw CCITT Group4");
2161 entry->mime_type=ConstantString("image/tiff");
2162 entry->module=ConstantString("TIFF");
2163 (void) RegisterMagickInfo(entry);
2164 entry=SetMagickInfo("PTIF");
2165 #if defined(MAGICKCORE_TIFF_DELEGATE)
2166 entry->decoder=(DecodeImageHandler *) ReadTIFFImage;
2167 entry->encoder=(EncodeImageHandler *) WritePTIFImage;
2169 entry->endian_support=MagickTrue;
2170 entry->seekable_stream=MagickTrue;
2171 entry->description=ConstantString("Pyramid encoded TIFF");
2172 entry->mime_type=ConstantString("image/tiff");
2173 entry->module=ConstantString("TIFF");
2174 (void) RegisterMagickInfo(entry);
2175 entry=SetMagickInfo("TIF");
2176 #if defined(MAGICKCORE_TIFF_DELEGATE)
2177 entry->decoder=(DecodeImageHandler *) ReadTIFFImage;
2178 entry->encoder=(EncodeImageHandler *) WriteTIFFImage;
2180 entry->endian_support=MagickTrue;
2181 entry->seekable_stream=MagickTrue;
2182 entry->stealth=MagickTrue;
2183 entry->description=ConstantString(TIFFDescription);
2184 if (*version != '\0')
2185 entry->version=ConstantString(version);
2186 entry->mime_type=ConstantString("image/tiff");
2187 entry->module=ConstantString("TIFF");
2188 (void) RegisterMagickInfo(entry);
2189 entry=SetMagickInfo("TIFF");
2190 #if defined(MAGICKCORE_TIFF_DELEGATE)
2191 entry->decoder=(DecodeImageHandler *) ReadTIFFImage;
2192 entry->encoder=(EncodeImageHandler *) WriteTIFFImage;
2194 entry->magick=(IsImageFormatHandler *) IsTIFF;
2195 entry->endian_support=MagickTrue;
2196 entry->seekable_stream=MagickTrue;
2197 entry->description=ConstantString(TIFFDescription);
2198 if (*version != '\0')
2199 entry->version=ConstantString(version);
2200 entry->mime_type=ConstantString("image/tiff");
2201 entry->module=ConstantString("TIFF");
2202 (void) RegisterMagickInfo(entry);
2203 entry=SetMagickInfo("TIFF64");
2204 #if defined(TIFF_VERSION_BIG)
2205 entry->decoder=(DecodeImageHandler *) ReadTIFFImage;
2206 entry->encoder=(EncodeImageHandler *) WriteTIFFImage;
2208 entry->adjoin=MagickFalse;
2209 entry->endian_support=MagickTrue;
2210 entry->seekable_stream=MagickTrue;
2211 entry->description=ConstantString("Tagged Image File Format (64-bit)");
2212 if (*version != '\0')
2213 entry->version=ConstantString(version);
2214 entry->mime_type=ConstantString("image/tiff");
2215 entry->module=ConstantString("TIFF");
2216 (void) RegisterMagickInfo(entry);
2217 return(MagickImageCoderSignature);
2221 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2225 % U n r e g i s t e r T I F F I m a g e %
2229 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2231 % UnregisterTIFFImage() removes format registrations made by the TIFF module
2232 % from the list of supported formats.
2234 % The format of the UnregisterTIFFImage method is:
2236 % UnregisterTIFFImage(void)
2239 ModuleExport void UnregisterTIFFImage(void)
2241 (void) UnregisterMagickInfo("TIFF64");
2242 (void) UnregisterMagickInfo("TIFF");
2243 (void) UnregisterMagickInfo("TIF");
2244 (void) UnregisterMagickInfo("PTIF");
2245 if (tiff_semaphore == (SemaphoreInfo *) NULL)
2246 ActivateSemaphoreInfo(&tiff_semaphore);
2247 LockSemaphoreInfo(tiff_semaphore);
2248 if (instantiate_key != MagickFalse)
2250 #if defined(MAGICKCORE_HAVE_TIFFMERGEFIELDINFO) && defined(MAGICKCORE_HAVE_TIFFSETTAGEXTENDER)
2251 if (tag_extender == (TIFFExtendProc) NULL)
2252 (void) TIFFSetTagExtender(tag_extender);
2254 if (MagickDeleteThreadKey(tiff_exception) == MagickFalse)
2255 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
2256 instantiate_key=MagickFalse;
2258 UnlockSemaphoreInfo(tiff_semaphore);
2259 RelinquishSemaphoreInfo(&tiff_semaphore);
2262 #if defined(MAGICKCORE_TIFF_DELEGATE)
2264 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2268 % W r i t e G R O U P 4 I m a g e %
2272 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2274 % WriteGROUP4Image() writes an image in the raw CCITT Group 4 image format.
2276 % The format of the WriteGROUP4Image method is:
2278 % MagickBooleanType WriteGROUP4Image(const ImageInfo *image_info,
2279 % Image *image,ExceptionInfo *)
2281 % A description of each parameter follows:
2283 % o image_info: the image info.
2285 % o image: The image.
2287 % o exception: return any errors or warnings in this structure.
2290 static MagickBooleanType WriteGROUP4Image(const ImageInfo *image_info,
2291 Image *image,ExceptionInfo *exception)
2294 filename[MaxTextExtent];
2328 Write image as CCITT Group4 TIFF image to a temporary file.
2330 assert(image_info != (const ImageInfo *) NULL);
2331 assert(image_info->signature == MagickSignature);
2332 assert(image != (Image *) NULL);
2333 assert(image->signature == MagickSignature);
2334 if (image->debug != MagickFalse)
2335 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2336 assert(exception != (ExceptionInfo *) NULL);
2337 assert(exception->signature == MagickSignature);
2338 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
2339 if (status == MagickFalse)
2341 huffman_image=CloneImage(image,0,0,MagickTrue,exception);
2342 if (huffman_image == (Image *) NULL)
2344 (void) CloseBlob(image);
2345 return(MagickFalse);
2347 huffman_image->endian=MSBEndian;
2349 unique_file=AcquireUniqueFileResource(filename);
2350 if (unique_file != -1)
2351 file=fdopen(unique_file,"wb");
2352 if ((unique_file == -1) || (file == (FILE *) NULL))
2354 ThrowFileException(exception,FileOpenError,"UnableToCreateTemporaryFile",
2356 return(MagickFalse);
2358 (void) FormatLocaleString(huffman_image->filename,MaxTextExtent,"tiff:%s",
2360 (void) SetImageType(huffman_image,BilevelType,exception);
2361 write_info=CloneImageInfo((ImageInfo *) NULL);
2362 SetImageInfoFile(write_info,file);
2363 write_info->compression=Group4Compression;
2364 write_info->type=BilevelType;
2365 (void) SetImageOption(write_info,"quantum:polarity","min-is-white");
2366 status=WriteTIFFImage(write_info,huffman_image,exception);
2367 (void) fflush(file);
2368 write_info=DestroyImageInfo(write_info);
2369 if (status == MagickFalse)
2371 huffman_image=DestroyImage(huffman_image);
2372 (void) fclose(file);
2373 (void) RelinquishUniqueFileResource(filename);
2374 return(MagickFalse);
2376 tiff=TIFFOpen(filename,"rb");
2377 if (tiff == (TIFF *) NULL)
2379 huffman_image=DestroyImage(huffman_image);
2380 (void) fclose(file);
2381 (void) RelinquishUniqueFileResource(filename);
2382 ThrowFileException(exception,FileOpenError,"UnableToOpenFile",
2383 image_info->filename);
2384 return(MagickFalse);
2387 Allocate raw strip buffer.
2389 if (TIFFGetField(tiff,TIFFTAG_STRIPBYTECOUNTS,&byte_count) != 1)
2392 huffman_image=DestroyImage(huffman_image);
2393 (void) fclose(file);
2394 (void) RelinquishUniqueFileResource(filename);
2395 return(MagickFalse);
2397 strip_size=byte_count[0];
2398 for (i=1; i < (ssize_t) TIFFNumberOfStrips(tiff); i++)
2399 if (byte_count[i] > strip_size)
2400 strip_size=byte_count[i];
2401 buffer=(unsigned char *) AcquireQuantumMemory((size_t) strip_size,
2403 if (buffer == (unsigned char *) NULL)
2406 huffman_image=DestroyImage(huffman_image);
2407 (void) fclose(file);
2408 (void) RelinquishUniqueFileResource(filename);
2409 ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
2410 image_info->filename);
2413 Compress runlength encoded to 2D Huffman pixels.
2415 for (i=0; i < (ssize_t) TIFFNumberOfStrips(tiff); i++)
2417 count=(ssize_t) TIFFReadRawStrip(tiff,(uint32) i,buffer,strip_size);
2418 if (WriteBlob(image,(size_t) count,buffer) != count)
2421 buffer=(unsigned char *) RelinquishMagickMemory(buffer);
2423 huffman_image=DestroyImage(huffman_image);
2424 (void) fclose(file);
2425 (void) RelinquishUniqueFileResource(filename);
2426 (void) CloseBlob(image);
2431 #if defined(MAGICKCORE_TIFF_DELEGATE)
2433 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2437 % W r i t e P T I F I m a g e %
2441 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2443 % WritePTIFImage() writes an image in the pyrimid-encoded Tagged image file
2446 % The format of the WritePTIFImage method is:
2448 % MagickBooleanType WritePTIFImage(const ImageInfo *image_info,
2449 % Image *image,ExceptionInfo *exception)
2451 % A description of each parameter follows:
2453 % o image_info: the image info.
2455 % o image: The image.
2457 % o exception: return any errors or warnings in this structure.
2460 static MagickBooleanType WritePTIFImage(const ImageInfo *image_info,
2461 Image *image,ExceptionInfo *exception)
2482 Create pyramid-encoded TIFF image.
2484 images=NewImageList();
2485 for (next=image; next != (Image *) NULL; next=GetNextImageInList(next))
2490 clone_image=CloneImage(next,0,0,MagickFalse,exception);
2491 clone_image->previous=NewImageList();
2492 clone_image->next=NewImageList();
2493 AppendImageToList(&images,clone_image);
2494 columns=next->columns;
2496 resolution=next->resolution;
2497 while ((columns > 64) && (rows > 64))
2503 pyramid_image=ResizeImage(next,columns,rows,image->filter,exception);
2504 if (pyramid_image == (Image *) NULL)
2506 pyramid_image->resolution=resolution;
2507 AppendImageToList(&images,pyramid_image);
2510 images=GetFirstImageInList(images);
2512 Write pyramid-encoded TIFF image.
2514 write_info=CloneImageInfo(image_info);
2515 write_info->adjoin=MagickTrue;
2516 (void) CopyMagickString(write_info->magick,"TIFF",MaxTextExtent);
2517 (void) CopyMagickString(images->magick,"TIFF",MaxTextExtent);
2518 status=WriteTIFFImage(write_info,images,exception);
2519 images=DestroyImageList(images);
2520 write_info=DestroyImageInfo(write_info);
2525 #if defined(MAGICKCORE_TIFF_DELEGATE)
2527 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2530 % W r i t e T I F F I m a g e %
2534 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2536 % WriteTIFFImage() writes an image in the Tagged image file format.
2538 % The format of the WriteTIFFImage method is:
2540 % MagickBooleanType WriteTIFFImage(const ImageInfo *image_info,
2541 % Image *image,ExceptionInfo *exception)
2543 % A description of each parameter follows:
2545 % o image_info: the image info.
2547 % o image: The image.
2549 % o exception: return any errors or warnings in this structure.
2553 typedef struct _TIFFInfo
2564 static void DestroyTIFFInfo(TIFFInfo *tiff_info)
2566 assert(tiff_info != (TIFFInfo *) NULL);
2567 if (tiff_info->scanlines != (unsigned char *) NULL)
2568 tiff_info->scanlines=(unsigned char *) RelinquishMagickMemory(
2569 tiff_info->scanlines);
2570 if (tiff_info->pixels != (unsigned char *) NULL)
2571 tiff_info->pixels=(unsigned char *) RelinquishMagickMemory(
2575 static MagickBooleanType EncodeLabImage(Image *image,ExceptionInfo *exception)
2587 image_view=AcquireAuthenticCacheView(image,exception);
2588 for (y=0; y < (ssize_t) image->rows; y++)
2596 if (status == MagickFalse)
2598 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2599 if (q == (Quantum *) NULL)
2604 for (x=0; x < (ssize_t) image->columns; x++)
2610 a=QuantumScale*GetPixela(image,q)-0.5;
2613 b=QuantumScale*GetPixelb(image,q)-0.5;
2616 SetPixela(image,QuantumRange*a,q);
2617 SetPixelb(image,QuantumRange*b,q);
2618 q+=GetPixelChannels(image);
2620 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2623 image_view=DestroyCacheView(image_view);
2627 static MagickBooleanType GetTIFFInfo(const ImageInfo *image_info,
2628 TIFF *tiff,TIFFInfo *tiff_info)
2640 assert(tiff_info != (TIFFInfo *) NULL);
2641 (void) ResetMagickMemory(tiff_info,0,sizeof(*tiff_info));
2642 option=GetImageOption(image_info,"tiff:tile-geometry");
2643 if (option == (const char *) NULL)
2645 flags=ParseAbsoluteGeometry(option,&tiff_info->tile_geometry);
2646 if ((flags & HeightValue) == 0)
2647 tiff_info->tile_geometry.height=tiff_info->tile_geometry.width;
2648 tile_columns=(uint32) tiff_info->tile_geometry.width;
2649 tile_rows=(uint32) tiff_info->tile_geometry.height;
2650 TIFFDefaultTileSize(tiff,&tile_columns,&tile_rows);
2651 (void) TIFFSetField(tiff,TIFFTAG_TILEWIDTH,tile_columns);
2652 (void) TIFFSetField(tiff,TIFFTAG_TILELENGTH,tile_rows);
2653 tiff_info->tile_geometry.width=tile_columns;
2654 tiff_info->tile_geometry.height=tile_rows;
2655 tiff_info->scanlines=(unsigned char *) AcquireQuantumMemory((size_t)
2656 tile_rows*TIFFScanlineSize(tiff),sizeof(*tiff_info->scanlines));
2657 tiff_info->pixels=(unsigned char *) AcquireQuantumMemory((size_t)
2658 tile_rows*TIFFTileSize(tiff),sizeof(*tiff_info->scanlines));
2659 if ((tiff_info->scanlines == (unsigned char *) NULL) ||
2660 (tiff_info->pixels == (unsigned char *) NULL))
2662 DestroyTIFFInfo(tiff_info);
2663 return(MagickFalse);
2668 static int32 TIFFWritePixels(TIFF *tiff,TIFFInfo *tiff_info,ssize_t row,
2669 tsample_t sample,Image *image)
2677 register unsigned char
2691 if (TIFFIsTiled(tiff) == 0)
2692 return(TIFFWriteScanline(tiff,tiff_info->scanline,(uint32) row,sample));
2694 Fill scanlines to tile height.
2696 i=(ssize_t) (row % tiff_info->tile_geometry.height)*TIFFScanlineSize(tiff);
2697 (void) CopyMagickMemory(tiff_info->scanlines+i,(char *) tiff_info->scanline,
2698 (size_t) TIFFScanlineSize(tiff));
2699 if (((size_t) (row % tiff_info->tile_geometry.height) !=
2700 (tiff_info->tile_geometry.height-1)) &&
2701 (row != (ssize_t) (image->rows-1)))
2704 Write tile to TIFF image.
2707 bytes_per_pixel=TIFFTileSize(tiff)/(ssize_t) (
2708 tiff_info->tile_geometry.height*tiff_info->tile_geometry.width);
2709 number_tiles=(image->columns+tiff_info->tile_geometry.width)/
2710 tiff_info->tile_geometry.width;
2711 for (i=0; i < (ssize_t) number_tiles; i++)
2713 tile_width=(i == (ssize_t) (number_tiles-1)) ? image->columns-(i*
2714 tiff_info->tile_geometry.width) : tiff_info->tile_geometry.width;
2715 for (j=0; j < (ssize_t) ((row % tiff_info->tile_geometry.height)+1); j++)
2716 for (k=0; k < (ssize_t) tile_width; k++)
2718 if (bytes_per_pixel == 0)
2720 p=tiff_info->scanlines+(j*TIFFScanlineSize(tiff)+(i*
2721 tiff_info->tile_geometry.width+k)/8);
2722 q=tiff_info->pixels+(j*TIFFTileRowSize(tiff)+k/8);
2726 p=tiff_info->scanlines+(j*TIFFScanlineSize(tiff)+(i*
2727 tiff_info->tile_geometry.width+k)*bytes_per_pixel);
2728 q=tiff_info->pixels+(j*TIFFTileRowSize(tiff)+k*bytes_per_pixel);
2729 for (l=0; l < bytes_per_pixel; l++)
2732 if ((i*tiff_info->tile_geometry.width) != image->columns)
2733 status=TIFFWriteTile(tiff,tiff_info->pixels,(uint32) (i*
2734 tiff_info->tile_geometry.width),(uint32) ((row/
2735 tiff_info->tile_geometry.height)*tiff_info->tile_geometry.height),0,
2743 static void TIFFSetProfiles(TIFF *tiff,Image *image)
2751 if (image->profiles == (void *) NULL)
2753 ResetImageProfileIterator(image);
2754 for (name=GetNextImageProfile(image); name != (const char *) NULL; )
2756 profile=GetImageProfile(image,name);
2757 if (GetStringInfoLength(profile) == 0)
2759 name=GetNextImageProfile(image);
2762 #if defined(TIFFTAG_XMLPACKET)
2763 if (LocaleCompare(name,"xmp") == 0)
2764 (void) TIFFSetField(tiff,TIFFTAG_XMLPACKET,(uint32) GetStringInfoLength(
2765 profile),GetStringInfoDatum(profile));
2767 #if defined(TIFFTAG_ICCPROFILE)
2768 if (LocaleCompare(name,"icc") == 0)
2769 (void) TIFFSetField(tiff,TIFFTAG_ICCPROFILE,(uint32) GetStringInfoLength(
2770 profile),GetStringInfoDatum(profile));
2772 if (LocaleCompare(name,"iptc") == 0)
2780 iptc_profile=CloneStringInfo(profile);
2781 length=GetStringInfoLength(profile)+4-(GetStringInfoLength(profile) &
2783 SetStringInfoLength(iptc_profile,length);
2784 if (TIFFIsByteSwapped(tiff))
2785 TIFFSwabArrayOfLong((uint32 *) GetStringInfoDatum(iptc_profile),
2786 (unsigned long) (length/4));
2787 (void) TIFFSetField(tiff,TIFFTAG_RICHTIFFIPTC,(uint32)
2788 GetStringInfoLength(iptc_profile)/4,GetStringInfoDatum(iptc_profile));
2789 iptc_profile=DestroyStringInfo(iptc_profile);
2791 #if defined(TIFFTAG_PHOTOSHOP)
2792 if (LocaleCompare(name,"8bim") == 0)
2793 (void) TIFFSetField(tiff,TIFFTAG_PHOTOSHOP,(uint32)
2794 GetStringInfoLength(profile),GetStringInfoDatum(profile));
2796 if (LocaleCompare(name,"tiff:37724") == 0)
2797 (void) TIFFSetField(tiff,37724,(uint32) GetStringInfoLength(profile),
2798 GetStringInfoDatum(profile));
2799 if (LocaleCompare(name,"tiff:34118") == 0)
2800 (void) TIFFSetField(tiff,34118,(uint32) GetStringInfoLength(profile),
2801 GetStringInfoDatum(profile));
2802 name=GetNextImageProfile(image);
2806 static void TIFFSetProperties(TIFF *tiff,Image *image,ExceptionInfo *exception)
2811 value=GetImageArtifact(image,"tiff:document");
2812 if (value != (const char *) NULL)
2813 (void) TIFFSetField(tiff,TIFFTAG_DOCUMENTNAME,value);
2814 value=GetImageArtifact(image,"tiff:hostcomputer");
2815 if (value != (const char *) NULL)
2816 (void) TIFFSetField(tiff,TIFFTAG_HOSTCOMPUTER,value);
2817 value=GetImageArtifact(image,"tiff:artist");
2818 if (value != (const char *) NULL)
2819 (void) TIFFSetField(tiff,TIFFTAG_ARTIST,value);
2820 value=GetImageArtifact(image,"tiff:timestamp");
2821 if (value != (const char *) NULL)
2822 (void) TIFFSetField(tiff,TIFFTAG_DATETIME,value);
2823 value=GetImageArtifact(image,"tiff:make");
2824 if (value != (const char *) NULL)
2825 (void) TIFFSetField(tiff,TIFFTAG_MAKE,value);
2826 value=GetImageArtifact(image,"tiff:model");
2827 if (value != (const char *) NULL)
2828 (void) TIFFSetField(tiff,TIFFTAG_MODEL,value);
2829 value=GetImageArtifact(image,"tiff:software");
2830 if (value != (const char *) NULL)
2831 (void) TIFFSetField(tiff,TIFFTAG_SOFTWARE,value);
2832 value=GetImageArtifact(image,"tiff:copyright");
2833 if (value != (const char *) NULL)
2834 (void) TIFFSetField(tiff,TIFFTAG_COPYRIGHT,value);
2835 value=GetImageArtifact(image,"kodak-33423");
2836 if (value != (const char *) NULL)
2837 (void) TIFFSetField(tiff,33423,value);
2838 value=GetImageArtifact(image,"kodak-36867");
2839 if (value != (const char *) NULL)
2840 (void) TIFFSetField(tiff,36867,value);
2841 value=GetImageArtifact(image,"label");
2842 if (value != (const char *) NULL)
2843 (void) TIFFSetField(tiff,TIFFTAG_PAGENAME,value);
2844 value=GetImageArtifact(image,"comment");
2845 if (value != (const char *) NULL)
2846 (void) TIFFSetField(tiff,TIFFTAG_IMAGEDESCRIPTION,value);
2849 static void TIFFSetEXIFProperties(TIFF *tiff,Image *image,
2850 ExceptionInfo *exception)
2852 #if defined(MAGICKCORE_HAVE_TIFFREADEXIFDIRECTORY)
2863 Write EXIF properties.
2866 (void) TIFFSetField(tiff,TIFFTAG_SUBIFD,1,&offset);
2867 for (i=0; exif_info[i].tag != 0; i++)
2869 value=GetImageProperty(image,exif_info[i].property,exception);
2870 if (value == (const char *) NULL)
2872 switch (exif_info[i].type)
2876 (void) TIFFSetField(tiff,exif_info[i].tag,value);
2884 field=(uint16) StringToLong(value);
2885 (void) TIFFSetField(tiff,exif_info[i].tag,field);
2893 field=(uint16) StringToLong(value);
2894 (void) TIFFSetField(tiff,exif_info[i].tag,field);
2898 case TIFF_SRATIONAL:
2903 field=StringToDouble(value,(char **) NULL);
2904 (void) TIFFSetField(tiff,exif_info[i].tag,field);
2911 /* (void) TIFFSetField(tiff,TIFFTAG_EXIFIFD,offset); */
2918 static MagickBooleanType WriteTIFFImage(const ImageInfo *image_info,
2919 Image *image,ExceptionInfo *exception)
2921 #if !defined(TIFFDefaultStripSize)
2922 #define TIFFDefaultStripSize(tiff,request) (8192UL/TIFFScanlineSize(tiff))
2982 assert(image_info != (const ImageInfo *) NULL);
2983 assert(image_info->signature == MagickSignature);
2984 assert(image != (Image *) NULL);
2985 assert(image->signature == MagickSignature);
2986 if (image->debug != MagickFalse)
2987 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2988 assert(exception != (ExceptionInfo *) NULL);
2989 assert(exception->signature == MagickSignature);
2990 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
2991 if (status == MagickFalse)
2993 (void) MagickSetThreadValue(tiff_exception,exception);
2994 error_handler=TIFFSetErrorHandler((TIFFErrorHandler) TIFFErrors);
2995 warning_handler=TIFFSetWarningHandler((TIFFErrorHandler) TIFFWarnings);
2996 endian_type=UndefinedEndian;
2997 option=GetImageOption(image_info,"tiff:endian");
2998 if (option != (const char *) NULL)
3000 if (LocaleNCompare(option,"msb",3) == 0)
3001 endian_type=MSBEndian;
3002 if (LocaleNCompare(option,"lsb",3) == 0)
3003 endian_type=LSBEndian;;
3005 switch (endian_type)
3007 case LSBEndian: mode="wl"; break;
3008 case MSBEndian: mode="wb"; break;
3009 default: mode="w"; break;
3011 #if defined(TIFF_VERSION_BIG)
3012 if (LocaleCompare(image_info->magick,"TIFF64") == 0)
3013 switch (endian_type)
3015 case LSBEndian: mode="wl8"; break;
3016 case MSBEndian: mode="wb8"; break;
3017 default: mode="w8"; break;
3020 tiff=TIFFClientOpen(image->filename,mode,(thandle_t) image,TIFFReadBlob,
3021 TIFFWriteBlob,TIFFSeekBlob,TIFFCloseBlob,TIFFGetBlobSize,TIFFMapBlob,
3023 if (tiff == (TIFF *) NULL)
3025 (void) TIFFSetWarningHandler(warning_handler);
3026 (void) TIFFSetErrorHandler(error_handler);
3027 return(MagickFalse);
3030 debug=IsEventLogging();
3035 Initialize TIFF fields.
3037 if ((image_info->type != UndefinedType) &&
3038 (image_info->type != OptimizeType))
3039 (void) SetImageType(image,image_info->type,exception);
3040 compression=UndefinedCompression;
3041 if (image->compression != JPEGCompression)
3042 compression=image->compression;
3043 if (image_info->compression != UndefinedCompression)
3044 compression=image_info->compression;
3045 switch (compression)
3047 case FaxCompression:
3048 case Group4Compression:
3050 (void) SetImageType(image,BilevelType,exception);
3053 case JPEGCompression:
3055 (void) SetImageStorageClass(image,DirectClass,exception);
3056 (void) SetImageDepth(image,8,exception);
3062 quantum_info=AcquireQuantumInfo(image_info,image);
3063 if (quantum_info == (QuantumInfo *) NULL)
3064 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
3065 if ((image->storage_class != PseudoClass) && (image->depth >= 32) &&
3066 (quantum_info->format == UndefinedQuantumFormat) &&
3067 (IsHighDynamicRangeImage(image,exception) != MagickFalse))
3069 status=SetQuantumFormat(image,quantum_info,FloatingPointQuantumFormat);
3070 if (status == MagickFalse)
3071 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
3073 if ((LocaleCompare(image_info->magick,"PTIF") == 0) &&
3074 (GetPreviousImageInList(image) != (Image *) NULL))
3075 (void) TIFFSetField(tiff,TIFFTAG_SUBFILETYPE,FILETYPE_REDUCEDIMAGE);
3076 if ((image->columns != (uint32) image->columns) ||
3077 (image->rows != (uint32) image->rows))
3078 ThrowWriterException(ImageError,"WidthOrHeightExceedsLimit");
3079 (void) TIFFSetField(tiff,TIFFTAG_IMAGELENGTH,(uint32) image->rows);
3080 (void) TIFFSetField(tiff,TIFFTAG_IMAGEWIDTH,(uint32) image->columns);
3081 switch (compression)
3083 case FaxCompression:
3085 compress_tag=COMPRESSION_CCITTFAX3;
3086 SetQuantumMinIsWhite(quantum_info,MagickTrue);
3089 case Group4Compression:
3091 compress_tag=COMPRESSION_CCITTFAX4;
3092 SetQuantumMinIsWhite(quantum_info,MagickTrue);
3095 #if defined(COMPRESSION_JBIG)
3096 case JBIG1Compression:
3098 compress_tag=COMPRESSION_JBIG;
3102 case JPEGCompression:
3104 compress_tag=COMPRESSION_JPEG;
3107 #if defined(COMPRESSION_LZMA)
3108 case LZMACompression:
3110 compress_tag=COMPRESSION_LZMA;
3114 case LZWCompression:
3116 compress_tag=COMPRESSION_LZW;
3119 case RLECompression:
3121 compress_tag=COMPRESSION_PACKBITS;
3124 case ZipCompression:
3126 compress_tag=COMPRESSION_ADOBE_DEFLATE;
3132 compress_tag=COMPRESSION_NONE;
3136 #if defined(MAGICKCORE_HAVE_TIFFISCODECCONFIGURED) || (TIFFLIB_VERSION > 20040919)
3137 if ((compress_tag != COMPRESSION_NONE) &&
3138 (TIFFIsCODECConfigured(compress_tag) == 0))
3140 (void) ThrowMagickException(exception,GetMagickModule(),CoderError,
3141 "CompressionNotSupported","`%s'",CommandOptionToMnemonic(
3142 MagickCompressOptions,(ssize_t) compression));
3143 compress_tag=COMPRESSION_NONE;
3144 compression=NoCompression;
3147 switch (compress_tag)
3149 #if defined(CCITT_SUPPORT)
3150 case COMPRESSION_CCITTFAX3:
3151 case COMPRESSION_CCITTFAX4:
3153 #if defined(YCBCR_SUPPORT) && defined(JPEG_SUPPORT)
3154 case COMPRESSION_JPEG:
3156 #if defined(LZMA_SUPPORT) && defined(COMPRESSION_LZMA)
3157 case COMPRESSION_LZMA:
3159 #if defined(LZW_SUPPORT)
3160 case COMPRESSION_LZW:
3162 #if defined(PACKBITS_SUPPORT)
3163 case COMPRESSION_PACKBITS:
3165 #if defined(ZIP_SUPPORT)
3166 case COMPRESSION_ADOBE_DEFLATE:
3168 case COMPRESSION_NONE:
3172 (void) ThrowMagickException(exception,GetMagickModule(),CoderError,
3173 "CompressionNotSupported","`%s'",CommandOptionToMnemonic(
3174 MagickCompressOptions,(ssize_t) compression));
3175 compress_tag=COMPRESSION_NONE;
3176 compression=NoCompression;
3181 if (image->colorspace == CMYKColorspace)
3183 photometric=PHOTOMETRIC_SEPARATED;
3184 (void) TIFFSetField(tiff,TIFFTAG_SAMPLESPERPIXEL,4);
3185 (void) TIFFSetField(tiff,TIFFTAG_INKSET,INKSET_CMYK);
3190 Full color TIFF raster.
3192 if (image->colorspace == LabColorspace)
3194 photometric=PHOTOMETRIC_CIELAB;
3195 EncodeLabImage(image,exception);
3198 if (image->colorspace == YCbCrColorspace)
3200 photometric=PHOTOMETRIC_YCBCR;
3201 (void) TIFFSetField(tiff,TIFFTAG_YCBCRSUBSAMPLING,1,1);
3202 (void) SetImageStorageClass(image,DirectClass,exception);
3203 (void) SetImageDepth(image,8,exception);
3206 photometric=PHOTOMETRIC_RGB;
3207 (void) TIFFSetField(tiff,TIFFTAG_SAMPLESPERPIXEL,3);
3208 if ((image_info->type != TrueColorType) &&
3209 (image_info->type != TrueColorAlphaType))
3211 if ((image_info->type != PaletteType) &&
3212 (IsImageGray(image,exception) != MagickFalse))
3214 photometric=(uint16) (quantum_info->min_is_white !=
3215 MagickFalse ? PHOTOMETRIC_MINISWHITE :
3216 PHOTOMETRIC_MINISBLACK);
3217 (void) TIFFSetField(tiff,TIFFTAG_SAMPLESPERPIXEL,1);
3218 if ((image_info->depth == 0) &&
3219 (image->alpha_trait == UndefinedPixelTrait) &&
3220 (IsImageMonochrome(image,exception) != MagickFalse))
3222 status=SetQuantumDepth(image,quantum_info,1);
3223 if (status == MagickFalse)
3224 ThrowWriterException(ResourceLimitError,
3225 "MemoryAllocationFailed");
3229 if (image->storage_class == PseudoClass)
3235 Colormapped TIFF raster.
3237 (void) TIFFSetField(tiff,TIFFTAG_SAMPLESPERPIXEL,1);
3238 photometric=PHOTOMETRIC_PALETTE;
3240 while ((GetQuantumRange(depth)+1) < image->colors)
3242 status=SetQuantumDepth(image,quantum_info,depth);
3243 if (status == MagickFalse)
3244 ThrowWriterException(ResourceLimitError,
3245 "MemoryAllocationFailed");
3249 (void) TIFFGetFieldDefaulted(tiff,TIFFTAG_FILLORDER,&endian);
3250 if ((compress_tag == COMPRESSION_CCITTFAX3) &&
3251 (photometric != PHOTOMETRIC_MINISWHITE))
3253 compress_tag=COMPRESSION_NONE;
3254 endian=FILLORDER_MSB2LSB;
3257 if ((compress_tag == COMPRESSION_CCITTFAX4) &&
3258 (photometric != PHOTOMETRIC_MINISWHITE))
3260 compress_tag=COMPRESSION_NONE;
3261 endian=FILLORDER_MSB2LSB;
3263 option=GetImageOption(image_info,"tiff:fill-order");
3264 if (option != (const char *) NULL)
3266 if (LocaleNCompare(option,"msb",3) == 0)
3267 endian=FILLORDER_MSB2LSB;
3268 if (LocaleNCompare(option,"lsb",3) == 0)
3269 endian=FILLORDER_LSB2MSB;
3271 (void) TIFFSetField(tiff,TIFFTAG_COMPRESSION,compress_tag);
3272 (void) TIFFSetField(tiff,TIFFTAG_FILLORDER,endian);
3273 (void) TIFFSetField(tiff,TIFFTAG_BITSPERSAMPLE,quantum_info->depth);
3274 if (image->alpha_trait != UndefinedPixelTrait)
3282 TIFF has a matte channel.
3285 sample_info[0]=EXTRASAMPLE_UNASSALPHA;
3286 option=GetImageOption(image_info,"tiff:alpha");
3287 if (option != (const char *) NULL)
3289 if (LocaleCompare(option,"associated") == 0)
3290 sample_info[0]=EXTRASAMPLE_ASSOCALPHA;
3292 if (LocaleCompare(option,"unspecified") == 0)
3293 sample_info[0]=EXTRASAMPLE_UNSPECIFIED;
3295 (void) TIFFGetFieldDefaulted(tiff,TIFFTAG_SAMPLESPERPIXEL,
3296 &samples_per_pixel);
3297 (void) TIFFSetField(tiff,TIFFTAG_SAMPLESPERPIXEL,samples_per_pixel+1);
3298 (void) TIFFSetField(tiff,TIFFTAG_EXTRASAMPLES,extra_samples,
3300 if (sample_info[0] == EXTRASAMPLE_ASSOCALPHA)
3301 SetQuantumAlphaType(quantum_info,AssociatedQuantumAlpha);
3303 (void) TIFFSetField(tiff,TIFFTAG_PHOTOMETRIC,photometric);
3304 switch (quantum_info->format)
3306 case FloatingPointQuantumFormat:
3308 (void) TIFFSetField(tiff,TIFFTAG_SAMPLEFORMAT,SAMPLEFORMAT_IEEEFP);
3309 (void) TIFFSetField(tiff,TIFFTAG_SMINSAMPLEVALUE,quantum_info->minimum);
3310 (void) TIFFSetField(tiff,TIFFTAG_SMAXSAMPLEVALUE,quantum_info->maximum);
3313 case SignedQuantumFormat:
3315 (void) TIFFSetField(tiff,TIFFTAG_SAMPLEFORMAT,SAMPLEFORMAT_INT);
3318 case UnsignedQuantumFormat:
3320 (void) TIFFSetField(tiff,TIFFTAG_SAMPLEFORMAT,SAMPLEFORMAT_UINT);
3326 (void) TIFFSetField(tiff,TIFFTAG_ORIENTATION,ORIENTATION_TOPLEFT);
3327 (void) TIFFSetField(tiff,TIFFTAG_PLANARCONFIG,PLANARCONFIG_CONTIG);
3328 if (photometric == PHOTOMETRIC_RGB)
3329 if ((image_info->interlace == PlaneInterlace) ||
3330 (image_info->interlace == PartitionInterlace))
3331 (void) TIFFSetField(tiff,TIFFTAG_PLANARCONFIG,PLANARCONFIG_SEPARATE);
3332 rows_per_strip=TIFFDefaultStripSize(tiff,0);
3333 option=GetImageOption(image_info,"tiff:rows-per-strip");
3334 if (option != (const char *) NULL)
3335 rows_per_strip=(size_t) strtol(option,(char **) NULL,10);
3336 switch (compress_tag)
3338 case COMPRESSION_JPEG:
3340 #if defined(JPEG_SUPPORT)
3350 rows_per_strip+=(16-(rows_per_strip % 16));
3351 if (image_info->quality != UndefinedCompressionQuality)
3352 (void) TIFFSetField(tiff,TIFFTAG_JPEGQUALITY,image_info->quality);
3353 (void) TIFFSetField(tiff,TIFFTAG_JPEGCOLORMODE,JPEGCOLORMODE_RAW);
3354 if (IssRGBCompatibleColorspace(image->colorspace) != MagickFalse)
3359 (void) TIFFSetField(tiff,TIFFTAG_JPEGCOLORMODE,JPEGCOLORMODE_RGB);
3360 sampling_factor=(const char *) NULL;
3361 value=GetImageProperty(image,"jpeg:sampling-factor",exception);
3362 if (value != (char *) NULL)
3364 sampling_factor=value;
3365 if (image->debug != MagickFalse)
3366 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
3367 " Input sampling-factors=%s",sampling_factor);
3369 if (image_info->sampling_factor != (char *) NULL)
3370 sampling_factor=image_info->sampling_factor;
3371 if (sampling_factor != (const char *) NULL)
3373 flags=ParseGeometry(sampling_factor,&geometry_info);
3374 if ((flags & SigmaValue) == 0)
3375 geometry_info.sigma=geometry_info.rho;
3376 if (image->colorspace == YCbCrColorspace)
3377 (void) TIFFSetField(tiff,TIFFTAG_YCBCRSUBSAMPLING,(uint16)
3378 geometry_info.rho,(uint16) geometry_info.sigma);
3381 (void) TIFFGetFieldDefaulted(tiff,TIFFTAG_BITSPERSAMPLE,
3383 if (bits_per_sample == 12)
3384 (void) TIFFSetField(tiff,TIFFTAG_JPEGTABLESMODE,JPEGTABLESMODE_QUANT);
3388 case COMPRESSION_ADOBE_DEFLATE:
3390 rows_per_strip=(uint32) image->rows;
3391 (void) TIFFGetFieldDefaulted(tiff,TIFFTAG_BITSPERSAMPLE,
3393 if (((photometric == PHOTOMETRIC_RGB) ||
3394 (photometric == PHOTOMETRIC_MINISBLACK)) &&
3395 ((bits_per_sample == 8) || (bits_per_sample == 16)))
3396 (void) TIFFSetField(tiff,TIFFTAG_PREDICTOR,PREDICTOR_HORIZONTAL);
3397 (void) TIFFSetField(tiff,TIFFTAG_ZIPQUALITY,(long) (
3398 image_info->quality == UndefinedCompressionQuality ? 7 :
3399 MagickMin((ssize_t) image_info->quality/10,9)));
3402 case COMPRESSION_CCITTFAX3:
3407 rows_per_strip=(uint32) image->rows;
3408 (void) TIFFSetField(tiff,TIFFTAG_GROUP3OPTIONS,4);
3411 case COMPRESSION_CCITTFAX4:
3413 rows_per_strip=(uint32) image->rows;
3416 #if defined(LZMA_SUPPORT) && defined(COMPRESSION_LZMA)
3417 case COMPRESSION_LZMA:
3419 if (((photometric == PHOTOMETRIC_RGB) ||
3420 (photometric == PHOTOMETRIC_MINISBLACK)) &&
3421 ((bits_per_sample == 8) || (bits_per_sample == 16)))
3422 (void) TIFFSetField(tiff,TIFFTAG_PREDICTOR,PREDICTOR_HORIZONTAL);
3423 (void) TIFFSetField(tiff,TIFFTAG_LZMAPRESET,(long) (
3424 image_info->quality == UndefinedCompressionQuality ? 7 :
3425 MagickMin((ssize_t) image_info->quality/10,9)));
3429 case COMPRESSION_LZW:
3431 (void) TIFFGetFieldDefaulted(tiff,TIFFTAG_BITSPERSAMPLE,
3433 if (((photometric == PHOTOMETRIC_RGB) ||
3434 (photometric == PHOTOMETRIC_MINISBLACK)) &&
3435 ((bits_per_sample == 8) || (bits_per_sample == 16)))
3436 (void) TIFFSetField(tiff,TIFFTAG_PREDICTOR,PREDICTOR_HORIZONTAL);
3442 if (rows_per_strip < 1)
3444 if ((image->rows/rows_per_strip) >= (1UL << 15))
3445 rows_per_strip=(uint32) (image->rows >> 15);
3446 (void) TIFFSetField(tiff,TIFFTAG_ROWSPERSTRIP,rows_per_strip);
3447 if ((image->resolution.x != 0.0) && (image->resolution.y != 0.0))
3453 Set image resolution.
3456 if (image->units == PixelsPerInchResolution)
3458 if (image->units == PixelsPerCentimeterResolution)
3459 units=RESUNIT_CENTIMETER;
3460 (void) TIFFSetField(tiff,TIFFTAG_RESOLUTIONUNIT,(uint16) units);
3461 (void) TIFFSetField(tiff,TIFFTAG_XRESOLUTION,image->resolution.x);
3462 (void) TIFFSetField(tiff,TIFFTAG_YRESOLUTION,image->resolution.y);
3463 if ((image->page.x < 0) || (image->page.y < 0))
3464 (void) ThrowMagickException(exception,GetMagickModule(),CoderError,
3465 "TIFF: negative image positions unsupported","%s",image->filename);
3466 if ((image->page.x > 0) && (image->resolution.x > 0.0))
3469 Set horizontal image position.
3471 (void) TIFFSetField(tiff,TIFFTAG_XPOSITION,(float) image->page.x/
3472 image->resolution.x);
3474 if ((image->page.y > 0) && (image->resolution.y > 0.0))
3477 Set vertical image position.
3479 (void) TIFFSetField(tiff,TIFFTAG_YPOSITION,(float) image->page.y/
3480 image->resolution.y);
3483 if (image->chromaticity.white_point.x != 0.0)
3489 Set image chromaticity.
3491 chromaticity[0]=(float) image->chromaticity.red_primary.x;
3492 chromaticity[1]=(float) image->chromaticity.red_primary.y;
3493 chromaticity[2]=(float) image->chromaticity.green_primary.x;
3494 chromaticity[3]=(float) image->chromaticity.green_primary.y;
3495 chromaticity[4]=(float) image->chromaticity.blue_primary.x;
3496 chromaticity[5]=(float) image->chromaticity.blue_primary.y;
3497 (void) TIFFSetField(tiff,TIFFTAG_PRIMARYCHROMATICITIES,chromaticity);
3498 chromaticity[0]=(float) image->chromaticity.white_point.x;
3499 chromaticity[1]=(float) image->chromaticity.white_point.y;
3500 (void) TIFFSetField(tiff,TIFFTAG_WHITEPOINT,chromaticity);
3502 if ((LocaleCompare(image_info->magick,"PTIF") != 0) &&
3503 (image_info->adjoin != MagickFalse) && (GetImageListLength(image) > 1))
3505 (void) TIFFSetField(tiff,TIFFTAG_SUBFILETYPE,FILETYPE_PAGE);
3506 if (image->scene != 0)
3507 (void) TIFFSetField(tiff,TIFFTAG_PAGENUMBER,(uint16) image->scene,
3508 GetImageListLength(image));
3510 if (image->orientation != UndefinedOrientation)
3511 (void) TIFFSetField(tiff,TIFFTAG_ORIENTATION,(uint16) image->orientation);
3512 (void) TIFFSetProfiles(tiff,image);
3518 page=(uint16) scene;
3519 pages=(uint16) GetImageListLength(image);
3520 if ((LocaleCompare(image_info->magick,"PTIF") != 0) &&
3521 (image_info->adjoin != MagickFalse) && (pages > 1))
3522 (void) TIFFSetField(tiff,TIFFTAG_SUBFILETYPE,FILETYPE_PAGE);
3523 (void) TIFFSetField(tiff,TIFFTAG_PAGENUMBER,page,pages);
3525 (void) TIFFSetProperties(tiff,image,exception);
3526 DisableMSCWarning(4127)
3529 (void) TIFFSetEXIFProperties(tiff,image,exception);
3531 Write image scanlines.
3533 if (GetTIFFInfo(image_info,tiff,&tiff_info) == MagickFalse)
3534 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
3535 quantum_info->endian=LSBEndian;
3536 pixels=GetQuantumPixels(quantum_info);
3537 tiff_info.scanline=GetQuantumPixels(quantum_info);
3538 switch (photometric)
3540 case PHOTOMETRIC_CIELAB:
3541 case PHOTOMETRIC_YCBCR:
3542 case PHOTOMETRIC_RGB:
3547 switch (image_info->interlace)
3552 quantum_type=RGBQuantum;
3553 if (image->alpha_trait != UndefinedPixelTrait)
3554 quantum_type=RGBAQuantum;
3555 for (y=0; y < (ssize_t) image->rows; y++)
3557 register const Quantum
3560 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
3561 if (p == (const Quantum *) NULL)
3563 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
3564 quantum_type,pixels,exception);
3566 if (TIFFWritePixels(tiff,&tiff_info,y,0,image) == -1)
3568 if (image->previous == (Image *) NULL)
3570 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType)
3572 if (status == MagickFalse)
3578 case PlaneInterlace:
3579 case PartitionInterlace:
3582 Plane interlacing: RRRRRR...GGGGGG...BBBBBB...
3584 for (y=0; y < (ssize_t) image->rows; y++)
3586 register const Quantum
3589 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
3590 if (p == (const Quantum *) NULL)
3592 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
3593 RedQuantum,pixels,exception);
3594 if (TIFFWritePixels(tiff,&tiff_info,y,0,image) == -1)
3597 if (image->previous == (Image *) NULL)
3599 status=SetImageProgress(image,SaveImageTag,100,400);
3600 if (status == MagickFalse)
3603 for (y=0; y < (ssize_t) image->rows; y++)
3605 register const Quantum
3608 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
3609 if (p == (const Quantum *) NULL)
3611 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
3612 GreenQuantum,pixels,exception);
3613 if (TIFFWritePixels(tiff,&tiff_info,y,1,image) == -1)
3616 if (image->previous == (Image *) NULL)
3618 status=SetImageProgress(image,SaveImageTag,200,400);
3619 if (status == MagickFalse)
3622 for (y=0; y < (ssize_t) image->rows; y++)
3624 register const Quantum
3627 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
3628 if (p == (const Quantum *) NULL)
3630 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
3631 BlueQuantum,pixels,exception);
3632 if (TIFFWritePixels(tiff,&tiff_info,y,2,image) == -1)
3635 if (image->previous == (Image *) NULL)
3637 status=SetImageProgress(image,SaveImageTag,300,400);
3638 if (status == MagickFalse)
3641 if (image->alpha_trait != UndefinedPixelTrait)
3642 for (y=0; y < (ssize_t) image->rows; y++)
3644 register const Quantum
3647 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
3648 if (p == (const Quantum *) NULL)
3650 length=ExportQuantumPixels(image,(CacheView *) NULL,
3651 quantum_info,AlphaQuantum,pixels,exception);
3652 if (TIFFWritePixels(tiff,&tiff_info,y,3,image) == -1)
3655 if (image->previous == (Image *) NULL)
3657 status=SetImageProgress(image,SaveImageTag,400,400);
3658 if (status == MagickFalse)
3666 case PHOTOMETRIC_SEPARATED:
3671 quantum_type=CMYKQuantum;
3672 if (image->alpha_trait != UndefinedPixelTrait)
3673 quantum_type=CMYKAQuantum;
3674 if (image->colorspace != CMYKColorspace)
3675 (void) TransformImageColorspace(image,CMYKColorspace,exception);
3676 for (y=0; y < (ssize_t) image->rows; y++)
3678 register const Quantum
3681 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
3682 if (p == (const Quantum *) NULL)
3684 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
3685 quantum_type,pixels,exception);
3686 if (TIFFWritePixels(tiff,&tiff_info,y,0,image) == -1)
3688 if (image->previous == (Image *) NULL)
3690 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
3692 if (status == MagickFalse)
3698 case PHOTOMETRIC_PALETTE:
3706 Colormapped TIFF image.
3708 red=(uint16 *) AcquireQuantumMemory(65536,sizeof(*red));
3709 green=(uint16 *) AcquireQuantumMemory(65536,sizeof(*green));
3710 blue=(uint16 *) AcquireQuantumMemory(65536,sizeof(*blue));
3711 if ((red == (uint16 *) NULL) || (green == (uint16 *) NULL) ||
3712 (blue == (uint16 *) NULL))
3713 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
3715 Initialize TIFF colormap.
3717 (void) ResetMagickMemory(red,0,65536*sizeof(*red));
3718 (void) ResetMagickMemory(green,0,65536*sizeof(*green));
3719 (void) ResetMagickMemory(blue,0,65536*sizeof(*blue));
3720 for (i=0; i < (ssize_t) image->colors; i++)
3722 red[i]=ScaleQuantumToShort(image->colormap[i].red);
3723 green[i]=ScaleQuantumToShort(image->colormap[i].green);
3724 blue[i]=ScaleQuantumToShort(image->colormap[i].blue);
3726 (void) TIFFSetField(tiff,TIFFTAG_COLORMAP,red,green,blue);
3727 red=(uint16 *) RelinquishMagickMemory(red);
3728 green=(uint16 *) RelinquishMagickMemory(green);
3729 blue=(uint16 *) RelinquishMagickMemory(blue);
3734 Convert PseudoClass packets to contiguous grayscale scanlines.
3736 quantum_type=IndexQuantum;
3737 if (image->alpha_trait != UndefinedPixelTrait)
3739 if (photometric != PHOTOMETRIC_PALETTE)
3740 quantum_type=GrayAlphaQuantum;
3742 quantum_type=IndexAlphaQuantum;
3745 if (photometric != PHOTOMETRIC_PALETTE)
3746 quantum_type=GrayQuantum;
3747 for (y=0; y < (ssize_t) image->rows; y++)
3749 register const Quantum
3752 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
3753 if (p == (const Quantum *) NULL)
3755 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
3756 quantum_type,pixels,exception);
3757 if (TIFFWritePixels(tiff,&tiff_info,y,0,image) == -1)
3759 if (image->previous == (Image *) NULL)
3761 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
3763 if (status == MagickFalse)
3770 quantum_info=DestroyQuantumInfo(quantum_info);
3771 if (image->colorspace == LabColorspace)
3772 DecodeLabImage(image,exception);
3773 DestroyTIFFInfo(&tiff_info);
3774 DisableMSCWarning(4127)
3775 if (0 && (image_info->verbose != MagickFalse))
3777 TIFFPrintDirectory(tiff,stdout,MagickFalse);
3778 (void) TIFFWriteDirectory(tiff);
3779 image=SyncNextImageInList(image);
3780 if (image == (Image *) NULL)
3782 status=SetImageProgress(image,SaveImagesTag,scene++,
3783 GetImageListLength(image));
3784 if (status == MagickFalse)
3786 } while (image_info->adjoin != MagickFalse);
3787 (void) TIFFSetWarningHandler(warning_handler);
3788 (void) TIFFSetErrorHandler(error_handler);