summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/reference/gdk-pixbuf/gdk-pixbuf-sections.txt1
-rw-r--r--gdk-pixbuf/gdk-pixbuf-animation.c85
-rw-r--r--gdk-pixbuf/gdk-pixbuf-animation.h3
-rw-r--r--gdk-pixbuf/gdk-pixbuf-io.c1
-rw-r--r--gdk-pixbuf/gdk-pixbuf-private.h2
5 files changed, 91 insertions, 1 deletions
diff --git a/docs/reference/gdk-pixbuf/gdk-pixbuf-sections.txt b/docs/reference/gdk-pixbuf/gdk-pixbuf-sections.txt
index 5b5c58c1f..6b41f16f1 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_stream
gdk_pixbuf_animation_ref
gdk_pixbuf_animation_unref
gdk_pixbuf_animation_get_width
diff --git a/gdk-pixbuf/gdk-pixbuf-animation.c b/gdk-pixbuf/gdk-pixbuf-animation.c
index e47a9f18d..60ef4a131 100644
--- a/gdk-pixbuf/gdk-pixbuf-animation.c
+++ b/gdk-pixbuf/gdk-pixbuf-animation.c
@@ -26,6 +26,7 @@
#include <errno.h>
#include "gdk-pixbuf-private.h"
#include "gdk-pixbuf-animation.h"
+#include "gdk-pixbuf-loader.h"
#include <glib/gstdio.h>
@@ -311,6 +312,90 @@ gdk_pixbuf_animation_new_from_file (const char *filename,
#endif
/**
+ * gdk_pixbuf_animation_new_from_stream:
+ * @stream: a #GInputStream to load the pixbuf from
+ * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore
+ * @error: Return location for an error
+ *
+ * Creates a new animation by loading it from an input stream.
+ *
+ * The file format is detected automatically. If %NULL is returned, then
+ * @error will be set. The @cancellable can be used to abort the operation
+ * from another thread. If the operation was cancelled, the error
+ * %G_IO_ERROR_CANCELLED will be returned. Other possible errors are in
+ * the #GDK_PIXBUF_ERROR and %G_IO_ERROR domains.
+ *
+ * The stream is not closed.
+ *
+ * Return value: A newly-created pixbuf, 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_stream (GInputStream *stream,
+ GCancellable *cancellable,
+ GError **error)
+{
+ GdkPixbufAnimation *animation;
+ GdkPixbufLoader *loader;
+ gssize n_read;
+ guchar buffer[LOAD_BUFFER_SIZE];
+ gboolean res;
+
+ g_return_val_if_fail (G_IS_INPUT_STREAM (stream), NULL);
+ g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
+ g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+
+ loader = gdk_pixbuf_loader_new ();
+
+ res = TRUE;
+ while (1) {
+ n_read = g_input_stream_read (stream,
+ buffer,
+ sizeof (buffer),
+ cancellable,
+ error);
+ if (n_read < 0) {
+ res = FALSE;
+ error = NULL; /* Ignore further errors */
+ break;
+ }
+
+ if (n_read == 0)
+ break;
+
+ if (!gdk_pixbuf_loader_write (loader,
+ buffer,
+ n_read,
+ error)) {
+ res = FALSE;
+ error = NULL;
+ break;
+ }
+ }
+
+ if (!gdk_pixbuf_loader_close (loader, error)) {
+ res = FALSE;
+ error = NULL;
+ }
+
+ if (res) {
+ animation = gdk_pixbuf_loader_get_animation (loader);
+ if (animation)
+ g_object_ref (animation);
+ } else {
+ animation = NULL;
+ }
+
+ g_object_unref (loader);
+
+ return animation;
+}
+
+/**
* 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 1f0c00f4f..38dfc020c 100644
--- a/gdk-pixbuf/gdk-pixbuf-animation.h
+++ b/gdk-pixbuf/gdk-pixbuf-animation.h
@@ -72,6 +72,9 @@ GType gdk_pixbuf_animation_get_type (void) G_GNUC_CONST;
GdkPixbufAnimation *gdk_pixbuf_animation_new_from_file (const char *filename,
GError **error);
+GdkPixbufAnimation *gdk_pixbuf_animation_new_from_stream (GInputStream *stream,
+ GCancellable *cancellable,
+ GError **error);
#ifndef GDK_PIXBUF_DISABLE_DEPRECATED
G_DEPRECATED_FOR(g_object_ref)
diff --git a/gdk-pixbuf/gdk-pixbuf-io.c b/gdk-pixbuf/gdk-pixbuf-io.c
index 0714afd5d..2dc7cd8f0 100644
--- a/gdk-pixbuf/gdk-pixbuf-io.c
+++ b/gdk-pixbuf/gdk-pixbuf-io.c
@@ -48,7 +48,6 @@
#endif
#define SNIFF_BUFFER_SIZE 4096
-#define LOAD_BUFFER_SIZE 65536
/**
* SECTION:file-loading
diff --git a/gdk-pixbuf/gdk-pixbuf-private.h b/gdk-pixbuf/gdk-pixbuf-private.h
index bb6eafa21..001e747ee 100644
--- a/gdk-pixbuf/gdk-pixbuf-private.h
+++ b/gdk-pixbuf/gdk-pixbuf-private.h
@@ -35,6 +35,8 @@
#include "gdk-pixbuf-io.h"
#include "gdk-pixbuf-i18n.h"
+#define LOAD_BUFFER_SIZE 65536
+
typedef struct _GdkPixbufClass GdkPixbufClass;