2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Read/Write Magick Persistant Cache Image Format %
20 % Copyright 1999-2009 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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
43 #include "magick/studio.h"
44 #include "magick/artifact.h"
45 #include "magick/blob.h"
46 #include "magick/blob-private.h"
47 #include "magick/cache.h"
48 #include "magick/color.h"
49 #include "magick/color-private.h"
50 #include "magick/constitute.h"
51 #include "magick/exception.h"
52 #include "magick/exception-private.h"
53 #include "magick/geometry.h"
54 #include "magick/hashmap.h"
55 #include "magick/image.h"
56 #include "magick/image-private.h"
57 #include "magick/list.h"
58 #include "magick/magick.h"
59 #include "magick/memory_.h"
60 #include "magick/monitor.h"
61 #include "magick/monitor-private.h"
62 #include "magick/option.h"
63 #include "magick/profile.h"
64 #include "magick/property.h"
65 #include "magick/quantum-private.h"
66 #include "magick/static.h"
67 #include "magick/statistic.h"
68 #include "magick/string_.h"
69 #include "magick/module.h"
70 #include "magick/utility.h"
75 static MagickBooleanType
76 WriteMPCImage(const ImageInfo *,Image *);
79 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
87 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
89 % IsMPC() returns MagickTrue if the image format type, identified by the
90 % magick string, is an Magick Persistent Cache image.
92 % The format of the IsMPC method is:
94 % MagickBooleanType IsMPC(const unsigned char *magick,const size_t length)
96 % A description of each parameter follows:
98 % o magick: compare image format pattern against these bytes.
100 % o length: Specifies the length of the magick string.
103 static MagickBooleanType IsMPC(const unsigned char *magick,const size_t length)
107 if (LocaleNCompare((const char *) magick,"id=MagickCache",14) == 0)
113 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
117 % R e a d C A C H E I m a g e %
121 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
123 % ReadMPCImage() reads an Magick Persistent Cache image file and returns
124 % it. It allocates the memory necessary for the new Image structure and
125 % returns a pointer to the new image.
127 % The format of the ReadMPCImage method is:
129 % Image *ReadMPCImage(const ImageInfo *image_info,ExceptionInfo *exception)
131 % Decompression code contributed by Kyle Shorter.
133 % A description of each parameter follows:
135 % o image_info: the image info.
137 % o exception: return any errors or warnings in this structure.
140 static Image *ReadMPCImage(const ImageInfo *image_info,ExceptionInfo *exception)
143 cache_filename[MaxTextExtent],
145 keyword[MaxTextExtent],
191 assert(image_info != (const ImageInfo *) NULL);
192 assert(image_info->signature == MagickSignature);
193 if (image_info->debug != MagickFalse)
194 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
195 image_info->filename);
196 assert(exception != (ExceptionInfo *) NULL);
197 assert(exception->signature == MagickSignature);
198 image=AcquireImage(image_info);
199 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
200 if (status == MagickFalse)
202 image=DestroyImageList(image);
203 return((Image *) NULL);
205 (void) CopyMagickString(cache_filename,image->filename,MaxTextExtent);
206 AppendImageFormat("cache",cache_filename);
207 c=ReadBlobByte(image);
210 image=DestroyImage(image);
211 return((Image *) NULL);
214 (void) ResetMagickMemory(keyword,0,sizeof(keyword));
219 Decode image header; header terminates one character beyond a ':'.
221 profiles=(LinkedListInfo *) NULL;
222 length=MaxTextExtent;
223 options=AcquireString((char *) NULL);
224 quantum_depth=MAGICKCORE_QUANTUM_DEPTH;
226 image->compression=NoCompression;
227 while ((isgraph(c) != MagickFalse) && (c != (int) ':'))
238 Read comment-- any text between { }.
240 length=MaxTextExtent;
241 comment=AcquireString((char *) NULL);
242 for (p=comment; comment != (char *) NULL; p++)
244 c=ReadBlobByte(image);
245 if ((c == EOF) || (c == (int) '}'))
247 if ((size_t) (p-comment+1) >= length)
251 comment=(char *) ResizeQuantumMemory(comment,length+
252 MaxTextExtent,sizeof(*comment));
253 if (comment == (char *) NULL)
255 p=comment+strlen(comment);
259 if (comment == (char *) NULL)
260 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
262 (void) SetImageProperty(image,"comment",comment);
263 comment=DestroyString(comment);
264 c=ReadBlobByte(image);
267 if (isalnum(c) != MagickFalse)
275 if (isspace((int) ((unsigned char) c)) != 0)
279 if ((size_t) (p-keyword) < (MaxTextExtent-1))
281 c=ReadBlobByte(image);
285 while (isspace((int) ((unsigned char) c)) != 0)
286 c=ReadBlobByte(image);
290 Get the keyword value.
292 c=ReadBlobByte(image);
293 while ((c != (int) '}') && (c != EOF))
295 if ((size_t) (p-options+1) >= length)
299 options=(char *) ResizeQuantumMemory(options,length+
300 MaxTextExtent,sizeof(*options));
301 if (options == (char *) NULL)
303 p=options+strlen(options);
305 if (options == (char *) NULL)
306 ThrowReaderException(ResourceLimitError,
307 "MemoryAllocationFailed");
309 c=ReadBlobByte(image);
311 if (isspace((int) ((unsigned char) c)) != 0)
317 (void) CopyMagickString(options,options+1,MaxTextExtent);
319 Assign a value to the specified keyword.
326 if (LocaleCompare(keyword,"background-color") == 0)
328 (void) QueryColorDatabase(options,&image->background_color,
332 if (LocaleCompare(keyword,"blue-primary") == 0)
334 flags=ParseGeometry(options,&geometry_info);
335 image->chromaticity.blue_primary.x=geometry_info.rho;
336 image->chromaticity.blue_primary.y=geometry_info.sigma;
337 if ((flags & SigmaValue) == 0)
338 image->chromaticity.blue_primary.y=
339 image->chromaticity.blue_primary.x;
342 if (LocaleCompare(keyword,"border-color") == 0)
344 (void) QueryColorDatabase(options,&image->border_color,
348 (void) SetImageProperty(image,keyword,options);
354 if (LocaleCompare(keyword,"class") == 0)
359 storage_class=ParseMagickOption(MagickClassOptions,
360 MagickFalse,options);
361 if (storage_class < 0)
363 image->storage_class=(ClassType) storage_class;
366 if (LocaleCompare(keyword,"colors") == 0)
368 image->colors=(unsigned long) atol(options);
371 if (LocaleCompare(keyword,"colorspace") == 0)
376 colorspace=ParseMagickOption(MagickColorspaceOptions,
377 MagickFalse,options);
380 image->colorspace=(ColorspaceType) colorspace;
383 if (LocaleCompare(keyword,"compression") == 0)
388 compression=ParseMagickOption(MagickCompressOptions,
389 MagickFalse,options);
392 image->compression=(CompressionType) compression;
395 if (LocaleCompare(keyword,"columns") == 0)
397 image->columns=(unsigned long) atol(options);
400 (void) SetImageProperty(image,keyword,options);
406 if (LocaleCompare(keyword,"delay") == 0)
408 image->delay=(unsigned long) atol(options);
411 if (LocaleCompare(keyword,"depth") == 0)
413 image->depth=(unsigned long) atol(options);
416 if (LocaleCompare(keyword,"dispose") == 0)
421 dispose=ParseMagickOption(MagickDisposeOptions,MagickFalse,
425 image->dispose=(DisposeType) dispose;
428 (void) SetImageProperty(image,keyword,options);
434 if (LocaleCompare(keyword,"endian") == 0)
439 endian=ParseMagickOption(MagickEndianOptions,MagickFalse,
443 image->endian=(EndianType) endian;
446 if (LocaleCompare(keyword,"error") == 0)
448 image->error.mean_error_per_pixel=atof(options);
451 (void) SetImageProperty(image,keyword,options);
457 if (LocaleCompare(keyword,"gamma") == 0)
459 image->gamma=atof(options);
462 if (LocaleCompare(keyword,"green-primary") == 0)
464 flags=ParseGeometry(options,&geometry_info);
465 image->chromaticity.green_primary.x=geometry_info.rho;
466 image->chromaticity.green_primary.y=geometry_info.sigma;
467 if ((flags & SigmaValue) == 0)
468 image->chromaticity.green_primary.y=
469 image->chromaticity.green_primary.x;
472 (void) SetImageProperty(image,keyword,options);
478 if (LocaleCompare(keyword,"id") == 0)
480 (void) CopyMagickString(id,options,MaxTextExtent);
483 if (LocaleCompare(keyword,"iterations") == 0)
485 image->iterations=(unsigned long) atol(options);
488 (void) SetImageProperty(image,keyword,options);
494 if (LocaleCompare(keyword,"matte") == 0)
499 matte=ParseMagickOption(MagickBooleanOptions,MagickFalse,
503 image->matte=(MagickBooleanType) matte;
506 if (LocaleCompare(keyword,"matte-color") == 0)
508 (void) QueryColorDatabase(options,&image->matte_color,
512 if (LocaleCompare(keyword,"maximum-error") == 0)
514 image->error.normalized_maximum_error=atof(options);
517 if (LocaleCompare(keyword,"mean-error") == 0)
519 image->error.normalized_mean_error=atof(options);
522 if (LocaleCompare(keyword,"montage") == 0)
524 (void) CloneString(&image->montage,options);
527 (void) SetImageProperty(image,keyword,options);
533 if (LocaleCompare(keyword,"opaque") == 0)
538 matte=ParseMagickOption(MagickBooleanOptions,MagickFalse,
542 image->matte=(MagickBooleanType) matte;
545 if (LocaleCompare(keyword,"orientation") == 0)
550 orientation=ParseMagickOption(MagickOrientationOptions,
551 MagickFalse,options);
554 image->orientation=(OrientationType) orientation;
557 (void) SetImageProperty(image,keyword,options);
563 if (LocaleCompare(keyword,"page") == 0)
568 geometry=GetPageGeometry(options);
569 (void) ParseAbsoluteGeometry(geometry,&image->page);
570 geometry=DestroyString(geometry);
573 if ((LocaleNCompare(keyword,"profile:",8) == 0) ||
574 (LocaleNCompare(keyword,"profile-",8) == 0))
576 if (profiles == (LinkedListInfo *) NULL)
577 profiles=NewLinkedList(0);
578 (void) AppendValueToLinkedList(profiles,
579 AcquireString(keyword+8));
580 profile=AcquireStringInfo((size_t) atol(options));
581 (void) SetImageProfile(image,keyword+8,profile);
582 profile=DestroyStringInfo(profile);
585 (void) SetImageProperty(image,keyword,options);
591 if (LocaleCompare(keyword,"quality") == 0)
593 image->quality=(unsigned long) atol(options);
596 if (LocaleCompare(keyword,"quantum-depth") == 0)
598 quantum_depth=(unsigned long) atol(options);
601 (void) SetImageProperty(image,keyword,options);
607 if (LocaleCompare(keyword,"red-primary") == 0)
609 flags=ParseGeometry(options,&geometry_info);
610 image->chromaticity.red_primary.x=geometry_info.rho;
611 if ((flags & SigmaValue) != 0)
612 image->chromaticity.red_primary.y=geometry_info.sigma;
615 if (LocaleCompare(keyword,"rendering-intent") == 0)
620 rendering_intent=ParseMagickOption(MagickIntentOptions,
621 MagickFalse,options);
622 if (rendering_intent < 0)
624 image->rendering_intent=(RenderingIntent) rendering_intent;
627 if (LocaleCompare(keyword,"resolution") == 0)
629 flags=ParseGeometry(options,&geometry_info);
630 image->x_resolution=geometry_info.rho;
631 image->y_resolution=geometry_info.sigma;
632 if ((flags & SigmaValue) == 0)
633 image->y_resolution=image->x_resolution;
636 if (LocaleCompare(keyword,"rows") == 0)
638 image->rows=(unsigned long) atol(options);
641 (void) SetImageProperty(image,keyword,options);
647 if (LocaleCompare(keyword,"scene") == 0)
649 image->scene=(unsigned long) atol(options);
652 (void) SetImageProperty(image,keyword,options);
658 if (LocaleCompare(keyword,"ticks-per-second") == 0)
660 image->ticks_per_second=(long) atol(options);
663 if (LocaleCompare(keyword,"tile-offset") == 0)
668 geometry=GetPageGeometry(options);
669 (void) ParseAbsoluteGeometry(geometry,&image->tile_offset);
670 geometry=DestroyString(geometry);
672 if (LocaleCompare(keyword,"type") == 0)
677 type=ParseMagickOption(MagickTypeOptions,MagickFalse,
681 image->type=(ImageType) type;
684 (void) SetImageProperty(image,keyword,options);
690 if (LocaleCompare(keyword,"units") == 0)
695 units=ParseMagickOption(MagickResolutionOptions,MagickFalse,
699 image->units=(ResolutionType) units;
702 (void) SetImageProperty(image,keyword,options);
708 if (LocaleCompare(keyword,"white-point") == 0)
710 flags=ParseGeometry(options,&geometry_info);
711 image->chromaticity.white_point.x=geometry_info.rho;
712 image->chromaticity.white_point.y=geometry_info.sigma;
713 if ((flags & SigmaValue) == 0)
714 image->chromaticity.white_point.y=
715 image->chromaticity.white_point.x;
718 (void) SetImageProperty(image,keyword,options);
723 (void) SetImageProperty(image,keyword,options);
729 c=ReadBlobByte(image);
730 while (isspace((int) ((unsigned char) c)) != 0)
731 c=ReadBlobByte(image);
733 options=DestroyString(options);
734 (void) ReadBlobByte(image);
736 Verify that required image information is defined.
738 if ((LocaleCompare(id,"MagickCache") != 0) ||
739 (image->storage_class == UndefinedClass) ||
740 (image->compression == UndefinedCompression) || (image->columns == 0) ||
742 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
743 if (quantum_depth != MAGICKCORE_QUANTUM_DEPTH)
744 ThrowReaderException(CacheError,"InconsistentPersistentCacheDepth");
745 if (image->montage != (char *) NULL)
753 length=MaxTextExtent;
754 image->directory=AcquireString((char *) NULL);
759 if ((strlen(image->directory)+MaxTextExtent) >= length)
762 Allocate more memory for the image directory.
765 image->directory=(char *) ResizeQuantumMemory(image->directory,
766 length+MaxTextExtent,sizeof(*image->directory));
767 if (image->directory == (char *) NULL)
768 ThrowReaderException(CorruptImageError,"UnableToReadImageData");
769 p=image->directory+strlen(image->directory);
771 c=ReadBlobByte(image);
773 } while (c != (int) '\0');
775 if (profiles != (LinkedListInfo *) NULL)
783 register unsigned char
789 ResetLinkedListIterator(profiles);
790 name=(const char *) GetNextValueInLinkedList(profiles);
791 while (name != (const char *) NULL)
793 profile=GetImageProfile(image,name);
794 if (profile != (StringInfo *) NULL)
796 p=GetStringInfoDatum(profile);
797 count=ReadBlob(image,GetStringInfoLength(profile),p);
799 name=(const char *) GetNextValueInLinkedList(profiles);
801 profiles=DestroyLinkedList(profiles,RelinquishMagickMemory);
803 depth=GetImageQuantumDepth(image,MagickFalse);
804 if (image->storage_class == PseudoClass)
807 Create image colormap.
809 if (AcquireImageColormap(image,image->colors) == MagickFalse)
810 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
811 if (image->colors != 0)
820 Read image colormap from file.
822 packet_size=(size_t) (3UL*depth/8UL);
823 colormap=(unsigned char *) AcquireQuantumMemory(image->colors,
824 packet_size*sizeof(*colormap));
825 if (colormap == (unsigned char *) NULL)
826 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
827 count=ReadBlob(image,packet_size*image->colors,colormap);
828 if (count != (ssize_t) (packet_size*image->colors))
829 ThrowReaderException(CorruptImageError,
830 "InsufficientImageDataInFile");
835 ThrowReaderException(CorruptImageError,
836 "ImageDepthNotSupported");
842 for (i=0; i < (long) image->colors; i++)
844 p=PushCharPixel(p,&pixel);
845 image->colormap[i].red=ScaleCharToQuantum(pixel);
846 p=PushCharPixel(p,&pixel);
847 image->colormap[i].green=ScaleCharToQuantum(pixel);
848 p=PushCharPixel(p,&pixel);
849 image->colormap[i].blue=ScaleCharToQuantum(pixel);
858 for (i=0; i < (long) image->colors; i++)
860 p=PushShortPixel(MSBEndian,p,&pixel);
861 image->colormap[i].red=ScaleShortToQuantum(pixel);
862 p=PushShortPixel(MSBEndian,p,&pixel);
863 image->colormap[i].green=ScaleShortToQuantum(pixel);
864 p=PushShortPixel(MSBEndian,p,&pixel);
865 image->colormap[i].blue=ScaleShortToQuantum(pixel);
874 for (i=0; i < (long) image->colors; i++)
876 p=PushLongPixel(MSBEndian,p,&pixel);
877 image->colormap[i].red=ScaleLongToQuantum(pixel);
878 p=PushLongPixel(MSBEndian,p,&pixel);
879 image->colormap[i].green=ScaleLongToQuantum(pixel);
880 p=PushLongPixel(MSBEndian,p,&pixel);
881 image->colormap[i].blue=ScaleLongToQuantum(pixel);
886 colormap=(unsigned char *) RelinquishMagickMemory(colormap);
889 if (EOFBlob(image) != MagickFalse)
891 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
895 if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0))
896 if (image->scene >= (image_info->scene+image_info->number_scenes-1))
899 Attach persistent pixel cache.
901 status=PersistPixelCache(image,cache_filename,MagickTrue,&offset,exception);
902 if (status == MagickFalse)
903 ThrowReaderException(CacheError,"UnableToPersistPixelCache");
905 Proceed to next image.
909 c=ReadBlobByte(image);
910 } while ((isgraph(c) == MagickFalse) && (c != EOF));
914 Allocate next image structure.
916 AcquireNextImage(image_info,image);
917 if (GetNextImageInList(image) == (Image *) NULL)
919 image=DestroyImageList(image);
920 return((Image *) NULL);
922 image=SyncNextImageInList(image);
923 status=SetImageProgress(image,LoadImagesTag,TellBlob(image),
925 if (status == MagickFalse)
929 (void) CloseBlob(image);
930 return(GetFirstImageInList(image));
934 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
938 % R e g i s t e r M P C I m a g e %
942 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
944 % RegisterMPCImage() adds properties for the Cache image format to
945 % the list of supported formats. The properties include the image format
946 % tag, a method to read and/or write the format, whether the format
947 % supports the saving of more than one frame to the same file or blob,
948 % whether the format supports native in-memory I/O, and a brief
949 % description of the format.
951 % The format of the RegisterMPCImage method is:
953 % unsigned long RegisterMPCImage(void)
956 ModuleExport unsigned long RegisterMPCImage(void)
961 entry=SetMagickInfo("CACHE");
962 entry->description=ConstantString("Magick Persistent Cache image format");
963 entry->module=ConstantString("CACHE");
964 entry->stealth=MagickTrue;
965 (void) RegisterMagickInfo(entry);
966 entry=SetMagickInfo("MPC");
967 entry->decoder=(DecodeImageHandler *) ReadMPCImage;
968 entry->encoder=(EncodeImageHandler *) WriteMPCImage;
969 entry->magick=(IsImageFormatHandler *) IsMPC;
970 entry->description=ConstantString("Magick Persistent Cache image format");
971 entry->module=ConstantString("MPC");
972 (void) RegisterMagickInfo(entry);
973 return(MagickImageCoderSignature);
977 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
981 % U n r e g i s t e r M P C I m a g e %
985 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
987 % UnregisterMPCImage() removes format registrations made by the
988 % MPC module from the list of supported formats.
990 % The format of the UnregisterMPCImage method is:
992 % UnregisterMPCImage(void)
995 ModuleExport void UnregisterMPCImage(void)
997 (void) UnregisterMagickInfo("CACHE");
998 (void) UnregisterMagickInfo("MPC");
1002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1006 % W r i t e M P C I m a g e %
1010 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1012 % WriteMPCImage() writes an Magick Persistent Cache image to a file.
1014 % The format of the WriteMPCImage method is:
1016 % MagickBooleanType WriteMPCImage(const ImageInfo *image_info,Image *image)
1018 % A description of each parameter follows:
1020 % o image_info: the image info.
1022 % o image: the image.
1025 static MagickBooleanType WriteMPCImage(const ImageInfo *image_info,Image *image)
1028 buffer[MaxTextExtent],
1029 cache_filename[MaxTextExtent];
1049 Open persistent cache.
1051 assert(image_info != (const ImageInfo *) NULL);
1052 assert(image_info->signature == MagickSignature);
1053 assert(image != (Image *) NULL);
1054 assert(image->signature == MagickSignature);
1055 if (image->debug != MagickFalse)
1056 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1057 status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
1058 if (status == MagickFalse)
1060 (void) CopyMagickString(cache_filename,image->filename,MaxTextExtent);
1061 AppendImageFormat("cache",cache_filename);
1067 Write persistent cache meta-information.
1069 depth=GetImageQuantumDepth(image,MagickTrue);
1070 if ((image->storage_class == PseudoClass) &&
1071 (image->colors > (1UL << depth)))
1072 image->storage_class=DirectClass;
1073 (void) WriteBlobString(image,"id=MagickCache\n");
1074 (void) FormatMagickString(buffer,MaxTextExtent,"quantum-depth=%d\n",
1075 MAGICKCORE_QUANTUM_DEPTH);
1076 (void) WriteBlobString(image,buffer);
1077 (void) FormatMagickString(buffer,MaxTextExtent,
1078 "class=%s colors=%lu matte=%s\n",MagickOptionToMnemonic(
1079 MagickClassOptions,image->storage_class),image->colors,
1080 MagickOptionToMnemonic(MagickBooleanOptions,(long) image->matte));
1081 (void) WriteBlobString(image,buffer);
1082 (void) FormatMagickString(buffer,MaxTextExtent,
1083 "columns=%lu rows=%lu depth=%lu\n",image->columns,image->rows,
1085 (void) WriteBlobString(image,buffer);
1086 if (image->type != UndefinedType)
1088 (void) FormatMagickString(buffer,MaxTextExtent,"type=%s\n",
1089 MagickOptionToMnemonic(MagickTypeOptions,image->type));
1090 (void) WriteBlobString(image,buffer);
1092 if (image->colorspace != UndefinedColorspace)
1094 (void) FormatMagickString(buffer,MaxTextExtent,"colorspace=%s\n",
1095 MagickOptionToMnemonic(MagickColorspaceOptions,image->colorspace));
1096 (void) WriteBlobString(image,buffer);
1098 if (image->endian != UndefinedEndian)
1100 (void) FormatMagickString(buffer,MaxTextExtent,"endian=%s\n",
1101 MagickOptionToMnemonic(MagickEndianOptions,image->endian));
1102 (void) WriteBlobString(image,buffer);
1104 if (image->compression != UndefinedCompression)
1106 (void) FormatMagickString(buffer,MaxTextExtent,
1107 "compression=%s quality=%lu\n",MagickOptionToMnemonic(
1108 MagickCompressOptions,image->compression),image->quality);
1109 (void) WriteBlobString(image,buffer);
1111 if (image->units != UndefinedResolution)
1113 (void) FormatMagickString(buffer,MaxTextExtent,"units=%s\n",
1114 MagickOptionToMnemonic(MagickResolutionOptions,image->units));
1115 (void) WriteBlobString(image,buffer);
1117 if ((image->x_resolution != 0) || (image->y_resolution != 0))
1119 (void) FormatMagickString(buffer,MaxTextExtent,"resolution=%gx%g\n",
1120 image->x_resolution,image->y_resolution);
1121 (void) WriteBlobString(image,buffer);
1123 if ((image->page.width != 0) || (image->page.height != 0))
1125 (void) FormatMagickString(buffer,MaxTextExtent,"page=%lux%lu%+ld%+ld\n",
1126 image->page.width,image->page.height,image->page.x,image->page.y);
1127 (void) WriteBlobString(image,buffer);
1130 if ((image->page.x != 0) || (image->page.y != 0))
1132 (void) FormatMagickString(buffer,MaxTextExtent,"page=%+ld%+ld\n",
1133 image->page.x,image->page.y);
1134 (void) WriteBlobString(image,buffer);
1136 if ((image->page.x != 0) || (image->page.y != 0))
1138 (void) FormatMagickString(buffer,MaxTextExtent,"tile-offset=%+ld%+ld\n",
1139 image->tile_offset.x,image->tile_offset.y);
1140 (void) WriteBlobString(image,buffer);
1142 if ((GetNextImageInList(image) != (Image *) NULL) ||
1143 (GetPreviousImageInList(image) != (Image *) NULL))
1145 if (image->scene == 0)
1146 (void) FormatMagickString(buffer,MaxTextExtent,
1147 "iterations=%lu delay=%lu ticks-per-second=%lu\n",
1148 image->iterations,image->delay,image->ticks_per_second);
1150 (void) FormatMagickString(buffer,MaxTextExtent,
1151 "scene=%lu iterations=%lu delay=%lu ticks-per-second=%lu\n",
1152 image->scene,image->iterations,image->delay,
1153 image->ticks_per_second);
1154 (void) WriteBlobString(image,buffer);
1158 if (image->scene != 0)
1160 (void) FormatMagickString(buffer,MaxTextExtent,"scene=%lu\n",
1162 (void) WriteBlobString(image,buffer);
1164 if (image->iterations != 0)
1166 (void) FormatMagickString(buffer,MaxTextExtent,"iterations=%lu\n",
1168 (void) WriteBlobString(image,buffer);
1170 if (image->delay != 0)
1172 (void) FormatMagickString(buffer,MaxTextExtent,"delay=%lu\n",
1174 (void) WriteBlobString(image,buffer);
1176 if (image->ticks_per_second != UndefinedTicksPerSecond)
1178 (void) FormatMagickString(buffer,MaxTextExtent,
1179 "ticks-per-second=%lu\n",image->ticks_per_second);
1180 (void) WriteBlobString(image,buffer);
1183 if (image->gravity != UndefinedGravity)
1185 (void) FormatMagickString(buffer,MaxTextExtent,"gravity=%s\n",
1186 MagickOptionToMnemonic(MagickGravityOptions,image->gravity));
1187 (void) WriteBlobString(image,buffer);
1189 if (image->dispose != UndefinedDispose)
1191 (void) FormatMagickString(buffer,MaxTextExtent,"dispose=%s\n",
1192 MagickOptionToMnemonic(MagickDisposeOptions,image->dispose));
1193 (void) WriteBlobString(image,buffer);
1195 if (image->rendering_intent != UndefinedIntent)
1197 (void) FormatMagickString(buffer,MaxTextExtent,
1198 "rendering-intent=%s\n",
1199 MagickOptionToMnemonic(MagickIntentOptions,image->rendering_intent));
1200 (void) WriteBlobString(image,buffer);
1202 if (image->gamma != 0.0)
1204 (void) FormatMagickString(buffer,MaxTextExtent,"gamma=%g\n",
1206 (void) WriteBlobString(image,buffer);
1208 if (image->chromaticity.white_point.x != 0.0)
1211 Note chomaticity points.
1213 (void) FormatMagickString(buffer,MaxTextExtent,
1214 "red-primary=%g,%g green-primary=%g,%g blue-primary=%g,%g\n",
1215 image->chromaticity.red_primary.x,image->chromaticity.red_primary.y,
1216 image->chromaticity.green_primary.x,
1217 image->chromaticity.green_primary.y,
1218 image->chromaticity.blue_primary.x,
1219 image->chromaticity.blue_primary.y);
1220 (void) WriteBlobString(image,buffer);
1221 (void) FormatMagickString(buffer,MaxTextExtent,"white-point=%g,%g\n",
1222 image->chromaticity.white_point.x,image->chromaticity.white_point.y);
1223 (void) WriteBlobString(image,buffer);
1225 if (image->orientation != UndefinedOrientation)
1227 (void) FormatMagickString(buffer,MaxTextExtent,
1228 "orientation=%s\n",MagickOptionToMnemonic(MagickOrientationOptions,
1229 image->orientation));
1230 (void) WriteBlobString(image,buffer);
1232 if (image->profiles != (void *) NULL)
1243 ResetImageProfileIterator(image);
1244 for (name=GetNextImageProfile(image); name != (const char *) NULL; )
1246 profile=GetImageProfile(image,name);
1247 if (profile != (StringInfo *) NULL)
1249 (void) FormatMagickString(buffer,MaxTextExtent,"profile:%s=%lu\n",
1250 name,(unsigned long) GetStringInfoLength(profile));
1251 (void) WriteBlobString(image,buffer);
1253 name=GetNextImageProfile(image);
1256 if (image->montage != (char *) NULL)
1258 (void) FormatMagickString(buffer,MaxTextExtent,"montage=%s\n",
1260 (void) WriteBlobString(image,buffer);
1262 ResetImagePropertyIterator(image);
1263 property=GetNextImageProperty(image);
1264 while (property != (const char *) NULL)
1266 (void) FormatMagickString(buffer,MaxTextExtent,"%s=",property);
1267 (void) WriteBlobString(image,buffer);
1268 value=GetImageProperty(image,property);
1269 if (value != (const char *) NULL)
1271 for (i=0; i < (long) strlen(value); i++)
1272 if (isspace((int) ((unsigned char) value[i])) != 0)
1274 if (i <= (long) strlen(value))
1275 (void) WriteBlobByte(image,'{');
1276 (void) WriteBlob(image,strlen(value),(unsigned char *) value);
1277 if (i <= (long) strlen(value))
1278 (void) WriteBlobByte(image,'}');
1280 (void) WriteBlobByte(image,'\n');
1281 property=GetNextImageProperty(image);
1283 ResetImageArtifactIterator(image);
1284 (void) WriteBlobString(image,"\f\n:\032");
1285 if (image->montage != (char *) NULL)
1288 Write montage tile directory.
1290 if (image->directory != (char *) NULL)
1291 (void) WriteBlobString(image,image->directory);
1292 (void) WriteBlobByte(image,'\0');
1294 if (image->profiles != 0)
1303 Write image profiles.
1305 ResetImageProfileIterator(image);
1306 name=GetNextImageProfile(image);
1307 while (name != (const char *) NULL)
1309 profile=GetImageProfile(image,name);
1310 (void) WriteBlob(image,GetStringInfoLength(profile),
1311 GetStringInfoDatum(profile));
1312 name=GetNextImageProfile(image);
1315 if (image->storage_class == PseudoClass)
1327 packet_size=(size_t) (3UL*depth/8UL);
1328 colormap=(unsigned char *) AcquireQuantumMemory(image->colors,
1329 packet_size*sizeof(*colormap));
1330 if (colormap == (unsigned char *) NULL)
1331 return(MagickFalse);
1333 Write colormap to file.
1336 for (i=0; i < (long) image->colors; i++)
1341 ThrowWriterException(CorruptImageError,"ImageDepthNotSupported");
1347 pixel=ScaleQuantumToLong(image->colormap[i].red);
1348 q=PopLongPixel(MSBEndian,pixel,q);
1349 pixel=ScaleQuantumToLong(image->colormap[i].green);
1350 q=PopLongPixel(MSBEndian,pixel,q);
1351 pixel=ScaleQuantumToLong(image->colormap[i].blue);
1352 q=PopLongPixel(MSBEndian,pixel,q);
1359 pixel=ScaleQuantumToShort(image->colormap[i].red);
1360 q=PopShortPixel(MSBEndian,pixel,q);
1361 pixel=ScaleQuantumToShort(image->colormap[i].green);
1362 q=PopShortPixel(MSBEndian,pixel,q);
1363 pixel=ScaleQuantumToShort(image->colormap[i].blue);
1364 q=PopShortPixel(MSBEndian,pixel,q);
1372 pixel=(unsigned char) ScaleQuantumToChar(image->colormap[i].red);
1373 q=PopCharPixel(pixel,q);
1374 pixel=(unsigned char) ScaleQuantumToChar(
1375 image->colormap[i].green);
1376 q=PopCharPixel(pixel,q);
1377 pixel=(unsigned char) ScaleQuantumToChar(image->colormap[i].blue);
1378 q=PopCharPixel(pixel,q);
1383 (void) WriteBlob(image,packet_size*image->colors,colormap);
1384 colormap=(unsigned char *) RelinquishMagickMemory(colormap);
1387 Initialize persistent pixel cache.
1389 status=PersistPixelCache(image,cache_filename,MagickFalse,&offset,
1391 if (status == MagickFalse)
1392 ThrowWriterException(CacheError,"UnableToPersistPixelCache");
1393 if (GetNextImageInList(image) == (Image *) NULL)
1395 image=SyncNextImageInList(image);
1396 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1398 status=image->progress_monitor(SaveImagesTag,scene,
1399 GetImageListLength(image),image->client_data);
1400 if (status == MagickFalse)
1404 } while (image_info->adjoin != MagickFalse);
1405 (void) CloseBlob(image);