[gnome-documents] utils: Add helper to serialize Pixbufs as GVariants



commit abb7fcfdef41664ee2d20104e3797e7db2b04cfb
Author: Florian MÃllner <fmuellner gnome org>
Date:   Wed Feb 15 00:58:17 2012 +0100

    utils: Add helper to serialize Pixbufs as GVariants
    
    Support for GVariants in GJS is quite good nowadays, but not quite
    good enough to serialize a GdkPixbuf ...
    
    https://bugzilla.gnome.org/show_bug.cgi?id=662453

 src/lib/gd-utils.c |   28 ++++++++++++++++++++++++++++
 src/lib/gd-utils.h |    2 ++
 2 files changed, 30 insertions(+), 0 deletions(-)
---
diff --git a/src/lib/gd-utils.c b/src/lib/gd-utils.c
index 75cfbb2..971d52d 100644
--- a/src/lib/gd-utils.c
+++ b/src/lib/gd-utils.c
@@ -655,3 +655,31 @@ gd_entry_focus_hack (GtkWidget *entry,
   /* send focus-in event */
   send_focus_change (entry, device, TRUE);
 }
+
+/**
+ * gd_create_variant_from_pixbuf:
+ * @pixbuf:
+ *
+ * Returns: (transfer full):
+ */
+GVariant *
+gd_create_variant_from_pixbuf (GdkPixbuf *pixbuf)
+{
+  GVariant *variant;
+  guchar *data;
+  guint   length;
+
+  data = gdk_pixbuf_get_pixels_with_length (pixbuf, &length);
+  variant = g_variant_new ("(iiibii ay)",
+                           gdk_pixbuf_get_width (pixbuf),
+                           gdk_pixbuf_get_height (pixbuf),
+                           gdk_pixbuf_get_rowstride (pixbuf),
+                           gdk_pixbuf_get_has_alpha (pixbuf),
+                           gdk_pixbuf_get_bits_per_sample (pixbuf),
+                           gdk_pixbuf_get_n_channels (pixbuf),
+                           g_variant_new_from_data (G_VARIANT_TYPE_BYTESTRING,
+                                                    data, length, TRUE,
+                                                    (GDestroyNotify)g_object_unref,
+                                                    g_object_ref (pixbuf)));
+  return g_variant_ref_sink (variant);
+}
diff --git a/src/lib/gd-utils.h b/src/lib/gd-utils.h
index 813cdf0..f6e856e 100644
--- a/src/lib/gd-utils.h
+++ b/src/lib/gd-utils.h
@@ -74,5 +74,7 @@ GIcon *gd_create_symbolic_icon (const gchar *name,
 void   gd_entry_focus_hack (GtkWidget *entry,
                             GdkDevice *device);
 
+GVariant *gd_create_variant_from_pixbuf (GdkPixbuf *pixbuf);
+
 #endif /* __GD_UTILS_H__ */
                                   



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]