[gimp] app: add gimp_selection_data_set_xcf() and _get_xcf()



commit 5136f131bea59c909ccc62baf55ed0fa6d1102a3
Author: Michael Natterer <mitch gimp org>
Date:   Sun Sep 18 21:43:45 2016 +0200

    app: add gimp_selection_data_set_xcf() and _get_xcf()
    
    using the new load/save XCF stream APIs added below.

 app/widgets/gimpselectiondata.c |   63 +++++++++++++++++++++++++++++++++++++++
 app/widgets/gimpselectiondata.h |    8 +++++
 2 files changed, 71 insertions(+), 0 deletions(-)
---
diff --git a/app/widgets/gimpselectiondata.c b/app/widgets/gimpselectiondata.c
index 118ab12..8ac8a48 100644
--- a/app/widgets/gimpselectiondata.c
+++ b/app/widgets/gimpselectiondata.c
@@ -43,6 +43,8 @@
 
 #include "text/gimpfont.h"
 
+#include "xcf/xcf.h"
+
 #include "gimpselectiondata.h"
 
 #include "gimp-log.h"
@@ -326,6 +328,67 @@ gimp_selection_data_get_color (GtkSelectionData *selection,
 }
 
 void
+gimp_selection_data_set_xcf (GtkSelectionData *selection,
+                             GimpImage        *image)
+{
+  GMemoryOutputStream *output;
+
+  g_return_if_fail (selection != NULL);
+  g_return_if_fail (GIMP_IS_IMAGE (image));
+
+  output = G_MEMORY_OUTPUT_STREAM (g_memory_output_stream_new_resizable ());
+
+  xcf_save_stream (image->gimp, image, G_OUTPUT_STREAM (output), NULL,
+                   NULL, NULL);
+
+  gtk_selection_data_set (selection,
+                          gtk_selection_data_get_target (selection),
+                          8,
+                          g_memory_output_stream_get_data (output),
+                          g_memory_output_stream_get_data_size (output));
+
+  g_object_unref (output);
+}
+
+GimpImage *
+gimp_selection_data_get_xcf (GtkSelectionData *selection,
+                             Gimp             *gimp)
+{
+  GInputStream *input;
+  GimpImage    *image;
+  gsize         length;
+  const guchar *data;
+  GError       *error = NULL;
+
+  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
+  g_return_val_if_fail (selection != NULL, NULL);
+
+  length = gtk_selection_data_get_length (selection);
+
+  if (gtk_selection_data_get_format (selection) != 8 || length < 1)
+    {
+      g_warning ("Received invalid data stream!");
+      return NULL;
+    }
+
+  data = gtk_selection_data_get_data (selection);
+
+  input = g_memory_input_stream_new_from_data (data, length, NULL);
+
+  image = xcf_load_stream (gimp, input, NULL, NULL, &error);
+
+  if (! image)
+    {
+      g_warning ("Recieved invalid XCF data: %s", error->message);
+      g_clear_error (&error);
+    }
+
+  g_object_unref (input);
+
+  return image;
+}
+
+void
 gimp_selection_data_set_stream (GtkSelectionData *selection,
                                 const guchar     *stream,
                                 gsize             stream_length)
diff --git a/app/widgets/gimpselectiondata.h b/app/widgets/gimpselectiondata.h
index bf52b97..9aef0fd 100644
--- a/app/widgets/gimpselectiondata.h
+++ b/app/widgets/gimpselectiondata.h
@@ -34,6 +34,14 @@ gboolean        gimp_selection_data_get_color     (GtkSelectionData *selection,
                                                    GimpRGB          *color);
 
 
+/*  image (xcf)  */
+
+void            gimp_selection_data_set_xcf       (GtkSelectionData *selection,
+                                                   GimpImage        *image);
+GimpImage     * gimp_selection_data_get_xcf       (GtkSelectionData *selection,
+                                                   Gimp             *gimp);
+
+
 /*  stream (svg/png)  */
 
 void            gimp_selection_data_set_stream    (GtkSelectionData *selection,


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