2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Read/Write Compuserv Graphics Interchange Format %
20 % Copyright 1999-2011 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/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/exception.h"
54 #include "MagickCore/exception-private.h"
55 #include "MagickCore/image.h"
56 #include "MagickCore/image-private.h"
57 #include "MagickCore/list.h"
58 #include "MagickCore/profile.h"
59 #include "MagickCore/magick.h"
60 #include "MagickCore/memory_.h"
61 #include "MagickCore/monitor.h"
62 #include "MagickCore/monitor-private.h"
63 #include "MagickCore/option.h"
64 #include "MagickCore/pixel.h"
65 #include "MagickCore/pixel-accessor.h"
66 #include "MagickCore/property.h"
67 #include "MagickCore/quantize.h"
68 #include "MagickCore/quantum-private.h"
69 #include "MagickCore/static.h"
70 #include "MagickCore/string_.h"
71 #include "MagickCore/module.h"
76 #define MaximumLZWBits 12
77 #define MaximumLZWCode (1UL << MaximumLZWBits)
82 typedef struct _LZWCodeInfo
95 typedef struct _LZWStack
103 typedef struct _LZWInfo
131 Forward declarations.
134 GetNextLZWCode(LZWInfo *,const size_t);
136 static MagickBooleanType
137 WriteGIFImage(const ImageInfo *,Image *);
140 ReadBlobBlock(Image *,unsigned char *);
143 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
147 % D e c o d e I m a g e %
151 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
153 % DecodeImage uncompresses an image via GIF-coding.
155 % The format of the DecodeImage method is:
157 % MagickBooleanType DecodeImage(Image *image,const ssize_t opacity)
159 % A description of each parameter follows:
161 % o image: the address of a structure of type Image.
163 % o opacity: The colormap index associated with the transparent color.
167 static LZWInfo *RelinquishLZWInfo(LZWInfo *lzw_info)
169 if (lzw_info->table[0] != (size_t *) NULL)
170 lzw_info->table[0]=(size_t *) RelinquishMagickMemory(
172 if (lzw_info->table[1] != (size_t *) NULL)
173 lzw_info->table[1]=(size_t *) RelinquishMagickMemory(
175 if (lzw_info->stack != (LZWStack *) NULL)
177 if (lzw_info->stack->codes != (size_t *) NULL)
178 lzw_info->stack->codes=(size_t *) RelinquishMagickMemory(
179 lzw_info->stack->codes);
180 lzw_info->stack=(LZWStack *) RelinquishMagickMemory(lzw_info->stack);
182 lzw_info=(LZWInfo *) RelinquishMagickMemory(lzw_info);
183 return((LZWInfo *) NULL);
186 static inline void ResetLZWInfo(LZWInfo *lzw_info)
191 lzw_info->bits=lzw_info->data_size+1;
193 lzw_info->maximum_code=one << lzw_info->bits;
194 lzw_info->slot=lzw_info->maximum_data_value+3;
195 lzw_info->genesis=MagickTrue;
198 static LZWInfo *AcquireLZWInfo(Image *image,const size_t data_size)
209 lzw_info=(LZWInfo *) AcquireMagickMemory(sizeof(*lzw_info));
210 if (lzw_info == (LZWInfo *) NULL)
211 return((LZWInfo *) NULL);
212 (void) ResetMagickMemory(lzw_info,0,sizeof(*lzw_info));
213 lzw_info->image=image;
214 lzw_info->data_size=data_size;
216 lzw_info->maximum_data_value=(one << data_size)-1;
217 lzw_info->clear_code=lzw_info->maximum_data_value+1;
218 lzw_info->end_code=lzw_info->maximum_data_value+2;
219 lzw_info->table[0]=(size_t *) AcquireQuantumMemory(MaximumLZWCode,
220 sizeof(*lzw_info->table));
221 lzw_info->table[1]=(size_t *) AcquireQuantumMemory(MaximumLZWCode,
222 sizeof(*lzw_info->table));
223 if ((lzw_info->table[0] == (size_t *) NULL) ||
224 (lzw_info->table[1] == (size_t *) NULL))
226 lzw_info=RelinquishLZWInfo(lzw_info);
227 return((LZWInfo *) NULL);
229 for (i=0; i <= (ssize_t) lzw_info->maximum_data_value; i++)
231 lzw_info->table[0][i]=0;
232 lzw_info->table[1][i]=(size_t) i;
234 ResetLZWInfo(lzw_info);
235 lzw_info->code_info.buffer[0]='\0';
236 lzw_info->code_info.buffer[1]='\0';
237 lzw_info->code_info.count=2;
238 lzw_info->code_info.bit=8*lzw_info->code_info.count;
239 lzw_info->code_info.eof=MagickFalse;
240 lzw_info->genesis=MagickTrue;
241 lzw_info->stack=(LZWStack *) AcquireMagickMemory(sizeof(*lzw_info->stack));
242 if (lzw_info->stack == (LZWStack *) NULL)
244 lzw_info=RelinquishLZWInfo(lzw_info);
245 return((LZWInfo *) NULL);
247 lzw_info->stack->codes=(size_t *) AcquireQuantumMemory(2UL*
248 MaximumLZWCode,sizeof(*lzw_info->stack->codes));
249 if (lzw_info->stack->codes == (size_t *) NULL)
251 lzw_info=RelinquishLZWInfo(lzw_info);
252 return((LZWInfo *) NULL);
254 lzw_info->stack->index=lzw_info->stack->codes;
255 lzw_info->stack->top=lzw_info->stack->codes+2*MaximumLZWCode;
259 static inline int GetNextLZWCode(LZWInfo *lzw_info,const size_t bits)
270 while (((lzw_info->code_info.bit+bits) > (8*lzw_info->code_info.count)) &&
271 (lzw_info->code_info.eof == MagickFalse))
276 lzw_info->code_info.buffer[0]=lzw_info->code_info.buffer[
277 lzw_info->code_info.count-2];
278 lzw_info->code_info.buffer[1]=lzw_info->code_info.buffer[
279 lzw_info->code_info.count-1];
280 lzw_info->code_info.bit-=8*(lzw_info->code_info.count-2);
281 lzw_info->code_info.count=2;
282 count=ReadBlobBlock(lzw_info->image,&lzw_info->code_info.buffer[
283 lzw_info->code_info.count]);
285 lzw_info->code_info.count+=count;
287 lzw_info->code_info.eof=MagickTrue;
289 if ((lzw_info->code_info.bit+bits) > (8*lzw_info->code_info.count))
293 for (i=0; i < (ssize_t) bits; i++)
295 code|=((lzw_info->code_info.buffer[lzw_info->code_info.bit/8] &
296 (one << (lzw_info->code_info.bit % 8))) != 0) << i;
297 lzw_info->code_info.bit++;
302 static inline int PopLZWStack(LZWStack *stack_info)
304 if (stack_info->index <= stack_info->codes)
307 return((int) *stack_info->index);
310 static inline void PushLZWStack(LZWStack *stack_info,const size_t value)
312 if (stack_info->index >= stack_info->top)
314 *stack_info->index=value;
318 static int ReadBlobLZWByte(LZWInfo *lzw_info)
330 if (lzw_info->stack->index != lzw_info->stack->codes)
331 return(PopLZWStack(lzw_info->stack));
332 if (lzw_info->genesis != MagickFalse)
334 lzw_info->genesis=MagickFalse;
337 lzw_info->first_code=(size_t) GetNextLZWCode(lzw_info,
339 lzw_info->last_code=lzw_info->first_code;
340 } while (lzw_info->first_code == lzw_info->clear_code);
341 return((int) lzw_info->first_code);
343 code=GetNextLZWCode(lzw_info,lzw_info->bits);
346 if ((size_t) code == lzw_info->clear_code)
348 ResetLZWInfo(lzw_info);
349 return(ReadBlobLZWByte(lzw_info));
351 if ((size_t) code == lzw_info->end_code)
353 if ((size_t) code < lzw_info->slot)
357 PushLZWStack(lzw_info->stack,lzw_info->first_code);
358 value=lzw_info->last_code;
361 while (value > lzw_info->maximum_data_value)
363 if ((size_t) count > MaximumLZWCode)
366 if ((size_t) value > MaximumLZWCode)
368 PushLZWStack(lzw_info->stack,lzw_info->table[1][value]);
369 value=lzw_info->table[0][value];
371 lzw_info->first_code=lzw_info->table[1][value];
372 PushLZWStack(lzw_info->stack,lzw_info->first_code);
374 if (lzw_info->slot < MaximumLZWCode)
376 lzw_info->table[0][lzw_info->slot]=lzw_info->last_code;
377 lzw_info->table[1][lzw_info->slot]=lzw_info->first_code;
379 if ((lzw_info->slot >= lzw_info->maximum_code) &&
380 (lzw_info->bits < MaximumLZWBits))
383 lzw_info->maximum_code=one << lzw_info->bits;
386 lzw_info->last_code=(size_t) code;
387 return(PopLZWStack(lzw_info->stack));
390 static MagickBooleanType DecodeImage(Image *image,const ssize_t opacity)
415 Allocate decoder tables.
417 assert(image != (Image *) NULL);
418 assert(image->signature == MagickSignature);
419 if (image->debug != MagickFalse)
420 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
421 data_size=(unsigned char) ReadBlobByte(image);
422 if (data_size > MaximumLZWBits)
423 ThrowBinaryException(CorruptImageError,"CorruptImage",image->filename);
424 lzw_info=AcquireLZWInfo(image,data_size);
425 if (lzw_info == (LZWInfo *) NULL)
426 ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
428 exception=(&image->exception);
431 for (y=0; y < (ssize_t) image->rows; y++)
439 q=GetAuthenticPixels(image,0,offset,image->columns,1,exception);
440 if (q == (const Quantum *) NULL)
442 for (x=0; x < (ssize_t) image->columns; )
444 c=ReadBlobLZWByte(lzw_info);
447 index=ConstrainColormapIndex(image,(size_t) c);
448 SetPixelIndex(image,index,q);
449 SetPixelPacket(image,image->colormap+(ssize_t) index,q);
450 SetPixelAlpha(image,(ssize_t) index == opacity ? TransparentAlpha :
453 q+=GetPixelChannels(image);
455 if (x < (ssize_t) image->columns)
457 if (image->interlace == NoInterlace)
466 if (offset >= (ssize_t) image->rows)
476 if (offset >= (ssize_t) image->rows)
486 if (offset >= (ssize_t) image->rows)
499 if (SyncAuthenticPixels(image,exception) == MagickFalse)
502 lzw_info=RelinquishLZWInfo(lzw_info);
503 if (y < (ssize_t) image->rows)
504 ThrowBinaryException(CorruptImageError,"CorruptImage",image->filename);
509 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
513 % E n c o d e I m a g e %
517 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
519 % EncodeImage compresses an image via GIF-coding.
521 % The format of the EncodeImage method is:
523 % MagickBooleanType EncodeImage(const ImageInfo *image_info,Image *image,
524 % const size_t data_size)
526 % A description of each parameter follows:
528 % o image_info: the image info.
530 % o image: the address of a structure of type Image.
532 % o data_size: The number of bits in the compressed packet.
535 static MagickBooleanType EncodeImage(const ImageInfo *image_info,Image *image,
536 const size_t data_size)
538 #define MaxCode(number_bits) ((one << (number_bits))-1)
539 #define MaxHashTable 5003
540 #define MaxGIFBits 12UL
541 #define MaxGIFTable (1UL << MaxGIFBits)
542 #define GIFOutputCode(code) \
548 datum|=(code) << bits; \
555 Add a character to current packet. \
557 packet[length++]=(unsigned char) (datum & 0xff); \
560 (void) WriteBlobByte(image,(unsigned char) length); \
561 (void) WriteBlob(image,length,packet); \
567 if (free_code > max_code) \
570 if (number_bits == MaxGIFBits) \
571 max_code=MaxGIFTable; \
573 max_code=MaxCode(number_bits); \
592 end_of_information_code,
612 Allocate encoder tables.
614 assert(image != (Image *) NULL);
616 packet=(unsigned char *) AcquireQuantumMemory(256,sizeof(*packet));
617 hash_code=(short *) AcquireQuantumMemory(MaxHashTable,sizeof(*hash_code));
618 hash_prefix=(short *) AcquireQuantumMemory(MaxHashTable,sizeof(*hash_prefix));
619 hash_suffix=(unsigned char *) AcquireQuantumMemory(MaxHashTable,
620 sizeof(*hash_suffix));
621 if ((packet == (unsigned char *) NULL) || (hash_code == (short *) NULL) ||
622 (hash_prefix == (short *) NULL) ||
623 (hash_suffix == (unsigned char *) NULL))
625 if (packet != (unsigned char *) NULL)
626 packet=(unsigned char *) RelinquishMagickMemory(packet);
627 if (hash_code != (short *) NULL)
628 hash_code=(short *) RelinquishMagickMemory(hash_code);
629 if (hash_prefix != (short *) NULL)
630 hash_prefix=(short *) RelinquishMagickMemory(hash_prefix);
631 if (hash_suffix != (unsigned char *) NULL)
632 hash_suffix=(unsigned char *) RelinquishMagickMemory(hash_suffix);
636 Initialize GIF encoder.
638 number_bits=data_size;
639 max_code=MaxCode(number_bits);
640 clear_code=((short) one << (data_size-1));
641 end_of_information_code=clear_code+1;
642 free_code=clear_code+2;
646 for (i=0; i < MaxHashTable; i++)
648 GIFOutputCode(clear_code);
655 for (y=0; y < (ssize_t) image->rows; y++)
657 register const Quantum
663 p=GetVirtualPixels(image,0,offset,image->columns,1,&image->exception);
664 if (p == (const Quantum *) NULL)
668 waiting_code=(short) GetPixelIndex(image,p);
669 p+=GetPixelChannels(image);
671 for (x=(ssize_t) (y == 0 ? 1 : 0); x < (ssize_t) image->columns; x++)
676 index=(Quantum) ((size_t) GetPixelIndex(image,p) & 0xff);
677 p+=GetPixelChannels(image);
678 k=(ssize_t) (((size_t) index << (MaxGIFBits-8))+waiting_code);
679 if (k >= MaxHashTable)
681 next_pixel=MagickFalse;
683 if (hash_code[k] > 0)
685 if ((hash_prefix[k] == waiting_code) &&
686 (hash_suffix[k] == (unsigned char) index))
688 waiting_code=hash_code[k];
692 displacement=MaxHashTable-k;
698 if (hash_code[k] == 0)
700 if ((hash_prefix[k] == waiting_code) &&
701 (hash_suffix[k] == (unsigned char) index))
703 waiting_code=hash_code[k];
704 next_pixel=MagickTrue;
708 if (next_pixel == MagickTrue)
711 GIFOutputCode((size_t) waiting_code);
712 if (free_code < MaxGIFTable)
714 hash_code[k]=(short) free_code++;
715 hash_prefix[k]=waiting_code;
716 hash_suffix[k]=(unsigned char) index;
721 Fill the hash table with empty entries.
723 for (k=0; k < MaxHashTable; k++)
726 Reset compressor and issue a clear code.
728 free_code=clear_code+2;
729 GIFOutputCode(clear_code);
730 number_bits=data_size;
731 max_code=MaxCode(number_bits);
733 waiting_code=(short) index;
735 if (image_info->interlace == NoInterlace)
744 if (offset >= (ssize_t) image->rows)
754 if (offset >= (ssize_t) image->rows)
764 if (offset >= (ssize_t) image->rows)
779 Flush out the buffered code.
781 GIFOutputCode((size_t) waiting_code);
782 GIFOutputCode(end_of_information_code);
786 Add a character to current packet.
788 packet[length++]=(unsigned char) (datum & 0xff);
791 (void) WriteBlobByte(image,(unsigned char) length);
792 (void) WriteBlob(image,length,packet);
797 Flush accumulated data.
801 (void) WriteBlobByte(image,(unsigned char) length);
802 (void) WriteBlob(image,length,packet);
807 hash_suffix=(unsigned char *) RelinquishMagickMemory(hash_suffix);
808 hash_prefix=(short *) RelinquishMagickMemory(hash_prefix);
809 hash_code=(short *) RelinquishMagickMemory(hash_code);
810 packet=(unsigned char *) RelinquishMagickMemory(packet);
815 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
823 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
825 % IsGIF() returns MagickTrue if the image format type, identified by the
826 % magick string, is GIF.
828 % The format of the IsGIF method is:
830 % MagickBooleanType IsGIF(const unsigned char *magick,const size_t length)
832 % A description of each parameter follows:
834 % o magick: compare image format pattern against these bytes.
836 % o length: Specifies the length of the magick string.
839 static MagickBooleanType IsGIF(const unsigned char *magick,const size_t length)
843 if (LocaleNCompare((char *) magick,"GIF8",4) == 0)
849 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
853 + R e a d B l o b B l o c k %
857 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
859 % ReadBlobBlock() reads data from the image file and returns it. The
860 % amount of data is determined by first reading a count byte. The number
861 % of bytes read is returned.
863 % The format of the ReadBlobBlock method is:
865 % size_t ReadBlobBlock(Image *image,unsigned char *data)
867 % A description of each parameter follows:
869 % o image: the image.
871 % o data: Specifies an area to place the information requested from
875 static ssize_t ReadBlobBlock(Image *image,unsigned char *data)
883 assert(image != (Image *) NULL);
884 assert(image->signature == MagickSignature);
885 assert(data != (unsigned char *) NULL);
886 count=ReadBlob(image,1,&block_count);
889 return(ReadBlob(image,(size_t) block_count,data));
893 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
897 % R e a d G I F I m a g e %
901 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
903 % ReadGIFImage() reads a Compuserve Graphics image file and returns it.
904 % It allocates the memory necessary for the new Image structure and returns a
905 % pointer to the new image.
907 % The format of the ReadGIFImage method is:
909 % Image *ReadGIFImage(const ImageInfo *image_info,ExceptionInfo *exception)
911 % A description of each parameter follows:
913 % o image_info: the image info.
915 % o exception: return any errors or warnings in this structure.
919 static inline size_t MagickMax(const size_t x,const size_t y)
926 static inline size_t MagickMin(const size_t x,const size_t y)
933 static MagickBooleanType PingGIFImage(Image *image)
940 assert(image != (Image *) NULL);
941 assert(image->signature == MagickSignature);
942 if (image->debug != MagickFalse)
943 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
944 if (ReadBlob(image,1,&data_size) != 1)
945 ThrowBinaryException(CorruptImageError,"CorruptImage",image->filename);
946 if (data_size > MaximumLZWBits)
947 ThrowBinaryException(CorruptImageError,"CorruptImage",image->filename);
948 if (ReadBlob(image,1,&length) != 1)
949 ThrowBinaryException(CorruptImageError,"CorruptImage",image->filename);
952 if (ReadBlob(image,length,buffer) != (ssize_t) length)
953 ThrowBinaryException(CorruptImageError,"CorruptImage",image->filename);
954 if (ReadBlob(image,1,&length) != 1)
955 ThrowBinaryException(CorruptImageError,"CorruptImage",image->filename);
960 static Image *ReadGIFImage(const ImageInfo *image_info,ExceptionInfo *exception)
962 #define BitSet(byte,bit) (((byte) & (bit)) == (bit))
963 #define LSBFirstOrder(x,y) (((y) << 8) | (x))
969 number_extensionss=0;
980 register unsigned char
1000 header[MaxTextExtent],
1006 assert(image_info != (const ImageInfo *) NULL);
1007 assert(image_info->signature == MagickSignature);
1008 if (image_info->debug != MagickFalse)
1009 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1010 image_info->filename);
1011 assert(exception != (ExceptionInfo *) NULL);
1012 assert(exception->signature == MagickSignature);
1013 image=AcquireImage(image_info);
1014 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
1015 if (status == MagickFalse)
1017 image=DestroyImageList(image);
1018 return((Image *) NULL);
1021 Determine if this a GIF file.
1023 count=ReadBlob(image,6,magick);
1024 if ((count != 6) || ((LocaleNCompare((char *) magick,"GIF87",5) != 0) &&
1025 (LocaleNCompare((char *) magick,"GIF89",5) != 0)))
1026 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
1027 page.width=ReadBlobLSBShort(image);
1028 page.height=ReadBlobLSBShort(image);
1029 flag=(unsigned char) ReadBlobByte(image);
1030 background=(unsigned char) ReadBlobByte(image);
1031 c=(unsigned char) ReadBlobByte(image); /* reserved */
1033 global_colors=one << (((size_t) flag & 0x07)+1);
1034 global_colormap=(unsigned char *) AcquireQuantumMemory((size_t)
1035 MagickMax(global_colors,256),3UL*sizeof(*global_colormap));
1036 if (global_colormap == (unsigned char *) NULL)
1037 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1038 if (BitSet((int) flag,0x80) != 0)
1039 count=ReadBlob(image,(size_t) (3*global_colors),global_colormap);
1047 count=ReadBlob(image,1,&c);
1050 if (c == (unsigned char) ';')
1051 break; /* terminator */
1052 if (c == (unsigned char) '!')
1055 GIF Extension block.
1058 count=ReadBlob(image,1,&c);
1061 global_colormap=(unsigned char *) RelinquishMagickMemory(
1063 ThrowReaderException(CorruptImageError,
1064 "UnableToReadExtensionBlock");
1071 Read graphics control extension.
1073 while (ReadBlobBlock(image,header) != 0) ;
1074 dispose=(size_t) (header[0] >> 2);
1075 delay=(size_t) ((header[2] << 8) | header[1]);
1076 if ((ssize_t) (header[0] & 0x01) == 0x01)
1077 opacity=(ssize_t) header[3];
1086 Read comment extension.
1088 comments=AcquireString((char *) NULL);
1091 count=(ssize_t) ReadBlobBlock(image,header);
1095 (void) ConcatenateString(&comments,(const char *) header);
1097 (void) SetImageProperty(image,"comment",comments);
1098 comments=DestroyString(comments);
1103 /* Read GIF application extension */
1109 Read Netscape Loop extension.
1112 if (ReadBlobBlock(image,header) != 0)
1113 loop=LocaleNCompare((char *) header,"NETSCAPE2.0",11) == 0 ?
1114 MagickTrue : MagickFalse;
1115 if (loop != MagickFalse)
1117 while (ReadBlobBlock(image,header) != 0)
1118 iterations=(size_t) ((header[2] << 8) | header[1]);
1124 name[MaxTextExtent];
1143 Store GIF application extension as a generic profile.
1145 i8bim=LocaleNCompare((char *) header,"MGK8BIM0000",11) == 0 ?
1146 MagickTrue : MagickFalse;
1147 icc=LocaleNCompare((char *) header,"ICCRGBG1012",11) == 0 ?
1148 MagickTrue : MagickFalse;
1149 iptc=LocaleNCompare((char *) header,"MGKIPTC0000",11) == 0 ?
1150 MagickTrue : MagickFalse;
1151 number_extensionss++;
1152 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
1153 " Reading GIF application extension");
1154 info=(unsigned char *) AcquireQuantumMemory(255UL,
1156 reserved_length=255;
1157 for (info_length=0; ; )
1159 block_length=(int) ReadBlobBlock(image,&info[info_length]);
1160 if (block_length == 0)
1162 info_length+=block_length;
1163 if (info_length > (reserved_length-255))
1165 reserved_length+=4096;
1166 info=(unsigned char *) ResizeQuantumMemory(info,
1167 (size_t) reserved_length,sizeof(*info));
1170 info=(unsigned char *) ResizeQuantumMemory(info,(size_t)
1171 (info_length+1),sizeof(*info));
1172 profile=AcquireStringInfo((size_t) info_length);
1173 SetStringInfoDatum(profile,(const unsigned char *) info);
1174 if (i8bim == MagickTrue)
1175 (void) CopyMagickString(name,"8bim",sizeof(name));
1176 else if (icc == MagickTrue)
1177 (void) CopyMagickString(name,"icc",sizeof(name));
1178 else if (iptc == MagickTrue)
1179 (void) CopyMagickString(name,"iptc",sizeof(name));
1181 (void) FormatLocaleString(name,sizeof(name),"gif:%.11s",
1183 (void) SetImageProfile(image,name,profile);
1184 info=(unsigned char *) RelinquishMagickMemory(info);
1185 profile=DestroyStringInfo(profile);
1186 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
1187 " profile name=%s",name);
1193 while (ReadBlobBlock(image,header) != 0) ;
1198 if (c != (unsigned char) ',')
1200 if (image_count != 0)
1203 Allocate next image structure.
1205 AcquireNextImage(image_info,image);
1206 if (GetNextImageInList(image) == (Image *) NULL)
1208 image=DestroyImageList(image);
1209 global_colormap=(unsigned char *) RelinquishMagickMemory(
1211 return((Image *) NULL);
1213 image=SyncNextImageInList(image);
1217 Read image attributes.
1219 image->storage_class=PseudoClass;
1220 image->compression=LZWCompression;
1221 page.x=(ssize_t) ReadBlobLSBShort(image);
1222 page.y=(ssize_t) ReadBlobLSBShort(image);
1223 image->columns=ReadBlobLSBShort(image);
1224 image->rows=ReadBlobLSBShort(image);
1226 flag=(unsigned char) ReadBlobByte(image);
1227 image->interlace=BitSet((int) flag,0x40) != 0 ? GIFInterlace :
1229 image->colors=BitSet((int) flag,0x80) == 0 ? global_colors :
1230 one << ((size_t) (flag & 0x07)+1);
1231 if (opacity >= (ssize_t) image->colors)
1233 image->page.width=page.width;
1234 image->page.height=page.height;
1235 image->page.y=page.y;
1236 image->page.x=page.x;
1238 image->ticks_per_second=100;
1239 image->dispose=(DisposeType) dispose;
1240 image->iterations=iterations;
1241 image->matte=opacity >= 0 ? MagickTrue : MagickFalse;
1245 if ((image->columns == 0) || (image->rows == 0))
1247 global_colormap=(unsigned char *) RelinquishMagickMemory(
1249 ThrowReaderException(CorruptImageError,"NegativeOrZeroImageSize");
1252 Inititialize colormap.
1254 if (AcquireImageColormap(image,image->colors) == MagickFalse)
1256 global_colormap=(unsigned char *) RelinquishMagickMemory(
1258 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1260 if (BitSet((int) flag,0x80) == 0)
1263 Use global colormap.
1266 for (i=0; i < (ssize_t) image->colors; i++)
1268 image->colormap[i].red=ScaleCharToQuantum(*p++);
1269 image->colormap[i].green=ScaleCharToQuantum(*p++);
1270 image->colormap[i].blue=ScaleCharToQuantum(*p++);
1273 image->colormap[i].alpha=(Quantum) TransparentAlpha;
1274 image->transparent_color=image->colormap[opacity];
1277 image->background_color=image->colormap[MagickMin(background,
1286 Read local colormap.
1288 colormap=(unsigned char *) AcquireQuantumMemory(image->colors,
1289 3*sizeof(*colormap));
1290 if (colormap == (unsigned char *) NULL)
1292 global_colormap=(unsigned char *) RelinquishMagickMemory(
1294 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1296 count=ReadBlob(image,(3*image->colors)*sizeof(*colormap),colormap);
1297 if (count != (ssize_t) (3*image->colors))
1299 global_colormap=(unsigned char *) RelinquishMagickMemory(
1301 colormap=(unsigned char *) RelinquishMagickMemory(colormap);
1302 ThrowReaderException(CorruptImageError,
1303 "InsufficientImageDataInFile");
1306 for (i=0; i < (ssize_t) image->colors; i++)
1308 image->colormap[i].red=ScaleCharToQuantum(*p++);
1309 image->colormap[i].green=ScaleCharToQuantum(*p++);
1310 image->colormap[i].blue=ScaleCharToQuantum(*p++);
1312 image->colormap[i].alpha=(Quantum) TransparentAlpha;
1314 colormap=(unsigned char *) RelinquishMagickMemory(colormap);
1316 if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0))
1317 if (image->scene >= (image_info->scene+image_info->number_scenes-1))
1322 if (image_info->ping != MagickFalse)
1323 status=PingGIFImage(image);
1325 status=DecodeImage(image,opacity);
1326 if ((image_info->ping == MagickFalse) && (status == MagickFalse))
1328 global_colormap=(unsigned char *) RelinquishMagickMemory(
1330 ThrowReaderException(CorruptImageError,"CorruptImage");
1332 if (image_info->number_scenes != 0)
1333 if (image->scene >= (image_info->scene+image_info->number_scenes-1))
1336 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) image->scene-
1338 if (status == MagickFalse)
1341 global_colormap=(unsigned char *) RelinquishMagickMemory(global_colormap);
1342 if ((image->columns == 0) || (image->rows == 0))
1343 ThrowReaderException(CorruptImageError,"NegativeOrZeroImageSize");
1344 (void) CloseBlob(image);
1345 return(GetFirstImageInList(image));
1349 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1353 % R e g i s t e r G I F I m a g e %
1357 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1359 % RegisterGIFImage() adds properties for the GIF image format to
1360 % the list of supported formats. The properties include the image format
1361 % tag, a method to read and/or write the format, whether the format
1362 % supports the saving of more than one frame to the same file or blob,
1363 % whether the format supports native in-memory I/O, and a brief
1364 % description of the format.
1366 % The format of the RegisterGIFImage method is:
1368 % size_t RegisterGIFImage(void)
1371 ModuleExport size_t RegisterGIFImage(void)
1376 entry=SetMagickInfo("GIF");
1377 entry->decoder=(DecodeImageHandler *) ReadGIFImage;
1378 entry->encoder=(EncodeImageHandler *) WriteGIFImage;
1379 entry->magick=(IsImageFormatHandler *) IsGIF;
1380 entry->description=ConstantString("CompuServe graphics interchange format");
1381 entry->module=ConstantString("GIF");
1382 (void) RegisterMagickInfo(entry);
1383 entry=SetMagickInfo("GIF87");
1384 entry->decoder=(DecodeImageHandler *) ReadGIFImage;
1385 entry->encoder=(EncodeImageHandler *) WriteGIFImage;
1386 entry->magick=(IsImageFormatHandler *) IsGIF;
1387 entry->adjoin=MagickFalse;
1388 entry->description=ConstantString("CompuServe graphics interchange format");
1389 entry->version=ConstantString("version 87a");
1390 entry->module=ConstantString("GIF");
1391 (void) RegisterMagickInfo(entry);
1392 return(MagickImageCoderSignature);
1396 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1400 % U n r e g i s t e r G I F I m a g e %
1404 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1406 % UnregisterGIFImage() removes format registrations made by the
1407 % GIF module from the list of supported formats.
1409 % The format of the UnregisterGIFImage method is:
1411 % UnregisterGIFImage(void)
1414 ModuleExport void UnregisterGIFImage(void)
1416 (void) UnregisterMagickInfo("GIF");
1417 (void) UnregisterMagickInfo("GIF87");
1421 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1425 % W r i t e G I F I m a g e %
1429 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1431 % WriteGIFImage() writes an image to a file in the Compuserve Graphics
1434 % The format of the WriteGIFImage method is:
1436 % MagickBooleanType WriteGIFImage(const ImageInfo *image_info,Image *image)
1438 % A description of each parameter follows.
1440 % o image_info: the image info.
1442 % o image: The image.
1445 static MagickBooleanType WriteGIFImage(const ImageInfo *image_info,Image *image)
1471 register unsigned char
1489 Open output image file.
1491 assert(image_info != (const ImageInfo *) NULL);
1492 assert(image_info->signature == MagickSignature);
1493 assert(image != (Image *) NULL);
1494 assert(image->signature == MagickSignature);
1495 if (image->debug != MagickFalse)
1496 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1497 status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
1498 if (status == MagickFalse)
1503 global_colormap=(unsigned char *) AcquireQuantumMemory(768UL,
1504 sizeof(*global_colormap));
1505 colormap=(unsigned char *) AcquireQuantumMemory(768UL,sizeof(*colormap));
1506 if ((global_colormap == (unsigned char *) NULL) ||
1507 (colormap == (unsigned char *) NULL))
1508 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
1509 for (i=0; i < 768; i++)
1510 colormap[i]=(unsigned char) 0;
1514 write_info=CloneImageInfo(image_info);
1515 if (LocaleCompare(write_info->magick,"GIF87") != 0)
1516 (void) WriteBlob(image,6,(unsigned char *) "GIF89a");
1519 (void) WriteBlob(image,6,(unsigned char *) "GIF87a");
1520 write_info->adjoin=MagickFalse;
1523 Determine image bounding box.
1525 page.width=image->columns;
1526 page.height=image->rows;
1529 if (write_info->adjoin != MagickFalse)
1530 for (next_image=image; next_image != (Image *) NULL; )
1532 page.x=next_image->page.x;
1533 page.y=next_image->page.y;
1534 if ((next_image->page.width+page.x) > page.width)
1535 page.width=next_image->page.width+page.x;
1536 if ((next_image->page.height+page.y) > page.height)
1537 page.height=next_image->page.height+page.y;
1538 next_image=GetNextImageInList(next_image);
1540 page.x=image->page.x;
1541 page.y=image->page.y;
1542 if ((image->page.width != 0) && (image->page.height != 0))
1544 (void) WriteBlobLSBShort(image,(unsigned short) page.width);
1545 (void) WriteBlobLSBShort(image,(unsigned short) page.height);
1547 Write images to file.
1549 interlace=write_info->interlace;
1550 if ((write_info->adjoin != MagickFalse) &&
1551 (GetNextImageInList(image) != (Image *) NULL))
1552 interlace=NoInterlace;
1557 if (IsRGBColorspace(image->colorspace) == MagickFalse)
1558 (void) TransformImageColorspace(image,RGBColorspace);
1560 if (IsImageOpaque(image,&image->exception) != MagickFalse)
1562 if ((image->storage_class == DirectClass) || (image->colors > 256))
1563 (void) SetImageType(image,PaletteType);
1572 Identify transparent colormap index.
1574 if ((image->storage_class == DirectClass) || (image->colors > 256))
1575 (void) SetImageType(image,PaletteBilevelMatteType);
1576 for (i=0; i < (ssize_t) image->colors; i++)
1577 if (image->colormap[i].alpha != OpaqueAlpha)
1584 alpha=(MagickRealType) TransparentAlpha-(MagickRealType)
1585 image->colormap[i].alpha;
1586 beta=(MagickRealType) TransparentAlpha-(MagickRealType)
1587 image->colormap[opacity].alpha;
1593 (void) SetImageType(image,PaletteBilevelMatteType);
1594 for (i=0; i < (ssize_t) image->colors; i++)
1595 if (image->colormap[i].alpha != OpaqueAlpha)
1602 alpha=(Quantum) TransparentAlpha-(MagickRealType)
1603 image->colormap[i].alpha;
1604 beta=(Quantum) TransparentAlpha-(MagickRealType)
1605 image->colormap[opacity].alpha;
1612 image->colormap[opacity].red=image->transparent_color.red;
1613 image->colormap[opacity].green=image->transparent_color.green;
1614 image->colormap[opacity].blue=image->transparent_color.blue;
1617 if ((image->storage_class == DirectClass) || (image->colors > 256))
1618 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
1619 for (bits_per_pixel=1; bits_per_pixel < 8; bits_per_pixel++)
1620 if ((one << bits_per_pixel) >= image->colors)
1623 for (i=0; i < (ssize_t) image->colors; i++)
1625 *q++=ScaleQuantumToChar(image->colormap[i].red);
1626 *q++=ScaleQuantumToChar(image->colormap[i].green);
1627 *q++=ScaleQuantumToChar(image->colormap[i].blue);
1629 for ( ; i < (ssize_t) (one << bits_per_pixel); i++)
1631 *q++=(unsigned char) 0x0;
1632 *q++=(unsigned char) 0x0;
1633 *q++=(unsigned char) 0x0;
1635 if ((GetPreviousImageInList(image) == (Image *) NULL) ||
1636 (write_info->adjoin == MagickFalse))
1639 Write global colormap.
1642 c|=(8-1) << 4; /* color resolution */
1643 c|=(bits_per_pixel-1); /* size of global colormap */
1644 (void) WriteBlobByte(image,(unsigned char) c);
1645 for (j=0; j < (ssize_t) image->colors; j++)
1646 if (IsPixelPacketEquivalent(&image->background_color,image->colormap+j))
1648 (void) WriteBlobByte(image,(unsigned char)
1649 (j == (ssize_t) image->colors ? 0 : j)); /* background color */
1650 (void) WriteBlobByte(image,(unsigned char) 0x00); /* reserved */
1651 length=(size_t) (3*(one << bits_per_pixel));
1652 (void) WriteBlob(image,length,colormap);
1653 for (j=0; j < 768; j++)
1654 global_colormap[j]=colormap[j];
1656 if (LocaleCompare(write_info->magick,"GIF87") != 0)
1659 Write graphics control extension.
1661 (void) WriteBlobByte(image,(unsigned char) 0x21);
1662 (void) WriteBlobByte(image,(unsigned char) 0xf9);
1663 (void) WriteBlobByte(image,(unsigned char) 0x04);
1664 c=image->dispose << 2;
1667 (void) WriteBlobByte(image,(unsigned char) c);
1668 delay=(size_t) (100*image->delay/MagickMax((size_t)
1669 image->ticks_per_second,1));
1670 (void) WriteBlobLSBShort(image,(unsigned short) delay);
1671 (void) WriteBlobByte(image,(unsigned char) (opacity >= 0 ? opacity :
1673 (void) WriteBlobByte(image,(unsigned char) 0x00);
1674 if ((LocaleCompare(write_info->magick,"GIF87") != 0) &&
1675 (GetImageProperty(image,"comment") != (const char *) NULL))
1687 Write Comment extension.
1689 (void) WriteBlobByte(image,(unsigned char) 0x21);
1690 (void) WriteBlobByte(image,(unsigned char) 0xfe);
1691 value=GetImageProperty(image,"comment");
1693 while (strlen(p) != 0)
1695 count=MagickMin(strlen(p),255);
1696 (void) WriteBlobByte(image,(unsigned char) count);
1697 for (i=0; i < (ssize_t) count; i++)
1698 (void) WriteBlobByte(image,(unsigned char) *p++);
1700 (void) WriteBlobByte(image,(unsigned char) 0x00);
1702 if ((GetPreviousImageInList(image) == (Image *) NULL) &&
1703 (GetNextImageInList(image) != (Image *) NULL) &&
1704 (image->iterations != 1))
1707 Write Netscape Loop extension.
1709 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
1710 " Writing GIF Extension %s","NETSCAPE2.0");
1711 (void) WriteBlobByte(image,(unsigned char) 0x21);
1712 (void) WriteBlobByte(image,(unsigned char) 0xff);
1713 (void) WriteBlobByte(image,(unsigned char) 0x0b);
1714 (void) WriteBlob(image,11,(unsigned char *) "NETSCAPE2.0");
1715 (void) WriteBlobByte(image,(unsigned char) 0x03);
1716 (void) WriteBlobByte(image,(unsigned char) 0x01);
1717 (void) WriteBlobLSBShort(image,(unsigned short) image->iterations);
1718 (void) WriteBlobByte(image,(unsigned char) 0x00);
1720 ResetImageProfileIterator(image);
1729 name=GetNextImageProfile(image);
1730 if (name == (const char *) NULL)
1732 profile=GetImageProfile(image,name);
1733 if (profile != (StringInfo *) NULL)
1735 if ((LocaleCompare(name,"ICC") == 0) ||
1736 (LocaleCompare(name,"ICM") == 0) ||
1737 (LocaleCompare(name,"IPTC") == 0) ||
1738 (LocaleCompare(name,"8BIM") == 0) ||
1739 (LocaleNCompare(name,"gif:",4) == 0))
1750 datum=GetStringInfoDatum(profile);
1751 length=GetStringInfoLength(profile);
1752 (void) WriteBlobByte(image,(unsigned char) 0x21);
1753 (void) WriteBlobByte(image,(unsigned char) 0xff);
1754 (void) WriteBlobByte(image,(unsigned char) 0x0b);
1755 if ((LocaleCompare(name,"ICC") == 0) ||
1756 (LocaleCompare(name,"ICM") == 0))
1759 Write ICC extension.
1761 (void) WriteBlob(image,11,(unsigned char *)"ICCRGBG1012");
1762 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
1763 " Writing GIF Extension %s","ICCRGBG1012");
1766 if ((LocaleCompare(name,"IPTC") == 0))
1769 write IPTC extension.
1771 (void) WriteBlob(image,11,(unsigned char *)"MGKIPTC0000");
1772 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
1773 " Writing GIF Extension %s","MGKIPTC0000");
1776 if ((LocaleCompare(name,"8BIM") == 0))
1779 Write 8BIM extension>
1781 (void) WriteBlob(image,11,(unsigned char *)
1783 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
1784 " Writing GIF Extension %s","MGK8BIM0000");
1789 extension[MaxTextExtent];
1791 /* write generic extension */
1792 (void) CopyMagickString(extension,name+4,
1794 (void) WriteBlob(image,11,(unsigned char *) extension);
1795 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
1796 " Writing GIF Extension %s",name);
1799 while ((ssize_t) length > offset)
1804 if ((length-offset) < 255)
1805 block_length=length-offset;
1808 (void) WriteBlobByte(image,(unsigned char) block_length);
1809 (void) WriteBlob(image,(size_t) block_length,datum+offset);
1810 offset+=(ssize_t) block_length;
1812 (void) WriteBlobByte(image,(unsigned char) 0x00);
1817 (void) WriteBlobByte(image,','); /* image separator */
1819 Write the image header.
1821 page.x=image->page.x;
1822 page.y=image->page.y;
1823 if ((image->page.width != 0) && (image->page.height != 0))
1825 (void) WriteBlobLSBShort(image,(unsigned short) (page.x < 0 ? 0 : page.x));
1826 (void) WriteBlobLSBShort(image,(unsigned short) (page.y < 0 ? 0 : page.y));
1827 (void) WriteBlobLSBShort(image,(unsigned short) image->columns);
1828 (void) WriteBlobLSBShort(image,(unsigned short) image->rows);
1830 if (interlace != NoInterlace)
1831 c|=0x40; /* pixel data is interlaced */
1832 for (j=0; j < (ssize_t) (3*image->colors); j++)
1833 if (colormap[j] != global_colormap[j])
1835 if (j == (ssize_t) (3*image->colors))
1836 (void) WriteBlobByte(image,(unsigned char) c);
1840 c|=(bits_per_pixel-1); /* size of local colormap */
1841 (void) WriteBlobByte(image,(unsigned char) c);
1842 length=(size_t) (3*(one << bits_per_pixel));
1843 (void) WriteBlob(image,length,colormap);
1846 Write the image data.
1848 c=(int) MagickMax(bits_per_pixel,2);
1849 (void) WriteBlobByte(image,(unsigned char) c);
1850 status=EncodeImage(write_info,image,(size_t) MagickMax(bits_per_pixel,2)+1);
1851 if (status == MagickFalse)
1853 global_colormap=(unsigned char *) RelinquishMagickMemory(
1855 colormap=(unsigned char *) RelinquishMagickMemory(colormap);
1856 write_info=DestroyImageInfo(write_info);
1857 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
1859 (void) WriteBlobByte(image,(unsigned char) 0x00);
1860 if (GetNextImageInList(image) == (Image *) NULL)
1862 image=SyncNextImageInList(image);
1864 status=SetImageProgress(image,SaveImagesTag,scene,
1865 GetImageListLength(image));
1866 if (status == MagickFalse)
1868 } while (write_info->adjoin != MagickFalse);
1869 (void) WriteBlobByte(image,';'); /* terminator */
1870 global_colormap=(unsigned char *) RelinquishMagickMemory(global_colormap);
1871 colormap=(unsigned char *) RelinquishMagickMemory(colormap);
1872 write_info=DestroyImageInfo(write_info);
1873 (void) CloseBlob(image);