2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 % M M IIIII FFFFF FFFFF %
13 % Read/Write MIFF Image Format %
20 % Copyright 1999-2018 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 % https://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/attribute.h"
44 #include "MagickCore/blob.h"
45 #include "MagickCore/blob-private.h"
46 #include "MagickCore/cache.h"
47 #include "MagickCore/color.h"
48 #include "MagickCore/color-private.h"
49 #include "MagickCore/colormap.h"
50 #include "MagickCore/colormap-private.h"
51 #include "MagickCore/colorspace.h"
52 #include "MagickCore/colorspace-private.h"
53 #include "MagickCore/constitute.h"
54 #include "MagickCore/exception.h"
55 #include "MagickCore/exception-private.h"
56 #include "MagickCore/geometry.h"
57 #include "MagickCore/image.h"
58 #include "MagickCore/image-private.h"
59 #include "MagickCore/linked-list.h"
60 #include "MagickCore/list.h"
61 #include "MagickCore/magick.h"
62 #include "MagickCore/memory_.h"
63 #include "MagickCore/memory-private.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.h"
69 #include "MagickCore/pixel-accessor.h"
70 #include "MagickCore/profile.h"
71 #include "MagickCore/property.h"
72 #include "MagickCore/quantum-private.h"
73 #include "MagickCore/static.h"
74 #include "MagickCore/statistic.h"
75 #include "MagickCore/string_.h"
76 #include "MagickCore/string-private.h"
77 #if defined(MAGICKCORE_BZLIB_DELEGATE)
80 #if defined(MAGICKCORE_LZMA_DELEGATE)
83 #if defined(MAGICKCORE_ZLIB_DELEGATE)
97 static MagickBooleanType
98 WriteMIFFImage(const ImageInfo *,Image *,ExceptionInfo *);
101 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
109 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
111 % IsMIFF() returns MagickTrue if the image format type, identified by the
112 % magick string, is MIFF.
114 % The format of the IsMIFF method is:
116 % MagickBooleanType IsMIFF(const unsigned char *magick,const size_t length)
118 % A description of each parameter follows:
120 % o magick: compare image format pattern against these bytes.
122 % o length: Specifies the length of the magick string.
125 static MagickBooleanType IsMIFF(const unsigned char *magick,const size_t length)
129 if (LocaleNCompare((const char *) magick,"id=ImageMagick",14) == 0)
135 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
139 % R e a d M I F F I m a g e %
143 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
145 % ReadMIFFImage() reads a MIFF image file and returns it. It allocates the
146 % memory necessary for the new Image structure and returns a pointer to the
149 % The format of the ReadMIFFImage method is:
151 % Image *ReadMIFFImage(const ImageInfo *image_info,
152 % ExceptionInfo *exception)
154 % Decompression code contributed by Kyle Shorter.
156 % A description of each parameter follows:
158 % o image_info: the image info.
160 % o exception: return any errors or warnings in this structure.
164 #if defined(MAGICKCORE_BZLIB_DELEGATE) || defined(MAGICKCORE_LZMA_DELEGATE) || defined(MAGICKCORE_ZLIB_DELEGATE)
165 static void *AcquireCompressionMemory(void *context,const size_t items,
172 if (HeapOverflowSanityCheck(items,size) != MagickFalse)
173 return((void *) NULL);
175 if (extent > GetMaxMemoryRequest())
176 return((void *) NULL);
177 return(AcquireMagickMemory(extent));
181 #if defined(MAGICKCORE_BZLIB_DELEGATE)
182 static void *AcquireBZIPMemory(void *context,int items,int size)
184 return(AcquireCompressionMemory(context,(size_t) items,(size_t) size));
188 #if defined(MAGICKCORE_LZMA_DELEGATE)
189 static void *AcquireLZMAMemory(void *context,size_t items,size_t size)
191 return(AcquireCompressionMemory(context,items,size));
195 #if defined(MAGICKCORE_ZLIB_DELEGATE)
196 static voidpf AcquireZIPMemory(voidpf context,unsigned int items,
199 return((voidpf) AcquireCompressionMemory(context,(size_t) items,
204 static void PushRunlengthPacket(Image *image,const unsigned char *pixels,
205 size_t *length,PixelInfo *pixel,ExceptionInfo *exception)
211 if (image->storage_class == PseudoClass)
214 switch (image->depth)
218 pixel->index=(MagickRealType) ConstrainColormapIndex(image,(ssize_t)
219 (((size_t) *p << 24) | ((size_t) *(p+1) << 16) |
220 ((size_t) *(p+2) << 8) | (size_t) *(p+3)),exception);
226 pixel->index=(MagickRealType) ConstrainColormapIndex(image,(ssize_t)
227 ((*p << 8) | *(p+1)),exception);
233 pixel->index=(MagickRealType) ConstrainColormapIndex(image,
234 (ssize_t) *p,exception);
239 (void) ThrowMagickException(exception,GetMagickModule(),
240 CorruptImageError,"ImageDepthNotSupported","`%s'",image->filename);
242 switch (image->depth)
249 if (image->alpha_trait != UndefinedPixelTrait)
251 p=PushCharPixel(p,&quantum);
252 pixel->alpha=(MagickRealType) ScaleCharToQuantum(quantum);
261 if (image->alpha_trait != UndefinedPixelTrait)
263 p=PushShortPixel(MSBEndian,p,&quantum);
264 pixel->alpha=(MagickRealType) (quantum >> (image->depth-
265 MAGICKCORE_QUANTUM_DEPTH));
274 if (image->alpha_trait != UndefinedPixelTrait)
276 p=PushLongPixel(MSBEndian,p,&quantum);
277 pixel->alpha=(MagickRealType) (quantum >> (image->depth-
278 MAGICKCORE_QUANTUM_DEPTH));
283 (void) ThrowMagickException(exception,GetMagickModule(),
284 CorruptImageError,"ImageDepthNotSupported","`%s'",image->filename);
286 *length=(size_t) (*p++)+1;
289 switch (image->depth)
296 p=PushCharPixel(p,&quantum);
297 pixel->red=(MagickRealType) ScaleCharToQuantum(quantum);
298 pixel->green=pixel->red;
299 pixel->blue=pixel->red;
300 if (IsGrayColorspace(image->colorspace) == MagickFalse)
302 p=PushCharPixel(p,&quantum);
303 pixel->green=(MagickRealType) ScaleCharToQuantum(quantum);
304 p=PushCharPixel(p,&quantum);
305 pixel->blue=(MagickRealType) ScaleCharToQuantum(quantum);
307 if (image->colorspace == CMYKColorspace)
309 p=PushCharPixel(p,&quantum);
310 pixel->black=(MagickRealType) ScaleCharToQuantum(quantum);
312 if (image->alpha_trait != UndefinedPixelTrait)
314 p=PushCharPixel(p,&quantum);
315 pixel->alpha=(MagickRealType) ScaleCharToQuantum(quantum);
324 p=PushShortPixel(MSBEndian,p,&quantum);
325 pixel->red=(MagickRealType) (quantum >> (image->depth-
326 MAGICKCORE_QUANTUM_DEPTH));
327 pixel->green=pixel->red;
328 pixel->blue=pixel->red;
329 if (IsGrayColorspace(image->colorspace) == MagickFalse)
331 p=PushShortPixel(MSBEndian,p,&quantum);
332 pixel->green=(MagickRealType) (quantum >> (image->depth-
333 MAGICKCORE_QUANTUM_DEPTH));
334 p=PushShortPixel(MSBEndian,p,&quantum);
335 pixel->blue=(MagickRealType) (quantum >> (image->depth-
336 MAGICKCORE_QUANTUM_DEPTH));
338 if (image->colorspace == CMYKColorspace)
340 p=PushShortPixel(MSBEndian,p,&quantum);
341 pixel->black=(MagickRealType) (quantum >> (image->depth-
342 MAGICKCORE_QUANTUM_DEPTH));
344 if (image->alpha_trait != UndefinedPixelTrait)
346 p=PushShortPixel(MSBEndian,p,&quantum);
347 pixel->alpha=(MagickRealType) (quantum >> (image->depth-
348 MAGICKCORE_QUANTUM_DEPTH));
357 p=PushLongPixel(MSBEndian,p,&quantum);
358 pixel->red=(MagickRealType) (quantum >> (image->depth-
359 MAGICKCORE_QUANTUM_DEPTH));
360 pixel->green=pixel->red;
361 pixel->blue=pixel->red;
362 if (IsGrayColorspace(image->colorspace) == MagickFalse)
364 p=PushLongPixel(MSBEndian,p,&quantum);
365 pixel->green=(MagickRealType) (quantum >> (image->depth-
366 MAGICKCORE_QUANTUM_DEPTH));
367 p=PushLongPixel(MSBEndian,p,&quantum);
368 pixel->blue=(MagickRealType) (quantum >> (image->depth-
369 MAGICKCORE_QUANTUM_DEPTH));
371 if (image->colorspace == CMYKColorspace)
373 p=PushLongPixel(MSBEndian,p,&quantum);
374 pixel->black=(MagickRealType) (quantum >> (image->depth-
375 MAGICKCORE_QUANTUM_DEPTH));
377 if (image->alpha_trait != UndefinedPixelTrait)
379 p=PushLongPixel(MSBEndian,p,&quantum);
380 pixel->alpha=(MagickRealType) (quantum >> (image->depth-
381 MAGICKCORE_QUANTUM_DEPTH));
386 (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageError,
387 "ImageDepthNotSupported","`%s'",image->filename);
389 *length=(size_t) (*p++)+1;
392 #if defined(MAGICKCORE_BZLIB_DELEGATE)
393 static void RelinquishBZIPMemory(void *context,void *memory)
396 memory=RelinquishMagickMemory(memory);
400 #if defined(MAGICKCORE_LZMA_DELEGATE)
401 static void RelinquishLZMAMemory(void *context,void *memory)
404 memory=RelinquishMagickMemory(memory);
408 #if defined(MAGICKCORE_ZLIB_DELEGATE)
409 static void RelinquishZIPMemory(voidpf context,voidpf memory)
412 memory=RelinquishMagickMemory(memory);
416 static Image *ReadMIFFImage(const ImageInfo *image_info,
417 ExceptionInfo *exception)
419 #define BZipMaxExtent(x) ((x)+((x)/100)+600)
420 #define LZMAMaxExtent(x) ((x)+((x)/3)+128)
421 #define ThrowMIFFException(exception,message) \
423 if (quantum_info != (QuantumInfo *) NULL) \
424 quantum_info=DestroyQuantumInfo(quantum_info); \
425 if (compress_pixels != (unsigned char *) NULL) \
426 compress_pixels=(unsigned char *) RelinquishMagickMemory(compress_pixels); \
427 ThrowReaderException((exception),(message)); \
429 #define ZipMaxExtent(x) ((x)+(((x)+7) >> 3)+(((x)+63) >> 6)+11)
431 #if defined(MAGICKCORE_BZLIB_DELEGATE)
437 id[MagickPathExtent],
438 keyword[MagickPathExtent],
456 #if defined(MAGICKCORE_LZMA_DELEGATE)
458 initialize_lzma = LZMA_STREAM_INIT,
505 #if defined(MAGICKCORE_ZLIB_DELEGATE)
513 assert(image_info != (const ImageInfo *) NULL);
514 assert(image_info->signature == MagickCoreSignature);
515 if (image_info->debug != MagickFalse)
516 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
517 image_info->filename);
518 assert(exception != (ExceptionInfo *) NULL);
519 assert(exception->signature == MagickCoreSignature);
520 image=AcquireImage(image_info,exception);
521 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
522 if (status == MagickFalse)
524 image=DestroyImageList(image);
525 return((Image *) NULL);
528 Decode image header; header terminates one character beyond a ':'.
530 c=ReadBlobByte(image);
532 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
534 compress_pixels=(unsigned char *) NULL;
535 quantum_info=(QuantumInfo *) NULL;
536 (void) memset(keyword,0,sizeof(keyword));
542 Decode image header; header terminates one character beyond a ':'.
544 SetGeometryInfo(&geometry_info);
545 length=MagickPathExtent;
546 options=AcquireString((char *) NULL);
547 quantum_format=UndefinedQuantumFormat;
548 profiles=(LinkedListInfo *) NULL;
551 image->compression=NoCompression;
552 while ((isgraph(c) != MagickFalse) && (c != (int) ':'))
563 Read comment-- any text between { }.
565 length=MagickPathExtent;
566 comment=AcquireString((char *) NULL);
567 for (p=comment; comment != (char *) NULL; p++)
569 c=ReadBlobByte(image);
571 c=ReadBlobByte(image);
573 if ((c == EOF) || (c == (int) '}'))
575 if ((size_t) (p-comment+1) >= length)
579 comment=(char *) ResizeQuantumMemory(comment,length+
580 MagickPathExtent,sizeof(*comment));
581 if (comment == (char *) NULL)
583 p=comment+strlen(comment);
587 if (comment == (char *) NULL)
589 options=DestroyString(options);
590 ThrowMIFFException(ResourceLimitError,"MemoryAllocationFailed");
593 (void) SetImageProperty(image,"comment",comment,exception);
594 comment=DestroyString(comment);
595 c=ReadBlobByte(image);
598 if (isalnum(c) != MagickFalse)
603 length=MagickPathExtent-1;
609 if ((size_t) (p-keyword) < (MagickPathExtent-1))
611 c=ReadBlobByte(image);
615 while ((isspace((int) ((unsigned char) c)) != 0) && (c != EOF))
616 c=ReadBlobByte(image);
620 Get the keyword value.
622 c=ReadBlobByte(image);
623 while ((c != (int) '}') && (c != EOF))
625 if ((size_t) (p-options+1) >= length)
629 options=(char *) ResizeQuantumMemory(options,length+
630 MagickPathExtent,sizeof(*options));
631 if (options == (char *) NULL)
633 p=options+strlen(options);
636 c=ReadBlobByte(image);
639 c=ReadBlobByte(image);
643 c=ReadBlobByte(image);
647 if (isspace((int) ((unsigned char) c)) != 0)
650 if (options == (char *) NULL)
651 ThrowMIFFException(ResourceLimitError,
652 "MemoryAllocationFailed");
656 (void) CopyMagickString(options,options+1,strlen(options));
658 Assign a value to the specified keyword.
665 if (LocaleCompare(keyword,"alpha-trait") == 0)
670 alpha_trait=ParseCommandOption(MagickPixelTraitOptions,
671 MagickFalse,options);
674 image->alpha_trait=(PixelTrait) alpha_trait;
677 (void) SetImageProperty(image,keyword,options,exception);
683 if (LocaleCompare(keyword,"background-color") == 0)
685 (void) QueryColorCompliance(options,AllCompliance,
686 &image->background_color,exception);
689 if (LocaleCompare(keyword,"blue-primary") == 0)
691 flags=ParseGeometry(options,&geometry_info);
692 image->chromaticity.blue_primary.x=geometry_info.rho;
693 image->chromaticity.blue_primary.y=geometry_info.sigma;
694 if ((flags & SigmaValue) == 0)
695 image->chromaticity.blue_primary.y=
696 image->chromaticity.blue_primary.x;
699 if (LocaleCompare(keyword,"border-color") == 0)
701 (void) QueryColorCompliance(options,AllCompliance,
702 &image->border_color,exception);
705 (void) SetImageProperty(image,keyword,options,exception);
711 if (LocaleCompare(keyword,"class") == 0)
716 storage_class=ParseCommandOption(MagickClassOptions,
717 MagickFalse,options);
718 if (storage_class < 0)
720 image->storage_class=(ClassType) storage_class;
723 if (LocaleCompare(keyword,"colors") == 0)
725 colors=StringToUnsignedLong(options);
728 if (LocaleCompare(keyword,"colorspace") == 0)
733 colorspace=ParseCommandOption(MagickColorspaceOptions,
734 MagickFalse,options);
737 image->colorspace=(ColorspaceType) colorspace;
740 if (LocaleCompare(keyword,"compression") == 0)
745 compression=ParseCommandOption(MagickCompressOptions,
746 MagickFalse,options);
749 image->compression=(CompressionType) compression;
752 if (LocaleCompare(keyword,"columns") == 0)
754 image->columns=StringToUnsignedLong(options);
757 (void) SetImageProperty(image,keyword,options,exception);
763 if (LocaleCompare(keyword,"delay") == 0)
765 image->delay=StringToUnsignedLong(options);
768 if (LocaleCompare(keyword,"depth") == 0)
770 image->depth=StringToUnsignedLong(options);
773 if (LocaleCompare(keyword,"dispose") == 0)
778 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,
782 image->dispose=(DisposeType) dispose;
785 (void) SetImageProperty(image,keyword,options,exception);
791 if (LocaleCompare(keyword,"endian") == 0)
796 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,
800 image->endian=(EndianType) endian;
803 (void) SetImageProperty(image,keyword,options,exception);
809 if (LocaleCompare(keyword,"gamma") == 0)
811 image->gamma=StringToDouble(options,(char **) NULL);
814 if (LocaleCompare(keyword,"gravity") == 0)
819 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,
823 image->gravity=(GravityType) gravity;
826 if (LocaleCompare(keyword,"green-primary") == 0)
828 flags=ParseGeometry(options,&geometry_info);
829 image->chromaticity.green_primary.x=geometry_info.rho;
830 image->chromaticity.green_primary.y=geometry_info.sigma;
831 if ((flags & SigmaValue) == 0)
832 image->chromaticity.green_primary.y=
833 image->chromaticity.green_primary.x;
836 (void) SetImageProperty(image,keyword,options,exception);
842 if (LocaleCompare(keyword,"id") == 0)
844 (void) CopyMagickString(id,options,MagickPathExtent);
847 if (LocaleCompare(keyword,"iterations") == 0)
849 image->iterations=StringToUnsignedLong(options);
852 (void) SetImageProperty(image,keyword,options,exception);
858 if (LocaleCompare(keyword,"matte") == 0)
863 matte=ParseCommandOption(MagickBooleanOptions,MagickFalse,
867 image->alpha_trait=matte == 0 ? UndefinedPixelTrait :
871 if (LocaleCompare(keyword,"mattecolor") == 0)
873 (void) QueryColorCompliance(options,AllCompliance,
874 &image->matte_color,exception);
877 if (LocaleCompare(keyword,"montage") == 0)
879 (void) CloneString(&image->montage,options);
882 (void) SetImageProperty(image,keyword,options,exception);
888 if (LocaleCompare(keyword,"orientation") == 0)
893 orientation=ParseCommandOption(MagickOrientationOptions,
894 MagickFalse,options);
897 image->orientation=(OrientationType) orientation;
900 (void) SetImageProperty(image,keyword,options,exception);
906 if (LocaleCompare(keyword,"page") == 0)
911 geometry=GetPageGeometry(options);
912 (void) ParseAbsoluteGeometry(geometry,&image->page);
913 geometry=DestroyString(geometry);
916 if (LocaleCompare(keyword,"pixel-intensity") == 0)
921 intensity=ParseCommandOption(MagickPixelIntensityOptions,
922 MagickFalse,options);
925 image->intensity=(PixelIntensityMethod) intensity;
928 if (LocaleCompare(keyword,"profile") == 0)
930 if (profiles == (LinkedListInfo *) NULL)
931 profiles=NewLinkedList(0);
932 (void) AppendValueToLinkedList(profiles,
933 AcquireString(options));
936 (void) SetImageProperty(image,keyword,options,exception);
942 if (LocaleCompare(keyword,"quality") == 0)
944 image->quality=StringToUnsignedLong(options);
947 if ((LocaleCompare(keyword,"quantum-format") == 0) ||
948 (LocaleCompare(keyword,"quantum:format") == 0))
953 format=ParseCommandOption(MagickQuantumFormatOptions,
954 MagickFalse,options);
957 quantum_format=(QuantumFormatType) format;
960 (void) SetImageProperty(image,keyword,options,exception);
966 if (LocaleCompare(keyword,"red-primary") == 0)
968 flags=ParseGeometry(options,&geometry_info);
969 image->chromaticity.red_primary.x=geometry_info.rho;
970 image->chromaticity.red_primary.y=geometry_info.sigma;
971 if ((flags & SigmaValue) == 0)
972 image->chromaticity.red_primary.y=
973 image->chromaticity.red_primary.x;
976 if (LocaleCompare(keyword,"rendering-intent") == 0)
981 rendering_intent=ParseCommandOption(MagickIntentOptions,
982 MagickFalse,options);
983 if (rendering_intent < 0)
985 image->rendering_intent=(RenderingIntent) rendering_intent;
988 if (LocaleCompare(keyword,"resolution") == 0)
990 flags=ParseGeometry(options,&geometry_info);
991 image->resolution.x=geometry_info.rho;
992 image->resolution.y=geometry_info.sigma;
993 if ((flags & SigmaValue) == 0)
994 image->resolution.y=image->resolution.x;
997 if (LocaleCompare(keyword,"rows") == 0)
999 image->rows=StringToUnsignedLong(options);
1002 (void) SetImageProperty(image,keyword,options,exception);
1008 if (LocaleCompare(keyword,"scene") == 0)
1010 image->scene=StringToUnsignedLong(options);
1013 (void) SetImageProperty(image,keyword,options,exception);
1019 if (LocaleCompare(keyword,"ticks-per-second") == 0)
1021 image->ticks_per_second=(ssize_t) StringToLong(options);
1024 if (LocaleCompare(keyword,"tile-offset") == 0)
1029 geometry=GetPageGeometry(options);
1030 (void) ParseAbsoluteGeometry(geometry,&image->tile_offset);
1031 geometry=DestroyString(geometry);
1034 if (LocaleCompare(keyword,"type") == 0)
1039 type=ParseCommandOption(MagickTypeOptions,MagickFalse,
1043 image->type=(ImageType) type;
1046 (void) SetImageProperty(image,keyword,options,exception);
1052 if (LocaleCompare(keyword,"units") == 0)
1057 units=ParseCommandOption(MagickResolutionOptions,
1058 MagickFalse,options);
1061 image->units=(ResolutionType) units;
1064 (void) SetImageProperty(image,keyword,options,exception);
1070 if (LocaleCompare(keyword,"version") == 0)
1072 version=StringToDouble(options,(char **) NULL);
1075 (void) SetImageProperty(image,keyword,options,exception);
1081 if (LocaleCompare(keyword,"white-point") == 0)
1083 flags=ParseGeometry(options,&geometry_info);
1084 image->chromaticity.white_point.x=geometry_info.rho;
1085 image->chromaticity.white_point.y=geometry_info.sigma;
1086 if ((flags & SigmaValue) == 0)
1087 image->chromaticity.white_point.y=
1088 image->chromaticity.white_point.x;
1091 (void) SetImageProperty(image,keyword,options,exception);
1096 (void) SetImageProperty(image,keyword,options,exception);
1102 c=ReadBlobByte(image);
1103 while (isspace((int) ((unsigned char) c)) != 0)
1104 c=ReadBlobByte(image);
1106 options=DestroyString(options);
1107 (void) ReadBlobByte(image);
1109 Verify that required image information is defined.
1111 if ((LocaleCompare(id,"ImageMagick") != 0) || (image->depth > 64) ||
1112 (image->storage_class == UndefinedClass) ||
1113 (image->compression == UndefinedCompression) ||
1114 (image->colorspace == UndefinedColorspace) ||
1115 (image->columns == 0) || (image->rows == 0))
1117 if (profiles != (LinkedListInfo *) NULL)
1118 profiles=DestroyLinkedList(profiles,RelinquishMagickMemory);
1119 if (image->previous == (Image *) NULL)
1120 ThrowMIFFException(CorruptImageError,"ImproperImageHeader");
1121 DeleteImageFromList(&image);
1122 (void) ThrowMagickException(exception,GetMagickModule(),
1123 CorruptImageError,"ImproperImageHeader","`%s'",image->filename);
1126 if (image->montage != (char *) NULL)
1134 length=MagickPathExtent;
1135 image->directory=AcquireString((char *) NULL);
1140 if ((strlen(image->directory)+MagickPathExtent) >= length)
1143 Allocate more memory for the image directory.
1146 image->directory=(char *) ResizeQuantumMemory(image->directory,
1147 length+MagickPathExtent,sizeof(*image->directory));
1148 if (image->directory == (char *) NULL)
1149 ThrowMIFFException(CorruptImageError,"UnableToReadImageData");
1150 p=image->directory+strlen(image->directory);
1152 c=ReadBlobByte(image);
1156 } while (c != (int) '\0');
1158 if (profiles != (LinkedListInfo *) NULL)
1167 Read image profiles.
1169 ResetLinkedListIterator(profiles);
1170 name=(const char *) GetNextValueInLinkedList(profiles);
1171 while (name != (const char *) NULL)
1173 length=ReadBlobMSBLong(image);
1174 if ((MagickSizeType) length > GetBlobSize(image))
1176 profile=AcquireStringInfo(length);
1177 if (profile == (StringInfo *) NULL)
1179 count=ReadBlob(image,length,GetStringInfoDatum(profile));
1180 if (count != (ssize_t) length)
1182 profile=DestroyStringInfo(profile);
1185 status=SetImageProfile(image,name,profile,exception);
1186 profile=DestroyStringInfo(profile);
1187 if (status == MagickFalse)
1189 name=(const char *) GetNextValueInLinkedList(profiles);
1191 profiles=DestroyLinkedList(profiles,RelinquishMagickMemory);
1193 image->depth=GetImageQuantumDepth(image,MagickFalse);
1194 if (image->storage_class == PseudoClass)
1200 Create image colormap.
1202 packet_size=(size_t) (3UL*image->depth/8UL);
1203 if ((MagickSizeType) colors > GetBlobSize(image))
1204 ThrowMIFFException(CorruptImageError,"InsufficientImageDataInFile");
1205 if (((MagickSizeType) packet_size*colors) > GetBlobSize(image))
1206 ThrowMIFFException(CorruptImageError,"InsufficientImageDataInFile");
1207 status=AcquireImageColormap(image,colors != 0 ? colors : 256,exception);
1208 if (status == MagickFalse)
1209 ThrowMIFFException(ResourceLimitError,"MemoryAllocationFailed");
1216 Read image colormap from file.
1218 colormap=(unsigned char *) AcquireQuantumMemory(image->colors,
1219 packet_size*sizeof(*colormap));
1220 if (colormap == (unsigned char *) NULL)
1221 ThrowMIFFException(ResourceLimitError,"MemoryAllocationFailed");
1222 count=ReadBlob(image,packet_size*image->colors,colormap);
1224 switch (image->depth)
1228 colormap=(unsigned char *) RelinquishMagickMemory(colormap);
1229 ThrowMIFFException(CorruptImageError,"ImageDepthNotSupported");
1237 for (i=0; i < (ssize_t) image->colors; i++)
1239 p=PushCharPixel(p,&char_pixel);
1240 image->colormap[i].red=(MagickRealType)
1241 ScaleCharToQuantum(char_pixel);
1242 p=PushCharPixel(p,&char_pixel);
1243 image->colormap[i].green=(MagickRealType)
1244 ScaleCharToQuantum(char_pixel);
1245 p=PushCharPixel(p,&char_pixel);
1246 image->colormap[i].blue=(MagickRealType)
1247 ScaleCharToQuantum(char_pixel);
1256 for (i=0; i < (ssize_t) image->colors; i++)
1258 p=PushShortPixel(MSBEndian,p,&short_pixel);
1259 image->colormap[i].red=(MagickRealType)
1260 ScaleShortToQuantum(short_pixel);
1261 p=PushShortPixel(MSBEndian,p,&short_pixel);
1262 image->colormap[i].green=(MagickRealType)
1263 ScaleShortToQuantum(short_pixel);
1264 p=PushShortPixel(MSBEndian,p,&short_pixel);
1265 image->colormap[i].blue=(MagickRealType)
1266 ScaleShortToQuantum(short_pixel);
1275 for (i=0; i < (ssize_t) image->colors; i++)
1277 p=PushLongPixel(MSBEndian,p,&long_pixel);
1278 image->colormap[i].red=(MagickRealType)
1279 ScaleLongToQuantum(long_pixel);
1280 p=PushLongPixel(MSBEndian,p,&long_pixel);
1281 image->colormap[i].green=(MagickRealType)
1282 ScaleLongToQuantum(long_pixel);
1283 p=PushLongPixel(MSBEndian,p,&long_pixel);
1284 image->colormap[i].blue=(MagickRealType)
1285 ScaleLongToQuantum(long_pixel);
1290 colormap=(unsigned char *) RelinquishMagickMemory(colormap);
1293 if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0))
1294 if (image->scene >= (image_info->scene+image_info->number_scenes-1))
1296 status=SetImageExtent(image,image->columns,image->rows,exception);
1297 if (status == MagickFalse)
1298 return(DestroyImageList(image));
1299 status=ResetImagePixels(image,exception);
1300 if (status == MagickFalse)
1301 return(DestroyImageList(image));
1303 Allocate image pixels.
1305 quantum_info=AcquireQuantumInfo(image_info,image);
1306 if (quantum_info == (QuantumInfo *) NULL)
1307 ThrowMIFFException(ResourceLimitError,"MemoryAllocationFailed");
1308 if (quantum_format != UndefinedQuantumFormat)
1310 status=SetQuantumFormat(image,quantum_info,quantum_format);
1311 if (status == MagickFalse)
1312 ThrowMIFFException(ResourceLimitError,"MemoryAllocationFailed");
1314 packet_size=(size_t) (quantum_info->depth/8);
1315 if (image->storage_class == DirectClass)
1316 packet_size=(size_t) (3*quantum_info->depth/8);
1317 if (IsGrayColorspace(image->colorspace) != MagickFalse)
1318 packet_size=quantum_info->depth/8;
1319 if (image->alpha_trait != UndefinedPixelTrait)
1320 packet_size+=quantum_info->depth/8;
1321 if (image->colorspace == CMYKColorspace)
1322 packet_size+=quantum_info->depth/8;
1323 if (image->compression == RLECompression)
1325 compress_extent=MagickMax(MagickMax(BZipMaxExtent(packet_size*
1326 image->columns),LZMAMaxExtent(packet_size*image->columns)),
1327 ZipMaxExtent(packet_size*image->columns));
1328 compress_pixels=(unsigned char *) AcquireQuantumMemory(compress_extent,
1329 sizeof(*compress_pixels));
1330 if (compress_pixels == (unsigned char *) NULL)
1331 ThrowMIFFException(ResourceLimitError,"MemoryAllocationFailed");
1335 quantum_type=RGBQuantum;
1336 if (image->alpha_trait != UndefinedPixelTrait)
1337 quantum_type=RGBAQuantum;
1338 if (image->colorspace == CMYKColorspace)
1340 quantum_type=CMYKQuantum;
1341 if (image->alpha_trait != UndefinedPixelTrait)
1342 quantum_type=CMYKAQuantum;
1344 if (IsGrayColorspace(image->colorspace) != MagickFalse)
1346 quantum_type=GrayQuantum;
1347 if (image->alpha_trait != UndefinedPixelTrait)
1348 quantum_type=GrayAlphaQuantum;
1350 if (image->storage_class == PseudoClass)
1352 quantum_type=IndexQuantum;
1353 if (image->alpha_trait != UndefinedPixelTrait)
1354 quantum_type=IndexAlphaQuantum;
1357 GetPixelInfo(image,&pixel);
1358 #if defined(MAGICKCORE_BZLIB_DELEGATE)
1359 (void) memset(&bzip_info,0,sizeof(bzip_info));
1361 #if defined(MAGICKCORE_LZMA_DELEGATE)
1362 (void) memset(&allocator,0,sizeof(allocator));
1364 #if defined(MAGICKCORE_ZLIB_DELEGATE)
1365 (void) memset(&zip_info,0,sizeof(zip_info));
1367 switch (image->compression)
1369 #if defined(MAGICKCORE_BZLIB_DELEGATE)
1370 case BZipCompression:
1375 bzip_info.bzalloc=AcquireBZIPMemory;
1376 bzip_info.bzfree=RelinquishBZIPMemory;
1377 bzip_info.opaque=(void *) image;
1378 code=BZ2_bzDecompressInit(&bzip_info,(int) image_info->verbose,
1385 #if defined(MAGICKCORE_LZMA_DELEGATE)
1386 case LZMACompression:
1391 allocator.alloc=AcquireLZMAMemory;
1392 allocator.free=RelinquishLZMAMemory;
1393 allocator.opaque=(void *) image;
1394 lzma_info=initialize_lzma;
1395 lzma_info.allocator=(&allocator);
1396 code=lzma_auto_decoder(&lzma_info,(uint64_t) -1,0);
1397 if (code != LZMA_OK)
1402 #if defined(MAGICKCORE_ZLIB_DELEGATE)
1403 case LZWCompression:
1404 case ZipCompression:
1409 zip_info.zalloc=AcquireZIPMemory;
1410 zip_info.zfree=RelinquishZIPMemory;
1411 zip_info.opaque=(voidpf) image;
1412 code=inflateInit(&zip_info);
1418 case RLECompression:
1423 pixels=(unsigned char *) GetQuantumPixels(quantum_info);
1425 for (y=0; y < (ssize_t) image->rows; y++)
1433 if (status == MagickFalse)
1435 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
1436 if (q == (Quantum *) NULL)
1439 switch (image->compression)
1441 #if defined(MAGICKCORE_BZLIB_DELEGATE)
1442 case BZipCompression:
1444 bzip_info.next_out=(char *) pixels;
1445 bzip_info.avail_out=(unsigned int) (packet_size*image->columns);
1451 if (bzip_info.avail_in == 0)
1453 bzip_info.next_in=(char *) compress_pixels;
1454 length=(size_t) BZipMaxExtent(packet_size*image->columns);
1456 length=(size_t) ReadBlobMSBLong(image);
1457 if (length <= compress_extent)
1458 bzip_info.avail_in=(unsigned int) ReadBlob(image,length,
1459 (unsigned char *) bzip_info.next_in);
1460 if ((length > compress_extent) ||
1461 ((size_t) bzip_info.avail_in != length))
1463 (void) BZ2_bzDecompressEnd(&bzip_info);
1464 ThrowMIFFException(CorruptImageError,
1465 "UnableToReadImageData");
1468 code=BZ2_bzDecompress(&bzip_info);
1469 if ((code != BZ_OK) && (code != BZ_STREAM_END))
1474 if (code == BZ_STREAM_END)
1476 } while (bzip_info.avail_out != 0);
1477 extent=ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1478 quantum_type,pixels,exception);
1482 #if defined(MAGICKCORE_LZMA_DELEGATE)
1483 case LZMACompression:
1485 lzma_info.next_out=pixels;
1486 lzma_info.avail_out=packet_size*image->columns;
1492 if (lzma_info.avail_in == 0)
1494 lzma_info.next_in=compress_pixels;
1495 length=(size_t) ReadBlobMSBLong(image);
1496 if (length <= compress_extent)
1497 lzma_info.avail_in=(unsigned int) ReadBlob(image,length,
1498 (unsigned char *) lzma_info.next_in);
1499 if ((length > compress_extent) ||
1500 (lzma_info.avail_in != length))
1502 lzma_end(&lzma_info);
1503 ThrowMIFFException(CorruptImageError,
1504 "UnableToReadImageData");
1507 code=lzma_code(&lzma_info,LZMA_RUN);
1508 if ((code != LZMA_OK) && (code != LZMA_STREAM_END))
1513 if (code == LZMA_STREAM_END)
1515 } while (lzma_info.avail_out != 0);
1516 extent=ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1517 quantum_type,pixels,exception);
1521 #if defined(MAGICKCORE_ZLIB_DELEGATE)
1522 case LZWCompression:
1523 case ZipCompression:
1525 zip_info.next_out=pixels;
1526 zip_info.avail_out=(uInt) (packet_size*image->columns);
1532 if (zip_info.avail_in == 0)
1534 zip_info.next_in=compress_pixels;
1535 length=(size_t) ZipMaxExtent(packet_size*image->columns);
1537 length=(size_t) ReadBlobMSBLong(image);
1538 if (length <= compress_extent)
1539 zip_info.avail_in=(unsigned int) ReadBlob(image,length,
1541 if ((length > compress_extent) ||
1542 ((size_t) zip_info.avail_in != length))
1544 (void) inflateEnd(&zip_info);
1545 ThrowMIFFException(CorruptImageError,
1546 "UnableToReadImageData");
1549 code=inflate(&zip_info,Z_SYNC_FLUSH);
1550 if ((code != Z_OK) && (code != Z_STREAM_END))
1555 if (code == Z_STREAM_END)
1557 } while (zip_info.avail_out != 0);
1558 extent=ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1559 quantum_type,pixels,exception);
1563 case RLECompression:
1565 for (x=0; x < (ssize_t) image->columns; x++)
1569 count=ReadBlob(image,packet_size,pixels);
1570 if (count != (ssize_t) packet_size)
1571 ThrowMIFFException(CorruptImageError,"UnableToReadImageData");
1572 PushRunlengthPacket(image,pixels,&length,&pixel,exception);
1575 if (image->storage_class == PseudoClass)
1576 SetPixelIndex(image,ClampToQuantum(pixel.index),q);
1579 SetPixelRed(image,ClampToQuantum(pixel.red),q);
1580 SetPixelGreen(image,ClampToQuantum(pixel.green),q);
1581 SetPixelBlue(image,ClampToQuantum(pixel.blue),q);
1582 if (image->colorspace == CMYKColorspace)
1583 SetPixelBlack(image,ClampToQuantum(pixel.black),q);
1585 if (image->alpha_trait != UndefinedPixelTrait)
1586 SetPixelAlpha(image,ClampToQuantum(pixel.alpha),q);
1587 q+=GetPixelChannels(image);
1594 count=ReadBlob(image,packet_size*image->columns,pixels);
1595 if (count != (ssize_t) (packet_size*image->columns))
1596 ThrowMIFFException(CorruptImageError,"UnableToReadImageData");
1597 extent=ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1598 quantum_type,pixels,exception);
1602 if (extent < image->columns)
1604 if (SyncAuthenticPixels(image,exception) == MagickFalse)
1607 SetQuantumImageType(image,quantum_type);
1608 switch (image->compression)
1610 #if defined(MAGICKCORE_BZLIB_DELEGATE)
1611 case BZipCompression:
1621 offset=SeekBlob(image,-((MagickOffsetType) bzip_info.avail_in),
1625 (void) BZ2_bzDecompressEnd(&bzip_info);
1626 ThrowMIFFException(CorruptImageError,"ImproperImageHeader");
1629 code=BZ2_bzDecompressEnd(&bzip_info);
1635 #if defined(MAGICKCORE_LZMA_DELEGATE)
1636 case LZMACompression:
1641 code=lzma_code(&lzma_info,LZMA_FINISH);
1642 if ((code != LZMA_STREAM_END) && (code != LZMA_OK))
1644 lzma_end(&lzma_info);
1648 #if defined(MAGICKCORE_ZLIB_DELEGATE)
1649 case LZWCompression:
1650 case ZipCompression:
1660 offset=SeekBlob(image,-((MagickOffsetType) zip_info.avail_in),
1664 (void) inflateEnd(&zip_info);
1665 ThrowMIFFException(CorruptImageError,"ImproperImageHeader");
1668 code=inflateEnd(&zip_info);
1677 quantum_info=DestroyQuantumInfo(quantum_info);
1678 compress_pixels=(unsigned char *) RelinquishMagickMemory(compress_pixels);
1679 if (((y != (ssize_t) image->rows)) || (status == MagickFalse))
1681 image=DestroyImageList(image);
1682 return((Image *) NULL);
1684 if (EOFBlob(image) != MagickFalse)
1686 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
1691 Proceed to next image.
1693 if (image_info->number_scenes != 0)
1694 if (image->scene >= (image_info->scene+image_info->number_scenes-1))
1698 c=ReadBlobByte(image);
1699 } while ((isgraph(c) == MagickFalse) && (c != EOF));
1703 Allocate next image structure.
1705 AcquireNextImage(image_info,image,exception);
1706 if (GetNextImageInList(image) == (Image *) NULL)
1711 image=SyncNextImageInList(image);
1712 status=SetImageProgress(image,LoadImagesTag,TellBlob(image),
1713 GetBlobSize(image));
1714 if (status == MagickFalse)
1718 (void) CloseBlob(image);
1719 if (status == MagickFalse)
1720 return(DestroyImageList(image));
1721 return(GetFirstImageInList(image));
1725 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1729 % R e g i s t e r M I F F I m a g e %
1733 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1735 % RegisterMIFFImage() adds properties for the MIFF image format to the list of
1736 % supported formats. The properties include the image format tag, a method to
1737 % read and/or write the format, whether the format supports the saving of more
1738 % than one frame to the same file or blob, whether the format supports native
1739 % in-memory I/O, and a brief description of the format.
1741 % The format of the RegisterMIFFImage method is:
1743 % size_t RegisterMIFFImage(void)
1746 ModuleExport size_t RegisterMIFFImage(void)
1749 version[MagickPathExtent];
1755 #if defined(MagickImageCoderSignatureText)
1756 (void) CopyMagickString(version,MagickLibVersionText,MagickPathExtent);
1757 #if defined(ZLIB_VERSION)
1758 (void) ConcatenateMagickString(version," with Zlib ",MagickPathExtent);
1759 (void) ConcatenateMagickString(version,ZLIB_VERSION,MagickPathExtent);
1761 #if defined(MAGICKCORE_BZLIB_DELEGATE)
1762 (void) ConcatenateMagickString(version," and BZlib",MagickPathExtent);
1765 entry=AcquireMagickInfo("MIFF","MIFF","Magick Image File Format");
1766 entry->decoder=(DecodeImageHandler *) ReadMIFFImage;
1767 entry->encoder=(EncodeImageHandler *) WriteMIFFImage;
1768 entry->magick=(IsImageFormatHandler *) IsMIFF;
1769 entry->flags|=CoderDecoderSeekableStreamFlag;
1770 if (*version != '\0')
1771 entry->version=ConstantString(version);
1772 (void) RegisterMagickInfo(entry);
1773 return(MagickImageCoderSignature);
1777 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1781 % U n r e g i s t e r M I F F I m a g e %
1785 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1787 % UnregisterMIFFImage() removes format registrations made by the MIFF module
1788 % from the list of supported formats.
1790 % The format of the UnregisterMIFFImage method is:
1792 % UnregisterMIFFImage(void)
1795 ModuleExport void UnregisterMIFFImage(void)
1797 (void) UnregisterMagickInfo("MIFF");
1801 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1805 % W r i t e M I F F I m a g e %
1809 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1811 % WriteMIFFImage() writes a MIFF image to a file.
1813 % The format of the WriteMIFFImage method is:
1815 % MagickBooleanType WriteMIFFImage(const ImageInfo *image_info,
1816 % Image *image,ExceptionInfo *exception)
1818 % Compression code contributed by Kyle Shorter.
1820 % A description of each parameter follows:
1822 % o image_info: the image info.
1824 % o image: the image.
1826 % o exception: return any errors or warnings in this structure.
1830 static unsigned char *PopRunlengthPacket(Image *image,unsigned char *pixels,
1831 size_t length,PixelInfo *pixel,ExceptionInfo *exception)
1833 if (image->storage_class != DirectClass)
1838 value=(unsigned int) ClampToQuantum(pixel->index);
1839 switch (image->depth)
1843 *pixels++=(unsigned char) (value >> 24);
1844 *pixels++=(unsigned char) (value >> 16);
1847 *pixels++=(unsigned char) (value >> 8);
1850 *pixels++=(unsigned char) value;
1854 (void) ThrowMagickException(exception,GetMagickModule(),
1855 CorruptImageError,"ImageDepthNotSupported","`%s'",image->filename);
1857 switch (image->depth)
1864 if (image->alpha_trait != UndefinedPixelTrait)
1866 long_value=ScaleQuantumToLong(ClampToQuantum(pixel->alpha));
1867 pixels=PopLongPixel(MSBEndian,long_value,pixels);
1876 if (image->alpha_trait != UndefinedPixelTrait)
1878 short_value=ScaleQuantumToShort(ClampToQuantum(pixel->alpha));
1879 pixels=PopShortPixel(MSBEndian,short_value,pixels);
1888 if (image->alpha_trait != UndefinedPixelTrait)
1890 char_value=(unsigned char) ScaleQuantumToChar(ClampToQuantum(
1892 pixels=PopCharPixel(char_value,pixels);
1897 (void) ThrowMagickException(exception,GetMagickModule(),
1898 CorruptImageError,"ImageDepthNotSupported","`%s'",image->filename);
1900 *pixels++=(unsigned char) length;
1903 switch (image->depth)
1910 value=ScaleQuantumToLong(ClampToQuantum(pixel->red));
1911 pixels=PopLongPixel(MSBEndian,value,pixels);
1912 if (IsGrayColorspace(image->colorspace) == MagickFalse)
1914 value=ScaleQuantumToLong(ClampToQuantum(pixel->green));
1915 pixels=PopLongPixel(MSBEndian,value,pixels);
1916 value=ScaleQuantumToLong(ClampToQuantum(pixel->blue));
1917 pixels=PopLongPixel(MSBEndian,value,pixels);
1919 if (image->colorspace == CMYKColorspace)
1921 value=ScaleQuantumToLong(ClampToQuantum(pixel->black));
1922 pixels=PopLongPixel(MSBEndian,value,pixels);
1924 if (image->alpha_trait != UndefinedPixelTrait)
1926 value=ScaleQuantumToLong(ClampToQuantum(pixel->alpha));
1927 pixels=PopLongPixel(MSBEndian,value,pixels);
1936 value=ScaleQuantumToShort(ClampToQuantum(pixel->red));
1937 pixels=PopShortPixel(MSBEndian,value,pixels);
1938 if (IsGrayColorspace(image->colorspace) == MagickFalse)
1940 value=ScaleQuantumToShort(ClampToQuantum(pixel->green));
1941 pixels=PopShortPixel(MSBEndian,value,pixels);
1942 value=ScaleQuantumToShort(ClampToQuantum(pixel->blue));
1943 pixels=PopShortPixel(MSBEndian,value,pixels);
1945 if (image->colorspace == CMYKColorspace)
1947 value=ScaleQuantumToShort(ClampToQuantum(pixel->black));
1948 pixels=PopShortPixel(MSBEndian,value,pixels);
1950 if (image->alpha_trait != UndefinedPixelTrait)
1952 value=ScaleQuantumToShort(ClampToQuantum(pixel->alpha));
1953 pixels=PopShortPixel(MSBEndian,value,pixels);
1962 value=(unsigned char) ScaleQuantumToChar(ClampToQuantum(pixel->red));
1963 pixels=PopCharPixel(value,pixels);
1964 if (IsGrayColorspace(image->colorspace) == MagickFalse)
1966 value=(unsigned char) ScaleQuantumToChar(ClampToQuantum(
1968 pixels=PopCharPixel(value,pixels);
1969 value=(unsigned char) ScaleQuantumToChar(ClampToQuantum(pixel->blue));
1970 pixels=PopCharPixel(value,pixels);
1972 if (image->colorspace == CMYKColorspace)
1974 value=(unsigned char) ScaleQuantumToChar(ClampToQuantum(
1976 pixels=PopCharPixel(value,pixels);
1978 if (image->alpha_trait != UndefinedPixelTrait)
1980 value=(unsigned char) ScaleQuantumToChar(ClampToQuantum(
1982 pixels=PopCharPixel(value,pixels);
1987 (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageError,
1988 "ImageDepthNotSupported","`%s'",image->filename);
1990 *pixels++=(unsigned char) length;
1994 static MagickBooleanType WriteMIFFImage(const ImageInfo *image_info,
1995 Image *image,ExceptionInfo *exception)
1997 #if defined(MAGICKCORE_BZLIB_DELEGATE)
2003 buffer[MagickPathExtent];
2012 #if defined(MAGICKCORE_LZMA_DELEGATE)
2017 initialize_lzma = LZMA_STREAM_INIT,
2053 #if defined(MAGICKCORE_ZLIB_DELEGATE)
2059 Open output image file.
2061 assert(image_info != (const ImageInfo *) NULL);
2062 assert(image_info->signature == MagickCoreSignature);
2063 assert(image != (Image *) NULL);
2064 assert(image->signature == MagickCoreSignature);
2065 if (image->debug != MagickFalse)
2066 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2067 assert(exception != (ExceptionInfo *) NULL);
2068 assert(exception->signature == MagickCoreSignature);
2069 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
2070 if (status == MagickFalse)
2073 imageListLength=GetImageListLength(image);
2077 Allocate image pixels.
2079 if ((image->storage_class == PseudoClass) &&
2080 (image->colors > (size_t) (GetQuantumRange(image->depth)+1)))
2081 (void) SetImageStorageClass(image,DirectClass,exception);
2082 image->depth=image->depth <= 8 ? 8UL : image->depth <= 16 ? 16UL :
2083 image->depth <= 32 ? 32UL : 64UL;
2084 quantum_info=AcquireQuantumInfo(image_info,image);
2085 if (quantum_info == (QuantumInfo *) NULL)
2086 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
2087 if ((image->storage_class != PseudoClass) && (image->depth >= 16) &&
2088 (quantum_info->format == UndefinedQuantumFormat) &&
2089 (IsHighDynamicRangeImage(image,exception) != MagickFalse))
2091 status=SetQuantumFormat(image,quantum_info,FloatingPointQuantumFormat);
2092 if (status == MagickFalse)
2094 quantum_info=DestroyQuantumInfo(quantum_info);
2095 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
2099 if (image->depth < 16)
2100 (void) DeleteImageProperty(image,"quantum:format");
2101 compression=UndefinedCompression;
2102 if (image_info->compression != UndefinedCompression)
2103 compression=image_info->compression;
2104 switch (compression)
2106 #if !defined(MAGICKCORE_LZMA_DELEGATE)
2107 case LZMACompression: compression=NoCompression; break;
2109 #if !defined(MAGICKCORE_ZLIB_DELEGATE)
2110 case LZWCompression:
2111 case ZipCompression: compression=NoCompression; break;
2113 #if !defined(MAGICKCORE_BZLIB_DELEGATE)
2114 case BZipCompression: compression=NoCompression; break;
2116 case RLECompression:
2118 if (quantum_info->format == FloatingPointQuantumFormat)
2119 compression=NoCompression;
2120 GetPixelInfo(image,&target);
2126 packet_size=(size_t) (quantum_info->depth/8);
2127 if (image->storage_class == DirectClass)
2128 packet_size=(size_t) (3*quantum_info->depth/8);
2129 if (IsGrayColorspace(image->colorspace) != MagickFalse)
2130 packet_size=(size_t) (quantum_info->depth/8);
2131 if (image->alpha_trait != UndefinedPixelTrait)
2132 packet_size+=quantum_info->depth/8;
2133 if (image->colorspace == CMYKColorspace)
2134 packet_size+=quantum_info->depth/8;
2135 if (compression == RLECompression)
2137 length=MagickMax(BZipMaxExtent(packet_size*image->columns),ZipMaxExtent(
2138 packet_size*image->columns));
2139 if ((compression == BZipCompression) || (compression == ZipCompression))
2140 if (length != (size_t) ((unsigned int) length))
2141 compression=NoCompression;
2142 compress_pixels=(unsigned char *) AcquireQuantumMemory(length,
2143 sizeof(*compress_pixels));
2144 if (compress_pixels == (unsigned char *) NULL)
2145 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
2149 (void) WriteBlobString(image,"id=ImageMagick version=1.0\n");
2150 (void) FormatLocaleString(buffer,MagickPathExtent,
2151 "class=%s colors=%.20g alpha-trait=%s\n",CommandOptionToMnemonic(
2152 MagickClassOptions,image->storage_class),(double) image->colors,
2153 CommandOptionToMnemonic(MagickPixelTraitOptions,(ssize_t)
2154 image->alpha_trait));
2155 (void) WriteBlobString(image,buffer);
2156 if (image->alpha_trait != UndefinedPixelTrait)
2157 (void) WriteBlobString(image,"matte=True\n");
2158 (void) FormatLocaleString(buffer,MagickPathExtent,
2159 "columns=%.20g rows=%.20g depth=%.20g\n",(double) image->columns,
2160 (double) image->rows,(double) image->depth);
2161 (void) WriteBlobString(image,buffer);
2162 if (image->type != UndefinedType)
2164 (void) FormatLocaleString(buffer,MagickPathExtent,"type=%s\n",
2165 CommandOptionToMnemonic(MagickTypeOptions,image->type));
2166 (void) WriteBlobString(image,buffer);
2168 if (image->colorspace != UndefinedColorspace)
2170 (void) FormatLocaleString(buffer,MagickPathExtent,"colorspace=%s\n",
2171 CommandOptionToMnemonic(MagickColorspaceOptions,image->colorspace));
2172 (void) WriteBlobString(image,buffer);
2174 if (image->intensity != UndefinedPixelIntensityMethod)
2176 (void) FormatLocaleString(buffer,MagickPathExtent,
2177 "pixel-intensity=%s\n",CommandOptionToMnemonic(
2178 MagickPixelIntensityOptions,image->intensity));
2179 (void) WriteBlobString(image,buffer);
2181 if (image->endian != UndefinedEndian)
2183 (void) FormatLocaleString(buffer,MagickPathExtent,"endian=%s\n",
2184 CommandOptionToMnemonic(MagickEndianOptions,image->endian));
2185 (void) WriteBlobString(image,buffer);
2187 if (compression != UndefinedCompression)
2189 (void) FormatLocaleString(buffer,MagickPathExtent,"compression=%s "
2190 "quality=%.20g\n",CommandOptionToMnemonic(MagickCompressOptions,
2191 compression),(double) image->quality);
2192 (void) WriteBlobString(image,buffer);
2194 if (image->units != UndefinedResolution)
2196 (void) FormatLocaleString(buffer,MagickPathExtent,"units=%s\n",
2197 CommandOptionToMnemonic(MagickResolutionOptions,image->units));
2198 (void) WriteBlobString(image,buffer);
2200 if ((image->resolution.x != 0) || (image->resolution.y != 0))
2202 (void) FormatLocaleString(buffer,MagickPathExtent,
2203 "resolution=%gx%g\n",image->resolution.x,image->resolution.y);
2204 (void) WriteBlobString(image,buffer);
2206 if ((image->page.width != 0) || (image->page.height != 0))
2208 (void) FormatLocaleString(buffer,MagickPathExtent,
2209 "page=%.20gx%.20g%+.20g%+.20g\n",(double) image->page.width,(double)
2210 image->page.height,(double) image->page.x,(double) image->page.y);
2211 (void) WriteBlobString(image,buffer);
2214 if ((image->page.x != 0) || (image->page.y != 0))
2216 (void) FormatLocaleString(buffer,MagickPathExtent,"page=%+ld%+ld\n",
2217 (long) image->page.x,(long) image->page.y);
2218 (void) WriteBlobString(image,buffer);
2220 if ((image->tile_offset.x != 0) || (image->tile_offset.y != 0))
2222 (void) FormatLocaleString(buffer,MagickPathExtent,
2223 "tile-offset=%+ld%+ld\n",(long) image->tile_offset.x,(long)
2224 image->tile_offset.y);
2225 (void) WriteBlobString(image,buffer);
2227 if ((GetNextImageInList(image) != (Image *) NULL) ||
2228 (GetPreviousImageInList(image) != (Image *) NULL))
2230 if (image->scene == 0)
2231 (void) FormatLocaleString(buffer,MagickPathExtent,"iterations=%.20g "
2232 "delay=%.20g ticks-per-second=%.20g\n",(double) image->iterations,
2233 (double) image->delay,(double) image->ticks_per_second);
2235 (void) FormatLocaleString(buffer,MagickPathExtent,"scene=%.20g "
2236 "iterations=%.20g delay=%.20g ticks-per-second=%.20g\n",(double)
2237 image->scene,(double) image->iterations,(double) image->delay,
2238 (double) image->ticks_per_second);
2239 (void) WriteBlobString(image,buffer);
2243 if (image->scene != 0)
2245 (void) FormatLocaleString(buffer,MagickPathExtent,"scene=%.20g\n",
2246 (double) image->scene);
2247 (void) WriteBlobString(image,buffer);
2249 if (image->iterations != 0)
2251 (void) FormatLocaleString(buffer,MagickPathExtent,
2252 "iterations=%.20g\n",(double) image->iterations);
2253 (void) WriteBlobString(image,buffer);
2255 if (image->delay != 0)
2257 (void) FormatLocaleString(buffer,MagickPathExtent,"delay=%.20g\n",
2258 (double) image->delay);
2259 (void) WriteBlobString(image,buffer);
2261 if (image->ticks_per_second != UndefinedTicksPerSecond)
2263 (void) FormatLocaleString(buffer,MagickPathExtent,
2264 "ticks-per-second=%.20g\n",(double) image->ticks_per_second);
2265 (void) WriteBlobString(image,buffer);
2268 if (image->gravity != UndefinedGravity)
2270 (void) FormatLocaleString(buffer,MagickPathExtent,"gravity=%s\n",
2271 CommandOptionToMnemonic(MagickGravityOptions,image->gravity));
2272 (void) WriteBlobString(image,buffer);
2274 if (image->dispose != UndefinedDispose)
2276 (void) FormatLocaleString(buffer,MagickPathExtent,"dispose=%s\n",
2277 CommandOptionToMnemonic(MagickDisposeOptions,image->dispose));
2278 (void) WriteBlobString(image,buffer);
2280 if (image->rendering_intent != UndefinedIntent)
2282 (void) FormatLocaleString(buffer,MagickPathExtent,
2283 "rendering-intent=%s\n",CommandOptionToMnemonic(MagickIntentOptions,
2284 image->rendering_intent));
2285 (void) WriteBlobString(image,buffer);
2287 if (image->gamma != 0.0)
2289 (void) FormatLocaleString(buffer,MagickPathExtent,"gamma=%g\n",
2291 (void) WriteBlobString(image,buffer);
2293 if (image->chromaticity.white_point.x != 0.0)
2296 Note chomaticity points.
2298 (void) FormatLocaleString(buffer,MagickPathExtent,"red-primary=%g,"
2299 "%g green-primary=%g,%g blue-primary=%g,%g\n",
2300 image->chromaticity.red_primary.x,image->chromaticity.red_primary.y,
2301 image->chromaticity.green_primary.x,
2302 image->chromaticity.green_primary.y,
2303 image->chromaticity.blue_primary.x,
2304 image->chromaticity.blue_primary.y);
2305 (void) WriteBlobString(image,buffer);
2306 (void) FormatLocaleString(buffer,MagickPathExtent,
2307 "white-point=%g,%g\n",image->chromaticity.white_point.x,
2308 image->chromaticity.white_point.y);
2309 (void) WriteBlobString(image,buffer);
2311 if (image->orientation != UndefinedOrientation)
2313 (void) FormatLocaleString(buffer,MagickPathExtent,"orientation=%s\n",
2314 CommandOptionToMnemonic(MagickOrientationOptions,image->orientation));
2315 (void) WriteBlobString(image,buffer);
2317 if (image->profiles != (void *) NULL)
2326 Write image profile names.
2328 ResetImageProfileIterator(image);
2329 for (name=GetNextImageProfile(image); name != (const char *) NULL; )
2331 profile=GetImageProfile(image,name);
2332 if (profile != (StringInfo *) NULL)
2334 (void) FormatLocaleString(buffer,MagickPathExtent,"profile=%s\n",
2336 (void) WriteBlobString(image,buffer);
2338 name=GetNextImageProfile(image);
2341 if (image->montage != (char *) NULL)
2343 (void) FormatLocaleString(buffer,MagickPathExtent,"montage=%s\n",
2345 (void) WriteBlobString(image,buffer);
2347 if (quantum_info->format == FloatingPointQuantumFormat)
2348 (void) SetImageProperty(image,"quantum:format","floating-point",
2350 ResetImagePropertyIterator(image);
2351 property=GetNextImageProperty(image);
2352 while (property != (const char *) NULL)
2354 (void) FormatLocaleString(buffer,MagickPathExtent,"%s=",property);
2355 (void) WriteBlobString(image,buffer);
2356 value=GetImageProperty(image,property,exception);
2357 if (value != (const char *) NULL)
2359 length=strlen(value);
2360 for (i=0; i < (ssize_t) length; i++)
2361 if ((isspace((int) ((unsigned char) value[i])) != 0) ||
2364 if ((i == (ssize_t) length) && (i != 0))
2365 (void) WriteBlob(image,length,(const unsigned char *) value);
2368 (void) WriteBlobByte(image,'{');
2369 if (strchr(value,'}') == (char *) NULL)
2370 (void) WriteBlob(image,length,(const unsigned char *) value);
2372 for (i=0; i < (ssize_t) length; i++)
2374 if (value[i] == (int) '}')
2375 (void) WriteBlobByte(image,'\\');
2376 (void) WriteBlobByte(image,(unsigned char) value[i]);
2378 (void) WriteBlobByte(image,'}');
2381 (void) WriteBlobByte(image,'\n');
2382 property=GetNextImageProperty(image);
2384 (void) WriteBlobString(image,"\f\n:\032");
2385 if (image->montage != (char *) NULL)
2388 Write montage tile directory.
2390 if (image->directory != (char *) NULL)
2391 (void) WriteBlob(image,strlen(image->directory),(unsigned char *)
2393 (void) WriteBlobByte(image,'\0');
2395 if (image->profiles != 0)
2404 Write image profile blob.
2406 ResetImageProfileIterator(image);
2407 name=GetNextImageProfile(image);
2408 while (name != (const char *) NULL)
2410 profile=GetImageProfile(image,name);
2411 (void) WriteBlobMSBLong(image,(unsigned int)
2412 GetStringInfoLength(profile));
2413 (void) WriteBlob(image,GetStringInfoLength(profile),
2414 GetStringInfoDatum(profile));
2415 name=GetNextImageProfile(image);
2418 if (image->storage_class == PseudoClass)
2429 colormap_size=(size_t) (3*quantum_info->depth/8);
2430 colormap=(unsigned char *) AcquireQuantumMemory(image->colors,
2431 colormap_size*sizeof(*colormap));
2432 if (colormap == (unsigned char *) NULL)
2433 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
2435 Write colormap to file.
2438 for (i=0; i < (ssize_t) image->colors; i++)
2440 switch (quantum_info->depth)
2443 ThrowWriterException(CorruptImageError,"ImageDepthNotSupported");
2446 register unsigned int
2449 long_pixel=ScaleQuantumToLong((Quantum)
2450 image->colormap[i].red);
2451 q=PopLongPixel(MSBEndian,long_pixel,q);
2452 long_pixel=ScaleQuantumToLong((Quantum)
2453 image->colormap[i].green);
2454 q=PopLongPixel(MSBEndian,long_pixel,q);
2455 long_pixel=ScaleQuantumToLong((Quantum)
2456 image->colormap[i].blue);
2457 q=PopLongPixel(MSBEndian,long_pixel,q);
2462 register unsigned short
2465 short_pixel=ScaleQuantumToShort((Quantum)
2466 image->colormap[i].red);
2467 q=PopShortPixel(MSBEndian,short_pixel,q);
2468 short_pixel=ScaleQuantumToShort((Quantum)
2469 image->colormap[i].green);
2470 q=PopShortPixel(MSBEndian,short_pixel,q);
2471 short_pixel=ScaleQuantumToShort((Quantum)
2472 image->colormap[i].blue);
2473 q=PopShortPixel(MSBEndian,short_pixel,q);
2478 register unsigned char
2481 char_pixel=(unsigned char) ScaleQuantumToChar((Quantum)
2482 image->colormap[i].red);
2483 q=PopCharPixel(char_pixel,q);
2484 char_pixel=(unsigned char) ScaleQuantumToChar((Quantum)
2485 image->colormap[i].green);
2486 q=PopCharPixel(char_pixel,q);
2487 char_pixel=(unsigned char) ScaleQuantumToChar((Quantum)
2488 image->colormap[i].blue);
2489 q=PopCharPixel(char_pixel,q);
2494 (void) WriteBlob(image,colormap_size*image->colors,colormap);
2495 colormap=(unsigned char *) RelinquishMagickMemory(colormap);
2498 Write image pixels to file.
2501 switch (compression)
2503 #if defined(MAGICKCORE_BZLIB_DELEGATE)
2504 case BZipCompression:
2509 (void) memset(&bzip_info,0,sizeof(bzip_info));
2510 bzip_info.bzalloc=AcquireBZIPMemory;
2511 bzip_info.bzfree=RelinquishBZIPMemory;
2512 bzip_info.opaque=(void *) NULL;
2513 code=BZ2_bzCompressInit(&bzip_info,(int) (image->quality ==
2514 UndefinedCompressionQuality ? 7 : MagickMin(image->quality/10,9)),
2515 (int) image_info->verbose,0);
2521 #if defined(MAGICKCORE_LZMA_DELEGATE)
2522 case LZMACompression:
2527 allocator.alloc=AcquireLZMAMemory;
2528 allocator.free=RelinquishLZMAMemory;
2529 allocator.opaque=(void *) NULL;
2530 lzma_info=initialize_lzma;
2531 lzma_info.allocator=&allocator;
2532 code=lzma_easy_encoder(&lzma_info,(uint32_t) (image->quality/10),
2534 if (code != LZMA_OK)
2539 #if defined(MAGICKCORE_ZLIB_DELEGATE)
2540 case LZWCompression:
2541 case ZipCompression:
2546 zip_info.zalloc=AcquireZIPMemory;
2547 zip_info.zfree=RelinquishZIPMemory;
2548 zip_info.opaque=(void *) NULL;
2549 code=deflateInit(&zip_info,(int) (image->quality ==
2550 UndefinedCompressionQuality ? 7 : MagickMin(image->quality/10,9)));
2559 quantum_type=GetQuantumType(image,exception);
2560 pixels=(unsigned char *) GetQuantumPixels(quantum_info);
2561 for (y=0; y < (ssize_t) image->rows; y++)
2563 register const Quantum
2569 if (status == MagickFalse)
2571 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
2572 if (p == (const Quantum *) NULL)
2575 switch (compression)
2577 #if defined(MAGICKCORE_BZLIB_DELEGATE)
2578 case BZipCompression:
2580 bzip_info.next_in=(char *) pixels;
2581 bzip_info.avail_in=(unsigned int) (packet_size*image->columns);
2582 (void) ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
2583 quantum_type,pixels,exception);
2589 bzip_info.next_out=(char *) compress_pixels;
2590 bzip_info.avail_out=(unsigned int) BZipMaxExtent(packet_size*
2592 code=BZ2_bzCompress(&bzip_info,BZ_FLUSH);
2595 length=(size_t) (bzip_info.next_out-(char *) compress_pixels);
2598 (void) WriteBlobMSBLong(image,(unsigned int) length);
2599 (void) WriteBlob(image,length,compress_pixels);
2601 } while (bzip_info.avail_in != 0);
2605 #if defined(MAGICKCORE_LZMA_DELEGATE)
2606 case LZMACompression:
2608 lzma_info.next_in=pixels;
2609 lzma_info.avail_in=packet_size*image->columns;
2610 (void) ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
2611 quantum_type,pixels,exception);
2617 lzma_info.next_out=compress_pixels;
2618 lzma_info.avail_out=packet_size*image->columns;
2619 code=lzma_code(&lzma_info,LZMA_RUN);
2620 if (code != LZMA_OK)
2622 length=(size_t) (lzma_info.next_out-compress_pixels);
2625 (void) WriteBlobMSBLong(image,(unsigned int) length);
2626 (void) WriteBlob(image,length,compress_pixels);
2628 } while (lzma_info.avail_in != 0);
2632 #if defined(MAGICKCORE_ZLIB_DELEGATE)
2633 case LZWCompression:
2634 case ZipCompression:
2636 zip_info.next_in=pixels;
2637 zip_info.avail_in=(uInt) (packet_size*image->columns);
2638 (void) ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
2639 quantum_type,pixels,exception);
2645 zip_info.next_out=compress_pixels;
2646 zip_info.avail_out=(uInt) ZipMaxExtent(packet_size*image->columns);
2647 code=deflate(&zip_info,Z_SYNC_FLUSH);
2650 length=(size_t) (zip_info.next_out-compress_pixels);
2653 (void) WriteBlobMSBLong(image,(unsigned int) length);
2654 (void) WriteBlob(image,length,compress_pixels);
2656 } while (zip_info.avail_in != 0);
2660 case RLECompression:
2663 GetPixelInfoPixel(image,p,&pixel);
2664 p+=GetPixelChannels(image);
2665 for (x=1; x < (ssize_t) image->columns; x++)
2667 GetPixelInfoPixel(image,p,&target);
2668 if ((length < 255) &&
2669 (IsPixelInfoEquivalent(&pixel,&target) != MagickFalse))
2673 q=PopRunlengthPacket(image,q,length,&pixel,exception);
2676 GetPixelInfoPixel(image,p,&pixel);
2677 p+=GetPixelChannels(image);
2679 q=PopRunlengthPacket(image,q,length,&pixel,exception);
2680 (void) WriteBlob(image,(size_t) (q-pixels),pixels);
2685 (void) ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
2686 quantum_type,pixels,exception);
2687 (void) WriteBlob(image,packet_size*image->columns,pixels);
2691 if (image->previous == (Image *) NULL)
2693 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
2695 if (status == MagickFalse)
2699 switch (compression)
2701 #if defined(MAGICKCORE_BZLIB_DELEGATE)
2702 case BZipCompression:
2709 if (status == MagickFalse)
2711 bzip_info.next_out=(char *) compress_pixels;
2712 bzip_info.avail_out=(unsigned int) BZipMaxExtent(packet_size*
2714 code=BZ2_bzCompress(&bzip_info,BZ_FINISH);
2715 length=(size_t) (bzip_info.next_out-(char *) compress_pixels);
2718 (void) WriteBlobMSBLong(image,(unsigned int) length);
2719 (void) WriteBlob(image,length,compress_pixels);
2721 if (code == BZ_STREAM_END)
2724 code=BZ2_bzCompressEnd(&bzip_info);
2730 #if defined(MAGICKCORE_LZMA_DELEGATE)
2731 case LZMACompression:
2738 if (status == MagickFalse)
2740 lzma_info.next_out=compress_pixels;
2741 lzma_info.avail_out=packet_size*image->columns;
2742 code=lzma_code(&lzma_info,LZMA_FINISH);
2743 length=(size_t) (lzma_info.next_out-compress_pixels);
2746 (void) WriteBlobMSBLong(image,(unsigned int) length);
2747 (void) WriteBlob(image,length,compress_pixels);
2749 if (code == LZMA_STREAM_END)
2752 lzma_end(&lzma_info);
2756 #if defined(MAGICKCORE_ZLIB_DELEGATE)
2757 case LZWCompression:
2758 case ZipCompression:
2765 if (status == MagickFalse)
2767 zip_info.next_out=compress_pixels;
2768 zip_info.avail_out=(uInt) ZipMaxExtent(packet_size*image->columns);
2769 code=deflate(&zip_info,Z_FINISH);
2770 length=(size_t) (zip_info.next_out-compress_pixels);
2773 (void) WriteBlobMSBLong(image,(unsigned int) length);
2774 (void) WriteBlob(image,length,compress_pixels);
2776 if (code == Z_STREAM_END)
2779 code=deflateEnd(&zip_info);
2788 quantum_info=DestroyQuantumInfo(quantum_info);
2789 compress_pixels=(unsigned char *) RelinquishMagickMemory(compress_pixels);
2790 if (GetNextImageInList(image) == (Image *) NULL)
2792 image=SyncNextImageInList(image);
2793 status=SetImageProgress(image,SaveImagesTag,scene++,imageListLength);
2794 if (status == MagickFalse)
2796 } while (image_info->adjoin != MagickFalse);
2797 (void) CloseBlob(image);