[gdk-pixbuf] animation: Try using begin_load to load animations



commit d61332905bf0187dc117e85202590514e095f16e
Author: Benjamin Otte <otte redhat com>
Date:   Wed Jan 30 02:42:10 2013 +0100

    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.

 gdk-pixbuf/gdk-pixbuf-animation.c |   44 +++++++++++++++++++++++++++++++++++++
 1 files changed, 44 insertions(+), 0 deletions(-)
---
diff --git a/gdk-pixbuf/gdk-pixbuf-animation.c b/gdk-pixbuf/gdk-pixbuf-animation.c
index d176259..e47a9f1 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;
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]