From d4984ede33a905d92c4969ca34a78d37cec3bff3 Mon Sep 17 00:00:00 2001 From: Jonathan Blandford Date: Fri, 17 Dec 1999 21:42:47 +0000 Subject: [PATCH] moved the file here. It seems natural to put this function here, as that's 1999-12-17 Jonathan Blandford * gdk-pixbuf/gdk-pixbuf-io.c (gdk_pixbuf_animation_new_from_file): moved the file here. It seems natural to put this function here, as that's where the gdk_pixbuf_new_from_file function is, but it's still a little convoluted. The source files might be played with in a bit. --- gdk-pixbuf/ChangeLog | 14 ++++++ gdk-pixbuf/Makefile.am | 11 ++++- gdk-pixbuf/gdk-pixbuf-io.c | 79 +++++++++++++++++++++++++++++++++- gdk-pixbuf/gdk-pixbuf-loader.c | 25 +++++++++++ gdk-pixbuf/gdk-pixbuf.c | 26 ----------- gdk-pixbuf/gdk-pixbuf.h | 2 +- gtk/gdk-pixbuf-loader.c | 25 +++++++++++ 7 files changed, 152 insertions(+), 30 deletions(-) diff --git a/gdk-pixbuf/ChangeLog b/gdk-pixbuf/ChangeLog index 21ef624a0d..aeaabc876f 100644 --- a/gdk-pixbuf/ChangeLog +++ b/gdk-pixbuf/ChangeLog @@ -1,3 +1,17 @@ +1999-12-17 Jonathan Blandford + + * gdk-pixbuf/gdk-pixbuf-io.c (gdk_pixbuf_animation_new_from_file): + moved the file here. It seems natural to put this function here, + as that's where the gdk_pixbuf_new_from_file function is, but it's + still a little convoluted. The source files might be played with + in a bit. + +1999-12-14 Jonathan Blandford + + * gdk-pixbuf/gdk-pixbuf-loader.c + (gdk_pixbuf_loader_get_animation): Gets the animation from the + loader. + 1999-12-16 Federico Mena Quintero * doc/tmpl/rendering.sgml: Added notice about initializing GdkRGB diff --git a/gdk-pixbuf/Makefile.am b/gdk-pixbuf/Makefile.am index 0d8e6ff5ed..0879eeeca1 100644 --- a/gdk-pixbuf/Makefile.am +++ b/gdk-pixbuf/Makefile.am @@ -38,7 +38,7 @@ libexec_LTLIBRARIES = \ $(PNM_LIB) \ $(BMP_LIB) -noinst_PROGRAMS = testpixbuf testpixbuf-drawable +noinst_PROGRAMS = testpixbuf testpixbuf-drawable testanimation DEPS = libgdk_pixbuf.la INCLUDES = -I$(top_srcdir) -I$(top_builddir) \ @@ -57,6 +57,15 @@ testpixbuf_LDADD = $(LDADDS) $(LIBART_LIBS) $(GNOME_LIBS) -lgmodule testpixbuf_drawable_LDADD = $(LDADDS) $(GNOME_LIBS) endif +if INSIDE_GNOME_LIBS +testanimation_LDADD = $(LDADDS) $(LIBART_LIBS) -lgmodule +testanimation_drawable_LDADD = $(LDADDS) +else +testanimation_LDADD = $(LDADDS) $(LIBART_LIBS) $(GNOME_LIBS) -lgmodule +testanimation_drawable_LDADD = $(LDADDS) $(GNOME_LIBS) +endif + + GDK_PIXBUF_LIBS = $(LIBART_LIBS) $(GLIB_LIBS) $(GTK_LIBS) # diff --git a/gdk-pixbuf/gdk-pixbuf-io.c b/gdk-pixbuf/gdk-pixbuf-io.c index c30aae958a..429ac0e0dc 100644 --- a/gdk-pixbuf/gdk-pixbuf-io.c +++ b/gdk-pixbuf/gdk-pixbuf-io.c @@ -234,6 +234,9 @@ gdk_pixbuf_load_module (GdkPixbufModule *image_module) if (g_module_symbol (module, "image_load_increment", &load_sym)) image_module->load_increment = load_sym; + + if (g_module_symbol (module, "image_load_animation", &load_sym)) + image_module->load_animation = load_sym; } @@ -311,10 +314,10 @@ gdk_pixbuf_new_from_file (const char *filename) /** * gdk_pixbuf_new_from_xpm_data: * @data: Pointer to inline XPM data. - * + * * Creates a new pixbuf by parsing XPM data in memory. This data is commonly * the result of including an XPM file into a program's C source. - * + * * Return value: A newly-created pixbuf with a reference count of 1. **/ GdkPixbuf * @@ -341,3 +344,75 @@ gdk_pixbuf_new_from_xpm_data (const gchar **data) return pixbuf; } + + +/** + * gdk_pixbuf_animation_new_from_file: + * @filename: The filename. + * + * Creates a new @GdkPixbufAnimation with @filename loaded as the animation. If + * @filename doesn't exist or is an invalid file, the @n_frames member will be + * 0. If @filename is a static image (and not an animation) then the @n_frames + * member will be 1. + * + * Return value: A newly created GdkPixbufAnimation. + **/ +GdkPixbufAnimation * +gdk_pixbuf_animation_new_from_file (const gchar *filename) +{ + GdkPixbufAnimation *animation; + gint size; + FILE *f; + char buffer [128]; + GdkPixbufModule *image_module; + + f = fopen (filename, "r"); + if (!f) + return NULL; + + size = fread (&buffer, 1, sizeof (buffer), f); + + if (size == 0) { + fclose (f); + return NULL; + } + + image_module = gdk_pixbuf_get_module (buffer, size); + if (image_module){ + if (image_module->module == NULL) + gdk_pixbuf_load_module (image_module); + + if (image_module->load_animation == NULL) { + GdkPixbufFrame *frame; + if (image_module->load == NULL) { + fclose (f); + return NULL; + } + animation = g_new (GdkPixbufAnimation, 1); + frame = g_new (GdkPixbufFrame, 1); + + animation->n_frames = 1; + animation->frames = g_list_prepend (NULL, (gpointer) frame); + + frame->x_offset = 0; + frame->y_offset = 0; + frame->delaytime = -1; + frame->action = GDK_PIXBUF_FRAME_RETAIN; + + fseek (f, 0, SEEK_SET); + frame->pixbuf = (* image_module->load) (f); + fclose (f); + } else { + fseek (f, 0, SEEK_SET); + animation = (* image_module->load_animation) (f); + fclose (f); + } + + return animation; + } else { + g_warning ("Unable to find handler for file: %s", filename); + } + + fclose (f); + return NULL; +} diff --git a/gdk-pixbuf/gdk-pixbuf-loader.c b/gdk-pixbuf/gdk-pixbuf-loader.c index 9628944ea7..e5b81f1ee8 100644 --- a/gdk-pixbuf/gdk-pixbuf-loader.c +++ b/gdk-pixbuf/gdk-pixbuf-loader.c @@ -56,6 +56,7 @@ static guint pixbuf_loader_signals[LAST_SIGNAL] = { 0 }; typedef struct { GdkPixbuf *pixbuf; + GdkPixbufAnimation *animation; gboolean closed; gchar header_buf[LOADER_HEADER_SIZE]; gint header_buf_offset; @@ -380,6 +381,30 @@ gdk_pixbuf_loader_get_pixbuf (GdkPixbufLoader *loader) return priv->pixbuf; } +/** + * gdk_pixbuf_loader_get_animation: + * @loader: A pixbuf loader + * + * Queries the GdkPixbufAnimation that a pixbuf loader is currently creating. + * In general it only makes sense to call this function afer the "area_prepared" + * signal has been emitted by the loader. + * + * Return value: The GdkPixbufAnimation that the loader is loading, or NULL if + not enough data has been read to determine the information. + **/ +GdkPixbufAnimation * +gdk_pixbuf_loader_get_animation (GdkPixbufLoader *loader) +{ + GdkPixbufLoaderPrivate *priv; + + g_return_val_if_fail (loader != NULL, NULL); + g_return_val_if_fail (GDK_IS_PIXBUF_LOADER (loader), NULL); + + priv = loader->private; + + return priv->animation; +} + /** * gdk_pixbuf_loader_close: * @loader: A pixbuf loader. diff --git a/gdk-pixbuf/gdk-pixbuf.c b/gdk-pixbuf/gdk-pixbuf.c index ed276e55e0..eea251050e 100644 --- a/gdk-pixbuf/gdk-pixbuf.c +++ b/gdk-pixbuf/gdk-pixbuf.c @@ -293,32 +293,6 @@ gdk_pixbuf_get_rowstride (GdkPixbuf *pixbuf) return (pixbuf->art_pixbuf->rowstride); } - -/** - * gdk_pixbuf_animation_new_from_file: - * @filename: The filename. - * - * Creates a new @GdkPixbufAnimation with @filename loaded as the animation. If - * @filename doesn't exist or is an invalid file, the @n_frames member will be - * 0. If @filename is a static image (and not an animation) then the @n_frames - * member will be 1. - * - * Return value: A newly created GdkPixbufAnimation. - **/ -GdkPixbufAnimation * -gdk_pixbuf_animation_new_from_file (const char *filename) -{ - GdkPixbufAnimation *retval; - - g_return_val_if_fail (filename != NULL, NULL); - - retval = g_new (GdkPixbufAnimation, 1); - retval->n_frames = 0; - retval->frames = NULL; - - return retval; -} - /** * gdk_pixbuf_animation_destroy: * @animation: An animation. diff --git a/gdk-pixbuf/gdk-pixbuf.h b/gdk-pixbuf/gdk-pixbuf.h index 7c16915d27..75823e2906 100644 --- a/gdk-pixbuf/gdk-pixbuf.h +++ b/gdk-pixbuf/gdk-pixbuf.h @@ -63,7 +63,7 @@ struct _GdkPixbufFrame gushort x_offset; gushort y_offset; - guint delaytime; + gint delaytime; GdkPixbufFrameAction action; }; diff --git a/gtk/gdk-pixbuf-loader.c b/gtk/gdk-pixbuf-loader.c index 9628944ea7..e5b81f1ee8 100644 --- a/gtk/gdk-pixbuf-loader.c +++ b/gtk/gdk-pixbuf-loader.c @@ -56,6 +56,7 @@ static guint pixbuf_loader_signals[LAST_SIGNAL] = { 0 }; typedef struct { GdkPixbuf *pixbuf; + GdkPixbufAnimation *animation; gboolean closed; gchar header_buf[LOADER_HEADER_SIZE]; gint header_buf_offset; @@ -380,6 +381,30 @@ gdk_pixbuf_loader_get_pixbuf (GdkPixbufLoader *loader) return priv->pixbuf; } +/** + * gdk_pixbuf_loader_get_animation: + * @loader: A pixbuf loader + * + * Queries the GdkPixbufAnimation that a pixbuf loader is currently creating. + * In general it only makes sense to call this function afer the "area_prepared" + * signal has been emitted by the loader. + * + * Return value: The GdkPixbufAnimation that the loader is loading, or NULL if + not enough data has been read to determine the information. + **/ +GdkPixbufAnimation * +gdk_pixbuf_loader_get_animation (GdkPixbufLoader *loader) +{ + GdkPixbufLoaderPrivate *priv; + + g_return_val_if_fail (loader != NULL, NULL); + g_return_val_if_fail (GDK_IS_PIXBUF_LOADER (loader), NULL); + + priv = loader->private; + + return priv->animation; +} + /** * gdk_pixbuf_loader_close: * @loader: A pixbuf loader.