diff options
author | Gaël Bonithon <gael@xfce.org> | 2021-12-21 23:44:50 +0100 |
---|---|---|
committer | Gaël Bonithon <gael@xfce.org> | 2021-12-22 10:26:30 +0100 |
commit | 62d0f3e2faaf4cdab3dd9f45eaa03cb9ad4219c6 (patch) | |
tree | 2edd5fcec0b4921d35c026c2f20347a8a97206aa /plugins | |
parent | 283c7045d669941f3820f3963b9de6ea3baa96ea (diff) | |
download | tumbler-62d0f3e2faaf4cdab3dd9f45eaa03cb9ad4219c6.tar.gz |
pixbuf-thumbnailer: Stop animated image loading at first frame
Fixes #48.
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/pixbuf-thumbnailer/pixbuf-thumbnailer.c | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/plugins/pixbuf-thumbnailer/pixbuf-thumbnailer.c b/plugins/pixbuf-thumbnailer/pixbuf-thumbnailer.c index 7aacf12..7c01a63 100644 --- a/plugins/pixbuf-thumbnailer/pixbuf-thumbnailer.c +++ b/plugins/pixbuf-thumbnailer/pixbuf-thumbnailer.c @@ -158,10 +158,13 @@ pixbuf_thumbnailer_new_from_stream (GInputStream *stream, GError **error) { GdkPixbufLoader *loader; + GdkPixbufAnimation *animation; + GdkPixbufAnimationIter *iter; gssize n_read; GdkPixbuf *pixbuf = NULL; guchar *buffer; GError *err = NULL; + gboolean has_frame; g_return_val_if_fail (G_IS_INPUT_STREAM (stream), NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL); @@ -184,13 +187,27 @@ pixbuf_thumbnailer_new_from_stream (GInputStream *stream, /* read error (< 0), read finished (== 0) or write error */ if (n_read <= 0 || ! gdk_pixbuf_loader_write (loader, buffer, n_read, &err)) break; + + /* we only need the first frame to generate a thumbnail in case of an animation */ + animation = gdk_pixbuf_loader_get_animation (loader); + if (animation != NULL) + { + iter = gdk_pixbuf_animation_get_iter (animation, NULL); + has_frame = ! gdk_pixbuf_animation_iter_on_currently_loading_frame (iter); + g_object_unref (iter); + + if (has_frame) + break; + } } /* close the pixbuf loader, ignoring errors if there has been one before */ gdk_pixbuf_loader_close (loader, err == NULL ? &err : NULL); - /* some images reported as corrupt are still displayable */ - if (err == NULL || g_error_matches (err, GDK_PIXBUF_ERROR, GDK_PIXBUF_ERROR_CORRUPT_IMAGE)) + /* some images reported as corrupt are still displayable and we don't care about + * the rest of the animation */ + if (err == NULL || g_error_matches (err, GDK_PIXBUF_ERROR, GDK_PIXBUF_ERROR_CORRUPT_IMAGE) + || g_error_matches (err, GDK_PIXBUF_ERROR, GDK_PIXBUF_ERROR_INCOMPLETE_ANIMATION)) { pixbuf = gdk_pixbuf_loader_get_pixbuf (loader); if (G_LIKELY (pixbuf != NULL)) |