Ejemplo n.º 1
0
/**
 *	return number of frames per second and duration in msec
 */
gint 
pgpug_pixbuf_animation_get_detail (GdkPixbufAnimation *anim, gint *frames_count, gint *duration)
{
     //FIXME: there should be a better way to get frames count from animation     	       
     *frames_count = 0;
     *duration = 0;

     if (gdk_pixbuf_animation_is_static_image (anim)){
	  (*frames_count)++; 
	  return;
     }
     
     GTimeVal start_time = {0, 0};
     GdkPixbufAnimationIter *iter = gdk_pixbuf_animation_get_iter (anim, &start_time);
     GdkPixbuf *cur_frame, *first_frame = gdk_pixbuf_animation_iter_get_pixbuf (iter);
     int delay_time = gdk_pixbuf_animation_iter_get_delay_time (iter);

     while (delay_time > 0){

	  g_time_val_add (&start_time, delay_time*1000);

	  gboolean need_upd = gdk_pixbuf_animation_iter_advance (iter, &start_time);
	  if (need_upd){
	       (*frames_count)++; 
	       *duration += delay_time;
	  }

	  cur_frame = gdk_pixbuf_animation_iter_get_pixbuf (iter);
	  if (!need_upd || cur_frame == first_frame) {
	       delay_time = -1;
	  }
     }
     
     g_object_unref (iter);     
}
Ejemplo n.º 2
0
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);
}
Ejemplo n.º 3
0
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);
}
Ejemplo n.º 4
0
static void
load_picture (gchar *filename)
{
  anim_pb = gdk_pixbuf_animation_new_from_file (filename, NULL);
  orig_pb = gdk_pixbuf_animation_get_static_image (anim_pb);

  if (orig_pb)
    {
      if (gdk_pixbuf_animation_is_static_image (anim_pb))
        gtk_image_set_from_pixbuf (GTK_IMAGE (picture), orig_pb);
      else
        {
          gtk_image_set_from_animation (GTK_IMAGE (picture), anim_pb);
          animated = TRUE;
        }
      loaded = TRUE;
    }
  else
    gtk_image_set_from_stock (GTK_IMAGE (picture), "gtk-missing-image", GTK_ICON_SIZE_DIALOG);
}
Ejemplo n.º 5
0
void gaym_gtkconv_update_thumbnail(GaimConversation * conv, struct fetch_thumbnail_data
                                   *thumbnail_data)
{
    GaimGtkConversation *gtkconv;

    char filename[256];
    FILE *file;
    GError *err = NULL;

    size_t len;

    GdkPixbuf *buf;
    GdkPixbuf *scale;
    GdkPixmap *pm;
    GdkBitmap *bm;
    int scale_width, scale_height;


    GaimAccount *account;
    GaimPluginProtocolInfo *prpl_info = NULL;
    g_return_if_fail(conv != NULL);
    g_return_if_fail(GAIM_IS_GTK_CONVERSATION(conv));
    g_return_if_fail(gaim_conversation_get_type(conv) == GAIM_CONV_CHAT);

    gtkconv = GAIM_GTK_CONVERSATION(conv);

    GaymChatIcon *icon_data = g_hash_table_lookup(icons, conv);

    if (!thumbnail_data)
        return;
    if (!icon_data->show_icon)
        return;

    const char *data = thumbnail_data->pic_data;
    len = thumbnail_data->pic_data_len;

    account = gaim_conversation_get_account(conv);
    if (account && account->gc)
        prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(account->gc->prpl);


    if (icon_data->anim != NULL)
        g_object_unref(G_OBJECT(icon_data->anim));

    icon_data->anim = NULL;

    if (icon_data->icon_timer != 0)
        g_source_remove(icon_data->icon_timer);

    icon_data->icon_timer = 0;

    if (icon_data->iter != NULL)
        g_object_unref(G_OBJECT(icon_data->iter));

    icon_data->iter = NULL;

    if (!gaim_prefs_get_bool
        ("/gaim/gtk/conversations/im/show_buddy_icons"))
        return;

    if (gaim_conversation_get_gc(conv) == NULL)
        return;


    /* this is such an evil hack, i don't know why i'm even considering
       it. we'll do it differently when gdk-pixbuf-loader isn't leaky
       anymore. */
    /* gdk-pixbuf-loader was leaky? is it still? */

    g_snprintf(filename, sizeof(filename),
               "%s" G_DIR_SEPARATOR_S "gaimicon-%s.%d",
               g_get_tmp_dir(), thumbnail_data->who, getpid());

    if (!(file = g_fopen(filename, "wb")))
        return;

    fwrite(data, 1, len, file);
    fclose(file);
    icon_data->anim = gdk_pixbuf_animation_new_from_file(filename, &err);

    /* make sure we remove the file as soon as possible */
    g_unlink(filename);

    if (err) {
        gaim_debug(GAIM_DEBUG_ERROR, "gtkconv",
                   "Buddy icon error: %s\n", err->message);
        g_error_free(err);
    }



    if (!icon_data->anim)
        return;

    if (gdk_pixbuf_animation_is_static_image(icon_data->anim)) {
        icon_data->iter = NULL;
        buf = gdk_pixbuf_animation_get_static_image(icon_data->anim);
    } else {
        icon_data->iter = gdk_pixbuf_animation_get_iter(icon_data->anim, NULL); /* LEAK 
                                                                                 */
        buf = gdk_pixbuf_animation_iter_get_pixbuf(icon_data->iter);
    }

    get_icon_scale_size(icon_data->anim,
                        prpl_info ? &prpl_info->icon_spec : NULL,
                        &scale_width, &scale_height);
    scale =
        gdk_pixbuf_scale_simple(buf,
                                MAX(gdk_pixbuf_get_width(buf) *
                                    scale_width /
                                    gdk_pixbuf_animation_get_width
                                    (icon_data->anim), 1),
                                MAX(gdk_pixbuf_get_height(buf) *
                                    scale_height /
                                    gdk_pixbuf_animation_get_height
                                    (icon_data->anim), 1),
                                GDK_INTERP_NEAREST);

    gdk_pixbuf_render_pixmap_and_mask(scale, &pm, &bm, 100);
    g_object_unref(G_OBJECT(scale));


    icon_data->event = gtk_event_box_new();
    gtk_container_add(GTK_CONTAINER(icon_data->frame), icon_data->event);
    gtk_widget_set_size_request(GTK_WIDGET(icon_data->frame), scale_width,
                                scale_height);

    // g_signal_connect(G_OBJECT(icon_data->event), "button-press-event",
    // G_CALLBACK(icon_menu), conv);
    gtk_widget_show(icon_data->event);
    icon_data->icon = gtk_image_new_from_pixmap(pm, bm);
    gtk_container_add(GTK_CONTAINER(icon_data->event), icon_data->icon);
    gtk_widget_show(icon_data->icon);

    g_object_unref(G_OBJECT(pm));

    if (bm)
        g_object_unref(G_OBJECT(bm));


}
Ejemplo n.º 6
0
void
splash_create (gboolean be_verbose)
{
  GtkWidget          *frame;
  GtkWidget          *vbox;
  GdkPixbufAnimation *pixbuf;
  GdkScreen          *screen;

  g_return_if_fail (splash == NULL);

  pixbuf = splash_image_load (be_verbose);

  if (! pixbuf)
    return;

  splash = g_slice_new0 (GimpSplash);

  splash->window =
    g_object_new (GTK_TYPE_WINDOW,
                  "type",            GTK_WINDOW_TOPLEVEL,
                  "type-hint",       GDK_WINDOW_TYPE_HINT_SPLASHSCREEN,
                  "title",           _("GIMP Startup"),
                  "role",            "gimp-startup",
                  "window-position", GTK_WIN_POS_CENTER,
                  "resizable",       FALSE,
                  NULL);

  g_signal_connect_swapped (splash->window, "delete-event",
                            G_CALLBACK (exit),
                            GINT_TO_POINTER (0));

  screen = gtk_widget_get_screen (splash->window);

  splash->width  = MIN (gdk_pixbuf_animation_get_width (pixbuf),
                        gdk_screen_get_width (screen));
  splash->height = MIN (gdk_pixbuf_animation_get_height (pixbuf),
                        gdk_screen_get_height (screen));

  frame = gtk_frame_new (NULL);
  gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT);
  gtk_container_add (GTK_CONTAINER (splash->window), frame);
  gtk_widget_show (frame);

  vbox = gtk_vbox_new (FALSE, 0);
  gtk_container_add (GTK_CONTAINER (frame), vbox);
  gtk_widget_show (vbox);

  /*  If the splash image is static, we use a drawing area and set the
   *  image as back pixmap, otherwise a GtkImage is being used.
   */
  if (gdk_pixbuf_animation_is_static_image (pixbuf))
    {
      splash->area = gtk_drawing_area_new ();
    }
  else
    {
      splash->area = gtk_image_new_from_animation (pixbuf);
    }

  gtk_box_pack_start (GTK_BOX (vbox), splash->area, TRUE, TRUE, 0);
  gtk_widget_show (splash->area);

  gtk_widget_set_size_request (splash->area, splash->width, splash->height);

  /*  create the pango layouts  */
  splash->upper = gtk_widget_create_pango_layout (splash->area, "");
  splash->lower = gtk_widget_create_pango_layout (splash->area, "");
  gimp_pango_layout_set_scale (splash->lower, PANGO_SCALE_SMALL);

  /*  this sets the initial layout positions  */
  splash_position_layouts (splash, "", "", NULL);

  splash_average_text_area (splash,
                            gdk_pixbuf_animation_get_static_image (pixbuf),
                            &splash->color);

  gtk_widget_realize (splash->area);

  if (gdk_pixbuf_animation_is_static_image (pixbuf))
    {
      GdkPixbuf *static_pixbuf = gdk_pixbuf_animation_get_static_image (pixbuf);
      GdkPixmap *pixmap;
      cairo_t   *cr;

      pixmap = gdk_pixmap_new (gtk_widget_get_window (splash->area),
                               splash->width, splash->height, -1);

      cr = gdk_cairo_create (pixmap);
      gdk_cairo_set_source_pixbuf (cr, static_pixbuf, 0.0, 0.0);
      cairo_paint (cr);
      cairo_destroy (cr);

      gdk_window_set_back_pixmap (gtk_widget_get_window (splash->area),
                                  pixmap, FALSE);
      g_object_unref (pixmap);
    }

  g_object_unref (pixbuf);

  g_signal_connect_after (splash->area, "expose-event",
			  G_CALLBACK (splash_area_expose),
			  splash);

  /*  add a progress bar  */
  splash->progress = gtk_progress_bar_new ();
  gtk_box_pack_end (GTK_BOX (vbox), splash->progress, FALSE, FALSE, 0);
  gtk_widget_show (splash->progress);

  gtk_widget_show_now (splash->window);

#ifdef STARTUP_TIMER
  splash->timer = g_timer_new ();
#endif
}