diff --git a/ChangeLog b/ChangeLog index 2b92f56831..6a84513672 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2004-07-01 Sven Neumann + + * app/widgets/gimpselectiondata.[ch]: added (yet unused) functions + gimp_selection_data_[get|set]_pixbuf(). + 2004-07-01 Michael Natterer * app/widgets/gimpfgbgarea.[ch]: implement GtkWidget::drag_motion() diff --git a/app/widgets/gimpselectiondata.c b/app/widgets/gimpselectiondata.c index ccff712225..ca7465e6b1 100644 --- a/app/widgets/gimpselectiondata.c +++ b/app/widgets/gimpselectiondata.c @@ -408,6 +408,65 @@ gimp_selection_data_get_stream (GtkSelectionData *selection, return (const guchar *) selection->data; } +void +gimp_selection_data_set_pixbuf (GtkSelectionData *selection, + GdkAtom atom, + GdkPixbuf *pixbuf) +{ + gchar *buffer; + gsize buffer_size; + GError *error = NULL; + + g_return_if_fail (selection != NULL); + g_return_if_fail (atom != GDK_NONE); + g_return_if_fail (GDK_IS_PIXBUF (pixbuf)); + + if (gdk_pixbuf_save_to_buffer (pixbuf, &buffer, &buffer_size, "png", &error)) + { + gtk_selection_data_set (selection, atom, + 8, (guchar *) buffer, buffer_size); + g_free (buffer); + } + else + { + g_warning ("%s: %s", G_STRFUNC, error->message); + g_error_free (error); + } +} + +GdkPixbuf * +gimp_selection_data_get_pixbuf (GtkSelectionData *selection) +{ + GdkPixbufLoader *loader; + GdkPixbuf *pixbuf = NULL; + GError *error = NULL; + + g_return_val_if_fail (selection != NULL, NULL); + + if ((selection->format != 8) || (selection->length < 1)) + { + g_warning ("Received invalid image data!"); + return NULL; + } + + loader = gdk_pixbuf_loader_new (); + + if (gdk_pixbuf_loader_write (loader, + selection->data, selection->length, &error)) + { + pixbuf = gdk_pixbuf_loader_get_pixbuf (loader); + } + else + { + g_warning ("%s: %s", G_STRFUNC, error->message); + g_error_free (error); + } + + g_object_unref (loader); + + return pixbuf; +} + void gimp_selection_data_set_image (GtkSelectionData *selection, GdkAtom atom, diff --git a/app/widgets/gimpselectiondata.h b/app/widgets/gimpselectiondata.h index a7e967be1e..edac8dc0ad 100644 --- a/app/widgets/gimpselectiondata.h +++ b/app/widgets/gimpselectiondata.h @@ -47,6 +47,14 @@ const guchar * gimp_selection_data_get_stream (GtkSelectionData *selection, gsize *stream_length); +/* pixbuf */ + +void gimp_selection_data_set_pixbuf (GtkSelectionData *selection, + GdkAtom atom, + GdkPixbuf *pixbuf); +GdkPixbuf * gimp_selection_data_get_pixbuf (GtkSelectionData *selection); + + /* image */ void gimp_selection_data_set_image (GtkSelectionData *selection,