[gimp] app: more WIP on GimpOperationHistogramSink, not used yet



commit a04d391ca601cf4e3d2c9f719a710adb3b99df4c
Author: Michael Natterer <mitch gimp org>
Date:   Mon Apr 16 07:57:43 2012 +0200

    app: more WIP on GimpOperationHistogramSink, not used yet

 app/core/gimpdrawable-histogram.c     |   89 +++++++++++++++++-----
 app/gegl/gimpoperationhistogramsink.c |  132 +++++++++++++++++++++++++++-----
 app/gegl/gimpoperationhistogramsink.h |   12 ++-
 3 files changed, 188 insertions(+), 45 deletions(-)
---
diff --git a/app/core/gimpdrawable-histogram.c b/app/core/gimpdrawable-histogram.c
index 50698fd..ebe4ac9b 100644
--- a/app/core/gimpdrawable-histogram.c
+++ b/app/core/gimpdrawable-histogram.c
@@ -25,6 +25,9 @@
 
 #include "base/pixel-region.h"
 
+#include "gegl/gimp-gegl-nodes.h"
+
+#include "gimp.h" /* gimp_use_gegl */
 #include "gimpchannel.h"
 #include "gimpdrawable-histogram.h"
 #include "gimphistogram.h"
@@ -36,8 +39,7 @@ gimp_drawable_calculate_histogram (GimpDrawable  *drawable,
                                    GimpHistogram *histogram)
 {
   GimpImage   *image;
-  PixelRegion  region;
-  PixelRegion  mask;
+  GimpChannel *mask;
   gint         x, y, width, height;
 
   g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
@@ -47,28 +49,77 @@ gimp_drawable_calculate_histogram (GimpDrawable  *drawable,
   if (! gimp_item_mask_intersect (GIMP_ITEM (drawable), &x, &y, &width, &height))
     return;
 
-  pixel_region_init (&region, gimp_drawable_get_tiles (drawable),
-                     x, y, width, height, FALSE);
-
   image = gimp_item_get_image (GIMP_ITEM (drawable));
+  mask  = gimp_image_get_mask (image);
 
-  if (! gimp_channel_is_empty (gimp_image_get_mask (image)))
+  if (FALSE) // gimp_use_gegl (image->gimp))
     {
-      GimpChannel *sel_mask;
-      GimpImage   *image;
-      gint         off_x, off_y;
-
-      image   = gimp_item_get_image (GIMP_ITEM (drawable));
-      sel_mask = gimp_image_get_mask (image);
-
-      gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
-      pixel_region_init (&mask,
-                         gimp_drawable_get_tiles (GIMP_DRAWABLE (sel_mask)),
-                         x + off_x, y + off_y, width, height, FALSE);
-      gimp_histogram_calculate (histogram, &region, &mask);
+      GeglNode      *node = gegl_node_new ();
+      GeglNode      *buffer_source;
+      GeglNode      *histogram_sink;
+      GeglProcessor *processor;
+
+      buffer_source =
+        gimp_gegl_add_buffer_source (node,
+                                     gimp_drawable_get_buffer (drawable),
+                                     0, 0);
+
+      histogram_sink =
+        gegl_node_new_child (node,
+                             "operation", "gimp:histogram-sink",
+                             "histogram", histogram,
+                             NULL);
+
+      gegl_node_connect_to (buffer_source,  "output",
+                            histogram_sink, "input");
+
+      if (! gimp_channel_is_empty (mask))
+        {
+          GeglNode *mask_source;
+          gint      off_x, off_y;
+
+          g_printerr ("adding mask aux\n");
+
+          gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
+
+          mask_source =
+            gimp_gegl_add_buffer_source (node,
+                                         gimp_drawable_get_buffer (GIMP_DRAWABLE (mask)),
+                                         -off_x, -off_y);
+
+          gegl_node_connect_to (mask_source,    "output",
+                                histogram_sink, "aux");
+        }
+
+      processor = gegl_node_new_processor (histogram_sink,
+                                           GEGL_RECTANGLE (x, y, width, height));
+
+      while (gegl_processor_work (processor, NULL));
+
+      g_object_unref (processor);
+      g_object_unref (node);
     }
   else
     {
-      gimp_histogram_calculate (histogram, &region, NULL);
+      PixelRegion  region;
+      PixelRegion  mask_region;
+
+      pixel_region_init (&region, gimp_drawable_get_tiles (drawable),
+                         x, y, width, height, FALSE);
+
+      if (! gimp_channel_is_empty (mask))
+        {
+          gint off_x, off_y;
+
+          gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
+          pixel_region_init (&mask_region,
+                             gimp_drawable_get_tiles (GIMP_DRAWABLE (mask)),
+                             x + off_x, y + off_y, width, height, FALSE);
+          gimp_histogram_calculate (histogram, &region, &mask_region);
+        }
+      else
+        {
+          gimp_histogram_calculate (histogram, &region, NULL);
+        }
     }
 }
diff --git a/app/gegl/gimpoperationhistogramsink.c b/app/gegl/gimpoperationhistogramsink.c
index 7e06fd5..22adeb6 100644
--- a/app/gegl/gimpoperationhistogramsink.c
+++ b/app/gegl/gimpoperationhistogramsink.c
@@ -24,38 +24,47 @@
 
 #include "gimp-gegl-types.h"
 
+#include "core/gimphistogram.h"
+
 #include "gimpoperationhistogramsink.h"
 
 
 enum
 {
   PROP_0,
-  PROP_INPUT,
-  PROP_AUX
+  PROP_AUX,
+  PROP_HISTOGRAM
 };
 
-static void     gimp_operation_histogram_sink_get_property (GObject             *gobject,
+
+static void     gimp_operation_histogram_sink_finalize     (GObject             *object);
+static void     gimp_operation_histogram_sink_get_property (GObject             *object,
                                                             guint                prop_id,
                                                             GValue              *value,
                                                             GParamSpec          *pspec);
-static void     gimp_operation_histogram_sink_set_property (GObject             *gobject,
+static void     gimp_operation_histogram_sink_set_property (GObject             *object,
                                                             guint                prop_id,
                                                             const GValue        *value,
                                                             GParamSpec          *pspec);
+
+static void     gimp_operation_histogram_sink_attach       (GeglOperation       *operation);
+static void     gimp_operation_histogram_sink_prepare      (GeglOperation       *operation);
+static GeglRectangle
+     gimp_operation_histogram_sink_get_required_for_output (GeglOperation        *self,
+                                                            const gchar         *input_pad,
+                                                            const GeglRectangle *roi);
 static gboolean gimp_operation_histogram_sink_process      (GeglOperation       *operation,
                                                             GeglOperationContext     *context,
                                                             const gchar         *output_prop,
                                                             const GeglRectangle *result,
                                                             gint                 level);
-static void     gimp_operation_histogram_sink_attach       (GeglOperation       *operation);
 
-static GeglRectangle gimp_operation_histogram_sink_get_required_for_output (GeglOperation        *self,
-                                                                            const gchar         *input_pad,
-                                                                            const GeglRectangle *roi);
 
 G_DEFINE_TYPE (GimpOperationHistogramSink, gimp_operation_histogram_sink,
                GEGL_TYPE_OPERATION_SINK)
 
+#define parent_class gimp_operation_histogram_sink_parent_class
+
 
 static void
 gimp_operation_histogram_sink_class_init (GimpOperationHistogramSinkClass *klass)
@@ -63,10 +72,18 @@ gimp_operation_histogram_sink_class_init (GimpOperationHistogramSinkClass *klass
   GObjectClass       *object_class    = G_OBJECT_CLASS (klass);
   GeglOperationClass *operation_class = GEGL_OPERATION_CLASS (klass);
 
+  object_class->finalize     = gimp_operation_histogram_sink_finalize;
   object_class->set_property = gimp_operation_histogram_sink_set_property;
   object_class->get_property = gimp_operation_histogram_sink_get_property;
 
+  gegl_operation_class_set_keys (operation_class,
+                                 "name"       , "gimp:histogram-sink",
+                                 "categories" , "color",
+                                 "description", "GIMP Histogram sink operation",
+                                 NULL);
+
   operation_class->attach                  = gimp_operation_histogram_sink_attach;
+  operation_class->prepare                 = gimp_operation_histogram_sink_prepare;
   operation_class->get_required_for_output = gimp_operation_histogram_sink_get_required_for_output;
   operation_class->process                 = gimp_operation_histogram_sink_process;
 
@@ -77,6 +94,12 @@ gimp_operation_histogram_sink_class_init (GimpOperationHistogramSinkClass *klass
                                                         GEGL_TYPE_BUFFER,
                                                         G_PARAM_READWRITE |
                                                         GEGL_PARAM_PAD_INPUT));
+
+  g_object_class_install_property (object_class, PROP_HISTOGRAM,
+                                   g_param_spec_pointer ("histogram",
+                                                         "Histogram",
+                                                         "The result histogram",
+                                                         G_PARAM_READWRITE));
 }
 
 static void
@@ -85,11 +108,40 @@ gimp_operation_histogram_sink_init (GimpOperationHistogramSink *self)
 }
 
 static void
+gimp_operation_histogram_sink_finalize (GObject *object)
+{
+  GimpOperationHistogramSink *sink = GIMP_OPERATION_HISTOGRAM_SINK (object);
+
+  if (sink->histogram)
+    {
+      gimp_histogram_unref (sink->histogram);
+      sink->histogram = NULL;
+    }
+
+  G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+static void
 gimp_operation_histogram_sink_get_property (GObject    *object,
                                             guint       prop_id,
                                             GValue     *value,
                                             GParamSpec *pspec)
 {
+  GimpOperationHistogramSink *sink = GIMP_OPERATION_HISTOGRAM_SINK (object);
+
+  switch (prop_id)
+    {
+    case PROP_AUX:
+      break;
+
+    case PROP_HISTOGRAM:
+      g_value_set_pointer (value, sink->histogram);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
 }
 
 static void
@@ -98,6 +150,25 @@ gimp_operation_histogram_sink_set_property (GObject      *object,
                                             const GValue *value,
                                             GParamSpec   *pspec)
 {
+  GimpOperationHistogramSink *sink = GIMP_OPERATION_HISTOGRAM_SINK (object);
+
+  switch (prop_id)
+    {
+    case PROP_AUX:
+      break;
+
+    case PROP_HISTOGRAM:
+      if (sink->histogram)
+        gimp_histogram_unref (sink->histogram);
+      sink->histogram = g_value_get_pointer (value);
+      if (sink->histogram)
+        gimp_histogram_ref (sink->histogram);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
 }
 
 static void
@@ -106,11 +177,20 @@ gimp_operation_histogram_sink_attach (GeglOperation *self)
   GeglOperation *operation    = GEGL_OPERATION (self);
   GObjectClass  *object_class = G_OBJECT_GET_CLASS (self);
 
+  GEGL_OPERATION_CLASS (parent_class)->attach (self);
+
   gegl_operation_create_pad (operation,
                              g_object_class_find_property (object_class,
                                                            "aux"));
 }
 
+static void
+gimp_operation_histogram_sink_prepare (GeglOperation *operation)
+{
+  /* XXX gegl_operation_set_format (operation, "input", babl_format ("Y u8")); */
+  gegl_operation_set_format (operation, "aux",   babl_format ("Y float"));
+}
+
 static GeglRectangle
 gimp_operation_histogram_sink_get_required_for_output (GeglOperation       *self,
                                                        const gchar         *input_pad,
@@ -139,21 +219,31 @@ gimp_operation_histogram_sink_process (GeglOperation        *operation,
   input = gegl_operation_context_get_source (context, "input");
   aux   = gegl_operation_context_get_source (context, "aux");
 
-  if (input)
+  if (! input)
     {
-      if (aux)
-        {
-          /* do hist with mask */
-        }
-      else
-        {
-          /* without */
-        }
-
-      return TRUE;
+      g_warning ("received NULL input");
+
+      return FALSE;
+    }
+
+  if (aux)
+    {
+      /* do hist with mask */
+
+      g_printerr ("aux format: %s\n",
+                  babl_get_name (gegl_buffer_get_format (aux)));
+
+      g_object_unref (aux);
     }
+  else
+    {
+      /* without */
+    }
+
+  g_printerr ("input format: %s\n",
+              babl_get_name (gegl_buffer_get_format (input)));
 
-  g_warning ("received NULL input");
+  g_object_unref (input);
 
-  return FALSE;
+  return TRUE;
 }
diff --git a/app/gegl/gimpoperationhistogramsink.h b/app/gegl/gimpoperationhistogramsink.h
index c48043d..4d0a5ff 100644
--- a/app/gegl/gimpoperationhistogramsink.h
+++ b/app/gegl/gimpoperationhistogramsink.h
@@ -27,11 +27,11 @@
 
 
 #define GIMP_TYPE_OPERATION_HISTOGRAM_SINK            (gimp_operation_histogram_sink_get_type ())
-#define GIMP_OPERATION_HISTOGRAM_SINK(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_HISTOGRAM_SINK, GimpOperationHistogramSink))
-#define GIMP_OPERATION_HISTOGRAM_SINK_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass),  GIMP_TYPE_HISTOGRAM_SINK, GimpOperationHistogramSinkClass))
-#define GEGL_IS_OPERATION_HISTOGRAM_SINK(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_HISTOGRAM_SINK))
-#define GEGL_IS_OPERATION_HISTOGRAM_SINK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),  GIMP_TYPE_HISTOGRAM_SINK))
-#define GIMP_OPERATION_HISTOGRAM_SINK_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),  GIMP_TYPE_HISTOGRAM_SINK, GimpOperationHistogramSinkClass))
+#define GIMP_OPERATION_HISTOGRAM_SINK(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_OPERATION_HISTOGRAM_SINK, GimpOperationHistogramSink))
+#define GIMP_OPERATION_HISTOGRAM_SINK_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass),  GIMP_TYPE_OPERATION_HISTOGRAM_SINK, GimpOperationHistogramSinkClass))
+#define GEGL_IS_OPERATION_HISTOGRAM_SINK(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_OPERATION_HISTOGRAM_SINK))
+#define GEGL_IS_OPERATION_HISTOGRAM_SINK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),  GIMP_TYPE_OPERATION_HISTOGRAM_SINK))
+#define GIMP_OPERATION_HISTOGRAM_SINK_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),  GIMP_TYPE_OPERATION_HISTOGRAM_SINK, GimpOperationHistogramSinkClass))
 
 
 typedef struct _GimpOperationHistogramSinkClass GimpOperationHistogramSinkClass;
@@ -39,6 +39,8 @@ typedef struct _GimpOperationHistogramSinkClass GimpOperationHistogramSinkClass;
 struct _GimpOperationHistogramSink
 {
   GeglOperation  parent_instance;
+
+  GimpHistogram *histogram;
 };
 
 struct _GimpOperationHistogramSinkClass



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