summaryrefslogtreecommitdiff
path: root/gdk-pixbuf
diff options
context:
space:
mode:
authorMatthias Clasen <matthias@localhost.localdomain>2003-06-22 19:08:12 +0000
committerMatthias Clasen <matthiasc@src.gnome.org>2003-06-22 19:08:12 +0000
commitde07fd2a7e0a2681759a2e99b5a0e44518d9e7fd (patch)
treee87e5b62f6c8def7fe0eac43a53c64d69e4b6254 /gdk-pixbuf
parenta378391aaa4b7e422a96ae42477f080cc90989a8 (diff)
downloadgdk-pixbuf-de07fd2a7e0a2681759a2e99b5a0e44518d9e7fd.tar.gz
Add gdk_pixbuf_loader_new_with_mime_type.
2003-06-22 Matthias Clasen <matthias@localhost.localdomain> * gdk-pixbuf/gdk-pixbuf-sections.txt: Add gdk_pixbuf_loader_new_with_mime_type.
Diffstat (limited to 'gdk-pixbuf')
-rw-r--r--gdk-pixbuf/ChangeLog3
-rw-r--r--gdk-pixbuf/gdk-pixbuf-loader.c59
-rw-r--r--gdk-pixbuf/gdk-pixbuf-loader.h2
3 files changed, 64 insertions, 0 deletions
diff --git a/gdk-pixbuf/ChangeLog b/gdk-pixbuf/ChangeLog
index 7e4f11a6d..f5907cb34 100644
--- a/gdk-pixbuf/ChangeLog
+++ b/gdk-pixbuf/ChangeLog
@@ -1,5 +1,8 @@
2003-06-22 Matthias Clasen <matthias@localhost.localdomain>
+ * gdk-pixbuf-loader.[hc] (gdk_pixbuf_loader_new_with_mime_type): New function to obtain a loader for a specific mime
+ type. (#105324, Dom Lachowicz)
+
* io-gif.c (gif_get_extension): Reset block_count to 0 for all application extensions, otherwise the data blocks
of unknown extensions are not propertly skipped.
diff --git a/gdk-pixbuf/gdk-pixbuf-loader.c b/gdk-pixbuf/gdk-pixbuf-loader.c
index 79f7230a9..90635ed62 100644
--- a/gdk-pixbuf/gdk-pixbuf-loader.c
+++ b/gdk-pixbuf/gdk-pixbuf-loader.c
@@ -517,6 +517,65 @@ gdk_pixbuf_loader_new_with_type (const char *image_type,
}
/**
+ * gdk_pixbuf_loader_new_with_mime_type:
+ * @mime_type: the mime type to be loaded
+ * @error: return location for an allocated #GError, or %NULL to ignore errors
+ *
+ * Creates a new pixbuf loader object that always attempts to parse
+ * image data as if it were an image of mime type @mime_type, instead of
+ * identifying the type automatically. Useful if you want an error if
+ * the image isn't the expected mime type, for loading image formats
+ * that can't be reliably identified by looking at the data, or if
+ * the user manually forces a specific mime type.
+ *
+ * Return value: A newly-created pixbuf loader.
+ * Since: 2.4
+ **/
+GdkPixbufLoader *
+gdk_pixbuf_loader_new_with_mime_type (const char *mime_type,
+ GError **error)
+{
+ const char * image_type = NULL;
+ char ** mimes;
+
+ GdkPixbufLoader *retval;
+ GError *tmp;
+
+ GSList * formats;
+ GdkPixbufFormat *info;
+ int i, j, length;
+
+ formats = gdk_pixbuf_get_formats ();
+ length = g_slist_length (formats);
+
+ for (i = 0; i < length && image_type == NULL; i++) {
+ info = (GdkPixbufFormat *)g_slist_nth_data (formats, i);
+ mimes = info->mime_types;
+
+ for (j = 0; mimes[j] != NULL; j++)
+ if (g_ascii_strcasecmp (mimes[i], mime_type)) {
+ image_type = info->name;
+ break;
+ }
+ }
+
+ g_slist_free (formats);
+
+ retval = g_object_new (GDK_TYPE_PIXBUF_LOADER, NULL);
+
+ tmp = NULL;
+ gdk_pixbuf_loader_load_module(retval, image_type, &tmp);
+ if (tmp != NULL)
+ {
+ g_propagate_error (error, tmp);
+ g_object_unref (retval);
+ return NULL;
+ }
+
+ return retval;
+}
+
+/**
* gdk_pixbuf_loader_get_pixbuf:
* @loader: A pixbuf loader.
*
diff --git a/gdk-pixbuf/gdk-pixbuf-loader.h b/gdk-pixbuf/gdk-pixbuf-loader.h
index 3b870fc90..743faf92d 100644
--- a/gdk-pixbuf/gdk-pixbuf-loader.h
+++ b/gdk-pixbuf/gdk-pixbuf-loader.h
@@ -70,6 +70,8 @@ GType gdk_pixbuf_loader_get_type (void) G_GNUC_CONST;
GdkPixbufLoader * gdk_pixbuf_loader_new (void);
GdkPixbufLoader * gdk_pixbuf_loader_new_with_type (const char *image_type,
GError **error);
+GdkPixbufLoader * gdk_pixbuf_loader_new_with_mime_type (const char *mime_type,
+ GError **error);
void gdk_pixbuf_loader_set_size (GdkPixbufLoader *loader,
int width,
int height);