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-2014 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/constitute.h"
47 #include "MagickCore/display.h"
48 #include "MagickCore/exception.h"
49 #include "MagickCore/exception-private.h"
50 #include "MagickCore/image.h"
51 #include "MagickCore/image-private.h"
52 #include "MagickCore/list.h"
53 #include "MagickCore/magick.h"
54 #include "MagickCore/memory_.h"
55 #include "MagickCore/option.h"
56 #include "MagickCore/quantum-private.h"
57 #include "MagickCore/static.h"
58 #include "MagickCore/string_.h"
59 #include "MagickCore/module.h"
60 #include "MagickCore/utility.h"
61 #include "MagickCore/xwindow.h"
62 #include "MagickCore/xwindow-private.h"
65 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
69 % R e a d I N L I N E I m a g e %
73 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75 % ReadINLINEImage() reads base64-encoded inlines images.
77 % The format of the ReadINLINEImage method is:
79 % Image *ReadINLINEImage(const ImageInfo *image_info,
80 % ExceptionInfo *exception)
82 % A description of each parameter follows:
84 % o image_info: the image info.
86 % o exception: return any errors or warnings in this structure.
90 static inline size_t MagickMin(const size_t x,const size_t y)
97 static Image *ReadINLINEImage(const ImageInfo *image_info,
98 ExceptionInfo *exception)
121 assert(image_info != (const ImageInfo *) NULL);
122 assert(image_info->signature == MagickSignature);
123 if (image_info->debug != MagickFalse)
124 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
125 image_info->filename);
126 assert(exception != (ExceptionInfo *) NULL);
127 assert(exception->signature == MagickSignature);
128 if (LocaleNCompare(image_info->filename,"data:",5) == 0)
129 return(ReadInlineImage(image_info,image_info->filename,exception));
130 image=AcquireImage(image_info,exception);
131 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
132 if (status == MagickFalse)
134 image=DestroyImageList(image);
135 return((Image *) NULL);
137 quantum=MagickMin((size_t) GetBlobSize(image),MagickMaxBufferExtent);
139 quantum=MagickMaxBufferExtent;
140 inline_image=(unsigned char *) AcquireQuantumMemory(quantum,
141 sizeof(*inline_image));
143 for (i=0; inline_image != (unsigned char *) NULL; i+=count)
145 count=(ssize_t) ReadBlob(image,quantum,inline_image+i);
152 if (~((size_t) i) < (quantum+1))
154 inline_image=(unsigned char *) RelinquishMagickMemory(inline_image);
157 inline_image=(unsigned char *) ResizeQuantumMemory(inline_image,i+quantum+1,
158 sizeof(*inline_image));
160 if (inline_image == (unsigned char *) NULL)
162 (void) ThrowMagickException(exception,GetMagickModule(),
163 ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
164 return((Image *) NULL);
166 inline_image[i+count]='\0';
167 image=DestroyImageList(image);
168 image=ReadInlineImage(image_info,(char *) inline_image,exception);
169 inline_image=(unsigned char *) RelinquishMagickMemory(inline_image);
174 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
178 % R e g i s t e r I N L I N E I m a g e %
182 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
184 % RegisterINLINEImage() adds attributes for the INLINE image format to
185 % the list of supported formats. The attributes include the image format
186 % tag, a method to read and/or write the format, whether the format
187 % supports the saving of more than one frame to the same file or blob,
188 % whether the format supports native in-memory I/O, and a brief
189 % description of the format.
191 % The format of the RegisterINLINEImage method is:
193 % size_t RegisterINLINEImage(void)
196 ModuleExport size_t RegisterINLINEImage(void)
201 entry=SetMagickInfo("INLINE");
202 entry->decoder=(DecodeImageHandler *) ReadINLINEImage;
203 entry->format_type=ImplicitFormatType;
204 entry->description=ConstantString("Base64-encoded inline images");
205 entry->module=ConstantString("INLINE");
206 (void) RegisterMagickInfo(entry);
207 return(MagickImageCoderSignature);
211 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
215 % U n r e g i s t e r I N L I N E I m a g e %
219 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
221 % UnregisterINLINEImage() removes format registrations made by the
222 % INLINE module from the list of supported formats.
224 % The format of the UnregisterINLINEImage method is:
226 % UnregisterINLINEImage(void)
229 ModuleExport void UnregisterINLINEImage(void)
231 (void) UnregisterMagickInfo("INLINE");