|
Packit |
a4058c |
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
|
|
Packit |
a4058c |
/* GdkPixbuf library - Simple animation support
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* Copyright (C) 1999 The Free Software Foundation
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* Authors: Jonathan Blandford <jrb@redhat.com>
|
|
Packit |
a4058c |
* Havoc Pennington <hp@redhat.com>
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* This library is free software; you can redistribute it and/or
|
|
Packit |
a4058c |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit |
a4058c |
* License as published by the Free Software Foundation; either
|
|
Packit |
a4058c |
* version 2 of the License, or (at your option) any later version.
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* This library is distributed in the hope that it will be useful,
|
|
Packit |
a4058c |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
a4058c |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
a4058c |
* Lesser General Public License for more details.
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit |
a4058c |
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
|
Packit |
a4058c |
*/
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
#include "config.h"
|
|
Packit |
a4058c |
#include <errno.h>
|
|
Packit |
a4058c |
#include "gdk-pixbuf-private.h"
|
|
Packit |
a4058c |
#include "gdk-pixbuf-animation.h"
|
|
Packit |
a4058c |
#include "gdk-pixbuf-loader.h"
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
#include <glib/gstdio.h>
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/**
|
|
Packit |
a4058c |
* SECTION:animation
|
|
Packit |
a4058c |
* @Short_description: Animated images.
|
|
Packit |
a4058c |
* @Title: Animations
|
|
Packit |
a4058c |
* @See_also: #GdkPixbufLoader.
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* The GdkPixBuf library provides a simple mechanism to load and
|
|
Packit |
a4058c |
* represent animations. An animation is conceptually a series of
|
|
Packit |
a4058c |
* frames to be displayed over time. The animation may not be
|
|
Packit |
a4058c |
* represented as a series of frames internally; for example, it may
|
|
Packit |
a4058c |
* be stored as a sprite and instructions for moving the sprite around
|
|
Packit |
a4058c |
* a background. To display an animation you don't need to understand
|
|
Packit |
a4058c |
* its representation, however; you just ask GdkPixBuf what should
|
|
Packit |
a4058c |
* be displayed at a given point in time.
|
|
Packit |
a4058c |
*/
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
typedef struct _GdkPixbufNonAnim GdkPixbufNonAnim;
|
|
Packit |
a4058c |
typedef struct _GdkPixbufNonAnimClass GdkPixbufNonAnimClass;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
#define GDK_TYPE_PIXBUF_NON_ANIM (gdk_pixbuf_non_anim_get_type ())
|
|
Packit |
a4058c |
#define GDK_PIXBUF_NON_ANIM(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GDK_TYPE_PIXBUF_NON_ANIM, GdkPixbufNonAnim))
|
|
Packit |
a4058c |
#define GDK_IS_PIXBUF_NON_ANIM(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), GDK_TYPE_PIXBUF_NON_ANIM))
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
#define GDK_PIXBUF_NON_ANIM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GDK_TYPE_PIXBUF_NON_ANIM, GdkPixbufNonAnimClass))
|
|
Packit |
a4058c |
#define GDK_IS_PIXBUF_NON_ANIM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDK_TYPE_PIXBUF_NON_ANIM))
|
|
Packit |
a4058c |
#define GDK_PIXBUF_NON_ANIM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GDK_TYPE_PIXBUF_NON_ANIM, GdkPixbufNonAnimClass))
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/* Private part of the GdkPixbufNonAnim structure */
|
|
Packit |
a4058c |
struct _GdkPixbufNonAnim {
|
|
Packit |
a4058c |
GdkPixbufAnimation parent_instance;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
GdkPixbuf *pixbuf;
|
|
Packit |
a4058c |
};
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
struct _GdkPixbufNonAnimClass {
|
|
Packit |
a4058c |
GdkPixbufAnimationClass parent_class;
|
|
Packit |
a4058c |
};
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
typedef struct _GdkPixbufNonAnimIter GdkPixbufNonAnimIter;
|
|
Packit |
a4058c |
typedef struct _GdkPixbufNonAnimIterClass GdkPixbufNonAnimIterClass;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
#define GDK_TYPE_PIXBUF_NON_ANIM_ITER (gdk_pixbuf_non_anim_iter_get_type ())
|
|
Packit |
a4058c |
#define GDK_PIXBUF_NON_ANIM_ITER(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GDK_TYPE_PIXBUF_NON_ANIM_ITER, GdkPixbufNonAnimIter))
|
|
Packit |
a4058c |
#define GDK_IS_PIXBUF_NON_ANIM_ITER(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), GDK_TYPE_PIXBUF_NON_ANIM_ITER))
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
#define GDK_PIXBUF_NON_ANIM_ITER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GDK_TYPE_PIXBUF_NON_ANIM_ITER, GdkPixbufNonAnimIterClass))
|
|
Packit |
a4058c |
#define GDK_IS_PIXBUF_NON_ANIM_ITER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDK_TYPE_PIXBUF_NON_ANIM_ITER))
|
|
Packit |
a4058c |
#define GDK_PIXBUF_NON_ANIM_ITER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GDK_TYPE_PIXBUF_NON_ANIM_ITER, GdkPixbufNonAnimIterClass))
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
struct _GdkPixbufNonAnimIter {
|
|
Packit |
a4058c |
GdkPixbufAnimationIter parent_instance;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
GdkPixbufNonAnim *non_anim;
|
|
Packit |
a4058c |
};
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
struct _GdkPixbufNonAnimIterClass {
|
|
Packit |
a4058c |
GdkPixbufAnimationIterClass parent_class;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
};
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
static GType gdk_pixbuf_non_anim_iter_get_type (void) G_GNUC_CONST;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
G_DEFINE_TYPE (GdkPixbufAnimation, gdk_pixbuf_animation, G_TYPE_OBJECT);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
static void
|
|
Packit |
a4058c |
gdk_pixbuf_animation_class_init (GdkPixbufAnimationClass *klass)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
static void
|
|
Packit |
a4058c |
gdk_pixbuf_animation_init (GdkPixbufAnimation *animation)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
static void
|
|
Packit |
a4058c |
prepared_notify (GdkPixbuf *pixbuf,
|
|
Packit |
a4058c |
GdkPixbufAnimation *anim,
|
|
Packit |
a4058c |
gpointer user_data)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
if (anim != NULL)
|
|
Packit |
a4058c |
g_object_ref (anim);
|
|
Packit |
a4058c |
else
|
|
Packit |
a4058c |
anim = gdk_pixbuf_non_anim_new (pixbuf);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
*((GdkPixbufAnimation **)user_data) = anim;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/**
|
|
Packit |
a4058c |
* gdk_pixbuf_animation_new_from_file:
|
|
Packit |
a4058c |
* @filename: Name of file to load, in the GLib file name encoding
|
|
Packit |
a4058c |
* @error: return location for error
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* Creates a new animation by loading it from a file. The file format is
|
|
Packit |
a4058c |
* detected automatically. If the file's format does not support multi-frame
|
|
Packit |
a4058c |
* images, then an animation with a single frame will be created. Possible errors
|
|
Packit |
a4058c |
* are in the #GDK_PIXBUF_ERROR and #G_FILE_ERROR domains.
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* Return value: A newly-created animation with a reference count of 1, or %NULL
|
|
Packit |
a4058c |
* if any of several error conditions ocurred: the file could not be opened,
|
|
Packit |
a4058c |
* there was no loader for the file's format, there was not enough memory to
|
|
Packit |
a4058c |
* allocate the image buffer, or the image file contained invalid data.
|
|
Packit |
a4058c |
*/
|
|
Packit |
a4058c |
GdkPixbufAnimation *
|
|
Packit |
a4058c |
gdk_pixbuf_animation_new_from_file (const gchar *filename,
|
|
Packit |
a4058c |
GError **error)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
GdkPixbufAnimation *animation;
|
|
Packit |
a4058c |
int size;
|
|
Packit |
a4058c |
FILE *f;
|
|
Packit |
a4058c |
guchar buffer[SNIFF_BUFFER_SIZE];
|
|
Packit |
a4058c |
GdkPixbufModule *image_module;
|
|
Packit |
a4058c |
gchar *display_name;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
g_return_val_if_fail (filename != NULL, NULL);
|
|
Packit |
a4058c |
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
display_name = g_filename_display_name (filename);
|
|
Packit |
a4058c |
f = g_fopen (filename, "rb");
|
|
Packit |
a4058c |
if (!f) {
|
|
Packit |
a4058c |
gint save_errno = errno;
|
|
Packit |
a4058c |
g_set_error (error,
|
|
Packit |
a4058c |
G_FILE_ERROR,
|
|
Packit |
a4058c |
g_file_error_from_errno (save_errno),
|
|
Packit |
a4058c |
_("Failed to open file '%s': %s"),
|
|
Packit |
a4058c |
display_name,
|
|
Packit |
a4058c |
g_strerror (save_errno));
|
|
Packit |
a4058c |
g_free (display_name);
|
|
Packit |
a4058c |
return NULL;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
size = fread (&buffer, 1, sizeof (buffer), f);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (size == 0) {
|
|
Packit |
a4058c |
g_set_error (error,
|
|
Packit |
a4058c |
GDK_PIXBUF_ERROR,
|
|
Packit |
a4058c |
GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
|
|
Packit |
a4058c |
_("Image file '%s' contains no data"),
|
|
Packit |
a4058c |
display_name);
|
|
Packit |
a4058c |
g_free (display_name);
|
|
Packit |
a4058c |
fclose (f);
|
|
Packit |
a4058c |
return NULL;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
image_module = _gdk_pixbuf_get_module (buffer, size, filename, error);
|
|
Packit |
a4058c |
if (!image_module) {
|
|
Packit |
a4058c |
g_free (display_name);
|
|
Packit |
a4058c |
fclose (f);
|
|
Packit |
a4058c |
return NULL;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (image_module->module == NULL)
|
|
Packit |
a4058c |
if (!_gdk_pixbuf_load_module (image_module, error)) {
|
|
Packit |
a4058c |
g_free (display_name);
|
|
Packit |
a4058c |
fclose (f);
|
|
Packit |
a4058c |
return NULL;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (image_module->load_animation != NULL) {
|
|
Packit |
a4058c |
fseek (f, 0, SEEK_SET);
|
|
Packit |
a4058c |
animation = (* image_module->load_animation) (f, error);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (animation == NULL && error != NULL && *error == NULL) {
|
|
Packit |
a4058c |
/* I don't trust these crufty longjmp()'ing
|
|
Packit |
a4058c |
* image libs to maintain proper error
|
|
Packit |
a4058c |
* invariants, and I don't want user code to
|
|
Packit |
a4058c |
* segfault as a result. We need to maintain
|
|
Packit |
a4058c |
* the invariant that error gets set if NULL
|
|
Packit |
a4058c |
* is returned.
|
|
Packit |
a4058c |
*/
|
|
Packit |
a4058c |
g_warning ("Bug! gdk-pixbuf loader '%s' didn't set an error on failure.",
|
|
Packit |
a4058c |
image_module->module_name);
|
|
Packit |
a4058c |
g_set_error (error,
|
|
Packit |
a4058c |
GDK_PIXBUF_ERROR,
|
|
Packit |
a4058c |
GDK_PIXBUF_ERROR_FAILED,
|
|
Packit |
a4058c |
_("Failed to load animation '%s': reason not known, probably a corrupt animation file"),
|
|
Packit |
a4058c |
display_name);
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
fclose (f);
|
|
Packit |
a4058c |
} else if (image_module->begin_load != NULL) {
|
|
Packit |
a4058c |
guchar buffer[4096];
|
|
Packit |
a4058c |
size_t length;
|
|
Packit |
a4058c |
gpointer context;
|
|
Packit |
a4058c |
gboolean success;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
success = FALSE;
|
|
Packit |
a4058c |
animation = NULL;
|
|
Packit |
a4058c |
fseek (f, 0, SEEK_SET);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
context = image_module->begin_load (NULL, prepared_notify, NULL, &animation, error);
|
|
Packit |
a4058c |
if (!context)
|
|
Packit |
a4058c |
goto fail_begin_load;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
while (!feof (f) && !ferror (f)) {
|
|
Packit |
a4058c |
length = fread (buffer, 1, sizeof (buffer), f);
|
|
Packit |
a4058c |
if (length > 0) {
|
|
Packit |
a4058c |
if (!image_module->load_increment (context, buffer, length, error)) {
|
|
Packit |
a4058c |
error = NULL;
|
|
Packit |
a4058c |
goto fail_load_increment;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
success = TRUE;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
fail_load_increment:
|
|
Packit |
a4058c |
if (!image_module->stop_load (context, error))
|
|
Packit |
a4058c |
success = FALSE;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
fail_begin_load:
|
|
Packit |
a4058c |
fclose (f);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (success) {
|
|
Packit |
a4058c |
/* If there was no error, there must be an animation that was successfully loaded */
|
|
Packit |
a4058c |
g_assert (animation);
|
|
Packit |
a4058c |
} else {
|
|
Packit |
a4058c |
if (animation) {
|
|
Packit |
a4058c |
g_object_unref (animation);
|
|
Packit |
a4058c |
animation = NULL;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
} else {
|
|
Packit |
a4058c |
GdkPixbuf *pixbuf;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/* Keep this logic in sync with gdk_pixbuf_new_from_file() */
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
fseek (f, 0, SEEK_SET);
|
|
Packit |
a4058c |
pixbuf = _gdk_pixbuf_generic_image_load (image_module, f, error);
|
|
Packit |
a4058c |
fclose (f);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (pixbuf == NULL && error != NULL && *error == NULL) {
|
|
Packit |
a4058c |
/* I don't trust these crufty longjmp()'ing image libs
|
|
Packit |
a4058c |
* to maintain proper error invariants, and I don't
|
|
Packit |
a4058c |
* want user code to segfault as a result. We need to maintain
|
|
Packit |
a4058c |
* the invariant that error gets set if NULL is returned.
|
|
Packit |
a4058c |
*/
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
g_warning ("Bug! gdk-pixbuf loader '%s' didn't set an error on failure.",
|
|
Packit |
a4058c |
image_module->module_name);
|
|
Packit |
a4058c |
g_set_error (error,
|
|
Packit |
a4058c |
GDK_PIXBUF_ERROR,
|
|
Packit |
a4058c |
GDK_PIXBUF_ERROR_FAILED,
|
|
Packit |
a4058c |
_("Failed to load image '%s': reason not known, probably a corrupt image file"),
|
|
Packit |
a4058c |
display_name);
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (pixbuf == NULL) {
|
|
Packit |
a4058c |
g_free (display_name);
|
|
Packit |
a4058c |
animation = NULL;
|
|
Packit |
a4058c |
goto out;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
animation = gdk_pixbuf_non_anim_new (pixbuf);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
g_object_unref (pixbuf);
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
g_free (display_name);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
out:
|
|
Packit |
a4058c |
return animation;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
#ifdef G_OS_WIN32
|
|
Packit |
a4058c |
/**
|
|
Packit |
a4058c |
* gdk_pixbuf_animation_new_from_file_utf8:
|
|
Packit |
a4058c |
* @filename: Name of file to load, in the GLib file name encoding
|
|
Packit |
a4058c |
* @error: return location for error
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* Same as gdk_pixbuf_animation_new_from_file()
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* Return value: A newly-created animation with a reference count of 1, or %NULL
|
|
Packit |
a4058c |
* if any of several error conditions ocurred: the file could not be opened,
|
|
Packit |
a4058c |
* there was no loader for the file's format, there was not enough memory to
|
|
Packit |
a4058c |
* allocate the image buffer, or the image file contained invalid data.
|
|
Packit |
a4058c |
*/
|
|
Packit |
a4058c |
GdkPixbufAnimation *
|
|
Packit |
a4058c |
gdk_pixbuf_animation_new_from_file_utf8 (const gchar *filename,
|
|
Packit |
a4058c |
GError **error)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
return gdk_pixbuf_animation_new_from_file (filename, error);
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
#endif
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/**
|
|
Packit |
a4058c |
* gdk_pixbuf_animation_new_from_stream:
|
|
Packit |
a4058c |
* @stream: a #GInputStream to load the pixbuf from
|
|
Packit |
a4058c |
* @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore
|
|
Packit |
a4058c |
* @error: Return location for an error
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* Creates a new animation by loading it from an input stream.
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* The file format is detected automatically. If %NULL is returned, then
|
|
Packit |
a4058c |
* @error will be set. The @cancellable can be used to abort the operation
|
|
Packit |
a4058c |
* from another thread. If the operation was cancelled, the error
|
|
Packit |
a4058c |
* %G_IO_ERROR_CANCELLED will be returned. Other possible errors are in
|
|
Packit |
a4058c |
* the #GDK_PIXBUF_ERROR and %G_IO_ERROR domains.
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* The stream is not closed.
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* Return value: A newly-created pixbuf, or %NULL if any of several error
|
|
Packit |
a4058c |
* conditions occurred: the file could not be opened, the image format is
|
|
Packit |
a4058c |
* not supported, there was not enough memory to allocate the image buffer,
|
|
Packit |
a4058c |
* the stream contained invalid data, or the operation was cancelled.
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* Since: 2.28
|
|
Packit |
a4058c |
*/
|
|
Packit |
a4058c |
GdkPixbufAnimation *
|
|
Packit |
a4058c |
gdk_pixbuf_animation_new_from_stream (GInputStream *stream,
|
|
Packit |
a4058c |
GCancellable *cancellable,
|
|
Packit |
a4058c |
GError **error)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
GdkPixbufAnimation *animation;
|
|
Packit |
a4058c |
GdkPixbufLoader *loader;
|
|
Packit |
a4058c |
gssize n_read;
|
|
Packit |
a4058c |
guchar buffer[LOAD_BUFFER_SIZE];
|
|
Packit |
a4058c |
gboolean res;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
g_return_val_if_fail (G_IS_INPUT_STREAM (stream), NULL);
|
|
Packit |
a4058c |
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
|
|
Packit |
a4058c |
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
loader = gdk_pixbuf_loader_new ();
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
res = TRUE;
|
|
Packit |
a4058c |
while (1) {
|
|
Packit |
a4058c |
n_read = g_input_stream_read (stream, buffer, sizeof (buffer), cancellable, error);
|
|
Packit |
a4058c |
if (n_read < 0) {
|
|
Packit |
a4058c |
res = FALSE;
|
|
Packit |
a4058c |
error = NULL; /* Ignore further errors */
|
|
Packit |
a4058c |
break;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (n_read == 0)
|
|
Packit |
a4058c |
break;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (!gdk_pixbuf_loader_write (loader, buffer, n_read, error)) {
|
|
Packit |
a4058c |
res = FALSE;
|
|
Packit |
a4058c |
error = NULL;
|
|
Packit |
a4058c |
break;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (!gdk_pixbuf_loader_close (loader, error)) {
|
|
Packit |
a4058c |
res = FALSE;
|
|
Packit |
a4058c |
error = NULL;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (res) {
|
|
Packit |
a4058c |
animation = gdk_pixbuf_loader_get_animation (loader);
|
|
Packit |
a4058c |
if (animation)
|
|
Packit |
a4058c |
g_object_ref (animation);
|
|
Packit |
a4058c |
} else {
|
|
Packit |
a4058c |
animation = NULL;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
g_object_unref (loader);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
return animation;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
static void
|
|
Packit |
a4058c |
animation_new_from_stream_thread (GTask *task,
|
|
Packit |
a4058c |
gpointer source_object,
|
|
Packit |
a4058c |
gpointer task_data,
|
|
Packit |
a4058c |
GCancellable *cancellable)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
GInputStream *stream = G_INPUT_STREAM (source_object);
|
|
Packit |
a4058c |
GdkPixbufAnimation *animation;
|
|
Packit |
a4058c |
GError *error = NULL;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
animation = gdk_pixbuf_animation_new_from_stream (stream, cancellable, &error);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/* Set the new pixbuf as the result, or error out */
|
|
Packit |
a4058c |
if (animation == NULL) {
|
|
Packit |
a4058c |
g_task_return_error (task, error);
|
|
Packit |
a4058c |
} else {
|
|
Packit |
a4058c |
g_task_return_pointer (task, animation, g_object_unref);
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/**
|
|
Packit |
a4058c |
* gdk_pixbuf_animation_new_from_stream_async:
|
|
Packit |
a4058c |
* @stream: a #GInputStream from which to load the animation
|
|
Packit |
a4058c |
* @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore
|
|
Packit |
a4058c |
* @callback: a #GAsyncReadyCallback to call when the pixbuf is loaded
|
|
Packit |
a4058c |
* @user_data: the data to pass to the callback function
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* Creates a new animation by asynchronously loading an image from an input stream.
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* For more details see gdk_pixbuf_new_from_stream(), which is the synchronous
|
|
Packit |
a4058c |
* version of this function.
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* When the operation is finished, @callback will be called in the main thread.
|
|
Packit |
a4058c |
* You can then call gdk_pixbuf_animation_new_from_stream_finish() to get the
|
|
Packit |
a4058c |
* result of the operation.
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* Since: 2.28
|
|
Packit |
a4058c |
**/
|
|
Packit |
a4058c |
void
|
|
Packit |
a4058c |
gdk_pixbuf_animation_new_from_stream_async (GInputStream *stream,
|
|
Packit |
a4058c |
GCancellable *cancellable,
|
|
Packit |
a4058c |
GAsyncReadyCallback callback,
|
|
Packit |
a4058c |
gpointer user_data)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
GTask *task;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
g_return_if_fail (G_IS_INPUT_STREAM (stream));
|
|
Packit |
a4058c |
g_return_if_fail (callback != NULL);
|
|
Packit |
a4058c |
g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
task = g_task_new (G_OBJECT (stream), cancellable, callback, user_data);
|
|
Packit |
a4058c |
g_task_set_source_tag (task, gdk_pixbuf_animation_new_from_stream_async);
|
|
Packit |
a4058c |
g_task_run_in_thread (task, animation_new_from_stream_thread);
|
|
Packit |
a4058c |
g_object_unref (task);
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/**
|
|
Packit |
a4058c |
* gdk_pixbuf_animation_new_from_stream_finish:
|
|
Packit |
a4058c |
* @async_result: a #GAsyncResult
|
|
Packit |
a4058c |
* @error: a #GError, or %NULL
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* Finishes an asynchronous pixbuf animation creation operation started with
|
|
Packit |
a4058c |
* gdk_pixbuf_animation_new_from_stream_async().
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* Return value: a #GdkPixbufAnimation or %NULL on error. Free the returned
|
|
Packit |
a4058c |
* object with g_object_unref().
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* Since: 2.28
|
|
Packit |
a4058c |
**/
|
|
Packit |
a4058c |
GdkPixbufAnimation *
|
|
Packit |
a4058c |
gdk_pixbuf_animation_new_from_stream_finish (GAsyncResult *async_result,
|
|
Packit |
a4058c |
GError **error)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
GTask *task = G_TASK (async_result);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
g_return_val_if_fail (G_IS_TASK (async_result), NULL);
|
|
Packit |
a4058c |
g_return_val_if_fail (!error || (error && !*error), NULL);
|
|
Packit |
a4058c |
g_warn_if_fail (g_task_get_source_tag (task) == gdk_pixbuf_animation_new_from_stream_async);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
return g_task_propagate_pointer (task, error);
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/**
|
|
Packit |
a4058c |
* gdk_pixbuf_animation_new_from_resource:
|
|
Packit |
a4058c |
* @resource_path: the path of the resource file
|
|
Packit |
a4058c |
* @error: Return location for an error
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* Creates a new pixbuf animation by loading an image from an resource.
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* The file format is detected automatically. If %NULL is returned, then
|
|
Packit |
a4058c |
* @error will be set.
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* Return value: A newly-created animation, or %NULL if any of several error
|
|
Packit |
a4058c |
* conditions occurred: the file could not be opened, the image format is
|
|
Packit |
a4058c |
* not supported, there was not enough memory to allocate the image buffer,
|
|
Packit |
a4058c |
* the stream contained invalid data, or the operation was cancelled.
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* Since: 2.28
|
|
Packit |
a4058c |
*/
|
|
Packit |
a4058c |
GdkPixbufAnimation *
|
|
Packit |
a4058c |
gdk_pixbuf_animation_new_from_resource (const gchar *resource_path,
|
|
Packit |
a4058c |
GError **error)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
GInputStream *stream;
|
|
Packit |
a4058c |
GdkPixbufAnimation *anim;
|
|
Packit |
a4058c |
GdkPixbuf *pixbuf;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
pixbuf = _gdk_pixbuf_new_from_resource_try_pixdata (resource_path);
|
|
Packit |
a4058c |
if (pixbuf) {
|
|
Packit |
a4058c |
anim = gdk_pixbuf_non_anim_new (pixbuf);
|
|
Packit |
a4058c |
g_object_unref (pixbuf);
|
|
Packit |
a4058c |
return anim;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
stream = g_resources_open_stream (resource_path, 0, error);
|
|
Packit |
a4058c |
if (stream == NULL)
|
|
Packit |
a4058c |
return NULL;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
anim = gdk_pixbuf_animation_new_from_stream (stream, NULL, error);
|
|
Packit |
a4058c |
g_object_unref (stream);
|
|
Packit |
a4058c |
return anim;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/**
|
|
Packit |
a4058c |
* gdk_pixbuf_animation_ref: (skip)
|
|
Packit |
a4058c |
* @animation: An animation.
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* Adds a reference to an animation.
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* Return value: The same as the @animation argument.
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* Deprecated: 2.0: Use g_object_ref().
|
|
Packit |
a4058c |
*/
|
|
Packit |
a4058c |
GdkPixbufAnimation *
|
|
Packit |
a4058c |
gdk_pixbuf_animation_ref (GdkPixbufAnimation *animation)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
return (GdkPixbufAnimation*) g_object_ref (animation);
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/**
|
|
Packit |
a4058c |
* gdk_pixbuf_animation_unref: (skip)
|
|
Packit |
a4058c |
* @animation: An animation.
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* Removes a reference from an animation.
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* Deprecated: 2.0: Use g_object_unref().
|
|
Packit |
a4058c |
*/
|
|
Packit |
a4058c |
void
|
|
Packit |
a4058c |
gdk_pixbuf_animation_unref (GdkPixbufAnimation *animation)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
g_object_unref (animation);
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/**
|
|
Packit |
a4058c |
* gdk_pixbuf_animation_is_static_image:
|
|
Packit |
a4058c |
* @animation: a #GdkPixbufAnimation
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* If you load a file with gdk_pixbuf_animation_new_from_file() and it
|
|
Packit |
a4058c |
* turns out to be a plain, unanimated image, then this function will
|
|
Packit |
a4058c |
* return %TRUE. Use gdk_pixbuf_animation_get_static_image() to retrieve
|
|
Packit |
a4058c |
* the image.
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* Return value: %TRUE if the "animation" was really just an image
|
|
Packit |
a4058c |
*/
|
|
Packit |
a4058c |
gboolean
|
|
Packit |
a4058c |
gdk_pixbuf_animation_is_static_image (GdkPixbufAnimation *animation)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
g_return_val_if_fail (GDK_IS_PIXBUF_ANIMATION (animation), FALSE);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
return GDK_PIXBUF_ANIMATION_GET_CLASS (animation)->is_static_image (animation);
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/**
|
|
Packit |
a4058c |
* gdk_pixbuf_animation_get_static_image:
|
|
Packit |
a4058c |
* @animation: a #GdkPixbufAnimation
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* If an animation is really just a plain image (has only one frame),
|
|
Packit |
a4058c |
* this function returns that image. If the animation is an animation,
|
|
Packit |
a4058c |
* this function returns a reasonable thing to display as a static
|
|
Packit |
a4058c |
* unanimated image, which might be the first frame, or something more
|
|
Packit |
a4058c |
* sophisticated. If an animation hasn't loaded any frames yet, this
|
|
Packit |
a4058c |
* function will return %NULL.
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* Return value: (transfer none): unanimated image representing the animation
|
|
Packit |
a4058c |
*/
|
|
Packit |
a4058c |
GdkPixbuf*
|
|
Packit |
a4058c |
gdk_pixbuf_animation_get_static_image (GdkPixbufAnimation *animation)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
g_return_val_if_fail (GDK_IS_PIXBUF_ANIMATION (animation), NULL);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
return GDK_PIXBUF_ANIMATION_GET_CLASS (animation)->get_static_image (animation);
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/**
|
|
Packit |
a4058c |
* gdk_pixbuf_animation_get_width:
|
|
Packit |
a4058c |
* @animation: An animation.
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* Queries the width of the bounding box of a pixbuf animation.
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* Return value: Width of the bounding box of the animation.
|
|
Packit |
a4058c |
*/
|
|
Packit |
a4058c |
gint
|
|
Packit |
a4058c |
gdk_pixbuf_animation_get_width (GdkPixbufAnimation *animation)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
gint width;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
g_return_val_if_fail (GDK_IS_PIXBUF_ANIMATION (animation), 0);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
width = 0;
|
|
Packit |
a4058c |
GDK_PIXBUF_ANIMATION_GET_CLASS (animation)->get_size (animation,
|
|
Packit |
a4058c |
&width, NULL);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
return width;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/**
|
|
Packit |
a4058c |
* gdk_pixbuf_animation_get_height:
|
|
Packit |
a4058c |
* @animation: An animation.
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* Queries the height of the bounding box of a pixbuf animation.
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* Return value: Height of the bounding box of the animation.
|
|
Packit |
a4058c |
*/
|
|
Packit |
a4058c |
gint
|
|
Packit |
a4058c |
gdk_pixbuf_animation_get_height (GdkPixbufAnimation *animation)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
gint height;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
g_return_val_if_fail (GDK_IS_PIXBUF_ANIMATION (animation), 0);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
height = 0;
|
|
Packit |
a4058c |
GDK_PIXBUF_ANIMATION_GET_CLASS (animation)->get_size (animation,
|
|
Packit |
a4058c |
NULL, &height);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
return height;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/**
|
|
Packit |
a4058c |
* gdk_pixbuf_animation_get_iter:
|
|
Packit |
a4058c |
* @animation: a #GdkPixbufAnimation
|
|
Packit |
a4058c |
* @start_time: (allow-none): time when the animation starts playing
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* Get an iterator for displaying an animation. The iterator provides
|
|
Packit |
a4058c |
* the frames that should be displayed at a given time. It should be
|
|
Packit |
a4058c |
* freed after use with g_object_unref().
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* @start_time would normally come from g_get_current_time(), and marks
|
|
Packit |
a4058c |
* the beginning of animation playback. After creating an iterator, you
|
|
Packit |
a4058c |
* should immediately display the pixbuf returned by
|
|
Packit |
a4058c |
* gdk_pixbuf_animation_iter_get_pixbuf(). Then, you should install
|
|
Packit |
a4058c |
* a timeout (with g_timeout_add()) or by some other mechanism ensure
|
|
Packit |
a4058c |
* that you'll update the image after
|
|
Packit |
a4058c |
* gdk_pixbuf_animation_iter_get_delay_time() milliseconds. Each time
|
|
Packit |
a4058c |
* the image is updated, you should reinstall the timeout with the new,
|
|
Packit |
a4058c |
* possibly-changed delay time.
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* As a shortcut, if @start_time is %NULL, the result of
|
|
Packit |
a4058c |
* g_get_current_time() will be used automatically.
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* To update the image (i.e. possibly change the result of
|
|
Packit |
a4058c |
* gdk_pixbuf_animation_iter_get_pixbuf() to a new frame of the animation),
|
|
Packit |
a4058c |
* call gdk_pixbuf_animation_iter_advance().
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* If you're using #GdkPixbufLoader, in addition to updating the image
|
|
Packit |
a4058c |
* after the delay time, you should also update it whenever you
|
|
Packit |
a4058c |
* receive the area_updated signal and
|
|
Packit |
a4058c |
* gdk_pixbuf_animation_iter_on_currently_loading_frame() returns
|
|
Packit |
a4058c |
* %TRUE. In this case, the frame currently being fed into the loader
|
|
Packit |
a4058c |
* has received new data, so needs to be refreshed. The delay time for
|
|
Packit |
a4058c |
* a frame may also be modified after an area_updated signal, for
|
|
Packit |
a4058c |
* example if the delay time for a frame is encoded in the data after
|
|
Packit |
a4058c |
* the frame itself. So your timeout should be reinstalled after any
|
|
Packit |
a4058c |
* area_updated signal.
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* A delay time of -1 is possible, indicating "infinite."
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* Return value: (transfer full): an iterator to move over the animation
|
|
Packit |
a4058c |
*/
|
|
Packit |
a4058c |
GdkPixbufAnimationIter*
|
|
Packit |
a4058c |
gdk_pixbuf_animation_get_iter (GdkPixbufAnimation *animation,
|
|
Packit |
a4058c |
const GTimeVal *start_time)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
GTimeVal val;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
g_return_val_if_fail (GDK_IS_PIXBUF_ANIMATION (animation), NULL);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (start_time)
|
|
Packit |
a4058c |
val = *start_time;
|
|
Packit |
a4058c |
else
|
|
Packit |
a4058c |
g_get_current_time (&val;;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
return GDK_PIXBUF_ANIMATION_GET_CLASS (animation)->get_iter (animation, &val;;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
G_DEFINE_TYPE (GdkPixbufAnimationIter, gdk_pixbuf_animation_iter, G_TYPE_OBJECT);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
static void
|
|
Packit |
a4058c |
gdk_pixbuf_animation_iter_class_init (GdkPixbufAnimationIterClass *klass)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
static void
|
|
Packit |
a4058c |
gdk_pixbuf_animation_iter_init (GdkPixbufAnimationIter *iter)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/**
|
|
Packit |
a4058c |
* gdk_pixbuf_animation_iter_get_delay_time:
|
|
Packit |
a4058c |
* @iter: an animation iterator
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* Gets the number of milliseconds the current pixbuf should be displayed,
|
|
Packit |
a4058c |
* or -1 if the current pixbuf should be displayed forever. g_timeout_add()
|
|
Packit |
a4058c |
* conveniently takes a timeout in milliseconds, so you can use a timeout
|
|
Packit |
a4058c |
* to schedule the next update.
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* Note that some formats, like GIF, might clamp the timeout values in the
|
|
Packit |
a4058c |
* image file to avoid updates that are just too quick. The minimum timeout
|
|
Packit |
a4058c |
* for GIF images is currently 20 milliseconds.
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* Return value: delay time in milliseconds (thousandths of a second)
|
|
Packit |
a4058c |
*/
|
|
Packit |
a4058c |
gint
|
|
Packit |
a4058c |
gdk_pixbuf_animation_iter_get_delay_time (GdkPixbufAnimationIter *iter)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
g_return_val_if_fail (GDK_IS_PIXBUF_ANIMATION_ITER (iter), -1);
|
|
Packit |
a4058c |
g_return_val_if_fail (GDK_PIXBUF_ANIMATION_ITER_GET_CLASS (iter)->get_delay_time, -1);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
return GDK_PIXBUF_ANIMATION_ITER_GET_CLASS (iter)->get_delay_time (iter);
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/**
|
|
Packit |
a4058c |
* gdk_pixbuf_animation_iter_get_pixbuf:
|
|
Packit |
a4058c |
* @iter: an animation iterator
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* Gets the current pixbuf which should be displayed; the pixbuf might not
|
|
Packit |
a4058c |
* be the same size as the animation itself
|
|
Packit |
a4058c |
* (gdk_pixbuf_animation_get_width(), gdk_pixbuf_animation_get_height()).
|
|
Packit |
a4058c |
* This pixbuf should be displayed for
|
|
Packit |
a4058c |
* gdk_pixbuf_animation_iter_get_delay_time() milliseconds. The caller
|
|
Packit |
a4058c |
* of this function does not own a reference to the returned pixbuf;
|
|
Packit |
a4058c |
* the returned pixbuf will become invalid when the iterator advances
|
|
Packit |
a4058c |
* to the next frame, which may happen anytime you call
|
|
Packit |
a4058c |
* gdk_pixbuf_animation_iter_advance(). Copy the pixbuf to keep it
|
|
Packit |
a4058c |
* (don't just add a reference), as it may get recycled as you advance
|
|
Packit |
a4058c |
* the iterator.
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* Return value: (transfer none): the pixbuf to be displayed
|
|
Packit |
a4058c |
*/
|
|
Packit |
a4058c |
GdkPixbuf*
|
|
Packit |
a4058c |
gdk_pixbuf_animation_iter_get_pixbuf (GdkPixbufAnimationIter *iter)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
g_return_val_if_fail (GDK_IS_PIXBUF_ANIMATION_ITER (iter), NULL);
|
|
Packit |
a4058c |
g_return_val_if_fail (GDK_PIXBUF_ANIMATION_ITER_GET_CLASS (iter)->get_pixbuf, NULL);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
return GDK_PIXBUF_ANIMATION_ITER_GET_CLASS (iter)->get_pixbuf (iter);
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/**
|
|
Packit |
a4058c |
* gdk_pixbuf_animation_iter_on_currently_loading_frame:
|
|
Packit |
a4058c |
* @iter: a #GdkPixbufAnimationIter
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* Used to determine how to respond to the area_updated signal on
|
|
Packit |
a4058c |
* #GdkPixbufLoader when loading an animation. area_updated is emitted
|
|
Packit |
a4058c |
* for an area of the frame currently streaming in to the loader. So if
|
|
Packit |
a4058c |
* you're on the currently loading frame, you need to redraw the screen for
|
|
Packit |
a4058c |
* the updated area.
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* Return value: %TRUE if the frame we're on is partially loaded, or the last frame
|
|
Packit |
a4058c |
*/
|
|
Packit |
a4058c |
gboolean
|
|
Packit |
a4058c |
gdk_pixbuf_animation_iter_on_currently_loading_frame (GdkPixbufAnimationIter *iter)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
g_return_val_if_fail (GDK_IS_PIXBUF_ANIMATION_ITER (iter), FALSE);
|
|
Packit |
a4058c |
g_return_val_if_fail (GDK_PIXBUF_ANIMATION_ITER_GET_CLASS (iter)->on_currently_loading_frame, FALSE);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
return GDK_PIXBUF_ANIMATION_ITER_GET_CLASS (iter)->on_currently_loading_frame (iter);
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/**
|
|
Packit |
a4058c |
* gdk_pixbuf_animation_iter_advance:
|
|
Packit |
a4058c |
* @iter: a #GdkPixbufAnimationIter
|
|
Packit |
a4058c |
* @current_time: (allow-none): current time
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* Possibly advances an animation to a new frame. Chooses the frame based
|
|
Packit |
a4058c |
* on the start time passed to gdk_pixbuf_animation_get_iter().
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* @current_time would normally come from g_get_current_time(), and
|
|
Packit |
a4058c |
* must be greater than or equal to the time passed to
|
|
Packit |
a4058c |
* gdk_pixbuf_animation_get_iter(), and must increase or remain
|
|
Packit |
a4058c |
* unchanged each time gdk_pixbuf_animation_iter_get_pixbuf() is
|
|
Packit |
a4058c |
* called. That is, you can't go backward in time; animations only
|
|
Packit |
a4058c |
* play forward.
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* As a shortcut, pass %NULL for the current time and g_get_current_time()
|
|
Packit |
a4058c |
* will be invoked on your behalf. So you only need to explicitly pass
|
|
Packit |
a4058c |
* @current_time if you're doing something odd like playing the animation
|
|
Packit |
a4058c |
* at double speed.
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* If this function returns %FALSE, there's no need to update the animation
|
|
Packit |
a4058c |
* display, assuming the display had been rendered prior to advancing;
|
|
Packit |
a4058c |
* if %TRUE, you need to call gdk_pixbuf_animation_iter_get_pixbuf()
|
|
Packit |
a4058c |
* and update the display with the new pixbuf.
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* Returns: %TRUE if the image may need updating
|
|
Packit |
a4058c |
*/
|
|
Packit |
a4058c |
gboolean
|
|
Packit |
a4058c |
gdk_pixbuf_animation_iter_advance (GdkPixbufAnimationIter *iter,
|
|
Packit |
a4058c |
const GTimeVal *current_time)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
GTimeVal val;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
g_return_val_if_fail (GDK_IS_PIXBUF_ANIMATION_ITER (iter), FALSE);
|
|
Packit |
a4058c |
g_return_val_if_fail (GDK_PIXBUF_ANIMATION_ITER_GET_CLASS (iter)->advance, FALSE);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (current_time)
|
|
Packit |
a4058c |
val = *current_time;
|
|
Packit |
a4058c |
else
|
|
Packit |
a4058c |
g_get_current_time (&val;;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
return GDK_PIXBUF_ANIMATION_ITER_GET_CLASS (iter)->advance (iter, &val;;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
static void gdk_pixbuf_non_anim_finalize (GObject *object);
|
|
Packit |
a4058c |
static gboolean gdk_pixbuf_non_anim_is_static_image (GdkPixbufAnimation *animation);
|
|
Packit |
a4058c |
static GdkPixbuf* gdk_pixbuf_non_anim_get_static_image (GdkPixbufAnimation *animation);
|
|
Packit |
a4058c |
static void gdk_pixbuf_non_anim_get_size (GdkPixbufAnimation *anim,
|
|
Packit |
a4058c |
gint *width,
|
|
Packit |
a4058c |
gint *height);
|
|
Packit |
a4058c |
static GdkPixbufAnimationIter* gdk_pixbuf_non_anim_get_iter (GdkPixbufAnimation *anim,
|
|
Packit |
a4058c |
const GTimeVal *start_time);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
G_DEFINE_TYPE (GdkPixbufNonAnim, gdk_pixbuf_non_anim, GDK_TYPE_PIXBUF_ANIMATION);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
static void
|
|
Packit |
a4058c |
gdk_pixbuf_non_anim_class_init (GdkPixbufNonAnimClass *klass)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
Packit |
a4058c |
GdkPixbufAnimationClass *anim_class = GDK_PIXBUF_ANIMATION_CLASS (klass);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
object_class->finalize = gdk_pixbuf_non_anim_finalize;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
anim_class->is_static_image = gdk_pixbuf_non_anim_is_static_image;
|
|
Packit |
a4058c |
anim_class->get_static_image = gdk_pixbuf_non_anim_get_static_image;
|
|
Packit |
a4058c |
anim_class->get_size = gdk_pixbuf_non_anim_get_size;
|
|
Packit |
a4058c |
anim_class->get_iter = gdk_pixbuf_non_anim_get_iter;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
static void
|
|
Packit |
a4058c |
gdk_pixbuf_non_anim_init (GdkPixbufNonAnim *non_anim)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
static void
|
|
Packit |
a4058c |
gdk_pixbuf_non_anim_finalize (GObject *object)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
GdkPixbufNonAnim *non_anim = GDK_PIXBUF_NON_ANIM (object);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (non_anim->pixbuf)
|
|
Packit |
a4058c |
g_object_unref (non_anim->pixbuf);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
G_OBJECT_CLASS (gdk_pixbuf_non_anim_parent_class)->finalize (object);
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
GdkPixbufAnimation*
|
|
Packit |
a4058c |
gdk_pixbuf_non_anim_new (GdkPixbuf *pixbuf)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
GdkPixbufNonAnim *non_anim;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
non_anim = g_object_new (GDK_TYPE_PIXBUF_NON_ANIM, NULL);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
non_anim->pixbuf = pixbuf;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (pixbuf)
|
|
Packit |
a4058c |
g_object_ref (pixbuf);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
return GDK_PIXBUF_ANIMATION (non_anim);
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
static gboolean
|
|
Packit |
a4058c |
gdk_pixbuf_non_anim_is_static_image (GdkPixbufAnimation *animation)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
return TRUE;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
static GdkPixbuf*
|
|
Packit |
a4058c |
gdk_pixbuf_non_anim_get_static_image (GdkPixbufAnimation *animation)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
GdkPixbufNonAnim *non_anim;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
non_anim = GDK_PIXBUF_NON_ANIM (animation);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
return non_anim->pixbuf;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
static void
|
|
Packit |
a4058c |
gdk_pixbuf_non_anim_get_size (GdkPixbufAnimation *anim,
|
|
Packit |
a4058c |
gint *width,
|
|
Packit |
a4058c |
gint *height)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
GdkPixbufNonAnim *non_anim;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
non_anim = GDK_PIXBUF_NON_ANIM (anim);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (width)
|
|
Packit |
a4058c |
*width = gdk_pixbuf_get_width (non_anim->pixbuf);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (height)
|
|
Packit |
a4058c |
*height = gdk_pixbuf_get_height (non_anim->pixbuf);
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
static GdkPixbufAnimationIter*
|
|
Packit |
a4058c |
gdk_pixbuf_non_anim_get_iter (GdkPixbufAnimation *anim,
|
|
Packit |
a4058c |
const GTimeVal *start_time)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
GdkPixbufNonAnimIter *iter;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
iter = g_object_new (GDK_TYPE_PIXBUF_NON_ANIM_ITER, NULL);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
iter->non_anim = GDK_PIXBUF_NON_ANIM (anim);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
g_object_ref (iter->non_anim);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
return GDK_PIXBUF_ANIMATION_ITER (iter);
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
static void gdk_pixbuf_non_anim_iter_finalize (GObject *object);
|
|
Packit |
a4058c |
static gint gdk_pixbuf_non_anim_iter_get_delay_time (GdkPixbufAnimationIter *iter);
|
|
Packit |
a4058c |
static GdkPixbuf* gdk_pixbuf_non_anim_iter_get_pixbuf (GdkPixbufAnimationIter *iter);
|
|
Packit |
a4058c |
static gboolean gdk_pixbuf_non_anim_iter_on_currently_loading_frame (GdkPixbufAnimationIter *iter);
|
|
Packit |
a4058c |
static gboolean gdk_pixbuf_non_anim_iter_advance (GdkPixbufAnimationIter *iter,
|
|
Packit |
a4058c |
const GTimeVal *current_time);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
G_DEFINE_TYPE (GdkPixbufNonAnimIter, gdk_pixbuf_non_anim_iter, GDK_TYPE_PIXBUF_ANIMATION_ITER)
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
static void
|
|
Packit |
a4058c |
gdk_pixbuf_non_anim_iter_class_init (GdkPixbufNonAnimIterClass *klass)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
Packit |
a4058c |
GdkPixbufAnimationIterClass *anim_iter_class =
|
|
Packit |
a4058c |
GDK_PIXBUF_ANIMATION_ITER_CLASS (klass);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
object_class->finalize = gdk_pixbuf_non_anim_iter_finalize;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
anim_iter_class->get_delay_time = gdk_pixbuf_non_anim_iter_get_delay_time;
|
|
Packit |
a4058c |
anim_iter_class->get_pixbuf = gdk_pixbuf_non_anim_iter_get_pixbuf;
|
|
Packit |
a4058c |
anim_iter_class->on_currently_loading_frame = gdk_pixbuf_non_anim_iter_on_currently_loading_frame;
|
|
Packit |
a4058c |
anim_iter_class->advance = gdk_pixbuf_non_anim_iter_advance;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
static void
|
|
Packit |
a4058c |
gdk_pixbuf_non_anim_iter_init (GdkPixbufNonAnimIter *non_iter)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
static void
|
|
Packit |
a4058c |
gdk_pixbuf_non_anim_iter_finalize (GObject *object)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
GdkPixbufNonAnimIter *iter = GDK_PIXBUF_NON_ANIM_ITER (object);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
g_object_unref (iter->non_anim);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
G_OBJECT_CLASS (gdk_pixbuf_non_anim_iter_parent_class)->finalize (object);
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
static gint
|
|
Packit |
a4058c |
gdk_pixbuf_non_anim_iter_get_delay_time (GdkPixbufAnimationIter *iter)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
return -1; /* show only frame forever */
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
static GdkPixbuf*
|
|
Packit |
a4058c |
gdk_pixbuf_non_anim_iter_get_pixbuf (GdkPixbufAnimationIter *iter)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
return GDK_PIXBUF_NON_ANIM_ITER (iter)->non_anim->pixbuf;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
static gboolean
|
|
Packit |
a4058c |
gdk_pixbuf_non_anim_iter_on_currently_loading_frame (GdkPixbufAnimationIter *iter)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
return TRUE;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
static gboolean
|
|
Packit |
a4058c |
gdk_pixbuf_non_anim_iter_advance (GdkPixbufAnimationIter *iter,
|
|
Packit |
a4058c |
const GTimeVal *current_time)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/* Advancing never requires a refresh */
|
|
Packit |
a4058c |
return FALSE;
|
|
Packit |
a4058c |
}
|