static void load_animation (GInputStream *input_stream, CbMedia *media) { GdkPixbufAnimation *animation; GdkPixbuf *frame; GError *error = NULL; cairo_surface_t *surface; cairo_t *ct; gboolean has_alpha; animation = gdk_pixbuf_animation_new_from_stream (input_stream, NULL, &error); if (error) { g_warning ("Couldn't load pixbuf: %s (%s)", error->message, media->url); mark_invalid (media); g_error_free (error); return; } frame = gdk_pixbuf_animation_get_static_image (animation); if (!gdk_pixbuf_animation_is_static_image (animation)) media->animation = animation; /* Takes ref */ else media->animation = NULL; has_alpha = gdk_pixbuf_get_has_alpha (frame); surface = cairo_image_surface_create (has_alpha ? CAIRO_FORMAT_ARGB32 : CAIRO_FORMAT_RGB24, gdk_pixbuf_get_width (frame), gdk_pixbuf_get_height (frame)); ct = cairo_create (surface); gdk_cairo_set_source_pixbuf (ct, frame, 0.0, 0.0); cairo_paint (ct); cairo_destroy (ct); media->surface = surface; if (media->surface == NULL) { g_warning ("Surface of %p is null", media); mark_invalid (media); goto out; } media->width = gdk_pixbuf_get_width (frame); media->height = gdk_pixbuf_get_height (frame); media->loaded = TRUE; media->invalid = FALSE; out: if (media->animation == NULL) g_object_unref (animation); cb_media_loading_finished (media); }
GthImage * gth_pixbuf_animation_new_from_file (GInputStream *istream, GthFileData *file_data, int requested_size, int *original_width, int *original_height, gboolean *loaded_original, gpointer user_data, GCancellable *cancellable, GError **error) { const char *mime_type; GthImage *image; mime_type = _g_content_type_get_from_stream (istream, (file_data != NULL ? file_data->file : NULL), cancellable, error); if (mime_type == NULL) return NULL; image = NULL; if (g_content_type_equals (mime_type, "image/gif")) { GdkPixbufAnimation *animation; animation = gdk_pixbuf_animation_new_from_stream (istream, cancellable, error); image = gth_image_new (); gth_image_set_pixbuf_animation (image, animation); _g_object_unref (animation); } else image = gth_pixbuf_new_from_file (istream, file_data, requested_size, original_width, original_height, loaded_original, FALSE, cancellable, error); return image; }