PageRenderTime 44ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/Libs/ImageMagick-6.7.4-Windows/coders/wmf.c

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