예제 #1
0
파일: utils.c 프로젝트: azuwis/cview
GdkPixbufAnimation *load_anime_from_archive(const char *archname,
        const char *archpath)
{
    GError *error = NULL;
    GdkPixbufLoader *loader = NULL;
    GdkPixbufAnimation *anim = NULL;

    loader = gdk_pixbuf_loader_new();
    if (loader == NULL)
        return NULL;

    if (file_has_extension(archname, "rar")) {
        extract_rar_file_into_loader(loader, archname, archpath);
    } else if (file_has_extension(archname, "zip")) {
        extract_zip_file_into_loader(loader, archname, archpath);
    }
    gdk_pixbuf_loader_close(loader, &error);
    if (error != NULL) {
        g_warning("load image \"%s\" in \"%s\" failed: %s\n", archpath,
                  archname, error->message);
        g_error_free(error);
        g_object_unref(loader);
        return NULL;
    }

    anim = g_object_ref(gdk_pixbuf_loader_get_animation(loader));
    g_object_unref(loader);
    return anim;
}
예제 #2
0
void
tray_icon_set_image_from_data(void *icon, const char *data, unsigned long size)
{
	GdkPixbufLoader *loader;
	GdkPixbufAnimation *animation;
	gboolean rc;
	
	TrayIcon *ticon;
	if (icon == NULL)
		return;
	ticon = (TrayIcon *) icon;
	
	loader=gdk_pixbuf_loader_new();
	rc = gdk_pixbuf_loader_write (loader, (const guchar *)data, (gsize) size,NULL);
	
	gdk_pixbuf_loader_close (loader,NULL);
	
	if(rc)
	{
		// get animation
		animation=gdk_pixbuf_loader_get_animation(loader);
		
		gtk_image_set_from_animation (GTK_IMAGE (ticon->image),animation);
	} 
	
}
예제 #3
0
파일: loader.c 프로젝트: onlyshk/GPicView
GdkPixbufAnimation* load_animation_from_stream(GInputStream* input_stream, GCancellable* generator_cancellable)
{
    GError** error = NULL;
    gboolean res = TRUE;
    gssize n_read = 0;
    guchar buffer[65535];

    GdkPixbufAnimation* animation = NULL;
    GdkPixbufLoader*    loader    = NULL;

    loader = gdk_pixbuf_loader_new();

    while (1)
    {
        n_read = g_input_stream_read (input_stream, buffer, sizeof (buffer), generator_cancellable, error);

        if (n_read < 0)
        {
            res = FALSE;
            error = NULL;
            break;
            return NULL;
        }

        if (n_read == 0)
        {
            break;
        }

        if (!gdk_pixbuf_loader_write (loader, buffer, n_read, error))
        {
            res = FALSE;
            error = NULL;
            break;
        }
    }

    animation = NULL;

    if (res)
    {
        animation = gdk_pixbuf_loader_get_animation(loader);

        if (animation)
        {
            g_object_ref (animation);
        }
    }

    if (!gdk_pixbuf_loader_close (loader, error))
    {
        res = FALSE;
        error = NULL;
        g_object_unref (loader);
        return;
    }

    return animation;
}
예제 #4
0
void *
tray_icon_new_from_data (const char *name, const char *data, unsigned long size)
{
	TrayIcon *ticon;

	GdkPixbufLoader *loader;
	GdkPixbufAnimation *animation;
	gboolean rc;
		
	ticon = malloc (sizeof (TrayIcon));
	
	if (__running)
			gtk_main_quit();
		
	pthread_mutex_lock(&mutex);
	
	ticon->icon = egg_tray_icon_new ((const gchar *) name);
	ticon->eventbox = gtk_event_box_new ();

	g_signal_connect (ticon->eventbox, "button_press_event",
			  G_CALLBACK (tray_icon_pressed), ticon);

	gtk_container_add (GTK_CONTAINER (ticon->icon), ticon->eventbox);

	// tray icon image

	loader=gdk_pixbuf_loader_new();
	rc = gdk_pixbuf_loader_write (loader, (const guchar *)data, (gsize) size,NULL);
	
	gdk_pixbuf_loader_close (loader,NULL);
	
	if(rc)
	{
		// get animation
		animation=gdk_pixbuf_loader_get_animation(loader);
		
		ticon->image = gtk_image_new_from_animation (animation);
	} 
	
	
	gtk_container_add (GTK_CONTAINER (ticon->eventbox), ticon->image);
	
	gtk_widget_show_all (GTK_WIDGET (ticon->icon));
	
	pthread_mutex_unlock(&mutex);
	
	if (__running)
		pthread_cond_signal(&cond);
	
		
	return (void *) ticon;
}
예제 #5
0
void gdk_pixbuf_area_updated(GdkPixbufLoader *loader,
                             gint             x,
                             gint             y,
                             gint             width,
                             gint             height,
                             wxAnimation      *anim)
{
    if (anim && anim->GetPixbuf() == NULL)
    {
        // we need to set the pixbuf only if this is the first time this signal
        // has been called!
        anim->SetPixbuf(gdk_pixbuf_loader_get_animation(loader));
    }
}
예제 #6
0
/* prepare frame information and register other callbacks */
static void
callback_area_prepared_anim (GdkPixbufLoader* loader)
{
    GdkPixbufAnimation *anim;
    FrameData* frame_copy = g_new (FrameData, 1);

    g_signal_connect (loader, "area-updated",
                      (GCallback) callback_area_updated_anim, (gpointer) frame_copy);
    g_signal_connect (loader, "closed",
                      (GCallback) callback_closed_anim, (gpointer) frame_copy);

    frame_copy->time.tv_sec = frame_copy->time.tv_usec = 0; /* some time */

    anim = gdk_pixbuf_loader_get_animation (loader);
    frame_copy->iter = gdk_pixbuf_animation_get_iter (anim, &frame_copy->time);
    frame_copy->pixbuf = gdk_pixbuf_copy (gdk_pixbuf_animation_iter_get_pixbuf (frame_copy->iter));
    update_currently_loaded_frame (frame_copy);
}
예제 #7
0
파일: testanimation.c 프로젝트: 3v1n0/gtk
static void
progressive_prepared_callback (GdkPixbufLoader* loader,
                               gpointer         data)
{
  GdkPixbuf* pixbuf;
  GtkWidget* image;

  image = GTK_WIDGET (data);
    
  pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);

  /* Avoid displaying random memory contents, since the pixbuf
   * isn't filled in yet.
   */
  gdk_pixbuf_fill (pixbuf, 0xaaaaaaff);

  /* Could set the pixbuf instead, if we only wanted to display
   * static images.
   */
  gtk_image_set_from_animation (GTK_IMAGE (image),
                                gdk_pixbuf_loader_get_animation (loader));
}
예제 #8
0
static GdkPixbuf *
_gdk_pixbuf_new_from_uri_at_scale (const char  *uri,
				   gint         size,
				   GError     **error)
{
    gboolean result;
    guchar buffer[LOAD_BUFFER_SIZE];
    gssize bytes_read;
    GdkPixbufLoader *loader = NULL;
    GdkPixbuf *pixbuf;	
    GdkPixbufAnimation *animation;
    GdkPixbufAnimationIter *iter;
    gboolean has_frame;
    SizePrepareContext info;
    GFile *file;
    GInputStream *input_stream;

    g_return_val_if_fail (uri != NULL, NULL);

    file = g_file_new_for_uri (uri);

    input_stream = G_INPUT_STREAM (g_file_read (file, NULL, error));
    if (input_stream == NULL) {
        g_object_unref (file);
        return NULL;
    }

    has_frame = FALSE;

    result = FALSE;
    while (!has_frame) {

	bytes_read = g_input_stream_read (input_stream,
					  buffer,
					  sizeof (buffer),
					  NULL,
					  error);
        if (bytes_read == -1) {
            break;
        }
	result = TRUE;
	if (bytes_read == 0) {
	    break;
	}

        if (loader == NULL) {
            loader = create_loader (file, buffer, bytes_read);
            if (1 <= size) {
              info.size = size;
              info.input_width = info.input_height = 0;
              g_signal_connect (loader, "size-prepared", G_CALLBACK (size_prepared_cb), &info);
            }
            g_assert (loader != NULL);
        }

	if (!gdk_pixbuf_loader_write (loader,
				      (unsigned char *)buffer,
				      bytes_read,
				      error)) {
	    result = FALSE;
	    break;
	}

	animation = gdk_pixbuf_loader_get_animation (loader);
	if (animation) {
		iter = gdk_pixbuf_animation_get_iter (animation, NULL);
		if (!gdk_pixbuf_animation_iter_on_currently_loading_frame (iter)) {
			has_frame = TRUE;
		}
		g_object_unref (iter);
	}
    }

    if (loader == NULL) {
        /* This can happen if the above loop was exited due to the
         * g_input_stream_read() call failing. */
        result = FALSE;
    } else if (*error != NULL) {
        gdk_pixbuf_loader_close (loader, NULL);
        result = FALSE;
    } else if (gdk_pixbuf_loader_close (loader, error) == FALSE) {
        if (!g_error_matches (*error, GDK_PIXBUF_ERROR, GDK_PIXBUF_ERROR_INCOMPLETE_ANIMATION))
          result = FALSE;
        else
          g_clear_error (error);
    }

    if (!result) {
        g_clear_object (&loader);
	g_input_stream_close (input_stream, NULL, NULL);
	g_object_unref (input_stream);
	g_object_unref (file);
	return NULL;
    }

    g_input_stream_close (input_stream, NULL, NULL);
    g_object_unref (input_stream);
    g_object_unref (file);

    pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
    if (pixbuf != NULL) {
	g_object_ref (G_OBJECT (pixbuf));
	g_object_set_data (G_OBJECT (pixbuf), "gnome-original-width",
			   GINT_TO_POINTER (info.input_width));
	g_object_set_data (G_OBJECT (pixbuf), "gnome-original-height",
			   GINT_TO_POINTER (info.input_height));
    }
    g_object_unref (G_OBJECT (loader));

    return pixbuf;
}
예제 #9
0
/**
 * gnome_gdk_pixbuf_new_from_uri:
 * @uri: the uri of an image
 * @width: The width the image should have or -1 to not constrain the width
 * @height: The height the image should have or -1 to not constrain the height
 * @preserve_aspect_ratio: %TRUE to preserve the image's aspect ratio
 * 
 * Loads a GdkPixbuf from the image file @uri points to, scaling it to the
 * desired size. If you pass -1 for @width or @height then the value
 * specified in the file will be used.
 *
 * When preserving aspect ratio, if both height and width are set the size
 * is picked such that the scaled image fits in a width * height rectangle.
 * 
 * Return value: The loaded pixbuf, or NULL on error
 *
 * Since: 2.14
 **/
GdkPixbuf *
gnome_gdk_pixbuf_new_from_uri_at_scale (const char *uri,
					gint        width,
					gint        height,
					gboolean    preserve_aspect_ratio)
{
    GnomeVFSResult result;
    char buffer[LOAD_BUFFER_SIZE];
    GnomeVFSFileSize bytes_read;
    GdkPixbufLoader *loader;
    GdkPixbuf *pixbuf;	
    GdkPixbufAnimation *animation;
    GdkPixbufAnimationIter *iter;
    gboolean has_frame;
    SizePrepareContext info;
    GFile *file;
    GFileInputStream *file_input_stream;

    g_return_val_if_fail (uri != NULL, NULL);

    file = g_file_new_for_uri (uri);
    file_input_stream = g_file_read (file, NULL, NULL);
    if (file_input_stream == NULL) {
	g_object_unref (file);
	return NULL;
    }

    loader = gdk_pixbuf_loader_new ();
    if (1 <= width || 1 <= height) {
        info.width = width;
        info.height = height;
	info.input_width = info.input_height = 0;
        info.preserve_aspect_ratio = preserve_aspect_ratio;        
        g_signal_connect (loader, "size-prepared", G_CALLBACK (size_prepared_cb), &info);
    }

    has_frame = FALSE;

    result = GNOME_VFS_ERROR_GENERIC;
    while (!has_frame) {

	bytes_read = g_input_stream_read (G_INPUT_STREAM (file_input_stream),
					  buffer,
					  sizeof (buffer),
					  NULL,
					  NULL);
	if (bytes_read == -1) {
	    break;
	}
	result = GNOME_VFS_OK;
	if (bytes_read == 0) {
	    break;
	}

	if (!gdk_pixbuf_loader_write (loader,
				      (unsigned char *)buffer,
				      bytes_read,
				      NULL)) {
	    result = GNOME_VFS_ERROR_WRONG_FORMAT;
	    break;
	}

	animation = gdk_pixbuf_loader_get_animation (loader);
	if (animation) {
		iter = gdk_pixbuf_animation_get_iter (animation, NULL);
		if (!gdk_pixbuf_animation_iter_on_currently_loading_frame (iter)) {
			has_frame = TRUE;
		}
		g_object_unref (iter);
	}
    }

    gdk_pixbuf_loader_close (loader, NULL);
    
    if (result != GNOME_VFS_OK) {
	g_object_unref (G_OBJECT (loader));
	g_input_stream_close (G_INPUT_STREAM (file_input_stream), NULL, NULL);
	g_object_unref (file_input_stream);
	g_object_unref (file);
	return NULL;
    }

    g_input_stream_close (G_INPUT_STREAM (file_input_stream), NULL, NULL);
    g_object_unref (file_input_stream);
    g_object_unref (file);

    pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
    if (pixbuf != NULL) {
	g_object_ref (G_OBJECT (pixbuf));
	g_object_set_data (G_OBJECT (pixbuf), "gnome-original-width",
			   GINT_TO_POINTER (info.input_width));
	g_object_set_data (G_OBJECT (pixbuf), "gnome-original-height",
			   GINT_TO_POINTER (info.input_height));
    }
    g_object_unref (G_OBJECT (loader));

    return pixbuf;
}
예제 #10
0
/* Creating animation */
static VALUE
get_animation(VALUE self)
{
    return GOBJ2RVAL(gdk_pixbuf_loader_get_animation(_SELF(self)));
}