gdip-pixbuf-loader r19 - trunk/src



Author: doml
Date: Tue Feb 19 01:52:59 2008
New Revision: 19
URL: http://svn.gnome.org/viewvc/gdip-pixbuf-loader?rev=19&view=rev

Log:
Start of animation loading; fix frame counting

Modified:
   trunk/src/io-gdip-utils.c
   trunk/src/io-gdip.c

Modified: trunk/src/io-gdip-utils.c
==============================================================================
--- trunk/src/io-gdip-utils.c	(original)
+++ trunk/src/io-gdip-utils.c	Tue Feb 19 01:52:59 2008
@@ -589,7 +589,7 @@
         if (bitmap == NULL || n_frames == NULL)
                 return FALSE;
 
-        *n_frames = 0;
+        *n_frames = 1;
 
         return (0 == GdipImageGetFrameCount((GpImage*) bitmap, (timeDimension ? &FrameDimensionTime : &FrameDimensionPage), n_frames));
 }

Modified: trunk/src/io-gdip.c
==============================================================================
--- trunk/src/io-gdip.c	(original)
+++ trunk/src/io-gdip.c	Tue Feb 19 01:52:59 2008
@@ -76,10 +76,10 @@
 }
 
 static void
-emit_prepared (GdipContext *context, GdkPixbuf *pixbuf)
+emit_prepared (GdipContext *context, GdkPixbuf *pixbuf, GdkPixbufAnimation *anim)
 {
         if (context->prepared_func != NULL)
-                (* context->prepared_func) (pixbuf, NULL, context->user_data);
+                (* context->prepared_func) (pixbuf, anim, context->user_data);
 }
 
 static gpointer
@@ -128,15 +128,9 @@
         return TRUE;
 }
 
-static gboolean
-gdk_pixbuf__gdip_image_stop_load (gpointer data, GError **error)
+static GdkPixbuf*
+gdi_bitmap_to_pixbuf (GpBitmap *bitmap)
 {
-        GdipContext      *context = (GdipContext *)data;
-	GpBitmap         *bitmap = NULL;
-
-	GByteArray *image_buffer = context->buffer;
-	guint8       *tmp_buffer = NULL;
-	guint	      buffer_len = 0;
         GdkPixbuf        *pixbuf = NULL;
 	guchar            *cursor = NULL;
         gint rowstride;
@@ -145,21 +139,6 @@
 
 	guint width = 0, height = 0, x, y;
 
-        if (error)
-                *error = NULL;
-
-	buffer_len = image_buffer->len;
-	tmp_buffer = image_buffer->data;
-
-	bitmap = io_gdip_buffer_to_bitmap ((gchar*)image_buffer->data, image_buffer->len);
-
-	if (!bitmap)
-                {
-                        destroy_gdipcontext (context);
-                        gdip_propegate_error (error, "Couldn't load bitmap", GDK_PIXBUF_ERROR_CORRUPT_IMAGE);
-                        return FALSE;
-                }
-
 	io_gdip_bitmap_get_size (bitmap, &width, &height);
         io_gdip_bitmap_get_has_alpha (bitmap, &has_alpha);
 
@@ -167,9 +146,7 @@
 
 	if (!pixbuf)
                 {
-                        destroy_gdipcontext (context);
-                        gdip_propegate_error (error, "Couldn't create pixbuf", GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY);
-                        return FALSE;
+                        return NULL;
                 }
 
         rowstride = gdk_pixbuf_get_rowstride (pixbuf);
@@ -205,44 +182,80 @@
                                                 }
                                 }
                 }
-        
-        if (context->size_func)
+
+        return pixbuf;
+}
+
+static gboolean
+gdk_pixbuf__gdip_image_stop_load (gpointer data, GError **error)
+{
+        GdipContext      *context = (GdipContext *)data;
+	GpBitmap         *bitmap = NULL;
+
+	GByteArray *image_buffer = context->buffer;
+	guint8       *tmp_buffer = NULL;
+	guint	      buffer_len = 0;
+        guint n_frames = 1, i;
+        GdkPixbufAnimation *anim = NULL;
+
+        if (error)
+                *error = NULL;
+
+	buffer_len = image_buffer->len;
+	tmp_buffer = image_buffer->data;
+
+	bitmap = io_gdip_buffer_to_bitmap ((gchar*)image_buffer->data, image_buffer->len);
+
+	if (!bitmap)
                 {
-                        gint w = width;
-                        gint h = height;
-                        
-                        (*context->size_func) (&w, &h, context->user_data);
-                        if (w == 0 || h == 0)
+                        destroy_gdipcontext (context);
+                        gdip_propegate_error (error, "Couldn't load bitmap", GDK_PIXBUF_ERROR_CORRUPT_IMAGE);
+                        return FALSE;
+                }
+
+        io_gdip_bitmap_get_n_frames (bitmap, &n_frames, TRUE);
+
+        for (i = 0; i < n_frames; i++)
+                {
+                        GdkPixbuf *pixbuf = NULL;
+
+                        io_gdip_bitmap_select_frame (bitmap, i, TRUE);
+
+                        if (n_frames > 1 && i == 0)
+                                {
+                                        guint delay; /* in hundredths per second */
+                                        guint width = 0, height = 0;
+                                        gfloat rate = 1;
+
+                                        io_gdip_bitmap_get_frame_delay (bitmap, &delay);                                        
+                                        rate = 1.0f / ((gfloat)delay / 100);
+
+                                        io_gdip_bitmap_get_size (bitmap, &width, &height);
+                                        // anim = GDK_PIXBUF_ANIMATION(gdk_pixbuf_simple_anim_new (width, height, rate));
+                                }
+
+                        pixbuf = gdi_bitmap_to_pixbuf (bitmap);
+
+                        if (!pixbuf)
                                 {
                                         destroy_gdipcontext (context);
-                                        g_object_unref (pixbuf);
-                                        gdip_propegate_error (error,
-                                                              "Transformed image has zero width or height.",
-                                                              GDK_PIXBUF_ERROR_FAILED);
+                                        gdip_propegate_error (error, "Couldn't create pixbuf", GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY);
                                         return FALSE;
-                                        
                                 }
-                        else if (w != width || h != height)
+
+                        if (anim != NULL)
                                 {
-                                        GdkPixbuf *new_pixbuf;
-                                        
-                                        new_pixbuf = gdk_pixbuf_scale_simple (pixbuf, w, h, GDK_INTERP_BILINEAR);
-                                        
-                                        g_object_unref (pixbuf);
-                                        pixbuf = new_pixbuf;
-                                        
-                                        if (pixbuf == NULL)
-                                                {
-                                                        destroy_gdipcontext (context);
-                                                        gdip_propegate_error (error, "Couldn't scale pixbuf", GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY);
-                                                        return FALSE;
-                                                }
+                                        gdk_pixbuf_simple_anim_add_frame (GDK_PIXBUF_SIMPLE_ANIM(anim), pixbuf);
                                 }
+
+                        if (i == 0)
+                                {
+                                        emit_prepared (context, pixbuf, anim);
+                                }
+
+                        emit_updated (context, pixbuf);
                 }
         
-	emit_updated (context, pixbuf);
-        emit_prepared (context, pixbuf);
-        
         destroy_gdipcontext (context);
         
         return TRUE;



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