| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 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 % |
| cristy | 735e894 | 2010-04-02 20:32:57 +0000 | [diff] [blame] | 16 | % John Cristy % |
| 17 | % December 2000 % |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 18 | % % |
| 19 | % % |
| cristy | 7e41fe8 | 2010-12-04 23:12:08 +0000 | [diff] [blame] | 20 | % Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization % |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 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 | |
| 37 | /* |
| 38 | Include declarations. |
| 39 | */ |
| cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 40 | #include "MagickCore/studio.h" |
| 41 | #include "MagickCore/property.h" |
| 42 | #include "MagickCore/blob.h" |
| 43 | #include "MagickCore/blob-private.h" |
| 44 | #include "MagickCore/color.h" |
| 45 | #include "MagickCore/color-private.h" |
| 46 | #include "MagickCore/constitute.h" |
| 47 | #include "MagickCore/exception.h" |
| 48 | #include "MagickCore/exception-private.h" |
| 49 | #include "MagickCore/image.h" |
| 50 | #include "MagickCore/image-private.h" |
| 51 | #include "MagickCore/list.h" |
| 52 | #include "MagickCore/log.h" |
| 53 | #include "MagickCore/magick.h" |
| 54 | #include "MagickCore/memory_.h" |
| 55 | #include "MagickCore/monitor.h" |
| 56 | #include "MagickCore/monitor-private.h" |
| 57 | #include "MagickCore/paint.h" |
| 58 | #include "MagickCore/quantum-private.h" |
| 59 | #include "MagickCore/static.h" |
| 60 | #include "MagickCore/string_.h" |
| 61 | #include "MagickCore/module.h" |
| 62 | #include "MagickCore/type.h" |
| 63 | #include "MagickCore/module.h" |
| 64 | #include "MagickWand/MagickWand.h" |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 65 | |
| cristy | 735e894 | 2010-04-02 20:32:57 +0000 | [diff] [blame] | 66 | #if defined(MAGICKCORE_WMF_DELEGATE) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 67 | #include "libwmf/api.h" |
| cristy | 2e68c0c | 2010-04-06 13:10:46 +0000 | [diff] [blame] | 68 | #include "libwmf/eps.h" |
| cristy | b85b2f3 | 2010-04-03 03:05:15 +0000 | [diff] [blame] | 69 | |
| 70 | /* |
| 71 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 72 | % % |
| 73 | % % |
| 74 | % % |
| 75 | % R e a d W M F I m a g e % |
| 76 | % % |
| 77 | % % |
| 78 | % % |
| 79 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 80 | % |
| 81 | % ReadWMFImage() reads an Windows Metafile image file and returns it. It |
| 82 | % allocates the memory necessary for the new Image structure and returns a |
| 83 | % pointer to the new image. |
| 84 | % |
| 85 | % The format of the ReadWMFImage method is: |
| 86 | % |
| 87 | % Image *ReadWMFImage(const ImageInfo *image_info,ExceptionInfo *exception) |
| 88 | % |
| 89 | % A description of each parameter follows: |
| 90 | % |
| 91 | % o image_info: the image info. |
| 92 | % |
| 93 | % o exception: return any errors or warnings in this structure. |
| 94 | % |
| 95 | */ |
| 96 | |
| 97 | static int WMFReadBlob(void *image) |
| 98 | { |
| 99 | return(ReadBlobByte((Image *) image)); |
| 100 | } |
| 101 | |
| cristy | f1d9124 | 2010-05-28 02:23:19 +0000 | [diff] [blame] | 102 | static int WMFSeekBlob(void *image,long offset) |
| cristy | b85b2f3 | 2010-04-03 03:05:15 +0000 | [diff] [blame] | 103 | { |
| 104 | return((int) SeekBlob((Image *) image,(MagickOffsetType) offset,SEEK_SET)); |
| 105 | } |
| 106 | |
| cristy | f1d9124 | 2010-05-28 02:23:19 +0000 | [diff] [blame] | 107 | static long WMFTellBlob(void *image) |
| cristy | b85b2f3 | 2010-04-03 03:05:15 +0000 | [diff] [blame] | 108 | { |
| cristy | f1d9124 | 2010-05-28 02:23:19 +0000 | [diff] [blame] | 109 | return((long) TellBlob((Image*) image)); |
| cristy | b85b2f3 | 2010-04-03 03:05:15 +0000 | [diff] [blame] | 110 | } |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 111 | |
| cristy | 735e894 | 2010-04-02 20:32:57 +0000 | [diff] [blame] | 112 | static Image *ReadWMFImage(const ImageInfo *image_info,ExceptionInfo *exception) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 113 | { |
| 114 | char |
| cristy | 735e894 | 2010-04-02 20:32:57 +0000 | [diff] [blame] | 115 | filename[MaxTextExtent]; |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 116 | |
| cristy | 735e894 | 2010-04-02 20:32:57 +0000 | [diff] [blame] | 117 | int |
| 118 | unique_file; |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 119 | |
| cristy | 735e894 | 2010-04-02 20:32:57 +0000 | [diff] [blame] | 120 | FILE |
| 121 | *file; |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 122 | |
| 123 | Image |
| 124 | *image; |
| 125 | |
| 126 | ImageInfo |
| cristy | 735e894 | 2010-04-02 20:32:57 +0000 | [diff] [blame] | 127 | *read_info; |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 128 | |
| cristy | 19eb641 | 2010-04-23 14:42:29 +0000 | [diff] [blame] | 129 | MagickBooleanType |
| 130 | status; |
| 131 | |
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 132 | size_t |
| cristy | 735e894 | 2010-04-02 20:32:57 +0000 | [diff] [blame] | 133 | flags; |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 134 | |
| 135 | wmfAPI |
| cristy | 735e894 | 2010-04-02 20:32:57 +0000 | [diff] [blame] | 136 | *wmf_info; |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 137 | |
| 138 | wmfAPI_Options |
| cristy | 735e894 | 2010-04-02 20:32:57 +0000 | [diff] [blame] | 139 | options; |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 140 | |
| 141 | wmfD_Rect |
| cristy | 735e894 | 2010-04-02 20:32:57 +0000 | [diff] [blame] | 142 | bounding_box; |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 143 | |
| cristy | 2e68c0c | 2010-04-06 13:10:46 +0000 | [diff] [blame] | 144 | wmf_eps_t |
| cristy | fc5fbc4 | 2010-04-06 17:58:30 +0000 | [diff] [blame] | 145 | *eps_info; |
| cristy | 735e894 | 2010-04-02 20:32:57 +0000 | [diff] [blame] | 146 | |
| 147 | wmf_error_t |
| cristy | 19eb641 | 2010-04-23 14:42:29 +0000 | [diff] [blame] | 148 | wmf_status; |
| cristy | 735e894 | 2010-04-02 20:32:57 +0000 | [diff] [blame] | 149 | |
| cristy | b85b2f3 | 2010-04-03 03:05:15 +0000 | [diff] [blame] | 150 | /* |
| 151 | Read WMF image. |
| 152 | */ |
| cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 153 | image=AcquireImage(image_info,exception); |
| cristy | 735e894 | 2010-04-02 20:32:57 +0000 | [diff] [blame] | 154 | status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); |
| 155 | if (status == MagickFalse) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 156 | { |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 157 | image=DestroyImageList(image); |
| 158 | return((Image *) NULL); |
| 159 | } |
| cristy | 735e894 | 2010-04-02 20:32:57 +0000 | [diff] [blame] | 160 | wmf_info=(wmfAPI *) NULL; |
| 161 | flags=0; |
| 162 | flags|=WMF_OPT_IGNORE_NONFATAL; |
| 163 | flags|=WMF_OPT_FUNCTION; |
| cristy | 2e68c0c | 2010-04-06 13:10:46 +0000 | [diff] [blame] | 164 | options.function=wmf_eps_function; |
| cristy | eaedf06 | 2010-05-29 22:36:02 +0000 | [diff] [blame] | 165 | wmf_status=wmf_api_create(&wmf_info,(unsigned long) flags,&options); |
| cristy | 19eb641 | 2010-04-23 14:42:29 +0000 | [diff] [blame] | 166 | if (wmf_status != wmf_E_None) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 167 | { |
| cristy | 735e894 | 2010-04-02 20:32:57 +0000 | [diff] [blame] | 168 | if (wmf_info != (wmfAPI *) NULL) |
| 169 | wmf_api_destroy(wmf_info); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 170 | ThrowReaderException(DelegateError,"UnableToInitializeWMFLibrary"); |
| 171 | } |
| cristy | 19eb641 | 2010-04-23 14:42:29 +0000 | [diff] [blame] | 172 | wmf_status=wmf_bbuf_input(wmf_info,WMFReadBlob,WMFSeekBlob,WMFTellBlob, |
| cristy | b85b2f3 | 2010-04-03 03:05:15 +0000 | [diff] [blame] | 173 | (void *) image); |
| cristy | 19eb641 | 2010-04-23 14:42:29 +0000 | [diff] [blame] | 174 | if (wmf_status != wmf_E_None) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 175 | { |
| cristy | b85b2f3 | 2010-04-03 03:05:15 +0000 | [diff] [blame] | 176 | wmf_api_destroy(wmf_info); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 177 | ThrowFileException(exception,FileOpenError,"UnableToOpenFile", |
| 178 | image->filename); |
| cristy | b85b2f3 | 2010-04-03 03:05:15 +0000 | [diff] [blame] | 179 | image=DestroyImageList(image); |
| 180 | return((Image *) NULL); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 181 | } |
| cristy | 19eb641 | 2010-04-23 14:42:29 +0000 | [diff] [blame] | 182 | wmf_status=wmf_scan(wmf_info,0,&bounding_box); |
| 183 | if (wmf_status != wmf_E_None) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 184 | { |
| cristy | b85b2f3 | 2010-04-03 03:05:15 +0000 | [diff] [blame] | 185 | wmf_api_destroy(wmf_info); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 186 | ThrowReaderException(DelegateError,"FailedToScanFile"); |
| 187 | } |
| cristy | 2e68c0c | 2010-04-06 13:10:46 +0000 | [diff] [blame] | 188 | eps_info=WMF_EPS_GetData(wmf_info); |
| cristy | 735e894 | 2010-04-02 20:32:57 +0000 | [diff] [blame] | 189 | file=(FILE *) NULL; |
| 190 | unique_file=AcquireUniqueFileResource(filename); |
| 191 | if (unique_file != -1) |
| 192 | file=fdopen(unique_file,"wb"); |
| 193 | if ((unique_file == -1) || (file == (FILE *) NULL)) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 194 | { |
| cristy | b85b2f3 | 2010-04-03 03:05:15 +0000 | [diff] [blame] | 195 | wmf_api_destroy(wmf_info); |
| 196 | ThrowReaderException(FileOpenError,"UnableToCreateTemporaryFile"); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 197 | } |
| cristy | 2e68c0c | 2010-04-06 13:10:46 +0000 | [diff] [blame] | 198 | eps_info->out=wmf_stream_create(wmf_info,file); |
| 199 | eps_info->bbox=bounding_box; |
| cristy | 19eb641 | 2010-04-23 14:42:29 +0000 | [diff] [blame] | 200 | wmf_status=wmf_play(wmf_info,0,&bounding_box); |
| 201 | if (wmf_status != wmf_E_None) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 202 | { |
| cristy | b85b2f3 | 2010-04-03 03:05:15 +0000 | [diff] [blame] | 203 | wmf_api_destroy(wmf_info); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 204 | ThrowReaderException(DelegateError,"FailedToRenderFile"); |
| 205 | } |
| cristy | 735e894 | 2010-04-02 20:32:57 +0000 | [diff] [blame] | 206 | (void) fclose(file); |
| cristy | b85b2f3 | 2010-04-03 03:05:15 +0000 | [diff] [blame] | 207 | wmf_api_destroy(wmf_info); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 208 | (void) CloseBlob(image); |
| cristy | 735e894 | 2010-04-02 20:32:57 +0000 | [diff] [blame] | 209 | image=DestroyImage(image); |
| 210 | /* |
| cristy | 2e68c0c | 2010-04-06 13:10:46 +0000 | [diff] [blame] | 211 | Read EPS image. |
| cristy | 735e894 | 2010-04-02 20:32:57 +0000 | [diff] [blame] | 212 | */ |
| 213 | read_info=CloneImageInfo(image_info); |
| cristy | 98f91ec | 2011-02-03 01:15:48 +0000 | [diff] [blame] | 214 | SetImageInfoBlob(read_info,(void *) NULL,0); |
| cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 215 | (void) FormatLocaleString(read_info->filename,MaxTextExtent,"eps:%s", |
| cristy | 735e894 | 2010-04-02 20:32:57 +0000 | [diff] [blame] | 216 | filename); |
| 217 | image=ReadImage(read_info,exception); |
| 218 | read_info=DestroyImageInfo(read_info); |
| 219 | if (image != (Image *) NULL) |
| 220 | { |
| 221 | (void) CopyMagickString(image->filename,image_info->filename, |
| 222 | MaxTextExtent); |
| 223 | (void) CopyMagickString(image->magick_filename,image_info->filename, |
| 224 | MaxTextExtent); |
| 225 | (void) CopyMagickString(image->magick,"WMF",MaxTextExtent); |
| 226 | } |
| 227 | (void) RelinquishUniqueFileResource(filename); |
| 228 | return(GetFirstImageInList(image)); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 229 | } |
| cristy | 735e894 | 2010-04-02 20:32:57 +0000 | [diff] [blame] | 230 | #endif |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 231 | |
| 232 | /* |
| 233 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 234 | % % |
| 235 | % % |
| 236 | % % |
| 237 | % R e g i s t e r W M F I m a g e % |
| 238 | % % |
| 239 | % % |
| 240 | % % |
| 241 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 242 | % |
| 243 | % RegisterWMFImage() adds attributes for the WMF image format to |
| 244 | % the list of supported formats. The attributes include the image format |
| 245 | % tag, a method to read and/or write the format, whether the format |
| 246 | % supports the saving of more than one frame to the same file or blob, |
| 247 | % whether the format supports native in-memory I/O, and a brief |
| 248 | % description of the format. |
| 249 | % |
| 250 | % The format of the RegisterWMFImage method is: |
| 251 | % |
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 252 | % size_t RegisterWMFImage(void) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 253 | % |
| 254 | */ |
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 255 | ModuleExport size_t RegisterWMFImage(void) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 256 | { |
| 257 | MagickInfo |
| 258 | *entry; |
| 259 | |
| 260 | entry = SetMagickInfo("WMZ"); |
| cristy | 735e894 | 2010-04-02 20:32:57 +0000 | [diff] [blame] | 261 | #if defined(MAGICKCORE_WMF_DELEGATE) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 262 | entry->decoder=ReadWMFImage; |
| 263 | #endif |
| 264 | entry->description=ConstantString("Compressed Windows Meta File"); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 265 | entry->module=ConstantString("WMZ"); |
| cristy | ffaf978 | 2011-04-13 19:50:51 +0000 | [diff] [blame] | 266 | entry->seekable_stream=MagickTrue; |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 267 | (void) RegisterMagickInfo(entry); |
| 268 | entry=SetMagickInfo("WMF"); |
| cristy | 735e894 | 2010-04-02 20:32:57 +0000 | [diff] [blame] | 269 | #if defined(MAGICKCORE_WMF_DELEGATE) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 270 | entry->decoder=ReadWMFImage; |
| 271 | #endif |
| 272 | entry->description=ConstantString("Windows Meta File"); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 273 | entry->module=ConstantString("WMF"); |
| 274 | (void) RegisterMagickInfo(entry); |
| 275 | return(MagickImageCoderSignature); |
| 276 | } |
| 277 | |
| 278 | /* |
| 279 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 280 | % % |
| 281 | % % |
| 282 | % % |
| 283 | % U n r e g i s t e r W M F I m a g e % |
| 284 | % % |
| 285 | % % |
| 286 | % % |
| 287 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 288 | % |
| 289 | % UnregisterWMFImage() removes format registrations made by the |
| 290 | % WMF module from the list of supported formats. |
| 291 | % |
| 292 | % The format of the UnregisterWMFImage method is: |
| 293 | % |
| 294 | % UnregisterWMFImage(void) |
| 295 | % |
| 296 | */ |
| 297 | ModuleExport void UnregisterWMFImage(void) |
| 298 | { |
| 299 | (void) UnregisterMagickInfo("WMZ"); |
| 300 | (void) UnregisterMagickInfo("WMF"); |
| 301 | } |