]> granicus.if.org Git - imagemagick/blobdiff - coders/wmf.c
(no commit message)
[imagemagick] / coders / wmf.c
index 6915ddc4b532b4d3ed52bb0910cc39274edc26b9..bc71baee355b0f38cce072521b85a4b862125ee7 100644 (file)
@@ -17,7 +17,7 @@
 %                               December 2000                                 %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization      %
+%  Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization      %
 %  dedicated to making software imaging solutions freely available.           %
 %                                                                             %
 %  You may not use this file except in compliance with the License.  You may  %
 /*
   Include declarations.
 */
-#include "magick/studio.h"
-#include "magick/property.h"
-#include "magick/blob.h"
-#include "magick/blob-private.h"
-#include "magick/color.h"
-#include "magick/color-private.h"
-#include "magick/constitute.h"
-#include "magick/exception.h"
-#include "magick/exception-private.h"
-#include "magick/image.h"
-#include "magick/image-private.h"
-#include "magick/list.h"
-#include "magick/log.h"
-#include "magick/magick.h"
-#include "magick/memory_.h"
-#include "magick/monitor.h"
-#include "magick/monitor-private.h"
-#include "magick/paint.h"
-#include "magick/quantum-private.h"
-#include "magick/static.h"
-#include "magick/string_.h"
-#include "magick/module.h"
-#include "magick/type.h"
-#include "magick/module.h"
-#include "wand/MagickWand.h"
+#include "MagickCore/studio.h"
+#include "MagickCore/property.h"
+#include "MagickCore/blob.h"
+#include "MagickCore/blob-private.h"
+#include "MagickCore/color.h"
+#include "MagickCore/color-private.h"
+#include "MagickCore/constitute.h"
+#include "MagickCore/exception.h"
+#include "MagickCore/exception-private.h"
+#include "MagickCore/image.h"
+#include "MagickCore/image-private.h"
+#include "MagickCore/list.h"
+#include "MagickCore/log.h"
+#include "MagickCore/magick.h"
+#include "MagickCore/memory_.h"
+#include "MagickCore/monitor.h"
+#include "MagickCore/monitor-private.h"
+#include "MagickCore/paint.h"
+#include "MagickCore/quantum-private.h"
+#include "MagickCore/static.h"
+#include "MagickCore/string_.h"
+#include "MagickCore/module.h"
+#include "MagickCore/type.h"
+#include "MagickCore/module.h"
+#include "MagickWand/MagickWand.h"
 
 #if defined(MAGICKCORE_WMF_DELEGATE)
 #include "libwmf/api.h"
 #include "libwmf/eps.h"
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%   R e a d W M F I m a g e                                                   %
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+%  ReadWMFImage() reads an Windows Metafile image file and returns it.  It
+%  allocates the memory necessary for the new Image structure and returns a
+%  pointer to the new image.
+%
+%  The format of the ReadWMFImage method is:
+%
+%      Image *ReadWMFImage(const ImageInfo *image_info,ExceptionInfo *exception)
+%
+%  A description of each parameter follows:
+%
+%    o image_info: the image info.
+%
+%    o exception: return any errors or warnings in this structure.
+%
+*/
+
+static int WMFReadBlob(void *image)
+{
+  return(ReadBlobByte((Image *) image));
+}
+
+static int WMFSeekBlob(void *image,long offset)
+{
+  return((int) SeekBlob((Image *) image,(MagickOffsetType) offset,SEEK_SET));
+}
+
+static long WMFTellBlob(void *image)
+{
+  return((long) TellBlob((Image*) image));
+}
 
 static Image *ReadWMFImage(const ImageInfo *image_info,ExceptionInfo *exception)
 {
@@ -84,7 +126,10 @@ static Image *ReadWMFImage(const ImageInfo *image_info,ExceptionInfo *exception)
   ImageInfo
     *read_info;
 
-  unsigned long
+  MagickBooleanType
+    status;
+
+  size_t
     flags;
 
   wmfAPI
@@ -97,12 +142,15 @@ static Image *ReadWMFImage(const ImageInfo *image_info,ExceptionInfo *exception)
     bounding_box;
 
   wmf_eps_t
-   *eps_info;
+    *eps_info;
 
   wmf_error_t
-    status;
+    wmf_status;
 
-  image=AcquireImage(image_info);
+  /*
+    Read WMF image.
+  */
+  image=AcquireImage(image_info,exception);
   status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
   if (status == MagickFalse)
     {
@@ -114,27 +162,27 @@ static Image *ReadWMFImage(const ImageInfo *image_info,ExceptionInfo *exception)
   flags|=WMF_OPT_IGNORE_NONFATAL;
   flags|=WMF_OPT_FUNCTION;
   options.function=wmf_eps_function;
-  status=wmf_api_create(&wmf_info,flags,&options);
-  if (status != wmf_E_None)
+  wmf_status=wmf_api_create(&wmf_info,(unsigned long) flags,&options);
+  if (wmf_status != wmf_E_None)
     {
       if (wmf_info != (wmfAPI *) NULL)
         wmf_api_destroy(wmf_info);
       ThrowReaderException(DelegateError,"UnableToInitializeWMFLibrary");
     }
-  status=wmf_file_open(wmf_info,image->filename);
-  if (status != wmf_E_None)
+  wmf_status=wmf_bbuf_input(wmf_info,WMFReadBlob,WMFSeekBlob,WMFTellBlob,
+    (void *) image);
+  if (wmf_status != wmf_E_None)
     {
-      if (wmf_info != (wmfAPI *) NULL)
-        wmf_api_destroy(wmf_info);
+      wmf_api_destroy(wmf_info);
       ThrowFileException(exception,FileOpenError,"UnableToOpenFile",
         image->filename);
-      return(DestroyImageList(image));
+      image=DestroyImageList(image);
+      return((Image *) NULL);
     }
-  status=wmf_scan(wmf_info,0,&bounding_box);
-  if (status != wmf_E_None)
+  wmf_status=wmf_scan(wmf_info,0,&bounding_box);
+  if (wmf_status != wmf_E_None)
     {
-      if (wmf_info != (wmfAPI *) NULL)
-        wmf_api_destroy(wmf_info);
+      wmf_api_destroy(wmf_info);
       ThrowReaderException(DelegateError,"FailedToScanFile");
     }
   eps_info=WMF_EPS_GetData(wmf_info);
@@ -144,28 +192,27 @@ static Image *ReadWMFImage(const ImageInfo *image_info,ExceptionInfo *exception)
     file=fdopen(unique_file,"wb");
   if ((unique_file == -1) || (file == (FILE *) NULL))
     {
-      if (wmf_info != (wmfAPI *) NULL)
-        wmf_api_destroy(wmf_info);
-      ThrowImageException(FileOpenError,"UnableToCreateTemporaryFile");
+      wmf_api_destroy(wmf_info);
+      ThrowReaderException(FileOpenError,"UnableToCreateTemporaryFile");
     }
   eps_info->out=wmf_stream_create(wmf_info,file);
   eps_info->bbox=bounding_box;
-  status=wmf_play(wmf_info,0,&bounding_box);
-  if (status != wmf_E_None)
+  wmf_status=wmf_play(wmf_info,0,&bounding_box);
+  if (wmf_status != wmf_E_None)
     {
-      if (wmf_info != (wmfAPI *) NULL)
-        wmf_api_destroy(wmf_info);
+      wmf_api_destroy(wmf_info);
       ThrowReaderException(DelegateError,"FailedToRenderFile");
     }
-  wmf_api_destroy(wmf_info);
   (void) fclose(file);
+  wmf_api_destroy(wmf_info);
   (void) CloseBlob(image);
   image=DestroyImage(image);
   /*
     Read EPS image.
   */
   read_info=CloneImageInfo(image_info);
-  (void) FormatMagickString(read_info->filename,MaxTextExtent,"eps:%.1024s",
+  SetImageInfoBlob(read_info,(void *) NULL,0);
+  (void) FormatLocaleString(read_info->filename,MaxTextExtent,"eps:%s",
     filename);
   image=ReadImage(read_info,exception);
   read_info=DestroyImageInfo(read_info);
@@ -202,10 +249,10 @@ static Image *ReadWMFImage(const ImageInfo *image_info,ExceptionInfo *exception)
 %
 %  The format of the RegisterWMFImage method is:
 %
-%      unsigned long RegisterWMFImage(void)
+%      size_t RegisterWMFImage(void)
 %
 */
-ModuleExport unsigned long RegisterWMFImage(void)
+ModuleExport size_t RegisterWMFImage(void)
 {
   MagickInfo
     *entry;
@@ -215,15 +262,14 @@ ModuleExport unsigned long RegisterWMFImage(void)
   entry->decoder=ReadWMFImage;
 #endif
   entry->description=ConstantString("Compressed Windows Meta File");
-  entry->blob_support=MagickFalse;
   entry->module=ConstantString("WMZ");
+  entry->seekable_stream=MagickTrue;
   (void) RegisterMagickInfo(entry);
   entry=SetMagickInfo("WMF");
 #if defined(MAGICKCORE_WMF_DELEGATE)
   entry->decoder=ReadWMFImage;
 #endif
   entry->description=ConstantString("Windows Meta File");
-  entry->blob_support=MagickFalse;
   entry->module=ConstantString("WMF");
   (void) RegisterMagickInfo(entry);
   return(MagickImageCoderSignature);