PageRenderTime 25ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/coders/dot.c

https://gitlab.com/jiapei100/ImageMagick
C | 245 lines | 124 code | 7 blank | 114 comment | 17 complexity | f2e729d27ccbe6a0ec2605f8488cb831 MD5 | raw file
  1. /*
  2. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  3. % %
  4. % %
  5. % %
  6. % DDDD OOO TTTTT %
  7. % D D O O T %
  8. % D D O O T %
  9. % D D O O T %
  10. % DDDD OOO T %
  11. % %
  12. % %
  13. % Read/Write Graphviz DOT Format %
  14. % %
  15. % Software Design %
  16. % Cristy %
  17. % July 1992 %
  18. % %
  19. % %
  20. % Copyright 1999-2016 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. */
  38. /*
  39. Include declarations.
  40. */
  41. #include "MagickCore/studio.h"
  42. #include "MagickCore/blob.h"
  43. #include "MagickCore/blob-private.h"
  44. #include "MagickCore/client.h"
  45. #include "MagickCore/constitute.h"
  46. #include "MagickCore/exception.h"
  47. #include "MagickCore/exception-private.h"
  48. #include "MagickCore/image.h"
  49. #include "MagickCore/image-private.h"
  50. #include "MagickCore/list.h"
  51. #include "MagickCore/magick.h"
  52. #include "MagickCore/memory_.h"
  53. #include "MagickCore/monitor.h"
  54. #include "MagickCore/monitor-private.h"
  55. #include "MagickCore/option.h"
  56. #include "MagickCore/resource_.h"
  57. #include "MagickCore/quantum-private.h"
  58. #include "MagickCore/static.h"
  59. #include "MagickCore/string_.h"
  60. #include "MagickCore/module.h"
  61. #include "MagickCore/utility.h"
  62. #include "MagickCore/xwindow-private.h"
  63. #if defined(MAGICKCORE_GVC_DELEGATE)
  64. #undef HAVE_CONFIG_H
  65. #include <gvc.h>
  66. static GVC_t
  67. *graphic_context = (GVC_t *) NULL;
  68. #endif
  69. #if defined(MAGICKCORE_GVC_DELEGATE)
  70. /*
  71. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  72. % %
  73. % %
  74. % %
  75. % R e a d D O T I m a g e %
  76. % %
  77. % %
  78. % %
  79. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  80. %
  81. % ReadDOTImage() reads a Graphviz image file and returns it. It allocates
  82. % the memory necessary for the new Image structure and returns a pointer to
  83. % the new image.
  84. %
  85. % The format of the ReadDOTImage method is:
  86. %
  87. % Image *ReadDOTImage(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. static Image *ReadDOTImage(const ImageInfo *image_info,ExceptionInfo *exception)
  97. {
  98. char
  99. command[MagickPathExtent];
  100. const char
  101. *option;
  102. graph_t
  103. *graph;
  104. Image
  105. *image;
  106. ImageInfo
  107. *read_info;
  108. MagickBooleanType
  109. status;
  110. /*
  111. Open image file.
  112. */
  113. assert(image_info != (const ImageInfo *) NULL);
  114. assert(image_info->signature == MagickCoreSignature);
  115. if (image_info->debug != MagickFalse)
  116. (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
  117. image_info->filename);
  118. assert(exception != (ExceptionInfo *) NULL);
  119. assert(exception->signature == MagickCoreSignature);
  120. assert(graphic_context != (GVC_t *) NULL);
  121. image=AcquireImage(image_info,exception);
  122. status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
  123. if (status == MagickFalse)
  124. return((Image *) NULL);
  125. read_info=CloneImageInfo(image_info);
  126. SetImageInfoBlob(read_info,(void *) NULL,0);
  127. (void) CopyMagickString(read_info->magick,"SVG",MagickPathExtent);
  128. (void) AcquireUniqueFilename(read_info->filename);
  129. (void) FormatLocaleString(command,MagickPathExtent,"-Tsvg -o%s %s",
  130. read_info->filename,image_info->filename);
  131. #if !defined(WITH_CGRAPH)
  132. graph=agread(GetBlobFileHandle(image));
  133. #else
  134. graph=agread(GetBlobFileHandle(image),(Agdisc_t *) NULL);
  135. #endif
  136. if (graph == (graph_t *) NULL)
  137. {
  138. (void) RelinquishUniqueFileResource(read_info->filename);
  139. return ((Image *) NULL);
  140. }
  141. option=GetImageOption(image_info,"dot:layout-engine");
  142. if (option == (const char *) NULL)
  143. gvLayout(graphic_context,graph,(char *) "dot");
  144. else
  145. gvLayout(graphic_context,graph,(char *) option);
  146. gvRenderFilename(graphic_context,graph,(char *) "svg",read_info->filename);
  147. gvFreeLayout(graphic_context,graph);
  148. agclose(graph);
  149. /*
  150. Read SVG graph.
  151. */
  152. image=ReadImage(read_info,exception);
  153. (void) RelinquishUniqueFileResource(read_info->filename);
  154. read_info=DestroyImageInfo(read_info);
  155. if (image == (Image *) NULL)
  156. return((Image *) NULL);
  157. return(GetFirstImageInList(image));
  158. }
  159. #endif
  160. /*
  161. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  162. % %
  163. % %
  164. % %
  165. % R e g i s t e r D O T I m a g e %
  166. % %
  167. % %
  168. % %
  169. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  170. %
  171. % RegisterDOTImage() adds attributes for the Display Postscript image
  172. % format to the list of supported formats. The attributes include the image
  173. % format tag, a method to read and/or write the format, whether the format
  174. % supports the saving of more than one frame to the same file or blob,
  175. % whether the format supports native in-memory I/O, and a brief
  176. % description of the format.
  177. %
  178. % The format of the RegisterDOTImage method is:
  179. %
  180. % size_t RegisterDOTImage(void)
  181. %
  182. */
  183. ModuleExport size_t RegisterDOTImage(void)
  184. {
  185. MagickInfo
  186. *entry;
  187. entry=AcquireMagickInfo("DOT","DOT","Graphviz");
  188. #if defined(MAGICKCORE_GVC_DELEGATE)
  189. entry->decoder=(DecodeImageHandler *) ReadDOTImage;
  190. #endif
  191. entry->flags^=CoderBlobSupportFlag;
  192. (void) RegisterMagickInfo(entry);
  193. entry=AcquireMagickInfo("DOT","GV","Graphviz");
  194. #if defined(MAGICKCORE_GVC_DELEGATE)
  195. entry->decoder=(DecodeImageHandler *) ReadDOTImage;
  196. #endif
  197. entry->flags^=CoderBlobSupportFlag;
  198. (void) RegisterMagickInfo(entry);
  199. #if defined(MAGICKCORE_GVC_DELEGATE)
  200. graphic_context=gvContext();
  201. #endif
  202. return(MagickImageCoderSignature);
  203. }
  204. /*
  205. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  206. % %
  207. % %
  208. % %
  209. % U n r e g i s t e r D O T I m a g e %
  210. % %
  211. % %
  212. % %
  213. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  214. %
  215. % UnregisterDOTImage() removes format registrations made by the
  216. % DOT module from the list of supported formats.
  217. %
  218. % The format of the UnregisterDOTImage method is:
  219. %
  220. % UnregisterDOTImage(void)
  221. %
  222. */
  223. ModuleExport void UnregisterDOTImage(void)
  224. {
  225. (void) UnregisterMagickInfo("GV");
  226. (void) UnregisterMagickInfo("DOT");
  227. #if defined(MAGICKCORE_GVC_DELEGATE)
  228. if (graphic_context != (GVC_t *) NULL)
  229. {
  230. gvFreeContext(graphic_context);
  231. graphic_context=(GVC_t *) NULL;
  232. }
  233. #endif
  234. }