]> granicus.if.org Git - imagemagick/blob - coders/wmf.c
(no commit message)
[imagemagick] / coders / wmf.c
1 /*
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %                                                                             %
4 %                                                                             %
5 %                                                                             %
6 %                             W   W   M   M  FFFFF                            %
7 %                             W   W   MM MM  F                                %
8 %                             W W W   M M M  FFF                              %
9 %                             WW WW   M   M  F                                %
10 %                             W   W   M   M  F                                %
11 %                                                                             %
12 %                                                                             %
13 %                        Read Windows Metafile Format                         %
14 %                                                                             %
15 %                              Software Design                                %
16 %                                John Cristy                                  %
17 %                               December 2000                                 %
18 %                                                                             %
19 %                                                                             %
20 %  Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization      %
21 %  dedicated to making software imaging solutions freely available.           %
22 %                                                                             %
23 %  You may not use this file except in compliance with the License.  You may  %
24 %  obtain a copy of the License at                                            %
25 %                                                                             %
26 %    http://www.imagemagick.org/script/license.php                            %
27 %                                                                             %
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.                                             %
33 %                                                                             %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35 */
36 \f
37 /*
38   Include declarations.
39 */
40 #include "magick/studio.h"
41 #include "magick/property.h"
42 #include "magick/blob.h"
43 #include "magick/blob-private.h"
44 #include "magick/color.h"
45 #include "magick/color-private.h"
46 #include "magick/constitute.h"
47 #include "magick/exception.h"
48 #include "magick/exception-private.h"
49 #include "magick/image.h"
50 #include "magick/image-private.h"
51 #include "magick/list.h"
52 #include "magick/log.h"
53 #include "magick/magick.h"
54 #include "magick/memory_.h"
55 #include "magick/monitor.h"
56 #include "magick/monitor-private.h"
57 #include "magick/paint.h"
58 #include "magick/quantum-private.h"
59 #include "magick/static.h"
60 #include "magick/string_.h"
61 #include "magick/module.h"
62 #include "magick/type.h"
63 #include "magick/module.h"
64 #include "wand/MagickWand.h"
65
66 #if defined(MAGICKCORE_WMF_DELEGATE)
67 #include "libwmf/api.h"
68 #include "libwmf/eps.h"
69
70 static Image *ReadWMFImage(const ImageInfo *image_info,ExceptionInfo *exception)
71 {
72   char
73     filename[MaxTextExtent];
74
75   int
76     unique_file;
77
78   FILE
79     *file;
80
81   Image
82     *image;
83
84   ImageInfo
85     *read_info;
86
87   unsigned long
88     flags;
89
90   wmfAPI
91     *wmf_info;
92
93   wmfAPI_Options
94     options;
95
96   wmfD_Rect
97     bounding_box;
98
99   wmf_eps_t
100    *eps_info;
101
102   wmf_error_t
103     status;
104
105   image=AcquireImage(image_info);
106   status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
107   if (status == MagickFalse)
108     {
109       image=DestroyImageList(image);
110       return((Image *) NULL);
111     }
112   wmf_info=(wmfAPI *) NULL;
113   flags=0;
114   flags|=WMF_OPT_IGNORE_NONFATAL;
115   flags|=WMF_OPT_FUNCTION;
116   options.function=wmf_eps_function;
117   status=wmf_api_create(&wmf_info,flags,&options);
118   if (status != wmf_E_None)
119     {
120       if (wmf_info != (wmfAPI *) NULL)
121         wmf_api_destroy(wmf_info);
122       ThrowReaderException(DelegateError,"UnableToInitializeWMFLibrary");
123     }
124   status=wmf_file_open(wmf_info,image->filename);
125   if (status != wmf_E_None)
126     {
127       if (wmf_info != (wmfAPI *) NULL)
128         wmf_api_destroy(wmf_info);
129       ThrowFileException(exception,FileOpenError,"UnableToOpenFile",
130         image->filename);
131       return(DestroyImageList(image));
132     }
133   status=wmf_scan(wmf_info,0,&bounding_box);
134   if (status != wmf_E_None)
135     {
136       if (wmf_info != (wmfAPI *) NULL)
137         wmf_api_destroy(wmf_info);
138       ThrowReaderException(DelegateError,"FailedToScanFile");
139     }
140   eps_info=WMF_EPS_GetData(wmf_info);
141   file=(FILE *) NULL;
142   unique_file=AcquireUniqueFileResource(filename);
143   if (unique_file != -1)
144     file=fdopen(unique_file,"wb");
145   if ((unique_file == -1) || (file == (FILE *) NULL))
146     {
147       if (wmf_info != (wmfAPI *) NULL)
148         wmf_api_destroy(wmf_info);
149       ThrowImageException(FileOpenError,"UnableToCreateTemporaryFile");
150     }
151   eps_info->out=wmf_stream_create(wmf_info,file);
152   eps_info->bbox=bounding_box;
153   status=wmf_play(wmf_info,0,&bounding_box);
154   if (status != wmf_E_None)
155     {
156       if (wmf_info != (wmfAPI *) NULL)
157         wmf_api_destroy(wmf_info);
158       ThrowReaderException(DelegateError,"FailedToRenderFile");
159     }
160   wmf_api_destroy(wmf_info);
161   (void) fclose(file);
162   (void) CloseBlob(image);
163   image=DestroyImage(image);
164   /*
165     Read EPS image.
166   */
167   read_info=CloneImageInfo(image_info);
168   (void) FormatMagickString(read_info->filename,MaxTextExtent,"eps:%.1024s",
169     filename);
170   image=ReadImage(read_info,exception);
171   read_info=DestroyImageInfo(read_info);
172   if (image != (Image *) NULL)
173     {
174       (void) CopyMagickString(image->filename,image_info->filename,
175         MaxTextExtent);
176       (void) CopyMagickString(image->magick_filename,image_info->filename,
177         MaxTextExtent);
178       (void) CopyMagickString(image->magick,"WMF",MaxTextExtent);
179     }
180   (void) RelinquishUniqueFileResource(filename);
181   return(GetFirstImageInList(image));
182 }
183 #endif
184 \f
185 /*
186 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
187 %                                                                             %
188 %                                                                             %
189 %                                                                             %
190 %   R e g i s t e r W M F I m a g e                                           %
191 %                                                                             %
192 %                                                                             %
193 %                                                                             %
194 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
195 %
196 %  RegisterWMFImage() adds attributes for the WMF image format to
197 %  the list of supported formats.  The attributes include the image format
198 %  tag, a method to read and/or write the format, whether the format
199 %  supports the saving of more than one frame to the same file or blob,
200 %  whether the format supports native in-memory I/O, and a brief
201 %  description of the format.
202 %
203 %  The format of the RegisterWMFImage method is:
204 %
205 %      unsigned long RegisterWMFImage(void)
206 %
207 */
208 ModuleExport unsigned long RegisterWMFImage(void)
209 {
210   MagickInfo
211     *entry;
212
213   entry = SetMagickInfo("WMZ");
214 #if defined(MAGICKCORE_WMF_DELEGATE)
215   entry->decoder=ReadWMFImage;
216 #endif
217   entry->description=ConstantString("Compressed Windows Meta File");
218   entry->blob_support=MagickFalse;
219   entry->module=ConstantString("WMZ");
220   (void) RegisterMagickInfo(entry);
221   entry=SetMagickInfo("WMF");
222 #if defined(MAGICKCORE_WMF_DELEGATE)
223   entry->decoder=ReadWMFImage;
224 #endif
225   entry->description=ConstantString("Windows Meta File");
226   entry->blob_support=MagickFalse;
227   entry->module=ConstantString("WMF");
228   (void) RegisterMagickInfo(entry);
229   return(MagickImageCoderSignature);
230 }
231 \f
232 /*
233 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
234 %                                                                             %
235 %                                                                             %
236 %                                                                             %
237 %   U n r e g i s t e r W M F I m a g e                                       %
238 %                                                                             %
239 %                                                                             %
240 %                                                                             %
241 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
242 %
243 %  UnregisterWMFImage() removes format registrations made by the
244 %  WMF module from the list of supported formats.
245 %
246 %  The format of the UnregisterWMFImage method is:
247 %
248 %      UnregisterWMFImage(void)
249 %
250 */
251 ModuleExport void UnregisterWMFImage(void)
252 {
253   (void) UnregisterMagickInfo("WMZ");
254   (void) UnregisterMagickInfo("WMF");
255 }