2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 % IIIII N N L IIIII N N EEEEE %
8 % I N N N L I N N N EEE %
10 % IIIII N N LLLLL IIIII N N EEEEE %
13 % Read Inline Images %
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/blob.h"
44 #include "MagickCore/blob-private.h"
45 #include "MagickCore/client.h"
46 #include "MagickCore/display.h"
47 #include "MagickCore/exception.h"
48 #include "MagickCore/exception-private.h"
49 #include "MagickCore/image.h"
50 #include "MagickCore/image-private.h"
51 #include "MagickCore/list.h"
52 #include "MagickCore/magick.h"
53 #include "MagickCore/memory_.h"
54 #include "MagickCore/option.h"
55 #include "MagickCore/quantum-private.h"
56 #include "MagickCore/static.h"
57 #include "MagickCore/string_.h"
58 #include "MagickCore/module.h"
59 #include "MagickCore/utility.h"
60 #include "MagickCore/xwindow.h"
61 #include "MagickCore/xwindow-private.h"
64 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
68 % R e a d I N L I N E I m a g e %
72 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
74 % ReadINLINEImage() reads base64-encoded inlines images.
76 % The format of the ReadINLINEImage method is:
78 % Image *ReadINLINEImage(const ImageInfo *image_info,
79 % ExceptionInfo *exception)
81 % A description of each parameter follows:
83 % o image_info: the image info.
85 % o exception: return any errors or warnings in this structure.
89 static inline size_t MagickMin(const size_t x,const size_t y)
96 static Image *ReadINLINEImage(const ImageInfo *image_info,
97 ExceptionInfo *exception)
120 assert(image_info != (const ImageInfo *) NULL);
121 assert(image_info->signature == MagickSignature);
122 if (image_info->debug != MagickFalse)
123 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
124 image_info->filename);
125 assert(exception != (ExceptionInfo *) NULL);
126 assert(exception->signature == MagickSignature);
127 if (LocaleNCompare(image_info->filename,"data:",5) == 0)
128 return(ReadInlineImage(image_info,image_info->filename,exception));
129 image=AcquireImage(image_info,exception);
130 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
131 if (status == MagickFalse)
133 image=DestroyImageList(image);
134 return((Image *) NULL);
136 quantum=MagickMin((size_t) GetBlobSize(image),MagickMaxBufferExtent);
137 inline_image=(unsigned char *) AcquireQuantumMemory(quantum,
138 sizeof(*inline_image));
139 for (i=0; inline_image != (unsigned char *) NULL; i+=count)
141 count=(ssize_t) ReadBlob(image,quantum,inline_image+i);
148 if (~(1UL*i) < (quantum+1))
150 inline_image=(unsigned char *) RelinquishMagickMemory(inline_image);
153 inline_image=(unsigned char *) ResizeQuantumMemory(inline_image,i+quantum+1,
154 sizeof(*inline_image));
156 if (inline_image == (unsigned char *) NULL)
158 (void) ThrowMagickException(exception,GetMagickModule(),
159 ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
160 return((Image *) NULL);
162 inline_image[i+count]='\0';
163 image=DestroyImageList(image);
164 image=ReadInlineImage(image_info,(char *) inline_image,exception);
165 inline_image=(unsigned char *) RelinquishMagickMemory(inline_image);
170 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
174 % R e g i s t e r I N L I N E I m a g e %
178 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
180 % RegisterINLINEImage() adds attributes for the INLINE image format to
181 % the list of supported formats. The attributes include the image format
182 % tag, a method to read and/or write the format, whether the format
183 % supports the saving of more than one frame to the same file or blob,
184 % whether the format supports native in-memory I/O, and a brief
185 % description of the format.
187 % The format of the RegisterINLINEImage method is:
189 % size_t RegisterINLINEImage(void)
192 ModuleExport size_t RegisterINLINEImage(void)
197 entry=SetMagickInfo("INLINE");
198 entry->decoder=(DecodeImageHandler *) ReadINLINEImage;
199 entry->format_type=ImplicitFormatType;
200 entry->description=ConstantString("Base64-encoded inline images");
201 entry->module=ConstantString("INLINE");
202 (void) RegisterMagickInfo(entry);
203 return(MagickImageCoderSignature);
207 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
211 % U n r e g i s t e r I N L I N E I m a g e %
215 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
217 % UnregisterINLINEImage() removes format registrations made by the
218 % INLINE module from the list of supported formats.
220 % The format of the UnregisterINLINEImage method is:
222 % UnregisterINLINEImage(void)
225 ModuleExport void UnregisterINLINEImage(void)
227 (void) UnregisterMagickInfo("INLINE");