[gimp] app: use gimp_create_image_from_buffer() to create the debug image graph



commit 7d4948b190f1e003286e8625d2c3ccbfee5d93a5
Author: Michael Natterer <mitch gimp org>
Date:   Fri Jun 19 23:49:41 2015 +0200

    app: use gimp_create_image_from_buffer() to create the debug image graph

 app/actions/debug-commands.c |   55 +++++++++++++++--------------------------
 app/core/gimp-utils.c        |   19 ++++++++++----
 app/core/gimp-utils.h        |    5 ++-
 3 files changed, 36 insertions(+), 43 deletions(-)
---
diff --git a/app/actions/debug-commands.c b/app/actions/debug-commands.c
index 9779dab..e6cd71f 100644
--- a/app/actions/debug-commands.c
+++ b/app/actions/debug-commands.c
@@ -19,7 +19,6 @@
 
 #include <string.h>
 
-#include <glib/gprintf.h>
 #include <gegl.h>
 #include <gtk/gtk.h>
 
@@ -31,9 +30,6 @@
 #include "core/gimp-utils.h"
 #include "core/gimpcontext.h"
 #include "core/gimpimage.h"
-#include "core/gimplayer.h"
-#include "core/gimplayer-new.h"
-#include "core/gimppickable.h"
 #include "core/gimpprojectable.h"
 #include "core/gimpprojection.h"
 
@@ -309,18 +305,18 @@ debug_benchmark_projection (GimpDisplay *display)
 static gboolean
 debug_show_image_graph (GimpImage *source_image)
 {
-  Gimp            *gimp        = source_image->gimp;
-  GimpProjectable *projectable = GIMP_PROJECTABLE (source_image);
-  GeglNode        *image_graph = gimp_projectable_get_graph (projectable);
-  GeglNode        *output_node = gegl_node_get_output_proxy (image_graph, "output");
-  GimpImage       *new_image   = NULL;
-  GimpLayer       *layer       = NULL;
-  GeglNode        *introspect  = NULL;
-  GeglNode        *sink        = NULL;
-  GeglBuffer      *buffer      = NULL;
-  gchar           *new_name    = NULL;
-
-  /* Setup and process the introspection graph */
+  GeglNode   *image_graph;
+  GeglNode   *output_node;
+  GimpImage  *new_image;
+  GeglNode   *introspect;
+  GeglNode   *sink;
+  GeglBuffer *buffer;
+  gchar      *new_name;
+
+  image_graph = gimp_projectable_get_graph (GIMP_PROJECTABLE (source_image));
+
+  output_node = gegl_node_get_output_proxy (image_graph, "output");
+
   introspect = gegl_node_new_child (NULL,
                                     "operation", "gegl:introspect",
                                     "node",      output_node,
@@ -329,35 +325,24 @@ debug_show_image_graph (GimpImage *source_image)
                               "operation", "gegl:buffer-sink",
                               "buffer",    &buffer,
                               NULL);
+
   gegl_node_link_many (introspect, sink, NULL);
   gegl_node_process (sink);
 
-  /* Create a new image of the result */
   new_name = g_strdup_printf ("%s GEGL graph",
                               gimp_image_get_display_name (source_image));
-  new_image = gimp_create_image (gimp,
-                                 gegl_buffer_get_width (buffer),
-                                 gegl_buffer_get_height (buffer),
-                                 GIMP_RGB,
-                                 GIMP_PRECISION_U8_GAMMA,
-                                 FALSE);
+
+  new_image = gimp_create_image_from_buffer (source_image->gimp,
+                                             buffer, new_name);
   gimp_image_set_file (new_image, g_file_new_for_uri (new_name));
-  layer = gimp_layer_new_from_buffer (buffer,
-                                      new_image,
-                                      gimp_image_get_layer_format (new_image,
-                                                                   TRUE),
-                                      new_name,
-                                      1.0,
-                                      GIMP_NORMAL_MODE);
-  gimp_image_add_layer (new_image, layer, NULL, 0, FALSE);
-  gimp_create_display (gimp, new_image, GIMP_UNIT_PIXEL, 1.0, NULL, 0);
-
-  /* Cleanup */
-  g_object_unref (new_image);
+
   g_free (new_name);
+
   g_object_unref (buffer);
+
   g_object_unref (sink);
   g_object_unref (introspect);
+
   g_object_unref (source_image);
 
   return FALSE;
diff --git a/app/core/gimp-utils.c b/app/core/gimp-utils.c
index 4f2236f..8cc5105 100644
--- a/app/core/gimp-utils.c
+++ b/app/core/gimp-utils.c
@@ -753,16 +753,20 @@ gimp_file_is_executable (GFile *file)
 #include "gimplayer.h"
 #include "gimplayer-new.h"
 
-void
-gimp_create_image_from_buffer (Gimp       *gimp,
-                               GeglBuffer *buffer)
+GimpImage *
+gimp_create_image_from_buffer (Gimp        *gimp,
+                               GeglBuffer  *buffer,
+                               const gchar *image_name)
 {
   GimpImage  *image;
   GimpLayer  *layer;
   const Babl *format;
 
-  g_return_if_fail (GIMP_IS_GIMP (gimp));
-  g_return_if_fail (GEGL_IS_BUFFER (buffer));
+  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
+  g_return_val_if_fail (GEGL_IS_BUFFER (buffer), NULL);
+
+  if (! image_name)
+    image_name = "Debug Image";
 
   format = gegl_buffer_get_format (buffer);
 
@@ -774,7 +778,7 @@ gimp_create_image_from_buffer (Gimp       *gimp,
                              FALSE);
 
   layer = gimp_layer_new_from_buffer (buffer, image, format,
-                                      "Debug Image",
+                                      image_name,
                                       GIMP_OPACITY_OPAQUE,
                                       GIMP_NORMAL_MODE);
   gimp_image_add_layer (image, layer, NULL, -1, FALSE);
@@ -782,5 +786,8 @@ gimp_create_image_from_buffer (Gimp       *gimp,
   gimp_create_display (gimp, image, GIMP_UNIT_PIXEL, 1.0, NULL, 0);
 
   /* unref the image unconditionally, even when no display was created */
+  g_object_add_weak_pointer (G_OBJECT (image), (gpointer) &image);
   g_object_unref (image);
+
+  return image;
 }
diff --git a/app/core/gimp-utils.h b/app/core/gimp-utils.h
index df1f90e..707faca 100644
--- a/app/core/gimp-utils.h
+++ b/app/core/gimp-utils.h
@@ -77,8 +77,9 @@ gint         gimp_file_compare                     (GFile           *file1,
                                                     GFile           *file2);
 gboolean     gimp_file_is_executable               (GFile           *file);
 
-void         gimp_create_image_from_buffer         (Gimp            *gimp,
-                                                    GeglBuffer      *buffer);
+GimpImage  * gimp_create_image_from_buffer         (Gimp            *gimp,
+                                                    GeglBuffer      *buffer,
+                                                    const gchar     *image_name);
 
 
 #endif /* __APP_GIMP_UTILS_H__ */


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