1 /* -*- mode: C; c-file-style: "linux" -*- */
2 /* GdkPixbuf library - Main loading interface.
4 * Copyright (C) 1999 The Free Software Foundation
6 * Authors: Miguel de Icaza <miguel@gnu.org>
7 * Federico Mena-Quintero <federico@gimp.org>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the
21 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 * Boston, MA 02111-1307, USA.
36 #include "gdk-pixbuf-private.h"
37 #include "gdk-pixbuf-io.h"
38 #include "gdk-pixbuf-alias.h"
40 #include <glib/gstdio.h>
49 format_check (GdkPixbufModule *module, guchar *buffer, int size)
53 GdkPixbufModulePattern *pattern;
58 for (pattern = module->info->signature; pattern->prefix; pattern++) {
59 if (pattern->mask && pattern->mask[0] == '*') {
60 prefix = (guchar *)pattern->prefix + 1;
61 mask = pattern->mask + 1;
65 prefix = (guchar *)pattern->prefix;
69 for (i = 0; i < size; i++) {
70 for (j = 0; i + j < size && prefix[j] != 0; j++) {
71 m = mask ? mask[j] : ' ';
73 if (buffer[i + j] != prefix[j])
77 if (buffer[i + j] == prefix[j])
81 if (buffer[i + j] != 0)
85 if (buffer[i + j] == 0)
91 return pattern->relevance;
100 G_LOCK_DEFINE_STATIC (init_lock);
101 G_LOCK_DEFINE_STATIC (threadunsafe_loader_lock);
104 _gdk_pixbuf_lock (GdkPixbufModule *image_module)
106 if (g_threads_got_initialized &&
107 !(image_module->info->flags & GDK_PIXBUF_FORMAT_THREADSAFE)) {
108 G_LOCK (threadunsafe_loader_lock);
117 _gdk_pixbuf_unlock (GdkPixbufModule *image_module)
119 if (!(image_module->info->flags & GDK_PIXBUF_FORMAT_THREADSAFE)) {
120 G_UNLOCK (threadunsafe_loader_lock);
124 static GSList *file_formats = NULL;
126 static void gdk_pixbuf_io_init (void);
129 get_file_formats (void)
132 if (file_formats == NULL)
133 gdk_pixbuf_io_init ();
134 G_UNLOCK (init_lock);
143 scan_string (const char **pos, GString *out)
145 const char *p = *pos, *q = *pos;
149 while (g_ascii_isspace (*p))
154 else if (*p == '"') {
157 for (q = p; (*q != '"') || quoted; q++) {
160 quoted = (*q == '\\') && !quoted;
163 tmp = g_strndup (p, q - p);
164 tmp2 = g_strcompress (tmp);
165 g_string_truncate (out, 0);
166 g_string_append (out, tmp2);
178 scan_int (const char **pos, int *out)
182 const char *p = *pos;
184 while (g_ascii_isspace (*p))
187 if (*p < '0' || *p > '9')
190 while ((*p >= '0') && (*p <= '9') && i < sizeof (buf)) {
196 if (i == sizeof (buf))
209 skip_space (const char **pos)
211 const char *p = *pos;
213 while (g_ascii_isspace (*p))
218 return !(*p == '\0');
223 /* DllMain function needed to tuck away the gdk-pixbuf DLL name */
224 G_WIN32_DLLMAIN_FOR_DLL_NAME (static, dll_name)
229 static char *toplevel = NULL;
231 if (toplevel == NULL)
232 toplevel = g_win32_get_package_installation_subdirectory
233 (GETTEXT_PACKAGE, dll_name, "");
239 get_sysconfdir (void)
241 static char *sysconfdir = NULL;
243 if (sysconfdir == NULL)
244 sysconfdir = g_win32_get_package_installation_subdirectory
245 (GETTEXT_PACKAGE, dll_name, "etc");
250 #undef GTK_SYSCONFDIR
251 #define GTK_SYSCONFDIR get_sysconfdir()
254 correct_prefix (gchar **path)
256 if (strncmp (*path, GTK_PREFIX "/", strlen (GTK_PREFIX "/")) == 0 ||
257 strncmp (*path, GTK_PREFIX "\\", strlen (GTK_PREFIX "\\")) == 0)
259 /* This is an entry put there by gdk-pixbuf-query-loaders on the
260 * packager's system. On Windows a prebuilt GTK+ package can be
261 * installed in a random location. The gdk-pixbuf.loaders file
262 * distributed in such a package contains paths from the package
263 * builder's machine. Replace the build-time prefix with the
264 * installation prefix on this machine.
267 *path = g_strconcat (get_toplevel (), tem + strlen (GTK_PREFIX), NULL);
272 #endif /* G_OS_WIN32 */
275 gdk_pixbuf_get_module_file (void)
277 gchar *result = g_strdup (g_getenv ("GDK_PIXBUF_MODULE_FILE"));
280 result = g_build_filename (GTK_SYSCONFDIR, "gtk-2.0", "gdk-pixbuf.loaders", NULL);
286 gdk_pixbuf_io_init (void)
291 GString *tmp_buf = g_string_new (NULL);
292 gboolean have_error = FALSE;
293 GdkPixbufModule *module = NULL;
294 gchar *filename = gdk_pixbuf_get_module_file ();
297 GdkPixbufModulePattern *pattern;
298 GError *error = NULL;
300 channel = g_io_channel_new_file (filename, "r", &error);
302 g_warning ("Cannot open pixbuf loader module file '%s': %s",
303 filename, error->message);
307 while (!have_error && g_io_channel_read_line (channel, &line_buf, NULL, &term, NULL) == G_IO_STATUS_NORMAL) {
314 if (!skip_space (&p)) {
315 /* Blank line marking the end of a module
317 if (module && *p != '#') {
319 correct_prefix (&module->module_path);
321 file_formats = g_slist_prepend (file_formats, module);
332 /* Read a module location
334 module = g_new0 (GdkPixbufModule, 1);
337 if (!scan_string (&p, tmp_buf)) {
338 g_warning ("Error parsing loader info in '%s'\n %s",
342 module->module_path = g_strdup (tmp_buf->str);
344 else if (!module->module_name) {
345 module->info = g_new0 (GdkPixbufFormat, 1);
346 if (!scan_string (&p, tmp_buf)) {
347 g_warning ("Error parsing loader info in '%s'\n %s",
351 module->info->name = g_strdup (tmp_buf->str);
352 module->module_name = module->info->name;
354 if (!scan_int (&p, &flags)) {
355 g_warning ("Error parsing loader info in '%s'\n %s",
359 module->info->flags = flags;
361 if (!scan_string (&p, tmp_buf)) {
362 g_warning ("Error parsing loader info in '%s'\n %s",
366 if (tmp_buf->str[0] != 0)
367 module->info->domain = g_strdup (tmp_buf->str);
369 if (!scan_string (&p, tmp_buf)) {
370 g_warning ("Error parsing loader info in '%s'\n %s",
374 module->info->description = g_strdup (tmp_buf->str);
376 else if (!module->info->mime_types) {
378 module->info->mime_types = g_new0 (gchar*, 1);
379 while (scan_string (&p, tmp_buf)) {
380 if (tmp_buf->str[0] != 0) {
381 module->info->mime_types =
382 g_realloc (module->info->mime_types, (n + 1) * sizeof (gchar*));
383 module->info->mime_types[n - 1] = g_strdup (tmp_buf->str);
384 module->info->mime_types[n] = NULL;
389 else if (!module->info->extensions) {
391 module->info->extensions = g_new0 (gchar*, 1);
392 while (scan_string (&p, tmp_buf)) {
393 if (tmp_buf->str[0] != 0) {
394 module->info->extensions =
395 g_realloc (module->info->extensions, (n + 1) * sizeof (gchar*));
396 module->info->extensions[n - 1] = g_strdup (tmp_buf->str);
397 module->info->extensions[n] = NULL;
404 module->info->signature = (GdkPixbufModulePattern *)
405 g_realloc (module->info->signature, (n_patterns + 1) * sizeof (GdkPixbufModulePattern));
406 pattern = module->info->signature + n_patterns;
407 pattern->prefix = NULL;
408 pattern->mask = NULL;
409 pattern->relevance = 0;
411 if (!scan_string (&p, tmp_buf))
413 pattern->prefix = g_strdup (tmp_buf->str);
415 if (!scan_string (&p, tmp_buf))
418 pattern->mask = g_strdup (tmp_buf->str);
420 pattern->mask = NULL;
422 if (!scan_int (&p, &pattern->relevance))
428 g_free (pattern->prefix);
429 g_free (pattern->mask);
431 g_warning ("Error parsing loader info in '%s'\n %s",
438 g_string_free (tmp_buf, TRUE);
439 g_io_channel_unref (channel);
443 /* actually load the image handler - gdk_pixbuf_get_module only get a */
444 /* reference to the module to load, it doesn't actually load it */
445 /* perhaps these actions should be combined in one function */
447 _gdk_pixbuf_load_module_unlocked (GdkPixbufModule *image_module,
454 g_return_val_if_fail (image_module->module == NULL, FALSE);
456 path = image_module->module_path;
457 module = g_module_open (path, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL);
462 GDK_PIXBUF_ERROR_FAILED,
463 _("Unable to load image-loading module: %s: %s"),
464 path, g_module_error ());
468 image_module->module = module;
470 if (g_module_symbol (module, "fill_vtable", &sym)) {
471 GdkPixbufModuleFillVtableFunc func = (GdkPixbufModuleFillVtableFunc) sym;
472 (* func) (image_module);
477 GDK_PIXBUF_ERROR_FAILED,
478 _("Image-loading module %s does not export the proper interface; perhaps it's from a different GTK version?"),
485 _gdk_pixbuf_load_module (GdkPixbufModule *image_module,
489 gboolean locked = FALSE;
491 /* be extra careful, maybe the module initializes
494 if (g_threads_got_initialized)
499 ret = _gdk_pixbuf_load_module_unlocked (image_module, error);
501 G_UNLOCK (init_lock);
505 #else /* !USE_GMODULE */
507 #define module(type) \
508 extern void MODULE_ENTRY (type, fill_info) (GdkPixbufFormat *info); \
509 extern void MODULE_ENTRY (type, fill_vtable) (GdkPixbufModule *module)
527 _gdk_pixbuf_load_module (GdkPixbufModule *image_module,
530 GdkPixbufModuleFillInfoFunc fill_info = NULL;
531 GdkPixbufModuleFillVtableFunc fill_vtable = NULL;
533 image_module->module = (void *) 1;
536 /* Ugly hack so we can use else if unconditionally below ;-) */
540 else if (strcmp (image_module->module_name, "png") == 0) {
541 fill_info = MODULE_ENTRY (png, fill_info);
542 fill_vtable = MODULE_ENTRY (png, fill_vtable);
547 else if (strcmp (image_module->module_name, "bmp") == 0) {
548 fill_info = MODULE_ENTRY (bmp, fill_info);
549 fill_vtable = MODULE_ENTRY (bmp, fill_vtable);
554 else if (strcmp (image_module->module_name, "wbmp") == 0) {
555 fill_info = MODULE_ENTRY (wbmp, fill_info);
556 fill_vtable = MODULE_ENTRY (wbmp, fill_vtable);
561 else if (strcmp (image_module->module_name, "gif") == 0) {
562 fill_info = MODULE_ENTRY (gif, fill_info);
563 fill_vtable = MODULE_ENTRY (gif, fill_vtable);
568 else if (strcmp (image_module->module_name, "ico") == 0) {
569 fill_info = MODULE_ENTRY (ico, fill_info);
570 fill_vtable = MODULE_ENTRY (ico, fill_vtable);
575 else if (strcmp (image_module->module_name, "ani") == 0) {
576 fill_info = MODULE_ENTRY (ani, fill_info);
577 fill_vtable = MODULE_ENTRY (ani, fill_vtable);
582 else if (strcmp (image_module->module_name, "jpeg") == 0) {
583 fill_info = MODULE_ENTRY (jpeg, fill_info);
584 fill_vtable = MODULE_ENTRY (jpeg, fill_vtable);
589 else if (strcmp (image_module->module_name, "pnm") == 0) {
590 fill_info = MODULE_ENTRY (pnm, fill_info);
591 fill_vtable = MODULE_ENTRY (pnm, fill_vtable);
596 else if (strcmp (image_module->module_name, "ras") == 0) {
597 fill_info = MODULE_ENTRY (ras, fill_info);
598 fill_vtable = MODULE_ENTRY (ras, fill_vtable);
603 else if (strcmp (image_module->module_name, "tiff") == 0) {
604 fill_info = MODULE_ENTRY (tiff, fill_info);
605 fill_vtable = MODULE_ENTRY (tiff, fill_vtable);
610 else if (strcmp (image_module->module_name, "xpm") == 0) {
611 fill_info = MODULE_ENTRY (xpm, fill_info);
612 fill_vtable = MODULE_ENTRY (xpm, fill_vtable);
617 else if (strcmp (image_module->module_name, "xbm") == 0) {
618 fill_info = MODULE_ENTRY (xbm, fill_info);
619 fill_vtable = MODULE_ENTRY (xbm, fill_vtable);
624 else if (strcmp (image_module->module_name, "tga") == 0) {
625 fill_info = MODULE_ENTRY (tga, fill_info);
626 fill_vtable = MODULE_ENTRY (tga, fill_vtable);
631 else if (strcmp (image_module->module_name, "pcx") == 0) {
632 fill_info = MODULE_ENTRY (pcx, fill_info);
633 fill_vtable = MODULE_ENTRY (pcx, fill_vtable);
638 (* fill_vtable) (image_module);
639 image_module->info = g_new0 (GdkPixbufFormat, 1);
640 (* fill_info) (image_module->info);
646 GDK_PIXBUF_ERROR_UNKNOWN_TYPE,
647 _("Image type '%s' is not supported"),
648 image_module->module_name);
655 gdk_pixbuf_io_init ()
657 gchar *included_formats[] = {
658 "ani", "png", "bmp", "wbmp", "gif",
659 "ico", "jpeg", "pnm", "ras", "tiff",
660 "xpm", "xbm", "tga", "pcx",
664 GdkPixbufModule *module = NULL;
666 for (name = included_formats; *name; name++) {
667 module = g_new0 (GdkPixbufModule, 1);
668 module->module_name = *name;
669 if (_gdk_pixbuf_load_module (module, NULL))
670 file_formats = g_slist_prepend (file_formats, module);
676 #endif /* !USE_GMODULE */
681 _gdk_pixbuf_get_named_module (const char *name,
686 for (modules = get_file_formats (); modules; modules = g_slist_next (modules)) {
687 GdkPixbufModule *module = (GdkPixbufModule *)modules->data;
689 if (module->info->disabled)
692 if (!strcmp (name, module->module_name))
698 GDK_PIXBUF_ERROR_UNKNOWN_TYPE,
699 _("Image type '%s' is not supported"),
706 _gdk_pixbuf_get_module (guchar *buffer, guint size,
707 const gchar *filename,
712 gint score, best = 0;
713 GdkPixbufModule *selected = NULL;
714 gchar *display_name = NULL;
716 for (modules = get_file_formats (); modules; modules = g_slist_next (modules)) {
717 GdkPixbufModule *module = (GdkPixbufModule *)modules->data;
719 if (module->info->disabled)
722 score = format_check (module, buffer, size);
730 if (selected != NULL)
735 display_name = g_filename_display_name (filename);
738 GDK_PIXBUF_ERROR_UNKNOWN_TYPE,
739 _("Couldn't recognize the image file format for file '%s'"),
741 g_free (display_name);
746 GDK_PIXBUF_ERROR_UNKNOWN_TYPE,
747 _("Unrecognized image file format"));
755 prepared_notify (GdkPixbuf *pixbuf,
756 GdkPixbufAnimation *anim,
760 g_object_ref (pixbuf);
761 *((GdkPixbuf **)user_data) = pixbuf;
765 _gdk_pixbuf_generic_image_load (GdkPixbufModule *module,
771 GdkPixbuf *pixbuf = NULL;
772 GdkPixbufAnimation *animation = NULL;
776 locked = _gdk_pixbuf_lock (module);
778 if (module->load != NULL) {
779 pixbuf = (* module->load) (f, error);
780 } else if (module->begin_load != NULL) {
782 context = module->begin_load (NULL, prepared_notify, NULL, &pixbuf, error);
787 while (!feof (f) && !ferror (f)) {
788 length = fread (buffer, 1, sizeof (buffer), f);
790 if (!module->load_increment (context, buffer, length, error)) {
791 module->stop_load (context, NULL);
792 if (pixbuf != NULL) {
793 g_object_unref (pixbuf);
800 if (!module->stop_load (context, error)) {
801 if (pixbuf != NULL) {
802 g_object_unref (pixbuf);
806 } else if (module->load_animation != NULL) {
807 animation = (* module->load_animation) (f, error);
808 if (animation != NULL) {
809 pixbuf = gdk_pixbuf_animation_get_static_image (animation);
811 g_object_ref (pixbuf);
812 g_object_unref (animation);
818 _gdk_pixbuf_unlock (module);
823 * gdk_pixbuf_new_from_file:
824 * @filename: Name of file to load, in the GLib file name encoding
825 * @error: Return location for an error
827 * Creates a new pixbuf by loading an image from a file. The file format is
828 * detected automatically. If %NULL is returned, then @error will be set.
829 * Possible errors are in the #GDK_PIXBUF_ERROR and #G_FILE_ERROR domains.
831 * Return value: A newly-created pixbuf with a reference count of 1, or %NULL if
832 * any of several error conditions occurred: the file could not be opened,
833 * there was no loader for the file's format, there was not enough memory to
834 * allocate the image buffer, or the image file contained invalid data.
837 gdk_pixbuf_new_from_file (const char *filename,
844 GdkPixbufModule *image_module;
847 g_return_val_if_fail (filename != NULL, NULL);
848 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
850 display_name = g_filename_display_name (filename);
852 f = g_fopen (filename, "rb");
854 gint save_errno = errno;
857 g_file_error_from_errno (save_errno),
858 _("Failed to open file '%s': %s"),
860 g_strerror (save_errno));
861 g_free (display_name);
865 size = fread (&buffer, 1, sizeof (buffer), f);
869 GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
870 _("Image file '%s' contains no data"),
872 g_free (display_name);
877 image_module = _gdk_pixbuf_get_module (buffer, size, filename, error);
878 if (image_module == NULL) {
879 g_free (display_name);
884 if (image_module->module == NULL)
885 if (!_gdk_pixbuf_load_module (image_module, error)) {
886 g_free (display_name);
891 fseek (f, 0, SEEK_SET);
892 pixbuf = _gdk_pixbuf_generic_image_load (image_module, f, error);
895 if (pixbuf == NULL && error != NULL && *error == NULL) {
897 /* I don't trust these crufty longjmp()'ing image libs
898 * to maintain proper error invariants, and I don't
899 * want user code to segfault as a result. We need to maintain
900 * the invariant that error gets set if NULL is returned.
903 g_warning ("Bug! gdk-pixbuf loader '%s' didn't set an error on failure.", image_module->module_name);
906 GDK_PIXBUF_ERROR_FAILED,
907 _("Failed to load image '%s': reason not known, probably a corrupt image file"),
909 } else if (error != NULL && *error != NULL) {
911 /* Add the filename to the error message */
916 e->message = g_strdup_printf (_("Failed to load image '%s': %s"),
922 g_free (display_name);
928 #undef gdk_pixbuf_new_from_file
930 gdk_pixbuf_new_from_file (const char *filename,
933 gchar *utf8_filename =
934 g_locale_to_utf8 (filename, -1, NULL, NULL, error);
937 if (utf8_filename == NULL)
940 retval = gdk_pixbuf_new_from_file_utf8 (utf8_filename, error);
942 g_free (utf8_filename);
949 size_prepared_cb (GdkPixbufLoader *loader,
957 gboolean preserve_aspect_ratio;
960 g_return_if_fail (width > 0 && height > 0);
962 if (info->preserve_aspect_ratio &&
963 (info->width > 0 || info->height > 0)) {
966 width = width * (double)info->height/(double)height;
967 height = info->height;
969 else if (info->height < 0)
971 height = height * (double)info->width/(double)width;
974 else if ((double)height * (double)info->width >
975 (double)width * (double)info->height) {
976 width = 0.5 + (double)width * (double)info->height / (double)height;
977 height = info->height;
979 height = 0.5 + (double)height * (double)info->width / (double)width;
985 if (info->height > 0)
986 height = info->height;
989 gdk_pixbuf_loader_set_size (loader, width, height);
993 * gdk_pixbuf_new_from_file_at_size:
994 * @filename: Name of file to load, in the GLib file name encoding
995 * @width: The width the image should have or -1 to not constrain the width
996 * @height: The height the image should have or -1 to not constrain the height
997 * @error: Return location for an error
999 * Creates a new pixbuf by loading an image from a file. The file format is
1000 * detected automatically. If %NULL is returned, then @error will be set.
1001 * Possible errors are in the #GDK_PIXBUF_ERROR and #G_FILE_ERROR domains.
1002 * The image will be scaled to fit in the requested size, preserving
1003 * the image's aspect ratio.
1005 * Return value: A newly-created pixbuf with a reference count of 1, or
1006 * %NULL if any of several error conditions occurred: the file could not
1007 * be opened, there was no loader for the file's format, there was not
1008 * enough memory to allocate the image buffer, or the image file contained
1014 gdk_pixbuf_new_from_file_at_size (const char *filename,
1019 return gdk_pixbuf_new_from_file_at_scale (filename,
1026 #undef gdk_pixbuf_new_from_file_at_size
1029 gdk_pixbuf_new_from_file_at_size (const char *filename,
1034 gchar *utf8_filename =
1035 g_locale_to_utf8 (filename, -1, NULL, NULL, error);
1038 if (utf8_filename == NULL)
1041 retval = gdk_pixbuf_new_from_file_at_size_utf8 (utf8_filename,
1045 g_free (utf8_filename);
1052 * gdk_pixbuf_new_from_file_at_scale:
1053 * @filename: Name of file to load, in the GLib file name encoding
1054 * @width: The width the image should have or -1 to not constrain the width
1055 * @height: The height the image should have or -1 to not constrain the height
1056 * @preserve_aspect_ratio: %TRUE to preserve the image's aspect ratio
1057 * @error: Return location for an error
1059 * Creates a new pixbuf by loading an image from a file. The file format is
1060 * detected automatically. If %NULL is returned, then @error will be set.
1061 * Possible errors are in the #GDK_PIXBUF_ERROR and #G_FILE_ERROR domains.
1062 * The image will be scaled to fit in the requested size, optionally preserving
1063 * the image's aspect ratio.
1065 * When preserving the aspect ratio, a @width of -1 will cause the image
1066 * to be scaled to the exact given height, and a @height of -1 will cause
1067 * the image to be scaled to the exact given width. When not preserving
1068 * aspect ratio, a @width or @height of -1 means to not scale the image
1069 * at all in that dimension. Negative values for @width and @height are
1070 * allowed since 2.8.
1072 * Return value: A newly-created pixbuf with a reference count of 1, or %NULL
1073 * if any of several error conditions occurred: the file could not be opened,
1074 * there was no loader for the file's format, there was not enough memory to
1075 * allocate the image buffer, or the image file contained invalid data.
1080 gdk_pixbuf_new_from_file_at_scale (const char *filename,
1083 gboolean preserve_aspect_ratio,
1087 GdkPixbufLoader *loader;
1090 guchar buffer [4096];
1096 gboolean preserve_aspect_ratio;
1098 GdkPixbufAnimation *animation;
1099 GdkPixbufAnimationIter *iter;
1102 g_return_val_if_fail (filename != NULL, NULL);
1103 g_return_val_if_fail (width > 0 || width == -1, NULL);
1104 g_return_val_if_fail (height > 0 || height == -1, NULL);
1106 f = g_fopen (filename, "rb");
1108 gint save_errno = errno;
1109 gchar *display_name = g_filename_display_name (filename);
1112 g_file_error_from_errno (save_errno),
1113 _("Failed to open file '%s': %s"),
1115 g_strerror (save_errno));
1116 g_free (display_name);
1120 loader = gdk_pixbuf_loader_new ();
1123 info.height = height;
1124 info.preserve_aspect_ratio = preserve_aspect_ratio;
1126 g_signal_connect (loader, "size-prepared", G_CALLBACK (size_prepared_cb), &info);
1129 while (!has_frame && !feof (f) && !ferror (f)) {
1130 length = fread (buffer, 1, sizeof (buffer), f);
1132 if (!gdk_pixbuf_loader_write (loader, buffer, length, error)) {
1133 gdk_pixbuf_loader_close (loader, NULL);
1135 g_object_unref (loader);
1139 animation = gdk_pixbuf_loader_get_animation (loader);
1141 iter = gdk_pixbuf_animation_get_iter (animation, NULL);
1142 if (!gdk_pixbuf_animation_iter_on_currently_loading_frame (iter)) {
1145 g_object_unref (iter);
1151 if (!gdk_pixbuf_loader_close (loader, error) && !has_frame) {
1152 g_object_unref (loader);
1156 pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
1159 gchar *display_name = g_filename_display_name (filename);
1160 g_object_unref (loader);
1163 GDK_PIXBUF_ERROR_FAILED,
1164 _("Failed to load image '%s': reason not known, probably a corrupt image file"),
1166 g_free (display_name);
1170 g_object_ref (pixbuf);
1172 g_object_unref (loader);
1179 #undef gdk_pixbuf_new_from_file_at_scale
1182 gdk_pixbuf_new_from_file_at_scale (const char *filename,
1185 gboolean preserve_aspect_ratio,
1188 gchar *utf8_filename =
1189 g_locale_to_utf8 (filename, -1, NULL, NULL, error);
1192 if (utf8_filename == NULL)
1195 retval = gdk_pixbuf_new_from_file_at_scale_utf8 (utf8_filename,
1197 preserve_aspect_ratio,
1200 g_free (utf8_filename);
1208 info_cb (GdkPixbufLoader *loader,
1214 GdkPixbufFormat *format;
1219 g_return_if_fail (width > 0 && height > 0);
1221 info->format = gdk_pixbuf_loader_get_format (loader);
1222 info->width = width;
1223 info->height = height;
1225 gdk_pixbuf_loader_set_size (loader, 0, 0);
1229 * gdk_pixbuf_get_file_info:
1230 * @filename: The name of the file to identify.
1231 * @width: Return location for the width of the image, or %NULL
1232 * @height: Return location for the height of the image, or %NULL
1234 * Parses an image file far enough to determine its format and size.
1236 * Returns: A #GdkPixbufFormat describing the image format of the file
1237 * or %NULL if the image format wasn't recognized. The return value
1238 * is owned by GdkPixbuf and should not be freed.
1243 gdk_pixbuf_get_file_info (const gchar *filename,
1247 GdkPixbufLoader *loader;
1248 guchar buffer [4096];
1252 GdkPixbufFormat *format;
1257 g_return_val_if_fail (filename != NULL, NULL);
1259 f = g_fopen (filename, "rb");
1263 loader = gdk_pixbuf_loader_new ();
1269 g_signal_connect (loader, "size-prepared", G_CALLBACK (info_cb), &info);
1271 while (!feof (f) && !ferror (f)) {
1272 length = fread (buffer, 1, sizeof (buffer), f);
1274 if (!gdk_pixbuf_loader_write (loader, buffer, length, NULL))
1277 if (info.format != NULL)
1282 gdk_pixbuf_loader_close (loader, NULL);
1283 g_object_unref (loader);
1286 *width = info.width;
1288 *height = info.height;
1294 * gdk_pixbuf_new_from_xpm_data:
1295 * @data: Pointer to inline XPM data.
1297 * Creates a new pixbuf by parsing XPM data in memory. This data is commonly
1298 * the result of including an XPM file into a program's C source.
1300 * Return value: A newly-created pixbuf with a reference count of 1.
1303 gdk_pixbuf_new_from_xpm_data (const char **data)
1305 GdkPixbuf *(* load_xpm_data) (const char **data);
1307 GError *error = NULL;
1308 GdkPixbufModule *xpm_module;
1311 xpm_module = _gdk_pixbuf_get_named_module ("xpm", &error);
1312 if (xpm_module == NULL) {
1313 g_warning ("Error loading XPM image loader: %s", error->message);
1314 g_error_free (error);
1318 if (xpm_module->module == NULL) {
1319 if (!_gdk_pixbuf_load_module (xpm_module, &error)) {
1320 g_warning ("Error loading XPM image loader: %s", error->message);
1321 g_error_free (error);
1326 locked = _gdk_pixbuf_lock (xpm_module);
1328 if (xpm_module->load_xpm_data == NULL) {
1329 g_warning ("gdk-pixbuf XPM module lacks XPM data capability");
1332 load_xpm_data = xpm_module->load_xpm_data;
1333 pixbuf = (* load_xpm_data) (data);
1337 _gdk_pixbuf_unlock (xpm_module);
1342 collect_save_options (va_list opts,
1355 next = va_arg (opts, gchar*);
1359 val = va_arg (opts, gchar*);
1364 *keys = g_realloc (*keys, sizeof(gchar*) * (count + 1));
1365 *vals = g_realloc (*vals, sizeof(gchar*) * (count + 1));
1367 (*keys)[count-1] = g_strdup (key);
1368 (*vals)[count-1] = g_strdup (val);
1370 (*keys)[count] = NULL;
1371 (*vals)[count] = NULL;
1373 next = va_arg (opts, gchar*);
1378 save_to_file_callback (const gchar *buf,
1383 FILE *filehandle = data;
1386 n = fwrite (buf, 1, count, filehandle);
1388 gint save_errno = errno;
1391 g_file_error_from_errno (save_errno),
1392 _("Error writing to image file: %s"),
1393 g_strerror (save_errno));
1400 gdk_pixbuf_real_save (GdkPixbuf *pixbuf,
1408 GdkPixbufModule *image_module = NULL;
1411 image_module = _gdk_pixbuf_get_named_module (type, error);
1413 if (image_module == NULL)
1416 if (image_module->module == NULL)
1417 if (!_gdk_pixbuf_load_module (image_module, error))
1420 locked = _gdk_pixbuf_lock (image_module);
1422 if (image_module->save) {
1424 ret = (* image_module->save) (filehandle, pixbuf,
1427 } else if (image_module->save_to_callback) {
1428 /* save with simple callback */
1429 ret = (* image_module->save_to_callback) (save_to_file_callback,
1437 GDK_PIXBUF_ERROR_UNSUPPORTED_OPERATION,
1438 _("This build of gdk-pixbuf does not support saving the image format: %s"),
1444 _gdk_pixbuf_unlock (image_module);
1448 #define TMP_FILE_BUF_SIZE 4096
1451 save_to_callback_with_tmp_file (GdkPixbufModule *image_module,
1453 GdkPixbufSaveFunc save_func,
1461 gboolean retval = FALSE;
1464 gchar *filename = NULL;
1467 buf = g_try_malloc (TMP_FILE_BUF_SIZE);
1471 GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY,
1472 _("Insufficient memory to save image to callback"));
1476 fd = g_file_open_tmp ("gdkpixbuf-save-tmp.XXXXXX", &filename, error);
1479 f = fdopen (fd, "wb+");
1481 gint save_errno = errno;
1484 g_file_error_from_errno (save_errno),
1485 _("Failed to open temporary file"));
1489 locked = _gdk_pixbuf_lock (image_module);
1490 retval = (image_module->save) (f, pixbuf, keys, values, error);
1492 _gdk_pixbuf_unlock (image_module);
1498 n = fread (buf, 1, TMP_FILE_BUF_SIZE, f);
1500 if (!save_func (buf, n, error, user_data))
1503 if (n != TMP_FILE_BUF_SIZE)
1507 gint save_errno = errno;
1510 g_file_error_from_errno (save_errno),
1511 _("Failed to read from temporary file"));
1517 /* cleanup and return retval */
1521 g_unlink (filename);
1530 gdk_pixbuf_real_save_to_callback (GdkPixbuf *pixbuf,
1531 GdkPixbufSaveFunc save_func,
1539 GdkPixbufModule *image_module = NULL;
1542 image_module = _gdk_pixbuf_get_named_module (type, error);
1544 if (image_module == NULL)
1547 if (image_module->module == NULL)
1548 if (!_gdk_pixbuf_load_module (image_module, error))
1551 locked = _gdk_pixbuf_lock (image_module);
1553 if (image_module->save_to_callback) {
1555 ret = (* image_module->save_to_callback) (save_func, user_data,
1556 pixbuf, keys, values,
1558 } else if (image_module->save) {
1559 /* use a temporary file */
1560 ret = save_to_callback_with_tmp_file (image_module, pixbuf,
1561 save_func, user_data,
1568 GDK_PIXBUF_ERROR_UNSUPPORTED_OPERATION,
1569 _("This build of gdk-pixbuf does not support saving the image format: %s"),
1575 _gdk_pixbuf_unlock (image_module);
1582 * @pixbuf: a #GdkPixbuf.
1583 * @filename: name of file to save.
1584 * @type: name of file format.
1585 * @error: return location for error, or %NULL
1586 * @Varargs: list of key-value save options
1588 * Saves pixbuf to a file in format @type. By default, "jpeg", "png", "ico"
1589 * and "bmp" are possible file formats to save in, but more formats may be
1590 * installed. The list of all writable formats can be determined in the
1593 * <informalexample><programlisting>
1594 * void add_if_writable (GdkPixbufFormat *data, GSList **list)
1596 * if (gdk_pixbuf_format_is_writable (data))
1597 * *list = g_slist_prepend (*list, data);
1600 * GSList *formats = gdk_pixbuf_get_formats (<!-- -->);
1601 * GSList *writable_formats = NULL;
1602 * g_slist_foreach (formats, add_if_writable, &writable_formats);
1603 * g_slist_free (formats);
1604 * </programlisting></informalexample>
1606 * If @error is set, %FALSE will be returned. Possible errors include
1607 * those in the #GDK_PIXBUF_ERROR domain and those in the #G_FILE_ERROR domain.
1609 * The variable argument list should be %NULL-terminated; if not empty,
1610 * it should contain pairs of strings that modify the save
1611 * parameters. For example:
1612 * <informalexample><programlisting>
1613 * gdk_pixbuf_save (pixbuf, handle, "jpeg", &error,
1614 * "quality", "100", NULL);
1615 * </programlisting></informalexample>
1617 * Currently only few parameters exist. JPEG images can be saved with a
1618 * "quality" parameter; its value should be in the range [0,100].
1620 * Text chunks can be attached to PNG images by specifying parameters of
1621 * the form "tEXt::key", where key is an ASCII string of length 1-79.
1622 * The values are UTF-8 encoded strings. The PNG compression level can
1623 * be specified using the "compression" parameter; it's value is in an
1624 * integer in the range of [0,9].
1626 * ICO images can be saved in depth 16, 24, or 32, by using the "depth"
1627 * parameter. When the ICO saver is given "x_hot" and "y_hot" parameters,
1628 * it produces a CUR instead of an ICO.
1630 * Return value: whether an error was set
1634 gdk_pixbuf_save (GdkPixbuf *pixbuf,
1635 const char *filename,
1640 gchar **keys = NULL;
1641 gchar **values = NULL;
1645 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
1647 va_start (args, error);
1649 collect_save_options (args, &keys, &values);
1653 result = gdk_pixbuf_savev (pixbuf, filename, type,
1658 g_strfreev (values);
1665 #undef gdk_pixbuf_save
1668 gdk_pixbuf_save (GdkPixbuf *pixbuf,
1669 const char *filename,
1674 char *utf8_filename;
1675 gchar **keys = NULL;
1676 gchar **values = NULL;
1680 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
1682 utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, error);
1684 if (utf8_filename == NULL)
1687 va_start (args, error);
1689 collect_save_options (args, &keys, &values);
1693 result = gdk_pixbuf_savev_utf8 (pixbuf, utf8_filename, type,
1697 g_free (utf8_filename);
1700 g_strfreev (values);
1709 * @pixbuf: a #GdkPixbuf.
1710 * @filename: name of file to save.
1711 * @type: name of file format.
1712 * @option_keys: name of options to set, %NULL-terminated
1713 * @option_values: values for named options
1714 * @error: return location for error, or %NULL
1716 * Saves pixbuf to a file in @type, which is currently "jpeg", "png", "tiff", "ico" or "bmp".
1717 * If @error is set, %FALSE will be returned.
1718 * See gdk_pixbuf_save () for more details.
1720 * Return value: whether an error was set
1724 gdk_pixbuf_savev (GdkPixbuf *pixbuf,
1725 const char *filename,
1728 char **option_values,
1734 g_return_val_if_fail (filename != NULL, FALSE);
1735 g_return_val_if_fail (type != NULL, FALSE);
1736 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
1738 f = g_fopen (filename, "wb");
1741 gint save_errno = errno;
1742 gchar *display_name = g_filename_display_name (filename);
1745 g_file_error_from_errno (save_errno),
1746 _("Failed to open '%s' for writing: %s"),
1748 g_strerror (save_errno));
1749 g_free (display_name);
1754 result = gdk_pixbuf_real_save (pixbuf, f, type,
1755 option_keys, option_values,
1760 g_return_val_if_fail (error == NULL || *error != NULL, FALSE);
1765 if (fclose (f) < 0) {
1766 gint save_errno = errno;
1767 gchar *display_name = g_filename_display_name (filename);
1770 g_file_error_from_errno (save_errno),
1771 _("Failed to close '%s' while writing image, all data may not have been saved: %s"),
1773 g_strerror (save_errno));
1774 g_free (display_name);
1783 #undef gdk_pixbuf_savev
1786 gdk_pixbuf_savev (GdkPixbuf *pixbuf,
1787 const char *filename,
1790 char **option_values,
1793 char *utf8_filename;
1796 g_return_val_if_fail (filename != NULL, FALSE);
1798 utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, error);
1800 if (utf8_filename == NULL)
1803 retval = gdk_pixbuf_savev_utf8 (pixbuf, utf8_filename, type,
1804 option_keys, option_values, error);
1806 g_free (utf8_filename);
1814 * gdk_pixbuf_save_to_callback:
1815 * @pixbuf: a #GdkPixbuf.
1816 * @save_func: a function that is called to save each block of data that
1817 * the save routine generates.
1818 * @user_data: user data to pass to the save function.
1819 * @type: name of file format.
1820 * @error: return location for error, or %NULL
1821 * @Varargs: list of key-value save options
1823 * Saves pixbuf in format @type by feeding the produced data to a
1824 * callback. Can be used when you want to store the image to something
1825 * other than a file, such as an in-memory buffer or a socket.
1826 * If @error is set, %FALSE will be returned. Possible errors
1827 * include those in the #GDK_PIXBUF_ERROR domain and whatever the save
1828 * function generates.
1830 * See gdk_pixbuf_save() for more details.
1832 * Return value: whether an error was set
1837 gdk_pixbuf_save_to_callback (GdkPixbuf *pixbuf,
1838 GdkPixbufSaveFunc save_func,
1844 gchar **keys = NULL;
1845 gchar **values = NULL;
1849 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
1851 va_start (args, error);
1853 collect_save_options (args, &keys, &values);
1857 result = gdk_pixbuf_save_to_callbackv (pixbuf, save_func, user_data,
1862 g_strfreev (values);
1868 * gdk_pixbuf_save_to_callbackv:
1869 * @pixbuf: a #GdkPixbuf.
1870 * @save_func: a function that is called to save each block of data that
1871 * the save routine generates.
1872 * @user_data: user data to pass to the save function.
1873 * @type: name of file format.
1874 * @option_keys: name of options to set, %NULL-terminated
1875 * @option_values: values for named options
1876 * @error: return location for error, or %NULL
1878 * Saves pixbuf to a callback in format @type, which is currently "jpeg",
1879 * "png", "tiff", "ico" or "bmp". If @error is set, %FALSE will be returned. See
1880 * gdk_pixbuf_save_to_callback () for more details.
1882 * Return value: whether an error was set
1887 gdk_pixbuf_save_to_callbackv (GdkPixbuf *pixbuf,
1888 GdkPixbufSaveFunc save_func,
1892 char **option_values,
1898 g_return_val_if_fail (save_func != NULL, FALSE);
1899 g_return_val_if_fail (type != NULL, FALSE);
1900 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
1902 result = gdk_pixbuf_real_save_to_callback (pixbuf,
1903 save_func, user_data, type,
1904 option_keys, option_values,
1908 g_return_val_if_fail (error == NULL || *error != NULL, FALSE);
1916 * gdk_pixbuf_save_to_buffer:
1917 * @pixbuf: a #GdkPixbuf.
1918 * @buffer: location to receive a pointer to the new buffer.
1919 * @buffer_size: location to receive the size of the new buffer.
1920 * @type: name of file format.
1921 * @error: return location for error, or %NULL
1922 * @Varargs: list of key-value save options
1924 * Saves pixbuf to a new buffer in format @type, which is currently "jpeg",
1925 * "png", "tiff", "ico" or "bmp". This is a convenience function that uses
1926 * gdk_pixbuf_save_to_callback() to do the real work. Note that the buffer
1927 * is not nul-terminated and may contain embedded nuls.
1928 * If @error is set, %FALSE will be returned and @string will be set to
1929 * %NULL. Possible errors include those in the #GDK_PIXBUF_ERROR
1932 * See gdk_pixbuf_save() for more details.
1934 * Return value: whether an error was set
1939 gdk_pixbuf_save_to_buffer (GdkPixbuf *pixbuf,
1946 gchar **keys = NULL;
1947 gchar **values = NULL;
1951 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
1953 va_start (args, error);
1955 collect_save_options (args, &keys, &values);
1959 result = gdk_pixbuf_save_to_bufferv (pixbuf, buffer, buffer_size,
1964 g_strfreev (values);
1969 struct SaveToBufferData {
1975 save_to_buffer_callback (const gchar *data,
1980 struct SaveToBufferData *sdata = user_data;
1984 if (sdata->len + count > sdata->max) {
1985 new_max = MAX (sdata->max*2, sdata->len + count);
1986 new_buffer = g_try_realloc (sdata->buffer, new_max);
1990 GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY,
1991 _("Insufficient memory to save image into a buffer"));
1994 sdata->buffer = new_buffer;
1995 sdata->max = new_max;
1997 memcpy (sdata->buffer + sdata->len, data, count);
1998 sdata->len += count;
2003 * gdk_pixbuf_save_to_bufferv:
2004 * @pixbuf: a #GdkPixbuf.
2005 * @buffer: location to receive a pointer to the new buffer.
2006 * @buffer_size: location to receive the size of the new buffer.
2007 * @type: name of file format.
2008 * @option_keys: name of options to set, %NULL-terminated
2009 * @option_values: values for named options
2010 * @error: return location for error, or %NULL
2012 * Saves pixbuf to a new buffer in format @type, which is currently "jpeg",
2013 * "tiff", "png", "ico" or "bmp". See gdk_pixbuf_save_to_buffer() for more details.
2015 * Return value: whether an error was set
2020 gdk_pixbuf_save_to_bufferv (GdkPixbuf *pixbuf,
2025 char **option_values,
2028 static const gint initial_max = 1024;
2029 struct SaveToBufferData sdata;
2034 sdata.buffer = g_try_malloc (initial_max);
2035 sdata.max = initial_max;
2037 if (!sdata.buffer) {
2040 GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY,
2041 _("Insufficient memory to save image into a buffer"));
2045 if (!gdk_pixbuf_save_to_callbackv (pixbuf,
2046 save_to_buffer_callback, &sdata,
2047 type, option_keys, option_values,
2049 g_free (sdata.buffer);
2053 *buffer = sdata.buffer;
2054 *buffer_size = sdata.len;
2059 * gdk_pixbuf_format_get_name:
2060 * @format: a #GdkPixbufFormat
2062 * Returns the name of the format.
2064 * Return value: the name of the format.
2069 gdk_pixbuf_format_get_name (GdkPixbufFormat *format)
2071 g_return_val_if_fail (format != NULL, NULL);
2073 return g_strdup (format->name);
2077 * gdk_pixbuf_format_get_description:
2078 * @format: a #GdkPixbufFormat
2080 * Returns a description of the format.
2082 * Return value: a description of the format.
2087 gdk_pixbuf_format_get_description (GdkPixbufFormat *format)
2091 g_return_val_if_fail (format != NULL, NULL);
2093 if (format->domain != NULL)
2094 domain = format->domain;
2096 domain = GETTEXT_PACKAGE;
2097 description = dgettext (domain, format->description);
2099 return g_strdup (description);
2103 * gdk_pixbuf_format_get_mime_types:
2104 * @format: a #GdkPixbufFormat
2106 * Returns the mime types supported by the format.
2108 * Return value: a %NULL-terminated array of mime types which must be freed with
2109 * g_strfreev() when it is no longer needed.
2114 gdk_pixbuf_format_get_mime_types (GdkPixbufFormat *format)
2116 g_return_val_if_fail (format != NULL, NULL);
2118 return g_strdupv (format->mime_types);
2122 * gdk_pixbuf_format_get_extensions:
2123 * @format: a #GdkPixbufFormat
2125 * Returns the filename extensions typically used for files in the
2128 * Return value: a %NULL-terminated array of filename extensions which must be
2129 * freed with g_strfreev() when it is no longer needed.
2134 gdk_pixbuf_format_get_extensions (GdkPixbufFormat *format)
2136 g_return_val_if_fail (format != NULL, NULL);
2138 return g_strdupv (format->extensions);
2142 * gdk_pixbuf_format_is_writable:
2143 * @format: a #GdkPixbufFormat
2145 * Returns whether pixbufs can be saved in the given format.
2147 * Return value: whether pixbufs can be saved in the given format.
2152 gdk_pixbuf_format_is_writable (GdkPixbufFormat *format)
2154 g_return_val_if_fail (format != NULL, FALSE);
2156 return (format->flags & GDK_PIXBUF_FORMAT_WRITABLE) != 0;
2160 * gdk_pixbuf_format_is_scalable:
2161 * @format: a #GdkPixbufFormat
2163 * Returns whether this image format is scalable. If a file is in a
2164 * scalable format, it is preferable to load it at the desired size,
2165 * rather than loading it at the default size and scaling the
2166 * resulting pixbuf to the desired size.
2168 * Return value: whether this image format is scalable.
2173 gdk_pixbuf_format_is_scalable (GdkPixbufFormat *format)
2175 g_return_val_if_fail (format != NULL, FALSE);
2177 return (format->flags & GDK_PIXBUF_FORMAT_SCALABLE) != 0;
2181 * gdk_pixbuf_format_is_disabled:
2182 * @format: a #GdkPixbufFormat
2184 * Returns whether this image format is disabled. See
2185 * gdk_pixbuf_format_set_disabled().
2187 * Return value: whether this image format is disabled.
2192 gdk_pixbuf_format_is_disabled (GdkPixbufFormat *format)
2194 g_return_val_if_fail (format != NULL, FALSE);
2196 return format->disabled;
2200 * gdk_pixbuf_format_set_disabled:
2201 * @format: a #GdkPixbufFormat
2202 * @disabled: %TRUE to disable the format @format
2204 * Disables or enables an image format. If a format is disabled,
2205 * gdk-pixbuf won't use the image loader for this format to load
2206 * images. Applications can use this to avoid using image loaders
2207 * with an inappropriate license, see gdk_pixbuf_format_get_license().
2212 gdk_pixbuf_format_set_disabled (GdkPixbufFormat *format,
2215 g_return_if_fail (format != NULL);
2217 format->disabled = disabled != FALSE;
2221 * gdk_pixbuf_format_get_license:
2222 * @format: a #GdkPixbufFormat
2224 * Returns information about the license of the image loader for the format. The
2225 * returned string should be a shorthand for a wellknown license, e.g. "LGPL",
2226 * "GPL", "QPL", "GPL/QPL", or "other" to indicate some other license. This
2227 * string should be freed with g_free() when it's no longer needed.
2229 * Returns: a string describing the license of @format.
2234 gdk_pixbuf_format_get_license (GdkPixbufFormat *format)
2236 g_return_val_if_fail (format != NULL, NULL);
2238 return g_strdup (format->license);
2242 _gdk_pixbuf_get_format (GdkPixbufModule *module)
2244 g_return_val_if_fail (module != NULL, NULL);
2246 return module->info;
2250 * gdk_pixbuf_get_formats:
2252 * Obtains the available information about the image formats supported
2255 * Returns: A list of #GdkPixbufFormat<!-- -->s describing the supported
2256 * image formats. The list should be freed when it is no longer needed,
2257 * but the structures themselves are owned by #GdkPixbuf and should not be
2263 gdk_pixbuf_get_formats (void)
2265 GSList *result = NULL;
2268 for (modules = get_file_formats (); modules; modules = g_slist_next (modules)) {
2269 GdkPixbufModule *module = (GdkPixbufModule *)modules->data;
2270 GdkPixbufFormat *info = _gdk_pixbuf_get_format (module);
2271 result = g_slist_prepend (result, info);
2278 #define __GDK_PIXBUF_IO_C__
2279 #include "gdk-pixbuf-aliasdef.c"