2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % ImageMagickObject BLOB Interface. %
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. %
35 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37 % This coder is a kind of backdoor used by the COM object that allows it to %
38 % pass blobs back and forth using the coder interface. It simply encodes and %
39 % decodes the filename as a comma delimited string and extracts the info it %
48 #include "MagickCore/studio.h"
49 #include "MagickCore/blob.h"
50 #include "MagickCore/blob-private.h"
51 #include "MagickCore/constitute.h"
52 #include "MagickCore/delegate.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/MagickCore.h"
59 #include "MagickCore/memory_.h"
60 #include "MagickCore/string_.h"
61 #if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(__MINGW32__)
62 #define WIN32_LEAN_AND_MEAN
70 static MagickBooleanType
71 WriteXTRNImage(const ImageInfo *,Image *,ExceptionInfo *exception);
75 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
79 % R e a d X T R N I m a g e %
83 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
85 % ReadXTRNImage() reads a XTRN image file and returns it. It
86 % allocates the memory necessary for the new Image structure and returns a
87 % pointer to the new image.
89 % The format of the ReadXTRNImage method is:
91 % Image *ReadXTRNImage(const ImageInfo *image_info,
92 % ExceptionInfo *exception)
94 % A description of each parameter follows:
96 % o image_info: Specifies a pointer to an ImageInfo structure.
98 % o exception: return any errors or warnings in this structure.
101 #if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(__MINGW32__)
102 static Image *ReadXTRNImage(const ImageInfo *image_info,
103 ExceptionInfo *exception)
107 filename[MagickPathExtent];
131 param1=(void *) NULL;
132 image=(Image *) NULL;
133 clone_info=CloneImageInfo(image_info);
134 if (clone_info->filename == NULL)
136 clone_info=DestroyImageInfo(clone_info);
137 ThrowReaderException(FileOpenWarning,"No filename specified");
140 (void) sscanf(clone_info->filename,"%p,%2048s",¶m1,filename);
142 pSafeArray=(SAFEARRAY *) param1;
145 hr=SafeArrayGetLBound(pSafeArray,1,&lBoundl);
148 hr=SafeArrayGetUBound(pSafeArray,1,&lBoundu);
151 blob_length=lBoundu-lBoundl+1;
152 hr=SafeArrayAccessData(pSafeArray,(void**) &blob_data);
155 *clone_info->filename='\0';
156 *clone_info->magick='\0';
157 if (*filename != '\0')
158 (void) CopyMagickString(clone_info->filename,filename,
160 image=BlobToImage(clone_info,blob_data,blob_length,
162 hr=SafeArrayUnaccessData(pSafeArray);
163 CatchException(exception);
168 clone_info=DestroyImageInfo(clone_info);
174 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
178 % R e g i s t e r X T R N I m a g e %
182 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
184 % RegisterXTRNImage() adds attributes for the XTRN 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 RegisterXTRNImage method is:
193 % size_t RegisterXTRNImage(void)
196 ModuleExport size_t RegisterXTRNImage(void)
201 entry=AcquireMagickInfo("XTRN","XTRNARRAY",
202 "External transfer via a smart array interface");
203 #if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(__MINGW32__)
204 entry->decoder=ReadXTRNImage;
205 entry->encoder=WriteXTRNImage;
207 entry->flags^=CoderAdjoinFlag;
208 entry->flags|=CoderStealthFlag;
209 RegisterMagickInfo(entry);
210 return(MagickImageCoderSignature);
214 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
218 % U n r e g i s t e r X T R N I m a g e %
222 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
224 % UnregisterXTRNImage() removes format registrations made by the
225 % XTRN module from the list of supported formats.
227 % The format of the UnregisterXTRNImage method is:
229 % UnregisterXTRNImage(void)
232 ModuleExport void UnregisterXTRNImage(void)
234 UnregisterMagickInfo("XTRNARRAY");
238 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
242 % W r i t e X T R N I m a g e %
246 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
248 % WriteXTRNImage() writes an image in the XTRN encoded image format.
249 % We use GIF because it is the only format that is compressed without
250 % requiring additional optional delegates (TIFF, ZIP, etc).
252 % The format of the WriteXTRNImage method is:
254 % MagickBooleanType WriteXTRNImage(const ImageInfo *image_info,
255 % Image *image,ExceptionInfo *exception)
257 % A description of each parameter follows.
259 % o image_info: Specifies a pointer to an ImageInfo structure.
261 % o image: A pointer to a Image structure.
263 % o exception: return any errors or warnings in this structure.
267 #if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(__MINGW32__)
268 static size_t SafeArrayFifo(const Image *image,const void *data,
271 SAFEARRAYBOUND NewArrayBounds[1]; /* 1 Dimension */
273 SAFEARRAY *pSafeArray = (SAFEARRAY *)image->client_data;
274 if (pSafeArray != NULL)
276 long lBoundl, lBoundu, lCount;
278 /* First see how big the buffer currently is */
279 hr = SafeArrayGetLBound(pSafeArray, 1, &lBoundl);
282 hr = SafeArrayGetUBound(pSafeArray, 1, &lBoundu);
285 lCount = lBoundu - lBoundl + 1;
289 unsigned char *pReturnBuffer = NULL;
290 NewArrayBounds[0].lLbound = 0; /* Start-Index 0 */
291 NewArrayBounds[0].cElements = (unsigned long) (length+lCount); /* # Elemente */
292 hr = SafeArrayRedim(pSafeArray, NewArrayBounds);
295 hr = SafeArrayAccessData(pSafeArray, (void**)&pReturnBuffer);
298 (void) memcpy(pReturnBuffer+lCount,(unsigned char *) data,length);
299 hr=SafeArrayUnaccessData(pSafeArray);
305 /* Adjust the length of the buffer to fit */
311 static MagickBooleanType WriteXTRNImage(const ImageInfo *image_info,
312 Image *image,ExceptionInfo *exception)
315 filename[MagickPathExtent];
338 param1 = (void *) NULL;
340 clone_info=CloneImageInfo(image_info);
341 if (*clone_info->filename != '\0')
343 (void) sscanf(clone_info->filename,"%p,%2048s",¶m1,filename);
344 image->client_data=param1;
346 (void) CopyMagickString(clone_info->filename,filename,
348 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
350 (void) CopyMagickString(p->filename,filename,MagickPathExtent);
353 SetImageInfo(clone_info,1,exception);
354 (void) CopyMagickString(image->magick,clone_info->magick,
356 blob_data=ImageToBlob(clone_info,image,&blob_length,
358 if (blob_data == (unsigned char *) NULL)
361 SafeArrayFifo(image,blob_data,blob_length);
362 if (status == MagickFalse)
363 CatchImageException(image);
365 clone_info=DestroyImageInfo(clone_info);