[gdk-pixbuf] API: Add gdk_pixbuf_animation_new_from_resource()



commit 1b4919298dd7692e71a642ddf959359b344fc805
Author: Benjamin Otte <otte redhat com>
Date:   Wed Jan 30 15:31:21 2013 +0100

    API: Add gdk_pixbuf_animation_new_from_resource()

 docs/reference/gdk-pixbuf/gdk-pixbuf-sections.txt |    1 +
 gdk-pixbuf/gdk-pixbuf-animation.c                 |   41 +++++++++++++++++++++
 gdk-pixbuf/gdk-pixbuf-animation.h                 |    2 +
 3 files changed, 44 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/gdk-pixbuf/gdk-pixbuf-sections.txt b/docs/reference/gdk-pixbuf/gdk-pixbuf-sections.txt
index a78b53b..97085d2 100644
--- a/docs/reference/gdk-pixbuf/gdk-pixbuf-sections.txt
+++ b/docs/reference/gdk-pixbuf/gdk-pixbuf-sections.txt
@@ -129,6 +129,7 @@ gdk_pixbuf_fill
 GdkPixbufAnimation
 GdkPixbufAnimationIter
 gdk_pixbuf_animation_new_from_file
+gdk_pixbuf_animation_new_from_resource
 gdk_pixbuf_animation_new_from_stream
 gdk_pixbuf_animation_new_from_stream_async
 gdk_pixbuf_animation_new_from_stream_finish
diff --git a/gdk-pixbuf/gdk-pixbuf-animation.c b/gdk-pixbuf/gdk-pixbuf-animation.c
index b3f9a64..9831a18 100644
--- a/gdk-pixbuf/gdk-pixbuf-animation.c
+++ b/gdk-pixbuf/gdk-pixbuf-animation.c
@@ -478,6 +478,47 @@ gdk_pixbuf_animation_new_from_stream_finish (GAsyncResult  *async_result,
 }
 
 /**
+ * gdk_pixbuf_animation_new_from_resource:
+ * @resource_path: the path of the resource file
+ * @error: Return location for an error
+ *
+ * Creates a new pixbuf animation by loading an image from an resource.
+ *
+ * The file format is detected automatically. If %NULL is returned, then
+ * @error will be set.
+ *
+ * Return value: A newly-created animation, or %NULL if any of several error
+ * conditions occurred: the file could not be opened, the image format is
+ * not supported, there was not enough memory to allocate the image buffer,
+ * the stream contained invalid data, or the operation was cancelled.
+ *
+ * Since: 2.28
+ **/
+GdkPixbufAnimation *
+gdk_pixbuf_animation_new_from_resource (const char *resource_path,
+                                        GError    **error)
+{
+	GInputStream *stream;
+	GdkPixbufAnimation *anim;
+	GdkPixbuf *pixbuf;
+
+        pixbuf = _gdk_pixbuf_new_from_resource_try_mmap (resource_path);
+        if (pixbuf) {
+                anim = gdk_pixbuf_non_anim_new (pixbuf);
+                g_object_unref (pixbuf);
+                return anim;
+        }
+
+	stream = g_resources_open_stream (resource_path, 0, error);
+	if (stream == NULL)
+		return NULL;
+
+	anim = gdk_pixbuf_animation_new_from_stream (stream, NULL, error);
+	g_object_unref (stream);
+	return anim;
+}
+
+/**
  * gdk_pixbuf_animation_ref: (skip)
  * @animation: An animation.
  *
diff --git a/gdk-pixbuf/gdk-pixbuf-animation.h b/gdk-pixbuf/gdk-pixbuf-animation.h
index 63d476e..3e68146 100644
--- a/gdk-pixbuf/gdk-pixbuf-animation.h
+++ b/gdk-pixbuf/gdk-pixbuf-animation.h
@@ -81,6 +81,8 @@ void                gdk_pixbuf_animation_new_from_stream_async (GInputStream *st
                                                           gpointer            user_data);
 GdkPixbufAnimation *gdk_pixbuf_animation_new_from_stream_finish (GAsyncResult*async_result,
                                                           GError            **error);
+GdkPixbufAnimation *gdk_pixbuf_animation_new_from_resource(const char        *resource_path,
+                                                          GError            **error);
 
 #ifndef GDK_PIXBUF_DISABLE_DEPRECATED
 G_DEPRECATED_FOR(g_object_ref)



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