void vnr_tools_apply_embedded_orientation (GdkPixbufAnimation **anim) { GdkPixbuf *pixbuf; GdkPixbuf *original; if(!gdk_pixbuf_animation_is_static_image (*anim)) return; pixbuf = gdk_pixbuf_animation_get_static_image (*anim); original = pixbuf; pixbuf = gdk_pixbuf_apply_embedded_orientation(pixbuf); if(original == pixbuf) { g_object_unref(pixbuf); return; } GdkPixbufSimpleAnim *s_anim; s_anim = gdk_pixbuf_simple_anim_new (gdk_pixbuf_get_width(pixbuf), gdk_pixbuf_get_height(pixbuf), -1); gdk_pixbuf_simple_anim_add_frame(s_anim, pixbuf); g_object_unref(pixbuf); g_object_unref(*anim); *anim = GDK_PIXBUF_ANIMATION(s_anim); }
static VALUE rg_initialize(VALUE self, VALUE width, VALUE height, VALUE rate) { GdkPixbufSimpleAnim* ret = gdk_pixbuf_simple_anim_new(NUM2INT(width), NUM2INT(height), NUM2DBL(rate)); G_INITIALIZE(self, ret); return Qnil; }
static GdkPixbufAnimation* compose_animation_from_array (animation_param_entry **anim_array, gint array_len, gint pix_size) { GdkPixbufSimpleAnim *result = NULL; gint frames = 1, duration = 0, duration_p, frames_p; /* calculate frames count as multiplication of all frames and duration as max */ gint i; GTimeVal start_time = {0, 0}; for (i = 0; i<array_len; i++){ /* initialize iterators for each animation*/ animation_param_entry *p_entry = anim_array[i]; p_entry->iter = gdk_pixbuf_animation_get_iter (p_entry->anim, &start_time); frames_p = duration_p = 0; pgpug_pixbuf_animation_get_detail (p_entry->anim, &frames_p, &duration_p); duration = duration < duration_p ? duration_p : duration; frames *= frames_p; } float fps = duration > 0 ? frames * 1000 / duration : 1; gint frame_change_time = duration / frames; DEBG_MSG ("Fps: %f. frame change time :%dmsec", fps,frame_change_time); result = gdk_pixbuf_simple_anim_new (pix_size, pix_size, fps); gint elapsed_time = 0, frames_counter = 1; while (elapsed_time <= duration && frames_counter++ <= frames){ animation_param_entry *p_entry = anim_array[0]; GdkPixbuf *base_pixbuf = gdk_pixbuf_copy (gdk_pixbuf_animation_iter_get_pixbuf (p_entry->iter)); g_time_val_add (&start_time, frame_change_time * 1000); gdk_pixbuf_animation_iter_advance (p_entry->iter, &start_time); for (i = 1; i < array_len; i++) { p_entry = anim_array[i]; GdkPixbuf *src_pixbuf = gdk_pixbuf_animation_iter_get_pixbuf (p_entry->iter); gint x_offset, y_offset, src_size; src_size = gdk_pixbuf_get_width (src_pixbuf); pgpug_pixbuf_calculate_composition_offset (pix_size, src_size, p_entry->pos, &x_offset, &y_offset); gdk_pixbuf_composite (src_pixbuf, base_pixbuf, x_offset, y_offset, src_size, src_size, x_offset, y_offset, 1.0f, 1.0f, GDK_INTERP_BILINEAR, 255); gboolean res; res = gdk_pixbuf_animation_iter_advance (p_entry->iter, &start_time); } gdk_pixbuf_simple_anim_add_frame (result, base_pixbuf); elapsed_time += frame_change_time; } gdk_pixbuf_simple_anim_set_loop (result, TRUE); for (i=0;i<array_len;i++){ g_object_unref (anim_array[i]->iter); } return GDK_PIXBUF_ANIMATION (result); }
GdkPixbufAnimation* pgpug_animated_icon (PgpugPixEnum icon_id, gint size) { g_return_val_if_fail (icon_id < PIX_NUMBER, NULL); GdkPixbufSimpleAnim *result = NULL; PgpugPixEntry entry = icon_entries_array [icon_id]; /* assert that ids are in order */ g_return_val_if_fail (entry.id == icon_id, NULL); GPtrArray *frames_array = g_ptr_array_new (); GtkIconTheme* theme; GdkPixbuf *pixbuf; GError *error = NULL, *error_anim = NULL; theme = gtk_icon_theme_get_default (); pixbuf = gtk_icon_theme_load_icon (theme, entry.name, size, GTK_ICON_LOOKUP_FORCE_SIZE, &error); if (error == NULL && pixbuf != NULL) { DEBG_MSG ("Loaded icon with name %s", entry.name); //it's a static image g_ptr_array_add (frames_array, (gpointer)pixbuf); }else{ //else try to get frame sequence gchar *name_template = g_strconcat (entry.name, "%02d", NULL); int i = 1; do { gchar *name = g_strdup_printf (name_template, i++); pixbuf = gtk_icon_theme_load_icon (theme, name, size, GTK_ICON_LOOKUP_FORCE_SIZE, &error_anim); if (pixbuf != NULL){ DEBG_MSG ("Loaded animation frame with name %s, address %p", name, pixbuf); g_ptr_array_add (frames_array, (gpointer)pixbuf); } g_free (name); } while (error_anim == NULL && i < 100); g_free (name_template); } if (frames_array->len != 0){ //construct animation result = gdk_pixbuf_simple_anim_new (size, size, frames_array->len); guint i; for (i = 0;i < frames_array->len; i++) gdk_pixbuf_simple_anim_add_frame (result, frames_array->pdata[i]); } else{ //we didn't find any images gchar **search_paths; gint index; gchar *search_path_str; gtk_icon_theme_get_search_path (theme, &search_paths, &index); search_path_str = g_strjoinv ("\n", search_paths); WARN_MSG ("Icon with name \"%s\" can not be loaded.\n" "Icon search paths are: \n%s\n" "Error message: %s", entry.name, search_path_str, error->message); g_strfreev (search_paths); g_free (search_path_str); } g_ptr_array_foreach (frames_array, (GFunc)g_object_unref, NULL); g_ptr_array_free (frames_array, TRUE); if (error != NULL) g_error_free (error); if (error_anim != NULL) g_error_free (error_anim); return GDK_PIXBUF_ANIMATION (result); }