From 6fcc8afa851ccc1a90eefd70ddf499ea219bcb0c Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 19 May 2003 21:44:18 +0000 Subject: [PATCH] Improve progressive loading from slow sources: (#107368) 2003-05-19 Matthias Clasen Improve progressive loading from slow sources: (#107368) * io-gif-animation.c (gdk_pixbuf_gif_anim_get_iter): Initialize first_loop_slowness. (gdk_pixbuf_gif_anim_iter_advance): Don't wrap during loading if the datasource falls behind the speed of the display. * io-gif-animation.h: Add a loading flag to GdkPixbufGifAnim and first_loop_slowness to GdkPixbufGifAnimIter. --- gdk-pixbuf/ChangeLog | 12 ++++++++++++ gdk-pixbuf/io-gif-animation.c | 21 +++++++++++++++++---- gdk-pixbuf/io-gif-animation.h | 3 +++ 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/gdk-pixbuf/ChangeLog b/gdk-pixbuf/ChangeLog index ac26a9f14a..b827e59692 100644 --- a/gdk-pixbuf/ChangeLog +++ b/gdk-pixbuf/ChangeLog @@ -1,3 +1,15 @@ +2003-05-19 Matthias Clasen + + Improve progressive loading from slow sources: (#107368) + + * io-gif-animation.c (gdk_pixbuf_gif_anim_get_iter): Initialize + first_loop_slowness. + (gdk_pixbuf_gif_anim_iter_advance): Don't wrap during loading if + the datasource falls behind the speed of the display. + + * io-gif-animation.h: Add a loading flag to GdkPixbufGifAnim and + first_loop_slowness to GdkPixbufGifAnimIter. + Wed May 14 18:24:50 2003 Owen Taylor * gdk-pixdata.c (gdk_pixdata_deserialize): Add a diff --git a/gdk-pixbuf/io-gif-animation.c b/gdk-pixbuf/io-gif-animation.c index ede356dea2..97062ba9c9 100644 --- a/gdk-pixbuf/io-gif-animation.c +++ b/gdk-pixbuf/io-gif-animation.c @@ -180,6 +180,7 @@ gdk_pixbuf_gif_anim_get_iter (GdkPixbufAnimation *anim, iter->start_time = *start_time; iter->current_time = *start_time; + iter->first_loop_slowness = 0; return GDK_PIXBUF_ANIMATION_ITER (iter); } @@ -287,8 +288,21 @@ gdk_pixbuf_gif_anim_iter_advance (GdkPixbufAnimationIter *anim_iter, * and subtract time for that. */ - loop = elapsed / iter->gif_anim->total_time; - elapsed = elapsed % iter->gif_anim->total_time; + if (iter->gif_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->gif_anim->total_time); + + loop = (elapsed - iter->first_loop_slowness) / iter->gif_anim->total_time; + elapsed = (elapsed - iter->first_loop_slowness) % iter->gif_anim->total_time; + } iter->position = elapsed; @@ -334,9 +348,8 @@ gdk_pixbuf_gif_anim_iter_get_delay_time (GdkPixbufAnimationIter *anim_iter) #endif return frame->delay_time - (iter->position - frame->elapsed); - } else { + } else return -1; /* show last frame forever */ - } } void diff --git a/gdk-pixbuf/io-gif-animation.h b/gdk-pixbuf/io-gif-animation.h index 00172cc474..3e8e52287b 100644 --- a/gdk-pixbuf/io-gif-animation.h +++ b/gdk-pixbuf/io-gif-animation.h @@ -78,6 +78,7 @@ struct _GdkPixbufGifAnim { guchar bg_blue; int loop; + gboolean loading; }; struct _GdkPixbufGifAnimClass { @@ -113,6 +114,8 @@ struct _GdkPixbufGifAnimIter { gint position; GList *current_frame; + + gint first_loop_slowness; }; struct _GdkPixbufGifAnimIterClass {