summaryrefslogtreecommitdiff
path: root/gdk-pixbuf/gdk-pixbuf-animation.c
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2013-01-30 02:42:10 +0100
committerBenjamin Otte <otte@redhat.com>2013-01-30 02:43:28 +0100
commitd61332905bf0187dc117e85202590514e095f16e (patch)
tree4479076f60cf369558626103d7383e7d87c9ce7e /gdk-pixbuf/gdk-pixbuf-animation.c
parent14abea3a93763757ddd1f3249f67f237853e7050 (diff)
downloadgdk-pixbuf-d61332905bf0187dc117e85202590514e095f16e.tar.gz
animation: Try using begin_load to load animations
... instead of just falling back to a regular pixbuf when the load_animation vfunc isn't implemented. The code is mostly copied from the ANI loader, which did exactly this in load_animation.
Diffstat (limited to 'gdk-pixbuf/gdk-pixbuf-animation.c')
-rw-r--r--gdk-pixbuf/gdk-pixbuf-animation.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/gdk-pixbuf/gdk-pixbuf-animation.c b/gdk-pixbuf/gdk-pixbuf-animation.c
index d17625980..e47a9f18d 100644
--- a/gdk-pixbuf/gdk-pixbuf-animation.c
+++ b/gdk-pixbuf/gdk-pixbuf-animation.c
@@ -107,6 +107,19 @@ gdk_pixbuf_animation_init (GdkPixbufAnimation *animation)
{
}
+static void
+prepared_notify (GdkPixbuf *pixbuf,
+ GdkPixbufAnimation *anim,
+ gpointer user_data)
+{
+ if (anim != NULL)
+ g_object_ref (anim);
+ else
+ anim = gdk_pixbuf_non_anim_new (pixbuf);
+
+ *((GdkPixbufAnimation **)user_data) = anim;
+}
+
/**
* gdk_pixbuf_animation_new_from_file:
* @filename: Name of file to load, in the GLib file name encoding
@@ -200,6 +213,37 @@ gdk_pixbuf_animation_new_from_file (const char *filename,
}
fclose (f);
+ } else if (image_module->begin_load != NULL) {
+ guchar buffer[4096];
+ size_t length;
+ GdkPixbufAnimation *anim = NULL;
+ gpointer context;
+
+ fseek (f, 0, SEEK_SET);
+
+ context = image_module->begin_load (NULL, prepared_notify, NULL, &anim, error);
+
+ if (!context)
+ return NULL;
+
+ while (!feof (f) && !ferror (f)) {
+ length = fread (buffer, 1, sizeof (buffer), f);
+ if (length > 0)
+ if (!image_module->load_increment (context, buffer, length, error)) {
+ image_module->stop_load (context, NULL);
+ if (anim != NULL)
+ g_object_unref (anim);
+ return NULL;
+ }
+ }
+
+ if (!image_module->stop_load (context, error)) {
+ if (anim != NULL)
+ g_object_unref (anim);
+ return NULL;
+ }
+
+ fclose (f);
} else {
GdkPixbuf *pixbuf;