gdk-pixbuf-io.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. /* GdkPixbuf library - Io handling. This is an internal header for
  2. * GdkPixbuf. You should never use it unless you are doing development for
  3. * GdkPixbuf itself.
  4. *
  5. * Copyright (C) 1999 The Free Software Foundation
  6. *
  7. * Authors: Mark Crichton <crichton@gimp.org>
  8. * Miguel de Icaza <miguel@gnu.org>
  9. * Federico Mena-Quintero <federico@gimp.org>
  10. * Jonathan Blandford <jrb@redhat.com>
  11. * Michael Fulbright <drmike@redhat.com>
  12. *
  13. * This library is free software; you can redistribute it and/or
  14. * modify it under the terms of the GNU Lesser General Public
  15. * License as published by the Free Software Foundation; either
  16. * version 2 of the License, or (at your option) any later version.
  17. *
  18. * This library is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  21. * Lesser General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Lesser General Public
  24. * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  25. */
  26. #ifndef GDK_PIXBUF_IO_H
  27. #define GDK_PIXBUF_IO_H
  28. #if defined(GDK_PIXBUF_DISABLE_SINGLE_INCLUDES) && !defined (GDK_PIXBUF_H_INSIDE) && !defined (GDK_PIXBUF_COMPILATION)
  29. #error "Only <gdk-pixbuf/gdk-pixbuf.h> can be included directly."
  30. #endif
  31. #include <stdio.h>
  32. #include <glib.h>
  33. #include <gmodule.h>
  34. #include <gdk-pixbuf/gdk-pixbuf-core.h>
  35. #include <gdk-pixbuf/gdk-pixbuf-animation.h>
  36. G_BEGIN_DECLS
  37. typedef struct _GdkPixbufFormat GdkPixbufFormat;
  38. GType gdk_pixbuf_format_get_type (void) G_GNUC_CONST;
  39. GSList *gdk_pixbuf_get_formats (void);
  40. gchar *gdk_pixbuf_format_get_name (GdkPixbufFormat *format);
  41. gchar *gdk_pixbuf_format_get_description (GdkPixbufFormat *format);
  42. gchar **gdk_pixbuf_format_get_mime_types (GdkPixbufFormat *format);
  43. gchar **gdk_pixbuf_format_get_extensions (GdkPixbufFormat *format);
  44. gboolean gdk_pixbuf_format_is_writable (GdkPixbufFormat *format);
  45. gboolean gdk_pixbuf_format_is_scalable (GdkPixbufFormat *format);
  46. gboolean gdk_pixbuf_format_is_disabled (GdkPixbufFormat *format);
  47. void gdk_pixbuf_format_set_disabled (GdkPixbufFormat *format,
  48. gboolean disabled);
  49. gchar *gdk_pixbuf_format_get_license (GdkPixbufFormat *format);
  50. GdkPixbufFormat *gdk_pixbuf_get_file_info (const gchar *filename,
  51. gint *width,
  52. gint *height);
  53. void gdk_pixbuf_get_file_info_async (const gchar *filename,
  54. GCancellable *cancellable,
  55. GAsyncReadyCallback callback,
  56. gpointer user_data);
  57. GdkPixbufFormat *gdk_pixbuf_get_file_info_finish (GAsyncResult *async_result,
  58. gint *width,
  59. gint *height,
  60. GError **error);
  61. GdkPixbufFormat *gdk_pixbuf_format_copy (const GdkPixbufFormat *format);
  62. void gdk_pixbuf_format_free (GdkPixbufFormat *format);
  63. #ifdef GDK_PIXBUF_ENABLE_BACKEND
  64. /**
  65. * GdkPixbufModuleSizeFunc:
  66. * @width: pointer to a location containing the current image width
  67. * @height: pointer to a location containing the current image height
  68. * @user_data: the loader.
  69. *
  70. * Defines the type of the function that gets called once the size
  71. * of the loaded image is known.
  72. *
  73. * The function is expected to set @width and @height to the desired
  74. * size to which the image should be scaled. If a module has no efficient
  75. * way to achieve the desired scaling during the loading of the image, it may
  76. * either ignore the size request, or only approximate it - gdk-pixbuf will
  77. * then perform the required scaling on the completely loaded image.
  78. *
  79. * If the function sets @width or @height to zero, the module should interpret
  80. * this as a hint that it will be closed soon and shouldn't allocate further
  81. * resources. This convention is used to implement gdk_pixbuf_get_file_info()
  82. * efficiently.
  83. *
  84. * Since: 2.2
  85. */
  86. typedef void (* GdkPixbufModuleSizeFunc) (gint *width,
  87. gint *height,
  88. gpointer user_data);
  89. /**
  90. * GdkPixbufModulePreparedFunc:
  91. * @pixbuf: the #GdkPixbuf that is currently being loaded.
  92. * @anim: if an animation is being loaded, the #GdkPixbufAnimation, else %NULL.
  93. * @user_data: the loader.
  94. *
  95. * Defines the type of the function that gets called once the initial
  96. * setup of @pixbuf is done.
  97. *
  98. * #GdkPixbufLoader uses a function of this type to emit the
  99. * "<link linkend="GdkPixbufLoader-area-prepared">area_prepared</link>"
  100. * signal.
  101. *
  102. * Since: 2.2
  103. */
  104. typedef void (* GdkPixbufModulePreparedFunc) (GdkPixbuf *pixbuf,
  105. GdkPixbufAnimation *anim,
  106. gpointer user_data);
  107. /**
  108. * GdkPixbufModuleUpdatedFunc:
  109. * @pixbuf: the #GdkPixbuf that is currently being loaded.
  110. * @x: the X origin of the updated area.
  111. * @y: the Y origin of the updated area.
  112. * @width: the width of the updated area.
  113. * @height: the height of the updated area.
  114. * @user_data: the loader.
  115. *
  116. * Defines the type of the function that gets called every time a region
  117. * of @pixbuf is updated.
  118. *
  119. * #GdkPixbufLoader uses a function of this type to emit the
  120. * "<link linkend="GdkPixbufLoader-area-updated">area_updated</link>"
  121. * signal.
  122. *
  123. * Since: 2.2
  124. */
  125. typedef void (* GdkPixbufModuleUpdatedFunc) (GdkPixbuf *pixbuf,
  126. int x,
  127. int y,
  128. int width,
  129. int height,
  130. gpointer user_data);
  131. /**
  132. * GdkPixbufModulePattern:
  133. * @prefix: the prefix for this pattern
  134. * @mask: mask containing bytes which modify how the prefix is matched against
  135. * test data
  136. * @relevance: relevance of this pattern
  137. *
  138. * The signature of a module is a set of prefixes. Prefixes are encoded as
  139. * pairs of ordinary strings, where the second string, called the mask, if
  140. * not %NULL, must be of the same length as the first one and may contain
  141. * ' ', '!', 'x', 'z', and 'n' to indicate bytes that must be matched,
  142. * not matched, "don't-care"-bytes, zeros and non-zeros.
  143. * Each prefix has an associated integer that describes the relevance of
  144. * the prefix, with 0 meaning a mismatch and 100 a "perfect match".
  145. *
  146. * Starting with gdk-pixbuf 2.8, the first byte of the mask may be '*',
  147. * indicating an unanchored pattern that matches not only at the beginning,
  148. * but also in the middle. Versions prior to 2.8 will interpret the '*'
  149. * like an 'x'.
  150. *
  151. * The signature of a module is stored as an array of
  152. * #GdkPixbufModulePatterns. The array is terminated by a pattern
  153. * where the @prefix is %NULL.
  154. *
  155. *
  156. * <informalexample><programlisting>
  157. * GdkPixbufModulePattern *signature[] = {
  158. * { "abcdx", " !x z", 100 },
  159. * { "bla", NULL, 90 },
  160. * { NULL, NULL, 0 }
  161. * };
  162. * </programlisting>
  163. * The example matches e.g. "auud\0" with relevance 100, and "blau" with
  164. * relevance 90.</informalexample>
  165. *
  166. * Since: 2.2
  167. */
  168. typedef struct _GdkPixbufModulePattern GdkPixbufModulePattern;
  169. struct _GdkPixbufModulePattern {
  170. char *prefix;
  171. char *mask;
  172. int relevance;
  173. };
  174. /**
  175. * GdkPixbufModule:
  176. * @module_name: the name of the module, usually the same as the
  177. * usual file extension for images of this type, eg. "xpm", "jpeg" or "png".
  178. * @module_path: the path from which the module is loaded.
  179. * @module: the loaded #GModule.
  180. * @info: a #GdkPixbufFormat holding information about the module.
  181. * @load: loads an image from a file.
  182. * @load_xpm_data: loads an image from data in memory.
  183. * @begin_load: begins an incremental load.
  184. * @stop_load: stops an incremental load.
  185. * @load_increment: continues an incremental load.
  186. * @load_animation: loads an animation from a file.
  187. * @save: saves a #GdkPixbuf to a file.
  188. * @save_to_callback: saves a #GdkPixbuf by calling the given #GdkPixbufSaveFunc.
  189. *
  190. * A #GdkPixbufModule contains the necessary functions to load and save
  191. * images in a certain file format.
  192. *
  193. * A #GdkPixbufModule can be loaded dynamically from a #GModule.
  194. * Each loadable module must contain a #GdkPixbufModuleFillVtableFunc function
  195. * named <function>fill_vtable</function>, which will get called when the module
  196. * is loaded and must set the function pointers of the #GdkPixbufModule.
  197. */
  198. typedef struct _GdkPixbufModule GdkPixbufModule;
  199. struct _GdkPixbufModule {
  200. char *module_name;
  201. char *module_path;
  202. GModule *module;
  203. GdkPixbufFormat *info;
  204. GdkPixbuf *(* load) (FILE *f,
  205. GError **error);
  206. GdkPixbuf *(* load_xpm_data) (const char **data);
  207. /* Incremental loading */
  208. gpointer (* begin_load) (GdkPixbufModuleSizeFunc size_func,
  209. GdkPixbufModulePreparedFunc prepare_func,
  210. GdkPixbufModuleUpdatedFunc update_func,
  211. gpointer user_data,
  212. GError **error);
  213. gboolean (* stop_load) (gpointer context,
  214. GError **error);
  215. gboolean (* load_increment) (gpointer context,
  216. const guchar *buf,
  217. guint size,
  218. GError **error);
  219. /* Animation loading */
  220. GdkPixbufAnimation *(* load_animation) (FILE *f,
  221. GError **error);
  222. /* Saving */
  223. gboolean (* save) (FILE *f,
  224. GdkPixbuf *pixbuf,
  225. gchar **param_keys,
  226. gchar **param_values,
  227. GError **error);
  228. gboolean (*save_to_callback) (GdkPixbufSaveFunc save_func,
  229. gpointer user_data,
  230. GdkPixbuf *pixbuf,
  231. gchar **option_keys,
  232. gchar **option_values,
  233. GError **error);
  234. /*< private >*/
  235. void (*_reserved1) (void);
  236. void (*_reserved2) (void);
  237. void (*_reserved3) (void);
  238. void (*_reserved4) (void);
  239. void (*_reserved5) (void);
  240. };
  241. /**
  242. * GdkPixbufModuleFillVtableFunc:
  243. * @module: a #GdkPixbufModule.
  244. *
  245. * Defines the type of the function used to set the vtable of a
  246. * #GdkPixbufModule when it is loaded.
  247. *
  248. * Since: 2.2
  249. */
  250. typedef void (* GdkPixbufModuleFillVtableFunc) (GdkPixbufModule *module);
  251. /**
  252. * GdkPixbufModuleFillInfoFunc:
  253. * @info: a #GdkPixbufFormat.
  254. *
  255. * Defines the type of the function used to fill a
  256. * #GdkPixbufFormat structure with information about a module.
  257. *
  258. * Since: 2.2
  259. */
  260. typedef void (* GdkPixbufModuleFillInfoFunc) (GdkPixbufFormat *info);
  261. /* key/value pairs that can be attached by the pixbuf loader */
  262. gboolean gdk_pixbuf_set_option (GdkPixbuf *pixbuf,
  263. const gchar *key,
  264. const gchar *value);
  265. /**
  266. * GdkPixbufFormatFlags:
  267. * @GDK_PIXBUF_FORMAT_WRITABLE: the module can write out images in the format.
  268. * @GDK_PIXBUF_FORMAT_SCALABLE: the image format is scalable
  269. * @GDK_PIXBUF_FORMAT_THREADSAFE: the module is threadsafe. gdk-pixbuf
  270. * ignores modules that are not marked as threadsafe. (Since 2.28).
  271. *
  272. * Flags which allow a module to specify further details about the supported
  273. * operations.
  274. *
  275. * Since: 2.2
  276. */
  277. typedef enum /*< skip >*/
  278. {
  279. GDK_PIXBUF_FORMAT_WRITABLE = 1 << 0,
  280. GDK_PIXBUF_FORMAT_SCALABLE = 1 << 1,
  281. GDK_PIXBUF_FORMAT_THREADSAFE = 1 << 2
  282. } GdkPixbufFormatFlags;
  283. /**
  284. * GdkPixbufFormat:
  285. * @name: the name of the image format.
  286. * @signature: the signature of the module.
  287. * @domain: the message domain for the @description.
  288. * @description: a description of the image format.
  289. * @mime_types: a %NULL-terminated array of MIME types for the image format.
  290. * @extensions: a %NULL-terminated array of typical filename extensions for the
  291. * image format.
  292. * @flags: a combination of #GdkPixbufFormatFlags.
  293. * @disabled: a boolean determining whether the loader is disabled.
  294. * @license: a string containing license information, typically set to
  295. * shorthands like "GPL", "LGPL", etc.
  296. *
  297. * A #GdkPixbufFormat contains information about the image format accepted by a
  298. * module. Only modules should access the fields directly, applications should
  299. * use the <function>gdk_pixbuf_format_*</function> functions.
  300. *
  301. * Since: 2.2
  302. */
  303. struct _GdkPixbufFormat {
  304. gchar *name;
  305. GdkPixbufModulePattern *signature;
  306. gchar *domain;
  307. gchar *description;
  308. gchar **mime_types;
  309. gchar **extensions;
  310. guint32 flags;
  311. gboolean disabled;
  312. gchar *license;
  313. };
  314. #endif /* GDK_PIXBUF_ENABLE_BACKEND */
  315. G_END_DECLS
  316. #endif /* GDK_PIXBUF_IO_H */