app: more WIP on GimpOperationHistogramSink, not used yet
This commit is contained in:
@ -25,6 +25,9 @@
|
|||||||
|
|
||||||
#include "base/pixel-region.h"
|
#include "base/pixel-region.h"
|
||||||
|
|
||||||
|
#include "gegl/gimp-gegl-nodes.h"
|
||||||
|
|
||||||
|
#include "gimp.h" /* gimp_use_gegl */
|
||||||
#include "gimpchannel.h"
|
#include "gimpchannel.h"
|
||||||
#include "gimpdrawable-histogram.h"
|
#include "gimpdrawable-histogram.h"
|
||||||
#include "gimphistogram.h"
|
#include "gimphistogram.h"
|
||||||
@ -36,8 +39,7 @@ gimp_drawable_calculate_histogram (GimpDrawable *drawable,
|
|||||||
GimpHistogram *histogram)
|
GimpHistogram *histogram)
|
||||||
{
|
{
|
||||||
GimpImage *image;
|
GimpImage *image;
|
||||||
PixelRegion region;
|
GimpChannel *mask;
|
||||||
PixelRegion mask;
|
|
||||||
gint x, y, width, height;
|
gint x, y, width, height;
|
||||||
|
|
||||||
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
|
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))
|
if (! gimp_item_mask_intersect (GIMP_ITEM (drawable), &x, &y, &width, &height))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
pixel_region_init (®ion, gimp_drawable_get_tiles (drawable),
|
|
||||||
x, y, width, height, FALSE);
|
|
||||||
|
|
||||||
image = gimp_item_get_image (GIMP_ITEM (drawable));
|
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;
|
GeglNode *node = gegl_node_new ();
|
||||||
GimpImage *image;
|
GeglNode *buffer_source;
|
||||||
gint off_x, off_y;
|
GeglNode *histogram_sink;
|
||||||
|
GeglProcessor *processor;
|
||||||
|
|
||||||
image = gimp_item_get_image (GIMP_ITEM (drawable));
|
buffer_source =
|
||||||
sel_mask = gimp_image_get_mask (image);
|
gimp_gegl_add_buffer_source (node,
|
||||||
|
gimp_drawable_get_buffer (drawable),
|
||||||
|
0, 0);
|
||||||
|
|
||||||
gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
|
histogram_sink =
|
||||||
pixel_region_init (&mask,
|
gegl_node_new_child (node,
|
||||||
gimp_drawable_get_tiles (GIMP_DRAWABLE (sel_mask)),
|
"operation", "gimp:histogram-sink",
|
||||||
x + off_x, y + off_y, width, height, FALSE);
|
"histogram", histogram,
|
||||||
gimp_histogram_calculate (histogram, ®ion, &mask);
|
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
|
else
|
||||||
{
|
{
|
||||||
gimp_histogram_calculate (histogram, ®ion, NULL);
|
PixelRegion region;
|
||||||
|
PixelRegion mask_region;
|
||||||
|
|
||||||
|
pixel_region_init (®ion, 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, ®ion, &mask_region);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gimp_histogram_calculate (histogram, ®ion, NULL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,38 +24,47 @@
|
|||||||
|
|
||||||
#include "gimp-gegl-types.h"
|
#include "gimp-gegl-types.h"
|
||||||
|
|
||||||
|
#include "core/gimphistogram.h"
|
||||||
|
|
||||||
#include "gimpoperationhistogramsink.h"
|
#include "gimpoperationhistogramsink.h"
|
||||||
|
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
PROP_0,
|
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,
|
guint prop_id,
|
||||||
GValue *value,
|
GValue *value,
|
||||||
GParamSpec *pspec);
|
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,
|
guint prop_id,
|
||||||
const GValue *value,
|
const GValue *value,
|
||||||
GParamSpec *pspec);
|
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,
|
static gboolean gimp_operation_histogram_sink_process (GeglOperation *operation,
|
||||||
GeglOperationContext *context,
|
GeglOperationContext *context,
|
||||||
const gchar *output_prop,
|
const gchar *output_prop,
|
||||||
const GeglRectangle *result,
|
const GeglRectangle *result,
|
||||||
gint level);
|
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,
|
G_DEFINE_TYPE (GimpOperationHistogramSink, gimp_operation_histogram_sink,
|
||||||
GEGL_TYPE_OPERATION_SINK)
|
GEGL_TYPE_OPERATION_SINK)
|
||||||
|
|
||||||
|
#define parent_class gimp_operation_histogram_sink_parent_class
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gimp_operation_histogram_sink_class_init (GimpOperationHistogramSinkClass *klass)
|
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);
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||||
GeglOperationClass *operation_class = GEGL_OPERATION_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->set_property = gimp_operation_histogram_sink_set_property;
|
||||||
object_class->get_property = gimp_operation_histogram_sink_get_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->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->get_required_for_output = gimp_operation_histogram_sink_get_required_for_output;
|
||||||
operation_class->process = gimp_operation_histogram_sink_process;
|
operation_class->process = gimp_operation_histogram_sink_process;
|
||||||
|
|
||||||
@ -77,6 +94,12 @@ gimp_operation_histogram_sink_class_init (GimpOperationHistogramSinkClass *klass
|
|||||||
GEGL_TYPE_BUFFER,
|
GEGL_TYPE_BUFFER,
|
||||||
G_PARAM_READWRITE |
|
G_PARAM_READWRITE |
|
||||||
GEGL_PARAM_PAD_INPUT));
|
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
|
static void
|
||||||
@ -84,12 +107,41 @@ 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
|
static void
|
||||||
gimp_operation_histogram_sink_get_property (GObject *object,
|
gimp_operation_histogram_sink_get_property (GObject *object,
|
||||||
guint prop_id,
|
guint prop_id,
|
||||||
GValue *value,
|
GValue *value,
|
||||||
GParamSpec *pspec)
|
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
|
static void
|
||||||
@ -98,6 +150,25 @@ gimp_operation_histogram_sink_set_property (GObject *object,
|
|||||||
const GValue *value,
|
const GValue *value,
|
||||||
GParamSpec *pspec)
|
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
|
static void
|
||||||
@ -106,11 +177,20 @@ gimp_operation_histogram_sink_attach (GeglOperation *self)
|
|||||||
GeglOperation *operation = GEGL_OPERATION (self);
|
GeglOperation *operation = GEGL_OPERATION (self);
|
||||||
GObjectClass *object_class = G_OBJECT_GET_CLASS (self);
|
GObjectClass *object_class = G_OBJECT_GET_CLASS (self);
|
||||||
|
|
||||||
|
GEGL_OPERATION_CLASS (parent_class)->attach (self);
|
||||||
|
|
||||||
gegl_operation_create_pad (operation,
|
gegl_operation_create_pad (operation,
|
||||||
g_object_class_find_property (object_class,
|
g_object_class_find_property (object_class,
|
||||||
"aux"));
|
"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
|
static GeglRectangle
|
||||||
gimp_operation_histogram_sink_get_required_for_output (GeglOperation *self,
|
gimp_operation_histogram_sink_get_required_for_output (GeglOperation *self,
|
||||||
const gchar *input_pad,
|
const gchar *input_pad,
|
||||||
@ -139,21 +219,31 @@ gimp_operation_histogram_sink_process (GeglOperation *operation,
|
|||||||
input = gegl_operation_context_get_source (context, "input");
|
input = gegl_operation_context_get_source (context, "input");
|
||||||
aux = gegl_operation_context_get_source (context, "aux");
|
aux = gegl_operation_context_get_source (context, "aux");
|
||||||
|
|
||||||
if (input)
|
if (! input)
|
||||||
{
|
{
|
||||||
if (aux)
|
g_warning ("received NULL input");
|
||||||
{
|
|
||||||
/* do hist with mask */
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* without */
|
|
||||||
}
|
|
||||||
|
|
||||||
return TRUE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_warning ("received NULL input");
|
if (aux)
|
||||||
|
{
|
||||||
|
/* do hist with mask */
|
||||||
|
|
||||||
return FALSE;
|
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_object_unref (input);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -27,11 +27,11 @@
|
|||||||
|
|
||||||
|
|
||||||
#define GIMP_TYPE_OPERATION_HISTOGRAM_SINK (gimp_operation_histogram_sink_get_type ())
|
#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(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_HISTOGRAM_SINK, GimpOperationHistogramSinkClass))
|
#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_HISTOGRAM_SINK))
|
#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_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_HISTOGRAM_SINK, GimpOperationHistogramSinkClass))
|
#define GIMP_OPERATION_HISTOGRAM_SINK_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_OPERATION_HISTOGRAM_SINK, GimpOperationHistogramSinkClass))
|
||||||
|
|
||||||
|
|
||||||
typedef struct _GimpOperationHistogramSinkClass GimpOperationHistogramSinkClass;
|
typedef struct _GimpOperationHistogramSinkClass GimpOperationHistogramSinkClass;
|
||||||
@ -39,6 +39,8 @@ typedef struct _GimpOperationHistogramSinkClass GimpOperationHistogramSinkClass;
|
|||||||
struct _GimpOperationHistogramSink
|
struct _GimpOperationHistogramSink
|
||||||
{
|
{
|
||||||
GeglOperation parent_instance;
|
GeglOperation parent_instance;
|
||||||
|
|
||||||
|
GimpHistogram *histogram;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GimpOperationHistogramSinkClass
|
struct _GimpOperationHistogramSinkClass
|
||||||
|
Reference in New Issue
Block a user