gdip-pixbuf-loader r36 - in trunk: . src
- From: doml svn gnome org
- To: svn-commits-list gnome org
- Subject: gdip-pixbuf-loader r36 - in trunk: . src
- Date: Sun, 24 Feb 2008 23:49:02 +0000 (GMT)
Author: doml
Date: Sun Feb 24 23:49:02 2008
New Revision: 36
URL: http://svn.gnome.org/viewvc/gdip-pixbuf-loader?rev=36&view=rev
Log:
2008-02-24 Dom Lachowicz <domlachowicz gmail com>
* src/io-gdip-animation.[ch]: Animation class and interator
* src/io-gdip-utils.c: Use animation iter. GDI+ animations now work.
Added:
trunk/src/io-gdip-animation.c
trunk/src/io-gdip-animation.h
Modified:
trunk/ChangeLog
trunk/src/Makefile.test
trunk/src/io-gdip-utils.c
Modified: trunk/src/Makefile.test
==============================================================================
--- trunk/src/Makefile.test (original)
+++ trunk/src/Makefile.test Sun Feb 24 23:49:02 2008
@@ -17,26 +17,26 @@
$(CC) -Wall -O0 -g $(CFLAGS) $(LDFLAGS) test-save.c -o test-save.exe -lole32 -lglib-2.0 -lgobject-2.0 -lgdk_pixbuf-2.0
$(CP) test-save.exe $(PREFIX)/bin
-libpixbufloader-gdip.dll: io-gdip-native.h io-gdip-utils.c io-gdip-utils.h io-gdip.c Makefile.test
- $(CC) -Wall -O0 -g -shared io-gdip-utils.c io-gdip.c $(CFLAGS) $(LDFLAGS) -lole32 -lglib-2.0 -lgobject-2.0 -lgdk_pixbuf-2.0 -o $@
+libpixbufloader-gdip.dll: io-gdip-native.h io-gdip-utils.c io-gdip-utils.h io-gdip.c io-gdip-animation.c io-gdip-animation.h Makefile.test
+ $(CC) -Wall -O0 -g -shared io-gdip-utils.c io-gdip.c io-gdip-animation.c $(CFLAGS) $(LDFLAGS) -lole32 -lglib-2.0 -lgobject-2.0 -lgdk_pixbuf-2.0 -o $@
$(CP) $@ $(LOADER_DIR)
-libpixbufloader-gdip-bmp.dll: io-gdip-native.h io-gdip-utils.c io-gdip-utils.h io-gdip-bmp.c Makefile.test
- $(CC) -Wall -O0 -g -shared io-gdip-utils.c io-gdip-bmp.c $(CFLAGS) $(LDFLAGS) -lole32 -lglib-2.0 -lgobject-2.0 -lgdk_pixbuf-2.0 -o $@
+libpixbufloader-gdip-bmp.dll: io-gdip-native.h io-gdip-utils.c io-gdip-utils.h io-gdip-bmp.c io-gdip-animation.c io-gdip-animation.h Makefile.test
+ $(CC) -Wall -O0 -g -shared io-gdip-utils.c io-gdip-bmp.c io-gdip-animation.c $(CFLAGS) $(LDFLAGS) -lole32 -lglib-2.0 -lgobject-2.0 -lgdk_pixbuf-2.0 -o $@
$(CP) $@ $(LOADER_DIR)
-libpixbufloader-gdip-gif.dll: io-gdip-native.h io-gdip-utils.c io-gdip-utils.h io-gdip-gif.c Makefile.test
- $(CC) -Wall -O0 -g -shared io-gdip-utils.c io-gdip-gif.c $(CFLAGS) $(LDFLAGS) -lole32 -lglib-2.0 -lgobject-2.0 -lgdk_pixbuf-2.0 -o $@
+libpixbufloader-gdip-gif.dll: io-gdip-native.h io-gdip-utils.c io-gdip-utils.h io-gdip-gif.c io-gdip-animation.c io-gdip-animation.h Makefile.test
+ $(CC) -Wall -O0 -g -shared io-gdip-utils.c io-gdip-gif.c io-gdip-animation.c $(CFLAGS) $(LDFLAGS) -lole32 -lglib-2.0 -lgobject-2.0 -lgdk_pixbuf-2.0 -o $@
$(CP) $@ $(LOADER_DIR)
-libpixbufloader-gdip-jpeg.dll: io-gdip-native.h io-gdip-utils.c io-gdip-utils.h io-gdip-jpeg.c Makefile.test
- $(CC) -Wall -O0 -g -shared io-gdip-utils.c io-gdip-jpeg.c $(CFLAGS) $(LDFLAGS) -lole32 -lglib-2.0 -lgobject-2.0 -lgdk_pixbuf-2.0 -o $@
+libpixbufloader-gdip-jpeg.dll: io-gdip-native.h io-gdip-utils.c io-gdip-utils.h io-gdip-jpeg.c io-gdip-animation.c io-gdip-animation.h Makefile.test
+ $(CC) -Wall -O0 -g -shared io-gdip-utils.c io-gdip-jpeg.c io-gdip-animation.c $(CFLAGS) $(LDFLAGS) -lole32 -lglib-2.0 -lgobject-2.0 -lgdk_pixbuf-2.0 -o $@
$(CP) $@ $(LOADER_DIR)
-libpixbufloader-gdip-png.dll: io-gdip-native.h io-gdip-utils.c io-gdip-utils.h io-gdip-png.c Makefile.test
- $(CC) -Wall -O0 -g -shared io-gdip-utils.c io-gdip-png.c $(CFLAGS) $(LDFLAGS) -lole32 -lglib-2.0 -lgobject-2.0 -lgdk_pixbuf-2.0 -o $@
+libpixbufloader-gdip-png.dll: io-gdip-native.h io-gdip-utils.c io-gdip-utils.h io-gdip-png.c io-gdip-animation.c io-gdip-animation.h Makefile.test
+ $(CC) -Wall -O0 -g -shared io-gdip-utils.c io-gdip-png.c io-gdip-animation.c $(CFLAGS) $(LDFLAGS) -lole32 -lglib-2.0 -lgobject-2.0 -lgdk_pixbuf-2.0 -o $@
$(CP) $@ $(LOADER_DIR)
-libpixbufloader-gdip-tiff.dll: io-gdip-native.h io-gdip-utils.c io-gdip-utils.h io-gdip-tiff.c Makefile.test
- $(CC) -Wall -O0 -g -shared io-gdip-utils.c io-gdip-tiff.c $(CFLAGS) $(LDFLAGS) -lole32 -lglib-2.0 -lgobject-2.0 -lgdk_pixbuf-2.0 -o $@
+libpixbufloader-gdip-tiff.dll: io-gdip-native.h io-gdip-utils.c io-gdip-utils.h io-gdip-tiff.c io-gdip-animation.c io-gdip-animation.h Makefile.test
+ $(CC) -Wall -O0 -g -shared io-gdip-utils.c io-gdip-tiff.c io-gdip-animation.c $(CFLAGS) $(LDFLAGS) -lole32 -lglib-2.0 -lgobject-2.0 -lgdk_pixbuf-2.0 -o $@
$(CP) $@ $(LOADER_DIR)
\ No newline at end of file
Added: trunk/src/io-gdip-animation.c
==============================================================================
--- (empty file)
+++ trunk/src/io-gdip-animation.c Sun Feb 24 23:49:02 2008
@@ -0,0 +1,465 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* GdkPixbuf library - animated gdip support
+ *
+ * Copyright (C) 1999 The Free Software Foundation
+ *
+ * Authors: Jonathan Blandford <jrb redhat com>
+ * Havoc Pennington <hp redhat com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#define GDK_PIXBUF_ENABLE_BACKEND
+#include <errno.h>
+#include "io-gdip-native.h"
+#include "io-gdip-animation.h"
+
+static void gdk_pixbuf_gdip_anim_class_init (GdkPixbufGdipAnimClass *klass);
+static void gdk_pixbuf_gdip_anim_finalize (GObject *object);
+
+static gboolean gdk_pixbuf_gdip_anim_is_static_image (GdkPixbufAnimation *animation);
+static GdkPixbuf* gdk_pixbuf_gdip_anim_get_static_image (GdkPixbufAnimation *animation);
+
+static void gdk_pixbuf_gdip_anim_get_size (GdkPixbufAnimation *anim,
+ int *width,
+ int *height);
+static GdkPixbufAnimationIter* gdk_pixbuf_gdip_anim_get_iter (GdkPixbufAnimation *anim,
+ const GTimeVal *start_time);
+
+static gpointer parent_class;
+
+#define GDIP_CLASS_FULL(name, prefix, base_init, base_finalize, \
+ class_init, class_finalize, instance_init, parent_type, \
+ abstract, interface_decl) \
+GType \
+prefix ## _get_type (void) \
+{ \
+ static GType type = 0; \
+ if (G_UNLIKELY (type == 0)) { \
+ static GTypeInfo const object_info = { \
+ sizeof (name ## Class), \
+ (GBaseInitFunc) base_init, \
+ (GBaseFinalizeFunc) base_finalize, \
+ (GClassInitFunc) class_init, \
+ (GClassFinalizeFunc) class_finalize, \
+ NULL, /* class_data */ \
+ sizeof (name), \
+ 0, /* n_preallocs */ \
+ (GInstanceInitFunc) instance_init, \
+ NULL \
+ }; \
+ type = g_type_from_name (#name); \
+ if (type == 0) { \
+ type = g_type_register_static (parent_type, #name, \
+ &object_info, (GTypeFlags) abstract); \
+ interface_decl \
+ } \
+ } \
+ return type; \
+}
+
+#define GDIP_CLASS(name, prefix, class_init, instance_init, parent) \
+ GDIP_CLASS_FULL(name, prefix, NULL, NULL, class_init, NULL, \
+ instance_init, parent, 0, {})
+
+#define _GDIP_GTYPE_THREADING_FIXED
+
+#ifdef _GDIP_GTYPE_THREADING_FIXED
+typedef GTypeModule GdipDummyTypeModule;
+typedef GTypeModuleClass GdipDummyTypeModuleClass;
+static gboolean
+gdip_dummy_type_module_load (GTypeModule *module)
+{
+ return TRUE;
+}
+static void
+gdip_dummy_type_module_class_init (GTypeModuleClass *gtm_class)
+{
+ gtm_class->load = gdip_dummy_type_module_load;
+}
+static GDIP_CLASS (GdipDummyTypeModule, gdip_dummy_type_module,
+ gdip_dummy_type_module_class_init, NULL,
+ G_TYPE_TYPE_MODULE)
+
+static GTypeModule *static_type_module = NULL;
+#endif
+
+void
+gdip_anim_init (void)
+{
+#ifdef _GDIP_GTYPE_THREADING_FIXED
+ if (NULL == static_type_module) {
+ static_type_module = g_object_new (gdip_dummy_type_module_get_type(), NULL);
+ g_assert (static_type_module != NULL);
+ g_type_module_use (static_type_module);
+ g_type_module_set_name (static_type_module, "libgdip-builtin");
+ }
+#endif
+}
+
+GType
+gdk_pixbuf_gdip_anim_get_type (void)
+{
+ static GType object_type = 0;
+
+ if (!object_type) {
+ static const GTypeInfo object_info = {
+ sizeof (GdkPixbufGdipAnimClass),
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) gdk_pixbuf_gdip_anim_class_init,
+ NULL, /* class_finalize */
+ NULL, /* class_data */
+ sizeof (GdkPixbufGdipAnim),
+ 0, /* n_preallocs */
+ (GInstanceInitFunc) NULL,
+ };
+
+#ifdef _GDIP_GTYPE_THREADING_FIXED
+ object_type = g_type_from_name ("GdkPixbufGdipAnim");
+ if (object_type == 0) {
+ object_type = g_type_module_register_type (static_type_module,
+ GDK_TYPE_PIXBUF_ANIMATION,
+ "GdkPixbufGdipAnim", &object_info, (GTypeFlags) 0);
+ }
+#else
+ object_type = g_type_register_static (GDK_TYPE_PIXBUF_ANIMATION,
+ g_intern_static_string ("GdkPixbufGdipAnim"),
+ &object_info, 0);
+#endif
+ }
+
+ return object_type;
+}
+
+static void
+gdk_pixbuf_gdip_anim_class_init (GdkPixbufGdipAnimClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GdkPixbufAnimationClass *anim_class = GDK_PIXBUF_ANIMATION_CLASS (klass);
+
+ parent_class = g_type_class_peek_parent (klass);
+
+ object_class->finalize = gdk_pixbuf_gdip_anim_finalize;
+
+ anim_class->is_static_image = gdk_pixbuf_gdip_anim_is_static_image;
+ anim_class->get_static_image = gdk_pixbuf_gdip_anim_get_static_image;
+ anim_class->get_size = gdk_pixbuf_gdip_anim_get_size;
+ anim_class->get_iter = gdk_pixbuf_gdip_anim_get_iter;
+}
+
+static void
+gdk_pixbuf_gdip_anim_finalize (GObject *object)
+{
+ GdkPixbufGdipAnim *gdip_anim = GDK_PIXBUF_GDIP_ANIM (object);
+
+ GList *l;
+ GdkPixbufFrame *frame;
+
+ for (l = gdip_anim->frames; l; l = l->next) {
+ frame = l->data;
+ g_object_unref (frame->pixbuf);
+ g_free (frame);
+ }
+
+ g_list_free (gdip_anim->frames);
+
+ G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+static gboolean
+gdk_pixbuf_gdip_anim_is_static_image (GdkPixbufAnimation *animation)
+{
+ GdkPixbufGdipAnim *gdip_anim;
+
+ gdip_anim = GDK_PIXBUF_GDIP_ANIM (animation);
+
+ return (gdip_anim->frames != NULL &&
+ gdip_anim->frames->next == NULL);
+}
+
+static GdkPixbuf*
+gdk_pixbuf_gdip_anim_get_static_image (GdkPixbufAnimation *animation)
+{
+ GdkPixbufGdipAnim *gdip_anim;
+
+ gdip_anim = GDK_PIXBUF_GDIP_ANIM (animation);
+
+ if (gdip_anim->frames == NULL)
+ return NULL;
+ else
+ return GDK_PIXBUF (((GdkPixbufFrame*)gdip_anim->frames->data)->pixbuf);
+}
+
+static void
+gdk_pixbuf_gdip_anim_get_size (GdkPixbufAnimation *anim,
+ int *width,
+ int *height)
+{
+ GdkPixbufGdipAnim *gdip_anim;
+
+ gdip_anim = GDK_PIXBUF_GDIP_ANIM (anim);
+
+ if (width)
+ *width = gdip_anim->width;
+
+ if (height)
+ *height = gdip_anim->height;
+}
+
+
+static void
+iter_clear (GdkPixbufGdipAnimIter *iter)
+{
+ iter->current_frame = NULL;
+}
+
+static void
+iter_restart (GdkPixbufGdipAnimIter *iter)
+{
+ iter_clear (iter);
+
+ iter->current_frame = iter->gdip_anim->frames;
+}
+
+static GdkPixbufAnimationIter*
+gdk_pixbuf_gdip_anim_get_iter (GdkPixbufAnimation *anim,
+ const GTimeVal *start_time)
+{
+ GdkPixbufGdipAnimIter *iter;
+
+ iter = g_object_new (GDK_TYPE_PIXBUF_GDIP_ANIM_ITER, NULL);
+
+ iter->gdip_anim = GDK_PIXBUF_GDIP_ANIM (anim);
+
+ g_object_ref (iter->gdip_anim);
+
+ iter_restart (iter);
+
+ iter->start_time = *start_time;
+ iter->current_time = *start_time;
+ iter->first_loop_slowness = 0;
+
+ return GDK_PIXBUF_ANIMATION_ITER (iter);
+}
+
+static void gdk_pixbuf_gdip_anim_iter_class_init (GdkPixbufGdipAnimIterClass *klass);
+static void gdk_pixbuf_gdip_anim_iter_finalize (GObject *object);
+
+static int gdk_pixbuf_gdip_anim_iter_get_delay_time (GdkPixbufAnimationIter *iter);
+static GdkPixbuf* gdk_pixbuf_gdip_anim_iter_get_pixbuf (GdkPixbufAnimationIter *iter);
+static gboolean gdk_pixbuf_gdip_anim_iter_on_currently_loading_frame (GdkPixbufAnimationIter *iter);
+static gboolean gdk_pixbuf_gdip_anim_iter_advance (GdkPixbufAnimationIter *iter,
+ const GTimeVal *current_time);
+
+static gpointer iter_parent_class;
+
+GType
+gdk_pixbuf_gdip_anim_iter_get_type (void)
+{
+ static GType object_type = 0;
+
+ if (!object_type) {
+ static const GTypeInfo object_info = {
+ sizeof (GdkPixbufGdipAnimIterClass),
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) gdk_pixbuf_gdip_anim_iter_class_init,
+ NULL, /* class_finalize */
+ NULL, /* class_data */
+ sizeof (GdkPixbufGdipAnimIter),
+ 0, /* n_preallocs */
+ (GInstanceInitFunc) NULL,
+ };
+
+#ifdef _GDIP_GTYPE_THREADING_FIXED
+ object_type = g_type_from_name ("GdkPixbufGdipAnimIter");
+ if (object_type == 0) {
+ object_type = g_type_module_register_type (static_type_module,
+ GDK_TYPE_PIXBUF_ANIMATION_ITER,
+ "GdkPixbufGdipAnimIter", &object_info, (GTypeFlags) 0);
+ }
+#else
+ object_type = g_type_register_static (GDK_TYPE_PIXBUF_ANIMATION_ITER,
+ g_intern_static_string ("GdkPixbufGdipAnimIter"),
+ &object_info, 0);
+#endif
+ }
+
+ return object_type;
+}
+
+static void
+gdk_pixbuf_gdip_anim_iter_class_init (GdkPixbufGdipAnimIterClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GdkPixbufAnimationIterClass *anim_iter_class =
+ GDK_PIXBUF_ANIMATION_ITER_CLASS (klass);
+
+ iter_parent_class = g_type_class_peek_parent (klass);
+
+ object_class->finalize = gdk_pixbuf_gdip_anim_iter_finalize;
+
+ anim_iter_class->get_delay_time = gdk_pixbuf_gdip_anim_iter_get_delay_time;
+ anim_iter_class->get_pixbuf = gdk_pixbuf_gdip_anim_iter_get_pixbuf;
+ anim_iter_class->on_currently_loading_frame = gdk_pixbuf_gdip_anim_iter_on_currently_loading_frame;
+ anim_iter_class->advance = gdk_pixbuf_gdip_anim_iter_advance;
+}
+
+static void
+gdk_pixbuf_gdip_anim_iter_finalize (GObject *object)
+{
+ GdkPixbufGdipAnimIter *iter = GDK_PIXBUF_GDIP_ANIM_ITER (object);
+
+ iter_clear (iter);
+
+ g_object_unref (iter->gdip_anim);
+
+ G_OBJECT_CLASS (iter_parent_class)->finalize (object);
+}
+
+static gboolean
+gdk_pixbuf_gdip_anim_iter_advance (GdkPixbufAnimationIter *anim_iter,
+ const GTimeVal *current_time)
+{
+ GdkPixbufGdipAnimIter *iter;
+ gint elapsed;
+ gint loop;
+ GList *tmp;
+ GList *old;
+
+ iter = GDK_PIXBUF_GDIP_ANIM_ITER (anim_iter);
+
+ iter->current_time = *current_time;
+
+ /* We use milliseconds for all times */
+ elapsed =
+ (((iter->current_time.tv_sec - iter->start_time.tv_sec) * G_USEC_PER_SEC +
+ iter->current_time.tv_usec - iter->start_time.tv_usec)) / 1000;
+
+ if (elapsed < 0) {
+ /* Try to compensate; probably the system clock
+ * was set backwards
+ */
+ iter->start_time = iter->current_time;
+ elapsed = 0;
+ }
+
+ g_assert (iter->gdip_anim->total_time > 0);
+
+ /* See how many times we've already played the full animation,
+ * and subtract time for that.
+ */
+
+ if (iter->gdip_anim->loading)
+ loop = 0;
+ else {
+ /* If current_frame is NULL at this point, we have loaded the
+ * animation from a source which fell behind the speed of the
+ * display. We remember how much slower the first loop was due
+ * to this and correct the position calculation in order to not
+ * jump in the middle of the second loop.
+ */
+ if (iter->current_frame == NULL)
+ iter->first_loop_slowness = MAX(0, elapsed - iter->gdip_anim->total_time);
+
+ loop = (elapsed - iter->first_loop_slowness) / iter->gdip_anim->total_time;
+ elapsed = (elapsed - iter->first_loop_slowness) % iter->gdip_anim->total_time;
+ }
+
+ iter->position = elapsed;
+
+ /* Now move to the proper frame */
+ if (iter->gdip_anim->loop == 0 || loop < iter->gdip_anim->loop)
+ tmp = iter->gdip_anim->frames;
+ else
+ tmp = NULL;
+ while (tmp != NULL) {
+ GdkPixbufFrame *frame = tmp->data;
+
+ if (iter->position >= frame->elapsed &&
+ iter->position < (frame->elapsed + frame->delay_time))
+ break;
+
+ tmp = tmp->next;
+ }
+
+ old = iter->current_frame;
+
+ iter->current_frame = tmp;
+
+ return iter->current_frame != old;
+}
+
+int
+gdk_pixbuf_gdip_anim_iter_get_delay_time (GdkPixbufAnimationIter *anim_iter)
+{
+ GdkPixbufFrame *frame;
+ GdkPixbufGdipAnimIter *iter;
+
+ iter = GDK_PIXBUF_GDIP_ANIM_ITER (anim_iter);
+
+ if (iter->current_frame) {
+ frame = iter->current_frame->data;
+
+#if 0
+ g_print ("frame start: %d pos: %d frame len: %d frame remaining: %d\n",
+ frame->elapsed,
+ iter->position,
+ frame->delay_time,
+ frame->delay_time - (iter->position - frame->elapsed));
+#endif
+
+ return frame->delay_time - (iter->position - frame->elapsed);
+ } else
+ return -1; /* show last frame forever */
+}
+
+GdkPixbuf*
+gdk_pixbuf_gdip_anim_iter_get_pixbuf (GdkPixbufAnimationIter *anim_iter)
+{
+ GdkPixbufGdipAnimIter *iter;
+ GdkPixbufFrame *frame;
+
+ iter = GDK_PIXBUF_GDIP_ANIM_ITER (anim_iter);
+
+ frame = iter->current_frame ? iter->current_frame->data : g_list_last (iter->gdip_anim->frames)->data;
+
+#if 0
+ if (FALSE && frame)
+ g_print ("current frame %d dispose mode %d %d x %d\n",
+ g_list_index (iter->gdip_anim->frames,
+ frame),
+ frame->action,
+ gdk_pixbuf_get_width (frame->pixbuf),
+ gdk_pixbuf_get_height (frame->pixbuf));
+#endif
+
+ if (frame == NULL)
+ return NULL;
+
+ return frame->pixbuf;
+}
+
+static gboolean
+gdk_pixbuf_gdip_anim_iter_on_currently_loading_frame (GdkPixbufAnimationIter *anim_iter)
+{
+ GdkPixbufGdipAnimIter *iter;
+
+ iter = GDK_PIXBUF_GDIP_ANIM_ITER (anim_iter);
+
+ return iter->current_frame == NULL || iter->current_frame->next == NULL;
+}
Added: trunk/src/io-gdip-animation.h
==============================================================================
--- (empty file)
+++ trunk/src/io-gdip-animation.h Sun Feb 24 23:49:02 2008
@@ -0,0 +1,120 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+/* GdkPixbuf library - GDIP loader declarations
+ *
+ * Copyright (C) 1999 The Free Software Foundation
+ *
+ * Authors: Mark Crichton <crichton gimp org>
+ * Miguel de Icaza <miguel gnu org>
+ * Federico Mena-Quintero <federico gimp org>
+ * Havoc Pennington <hp redhat com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef GDK_PIXBUF_GDIP_H
+#define GDK_PIXBUF_GDIP_H
+
+#include <gdk-pixbuf/gdk-pixbuf-animation.h>
+
+typedef struct _GdkPixbufGdipAnim GdkPixbufGdipAnim;
+typedef struct _GdkPixbufGdipAnimClass GdkPixbufGdipAnimClass;
+typedef struct _GdkPixbufFrame GdkPixbufFrame;
+
+#define GDK_TYPE_PIXBUF_GDIP_ANIM (gdk_pixbuf_gdip_anim_get_type ())
+#define GDK_PIXBUF_GDIP_ANIM(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GDK_TYPE_PIXBUF_GDIP_ANIM, GdkPixbufGdipAnim))
+#define GDK_IS_PIXBUF_GDIP_ANIM(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), GDK_TYPE_PIXBUF_GDIP_ANIM))
+
+#define GDK_PIXBUF_GDIP_ANIM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GDK_TYPE_PIXBUF_GDIP_ANIM, GdkPixbufGdipAnimClass))
+#define GDK_IS_PIXBUF_GDIP_ANIM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDK_TYPE_PIXBUF_GDIP_ANIM))
+#define GDK_PIXBUF_GDIP_ANIM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GDK_TYPE_PIXBUF_GDIP_ANIM, GdkPixbufGdipAnimClass))
+
+/* Private part of the GdkPixbufGdipAnim structure */
+struct _GdkPixbufGdipAnim {
+ GdkPixbufAnimation parent_instance;
+
+ /* Number of frames */
+ int n_frames;
+
+ /* Total length of animation */
+ int total_time;
+
+ /* List of GdkPixbufFrame structures */
+ GList *frames;
+
+ /* bounding box size */
+ int width, height;
+
+ int loop;
+ gboolean loading;
+};
+
+struct _GdkPixbufGdipAnimClass {
+ GdkPixbufAnimationClass parent_class;
+
+};
+
+GType gdk_pixbuf_gdip_anim_get_type (void) G_GNUC_CONST;
+
+typedef struct _GdkPixbufGdipAnimIter GdkPixbufGdipAnimIter;
+typedef struct _GdkPixbufGdipAnimIterClass GdkPixbufGdipAnimIterClass;
+
+
+#define GDK_TYPE_PIXBUF_GDIP_ANIM_ITER (gdk_pixbuf_gdip_anim_iter_get_type ())
+#define GDK_PIXBUF_GDIP_ANIM_ITER(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GDK_TYPE_PIXBUF_GDIP_ANIM_ITER, GdkPixbufGdipAnimIter))
+#define GDK_IS_PIXBUF_GDIP_ANIM_ITER(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), GDK_TYPE_PIXBUF_GDIP_ANIM_ITER))
+
+#define GDK_PIXBUF_GDIP_ANIM_ITER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GDK_TYPE_PIXBUF_GDIP_ANIM_ITER, GdkPixbufGdipAnimIterClass))
+#define GDK_IS_PIXBUF_GDIP_ANIM_ITER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDK_TYPE_PIXBUF_GDIP_ANIM_ITER))
+#define GDK_PIXBUF_GDIP_ANIM_ITER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GDK_TYPE_PIXBUF_GDIP_ANIM_ITER, GdkPixbufGdipAnimIterClass))
+
+struct _GdkPixbufGdipAnimIter {
+ GdkPixbufAnimationIter parent_instance;
+
+ GdkPixbufGdipAnim *gdip_anim;
+
+ GTimeVal start_time;
+ GTimeVal current_time;
+
+ /* Time in milliseconds into this run of the animation */
+ gint position;
+
+ GList *current_frame;
+
+ gint first_loop_slowness;
+};
+
+struct _GdkPixbufGdipAnimIterClass {
+ GdkPixbufAnimationIterClass parent_class;
+
+};
+
+GType gdk_pixbuf_gdip_anim_iter_get_type (void) G_GNUC_CONST;
+
+struct _GdkPixbufFrame {
+ /* The pixbuf with this frame's image data */
+ GdkPixbuf *pixbuf;
+
+ /* Frame duration in ms */
+ int delay_time;
+
+ /* Sum of preceding delay times */
+ int elapsed;
+};
+
+void gdip_anim_init (void);
+
+
+#endif
Modified: trunk/src/io-gdip-utils.c
==============================================================================
--- trunk/src/io-gdip-utils.c (original)
+++ trunk/src/io-gdip-utils.c Sun Feb 24 23:49:02 2008
@@ -27,7 +27,7 @@
#include "io-gdip-utils.h"
#include "io-gdip-native.h"
#include "io-gdip-propertytags.h"
-#include <gdk-pixbuf/gdk-pixbuf-simple-anim.h>
+#include "io-gdip-animation.h"
#define LOAD_BUFFER_SIZE 65536
@@ -117,6 +117,8 @@
#undef TRY_LOOKUP
#undef LOOKUP
+ gdip_anim_init ();
+
input.GdiplusVersion = 1;
input.DebugEventCallback = NULL;
input.SuppressBackgroundThread = input.SuppressExternalCodecs = FALSE;
@@ -663,7 +665,7 @@
guint8 *tmp_buffer = NULL;
guint buffer_len = 0;
guint n_frames = 1, i;
- GdkPixbufSimpleAnim *animation = NULL;
+ GdkPixbufGdipAnim *animation = NULL;
if (error)
*error = NULL;
@@ -683,7 +685,9 @@
for (i = 0; i < n_frames; i++) {
GdkPixbuf *pixbuf = NULL;
-
+ GdkPixbufFrame *frame;
+ guint frame_delay = 0;
+
io_gdip_bitmap_select_frame (bitmap, i, TRUE);
pixbuf = gdi_bitmap_to_pixbuf (bitmap);
@@ -695,35 +699,50 @@
}
if (animation == NULL) {
- guint n_loops, frame_delay;
+ guint n_loops = 1;
+ animation = g_object_new (GDK_TYPE_PIXBUF_GDIP_ANIM, NULL);
io_gdip_bitmap_get_n_loops (bitmap, &n_loops);
- io_gdip_bitmap_get_frame_delay (bitmap, &frame_delay);
+ animation->loop = n_loops;
+ }
- (void)n_loops;
+ frame = g_new (GdkPixbufFrame, 1);
+ frame->pixbuf = pixbuf;
- /* frame delay is in 100ths of a second */
- if (frame_delay > 0) {
- frame_delay = (int)((1.0 / frame_delay) * 100);
- }
+ io_gdip_bitmap_get_frame_delay (bitmap, &frame_delay);
+
+ animation->n_frames++;
+ animation->frames = g_list_append (animation->frames, frame);
- animation = gdk_pixbuf_simple_anim_new (gdk_pixbuf_get_width (pixbuf),
- gdk_pixbuf_get_height (pixbuf),
- frame_delay);
- }
+ animation->width = gdk_pixbuf_get_width (pixbuf);
+ animation->height = gdk_pixbuf_get_height (pixbuf);
+
+ /* GIF delay is in hundredths, we want thousandths */
+ frame->delay_time = frame_delay * 10;
+ frame->elapsed = animation->total_time;
+
+ /* Some GIFs apparently have delay time of 0,
+ * that crashes everything so set it to "fast".
+ * Also, timeouts less than 20 or so just lock up
+ * the app or make the animation choppy, so fix them.
+ */
+ if (frame->delay_time < 20)
+ frame->delay_time = 20; /* 20 = "fast" */
+
+ animation->total_time += frame->delay_time;
- gdk_pixbuf_simple_anim_add_frame (animation, pixbuf);
if (i == 0)
emit_prepared (context, pixbuf, GDK_PIXBUF_ANIMATION (animation));
emit_updated (context, pixbuf);
/* emit_prepared() takes a ref */
- g_object_unref (G_OBJECT (pixbuf));
+ /* g_object_unref (G_OBJECT (pixbuf)); */
}
if (animation != NULL)
g_object_unref (G_OBJECT (animation));
+
destroy_gdipcontext (context);
return TRUE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]