2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % ImageMagickObject BLOB Interface. %
20 % Copyright 1999-2007 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. %
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 %
40 % needs. The five methods of passing images are: %
42 % FILE - same thing as filename so it should be a NOP %
43 % IMAGE - passes an image and image info structure %
44 % BLOB - passes binary blob containining the image %
45 % STREAM - passes pointers to stream hooks in and does the hooking %
46 % ARRAY - passes a pointer to a Win32 smart array and streams to it %
48 % Of all of these, the only one getting any real use at the moment is the %
49 % ARRAY handler. It is the primary way that images are shuttled back and %
50 % forth as blobs via COM since this is what VB and VBSCRIPT use internally %
59 #if defined(_VISUALC_)
60 #include "magick/studio.h"
61 #include "magick/blob.h"
62 #include "magick/blob-private.h"
63 #include "magick/constitute.h"
64 #include "magick/delegate.h"
65 #include "magick/exception.h"
66 #include "magick/exception-private.h"
67 #include "magick/image.h"
68 #include "magick/image-private.h"
69 #include "magick/list.h"
70 #include "magick/magick.h"
71 #include "magick/memory_.h"
72 #include "magick/string_.h"
73 #define WIN32_LEAN_AND_MEAN
81 static MagickBooleanType
82 WriteXTRNImage(const ImageInfo *,Image *);
85 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
89 % R e a d X T R N I m a g e %
93 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
95 % ReadXTRNImage() reads a XTRN image file and returns it. It
96 % allocates the memory necessary for the new Image structure and returns a
97 % pointer to the new image.
99 % The format of the ReadXTRNImage method is:
101 % Image *ReadXTRNImage(const ImageInfo *image_info,
102 % ExceptionInfo *exception)
104 % A description of each parameter follows:
106 % o image_info: Specifies a pointer to an ImageInfo structure.
108 % o exception: return any errors or warnings in this structure.
111 static Image *ReadXTRNImage(const ImageInfo *image_info,
112 ExceptionInfo *exception)
125 param1 = param2 = param3 = (void *) NULL;
126 image = (Image *) NULL;
127 clone_info=CloneImageInfo(image_info);
128 if (clone_info->filename == NULL)
130 clone_info=DestroyImageInfo(clone_info);
131 ThrowReaderException(FileOpenWarning,"No filename specified");
133 if (LocaleCompare(image_info->magick,"XTRNFILE") == 0)
135 image=ReadImage(clone_info,exception);
136 CatchException(exception);
138 else if (LocaleCompare(image_info->magick,"XTRNIMAGE") == 0)
148 (void) sscanf(clone_info->filename,"%lx,%lx",¶m1,¶m2);
149 image_ptr=(Image **) param2;
150 if (*image_ptr != (Image *)NULL)
151 image=CloneImage(*image_ptr,0,0,MagickFalse,&(*image_ptr)->exception);
153 image_info_ptr=(ImageInfo **) param1;
154 if (*image_info_ptr != (ImageInfo *)NULL)
155 image_info=*image_info_ptr;
158 else if (LocaleCompare(image_info->magick,"XTRNBLOB") == 0)
167 filename[MaxTextExtent];
169 (void) sscanf(clone_info->filename,"%lx,%lx,%s",¶m1,¶m2,&filename);
170 blob_data=(char **) param1;
171 blob_length=(size_t *) param2;
172 image=BlobToImage(clone_info,*blob_data,*blob_length,exception);
173 CatchException(exception);
175 else if (LocaleCompare(image_info->magick,"XTRNARRAY") == 0)
194 filename[MaxTextExtent];
197 (void) sscanf(clone_info->filename,"%lx,%s",¶m1,&filename);
199 pSafeArray = (SAFEARRAY *) param1;
202 hr = SafeArrayGetLBound(pSafeArray, 1, &lBoundl);
204 hr = SafeArrayGetUBound(pSafeArray, 1, &lBoundu);
207 blob_length = lBoundu - lBoundl + 1;
208 hr = SafeArrayAccessData(pSafeArray, (void**)&blob_data);
211 if (*filename != '\0')
213 (void) CopyMagickString(clone_info->filename,filename,
215 (void) CopyMagickString(clone_info->magick,filename,
220 *clone_info->magick = '\0';
221 *clone_info->filename = '\0';
223 image=BlobToImage(clone_info,blob_data,blob_length,exception);
224 hr = SafeArrayUnaccessData(pSafeArray);
225 CatchException(exception);
230 clone_info=DestroyImageInfo(clone_info);
235 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
239 % R e g i s t e r X T R N I m a g e %
243 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
245 % RegisterXTRNImage() adds attributes for the XTRN image format to
246 % the list of supported formats. The attributes include the image format
247 % tag, a method to read and/or write the format, whether the format
248 % supports the saving of more than one frame to the same file or blob,
249 % whether the format supports native in-memory I/O, and a brief
250 % description of the format.
252 % The format of the RegisterXTRNImage method is:
254 % RegisterXTRNImage(void)
257 ModuleExport void RegisterXTRNImage(void)
262 entry=SetMagickInfo("XTRNFILE");
263 entry->decoder=ReadXTRNImage;
264 entry->encoder=WriteXTRNImage;
265 entry->adjoin=MagickFalse;
266 entry->stealth=MagickTrue;
267 entry->description=ConstantString("External transfer of a file");
268 entry->module=ConstantString("XTRN");
269 RegisterMagickInfo(entry);
271 entry=SetMagickInfo("XTRNIMAGE");
272 entry->decoder=ReadXTRNImage;
273 entry->encoder=WriteXTRNImage;
274 entry->adjoin=MagickFalse;
275 entry->stealth=MagickTrue;
276 entry->description=ConstantString("External transfer of a image in memory");
277 entry->module=ConstantString("XTRN");
278 RegisterMagickInfo(entry);
280 entry=SetMagickInfo("XTRNBLOB");
281 entry->decoder=ReadXTRNImage;
282 entry->encoder=WriteXTRNImage;
283 entry->adjoin=MagickFalse;
284 entry->stealth=MagickTrue;
285 entry->description=ConstantString("IExternal transfer of a blob in memory");
286 entry->module=ConstantString("XTRN");
287 RegisterMagickInfo(entry);
289 entry=SetMagickInfo("XTRNARRAY");
290 entry->decoder=ReadXTRNImage;
291 entry->encoder=WriteXTRNImage;
292 entry->adjoin=MagickFalse;
293 entry->stealth=MagickTrue;
294 entry->description=ConstantString("External transfer via a smart array interface");
295 entry->module=ConstantString("XTRN");
296 RegisterMagickInfo(entry);
300 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
304 % U n r e g i s t e r X T R N I m a g e %
308 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
310 % UnregisterXTRNImage() removes format registrations made by the
311 % XTRN module from the list of supported formats.
313 % The format of the UnregisterXTRNImage method is:
315 % UnregisterXTRNImage(void)
318 ModuleExport void UnregisterXTRNImage(void)
320 UnregisterMagickInfo("XTRNFILE");
321 UnregisterMagickInfo("XTRNIMAGE");
322 UnregisterMagickInfo("XTRNBLOB");
323 UnregisterMagickInfo("XTRNARRAY");
327 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
331 % W r i t e X T R N I m a g e %
335 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
337 % WriteXTRNImage() writes an image in the XTRN encoded image format.
338 % We use GIF because it is the only format that is compressed without
339 % requiring addition optional delegates (TIFF, ZIP, etc).
341 % The format of the WriteXTRNImage method is:
343 % MagickBooleanType WriteXTRNImage(const ImageInfo *image_info,Image *image)
345 % A description of each parameter follows.
347 % o image_info: Specifies a pointer to an ImageInfo structure.
349 % o image: A pointer to a Image structure.
354 size_t SafeArrayFifo(const Image *image,const void *data,const size_t length)
356 SAFEARRAYBOUND NewArrayBounds[1]; /* 1 Dimension */
358 SAFEARRAY *pSafeArray = (SAFEARRAY *)image->client_data;
359 if (pSafeArray != NULL)
361 long lBoundl, lBoundu, lCount;
363 /* First see how big the buffer currently is */
364 hr = SafeArrayGetLBound(pSafeArray, 1, &lBoundl);
367 hr = SafeArrayGetUBound(pSafeArray, 1, &lBoundu);
370 lCount = lBoundu - lBoundl + 1;
374 unsigned char *pReturnBuffer = NULL;
375 NewArrayBounds[0].lLbound = 0; /* Start-Index 0 */
376 NewArrayBounds[0].cElements = (unsigned long) (length+lCount); /* # Elemente */
377 hr = SafeArrayRedim(pSafeArray, NewArrayBounds);
380 hr = SafeArrayAccessData(pSafeArray, (void**)&pReturnBuffer);
383 (void) memcpy( pReturnBuffer+lCount, (unsigned char *)data, length );
384 hr = SafeArrayUnaccessData(pSafeArray);
390 /* Adjust the length of the buffer to fit */
396 static MagickBooleanType WriteXTRNImage(const ImageInfo *image_info,Image *image)
415 param1 = param2 = param3 = (void *) NULL;
416 if (LocaleCompare(image_info->magick,"XTRNFILE") == 0)
418 clone_info=CloneImageInfo(image_info);
419 status=WriteImage(image_info,image);
420 if (status == MagickFalse)
421 CatchImageException(image);
422 clone_info=DestroyImageInfo(clone_info);
424 else if (LocaleCompare(image_info->magick,"XTRNIMAGE") == 0)
432 clone_info=CloneImageInfo(image_info);
433 if (clone_info->filename[0])
435 (void) sscanf(clone_info->filename,"%lx,%lx",¶m1,¶m2);
436 image_info_ptr=(ImageInfo **) param1;
437 image_ptr=(Image **) param2;
438 if ((image_info_ptr != (ImageInfo **) NULL) &&
439 (image_ptr != (Image **) NULL))
441 *image_ptr=CloneImage(image,0,0,MagickFalse,&(image->exception));
442 *image_info_ptr=clone_info;
446 else if (LocaleCompare(image_info->magick,"XTRNBLOB") == 0)
458 filename[MaxTextExtent];
460 clone_info=CloneImageInfo(image_info);
461 if (clone_info->filename[0])
463 (void) sscanf(clone_info->filename,"%lx,%lx,%s",
464 ¶m1,¶m2,&filename);
466 blob_data=(char **) param1;
467 blob_length=(size_t *) param2;
470 (void) CopyMagickString(clone_info->filename,filename,MaxTextExtent);
471 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
473 (void) CopyMagickString(p->filename,filename,MaxTextExtent);
476 SetImageInfo(clone_info,1,&image->exception);
477 (void) CopyMagickString(image->magick,clone_info->magick,
479 GetExceptionInfo(&exception);
480 if (*blob_length == 0)
482 *blob_data=(char *) ImageToBlob(clone_info,image,blob_length,
484 if (*blob_data == NULL)
486 if (status == MagickFalse)
487 CatchImageException(image);
489 clone_info=DestroyImageInfo(clone_info);
491 else if (LocaleCompare(image_info->magick,"XTRNARRAY") == 0)
494 filename[MaxTextExtent];
502 clone_info=CloneImageInfo(image_info);
503 if (*clone_info->filename != '\0')
505 (void) sscanf(clone_info->filename,"%lx,%s",¶m1,&filename);
506 image->client_data=param1;
508 (void) CopyMagickString(clone_info->filename,filename,MaxTextExtent);
509 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
511 (void) CopyMagickString(p->filename,filename,MaxTextExtent);
514 SetImageInfo(clone_info,1,&image->exception);
515 (void) CopyMagickString(image->magick,clone_info->magick,
517 blob_data=ImageToBlob(clone_info,image,&blob_length,
519 if (blob_data == (unsigned char *) NULL)
522 SafeArrayFifo(image,blob_data,blob_length);
523 if (status == MagickFalse)
524 CatchImageException(image);
526 clone_info=DestroyImageInfo(clone_info);