[gimp] app: turn GimpHistorgram into a GimpObject, no other changes
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: turn GimpHistorgram into a GimpObject, no other changes
- Date: Tue, 11 Jun 2013 19:24:55 +0000 (UTC)
commit a7f42de4c0de8773e25c441a5b692000b9c8ac0d
Author: Michael Natterer <mitch gimp org>
Date: Tue Jun 11 21:23:32 2013 +0200
app: turn GimpHistorgram into a GimpObject, no other changes
app/core/gimpdrawable-equalize.c | 3 +-
app/core/gimpdrawable-levels.c | 2 +-
app/core/gimphistogram.c | 405 +++++++++++++++++++--------
app/core/gimphistogram.h | 32 ++-
app/operations/gimpoperationequalize.c | 19 +-
app/operations/gimpoperationhistogramsink.c | 17 +-
app/pdb/color-cmds.c | 2 +-
app/tools/gimpcurvestool.c | 2 +-
app/tools/gimplevelstool.c | 2 +-
app/tools/gimpthresholdtool.c | 2 +-
app/widgets/gimphistogrameditor.c | 8 +-
app/widgets/gimphistogramview.c | 12 +-
tools/pdbgen/pdb/color.pdb | 2 +-
13 files changed, 344 insertions(+), 164 deletions(-)
---
diff --git a/app/core/gimpdrawable-equalize.c b/app/core/gimpdrawable-equalize.c
index a2ec418..ff481e7 100644
--- a/app/core/gimpdrawable-equalize.c
+++ b/app/core/gimpdrawable-equalize.c
@@ -53,6 +53,5 @@ gimp_drawable_equalize (GimpDrawable *drawable,
equalize);
g_object_unref (equalize);
-
- gimp_histogram_unref (hist);
+ g_object_unref (hist);
}
diff --git a/app/core/gimpdrawable-levels.c b/app/core/gimpdrawable-levels.c
index 0b9d3fe..38da9f0 100644
--- a/app/core/gimpdrawable-levels.c
+++ b/app/core/gimpdrawable-levels.c
@@ -58,7 +58,7 @@ gimp_drawable_levels_stretch (GimpDrawable *drawable,
gimp_levels_config_stretch (config, histogram,
gimp_drawable_is_rgb (drawable));
- gimp_histogram_unref (histogram);
+ g_object_unref (histogram);
levels = g_object_new (GEGL_TYPE_NODE,
"operation", "gimp:levels",
diff --git a/app/core/gimphistogram.c b/app/core/gimphistogram.c
index 6963241..37fc7d4 100644
--- a/app/core/gimphistogram.c
+++ b/app/core/gimphistogram.c
@@ -32,9 +32,16 @@
#include "gimphistogram.h"
-struct _GimpHistogram
+enum
+{
+ PROP_0,
+ PROP_N_CHANNELS,
+ PROP_N_BINS,
+ PROP_VALUES
+};
+
+struct _GimpHistogramPrivate
{
- gint ref_count;
gint n_channels;
gint n_bins;
gdouble *values;
@@ -43,48 +50,146 @@ struct _GimpHistogram
/* local function prototypes */
-static void gimp_histogram_alloc_values (GimpHistogram *histogram,
- gint n_components,
- gint n_bins);
+static void gimp_histogram_finalize (GObject *object);
+static void gimp_histogram_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void gimp_histogram_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec);
+static gint64 gimp_histogram_get_memsize (GimpObject *object,
+ gint64 *gui_size);
-/* public functions */
+static void gimp_histogram_alloc_values (GimpHistogram *histogram,
+ gint n_components,
+ gint n_bins);
-GimpHistogram *
-gimp_histogram_new (void)
+
+G_DEFINE_TYPE (GimpHistogram, gimp_histogram, GIMP_TYPE_OBJECT)
+
+#define parent_class gimp_histogram_parent_class
+
+
+static void
+gimp_histogram_class_init (GimpHistogramClass *klass)
{
- GimpHistogram *histogram = g_slice_new0 (GimpHistogram);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GimpObjectClass *gimp_object_class = GIMP_OBJECT_CLASS (klass);
+
+ object_class->finalize = gimp_histogram_finalize;
+ object_class->set_property = gimp_histogram_set_property;
+ object_class->get_property = gimp_histogram_get_property;
+
+ gimp_object_class->get_memsize = gimp_histogram_get_memsize;
- histogram->ref_count = 1;
- histogram->n_bins = 256;
+ g_object_class_install_property (object_class, PROP_N_CHANNELS,
+ g_param_spec_int ("n-channels", NULL, NULL,
+ 0, 5, 0,
+ GIMP_PARAM_READABLE));
- return histogram;
+ g_object_class_install_property (object_class, PROP_N_BINS,
+ g_param_spec_int ("n-bins", NULL, NULL,
+ 256, 1024, 1024,
+ GIMP_PARAM_READABLE));
+
+ /* this is just for notifications */
+ g_object_class_install_property (object_class, PROP_VALUES,
+ g_param_spec_boolean ("values", NULL, NULL,
+ FALSE,
+ G_PARAM_READABLE));
+
+ g_type_class_add_private (klass, sizeof (GimpHistogramPrivate));
}
-GimpHistogram *
-gimp_histogram_ref (GimpHistogram *histogram)
+static void
+gimp_histogram_init (GimpHistogram *histogram)
{
- g_return_val_if_fail (histogram != NULL, NULL);
+ histogram->priv = G_TYPE_INSTANCE_GET_PRIVATE (histogram,
+ GIMP_TYPE_HISTOGRAM,
+ GimpHistogramPrivate);
- histogram->ref_count++;
+ histogram->priv->n_bins = 256;
+}
+
+static void
+gimp_histogram_finalize (GObject *object)
+{
+ GimpHistogram *histogram = GIMP_HISTOGRAM (object);
- return histogram;
+ gimp_histogram_clear_values (histogram);
+
+ G_OBJECT_CLASS (parent_class)->finalize (object);
}
-void
-gimp_histogram_unref (GimpHistogram *histogram)
+static void
+gimp_histogram_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- g_return_if_fail (histogram != NULL);
+ switch (property_id)
+ {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
- histogram->ref_count--;
+static void
+gimp_histogram_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GimpHistogram *histogram = GIMP_HISTOGRAM (object);
- if (histogram->ref_count == 0)
+ switch (property_id)
{
- gimp_histogram_clear_values (histogram);
- g_slice_free (GimpHistogram, histogram);
+ case PROP_N_CHANNELS:
+ g_value_set_int (value, histogram->priv->n_channels);
+ break;
+
+ case PROP_N_BINS:
+ g_value_set_int (value, histogram->priv->n_bins);
+ break;
+
+ case PROP_VALUES:
+ /* return a silly boolean */
+ g_value_set_boolean (value, histogram->priv->values != NULL);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
}
}
+static gint64
+gimp_histogram_get_memsize (GimpObject *object,
+ gint64 *gui_size)
+{
+ GimpHistogram *histogram = GIMP_HISTOGRAM (object);
+ gint64 memsize = 0;
+
+ if (histogram->priv->values)
+ memsize += (histogram->priv->n_channels *
+ histogram->priv->n_bins * sizeof (gdouble));
+
+ return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
+ gui_size);
+}
+
+/* public functions */
+
+GimpHistogram *
+gimp_histogram_new (void)
+{
+ return g_object_new (GIMP_TYPE_HISTOGRAM, NULL);
+}
+
/**
* gimp_histogram_duplicate:
* @histogram: a %GimpHistogram
@@ -99,14 +204,16 @@ gimp_histogram_duplicate (GimpHistogram *histogram)
{
GimpHistogram *dup;
- g_return_val_if_fail (histogram != NULL, NULL);
+ g_return_val_if_fail (GIMP_IS_HISTOGRAM (histogram), NULL);
dup = gimp_histogram_new ();
- dup->n_channels = histogram->n_channels;
- dup->n_bins = histogram->n_bins;
- dup->values = g_memdup (histogram->values,
- sizeof (gdouble) * dup->n_channels * dup->n_bins);
+ dup->priv->n_channels = histogram->priv->n_channels;
+ dup->priv->n_bins = histogram->priv->n_bins;
+ dup->priv->values = g_memdup (histogram->priv->values,
+ sizeof (gdouble) *
+ dup->priv->n_channels *
+ dup->priv->n_bins);
return dup;
}
@@ -118,15 +225,18 @@ gimp_histogram_calculate (GimpHistogram *histogram,
GeglBuffer *mask,
const GeglRectangle *mask_rect)
{
- GeglBufferIterator *iter;
- const Babl *format;
- gint n_components;
- gint n_bins;
+ GimpHistogramPrivate *priv;
+ GeglBufferIterator *iter;
+ const Babl *format;
+ gint n_components;
+ gint n_bins;
- g_return_if_fail (histogram != NULL);
+ g_return_if_fail (GIMP_IS_HISTOGRAM (histogram));
g_return_if_fail (GEGL_IS_BUFFER (buffer));
g_return_if_fail (buffer_rect != NULL);
+ priv = histogram->priv;
+
format = gegl_buffer_get_format (buffer);
if (babl_format_get_type (format, 0) == babl_type ("u8"))
@@ -185,6 +295,8 @@ gimp_histogram_calculate (GimpHistogram *histogram,
n_components = babl_format_get_n_components (format);
+ g_object_freeze_notify (G_OBJECT (histogram));
+
gimp_histogram_alloc_values (histogram, n_components, n_bins);
iter = gegl_buffer_iterator_new (buffer, buffer_rect, 0, format,
@@ -195,7 +307,7 @@ gimp_histogram_calculate (GimpHistogram *histogram,
babl_format ("Y float"),
GEGL_BUFFER_READ, GEGL_ABYSS_NONE);
-#define VALUE(c,i) (histogram->values[(c) * histogram->n_bins + (gint) ((i) * (histogram->n_bins - 0.0001))])
+#define VALUE(c,i) (priv->values[(c) * priv->n_bins + (gint) ((i) * (priv->n_bins - 0.0001))])
while (gegl_buffer_iterator_next (iter))
{
@@ -338,47 +450,61 @@ gimp_histogram_calculate (GimpHistogram *histogram,
}
}
+ g_object_notify (G_OBJECT (histogram), "values");
+
+ g_object_thaw_notify (G_OBJECT (histogram));
+
#undef VALUE
}
void
gimp_histogram_clear_values (GimpHistogram *histogram)
{
- g_return_if_fail (histogram != NULL);
+ g_return_if_fail (GIMP_IS_HISTOGRAM (histogram));
- if (histogram->values)
+ if (histogram->priv->values)
{
- g_free (histogram->values);
- histogram->values = NULL;
+ g_free (histogram->priv->values);
+ histogram->priv->values = NULL;
+
+ g_object_notify (G_OBJECT (histogram), "values");
}
- histogram->n_channels = 0;
+ if (histogram->priv->n_channels)
+ {
+ histogram->priv->n_channels = 0;
+
+ g_object_notify (G_OBJECT (histogram), "n-channels");
+ }
}
-#define HISTOGRAM_VALUE(c,i) (histogram->values[(c) * histogram->n_bins + (i)])
+#define HISTOGRAM_VALUE(c,i) (priv->values[(c) * priv->n_bins + (i)])
gdouble
gimp_histogram_get_maximum (GimpHistogram *histogram,
GimpHistogramChannel channel)
{
- gdouble max = 0.0;
- gint x;
+ GimpHistogramPrivate *priv;
+ gdouble max = 0.0;
+ gint x;
+
+ g_return_val_if_fail (GIMP_IS_HISTOGRAM (histogram), 0.0);
- g_return_val_if_fail (histogram != NULL, 0.0);
+ priv = histogram->priv;
/* the gray alpha channel is in slot 1 */
- if (histogram->n_channels == 3 && channel == GIMP_HISTOGRAM_ALPHA)
+ if (priv->n_channels == 3 && channel == GIMP_HISTOGRAM_ALPHA)
channel = 1;
- if (! histogram->values ||
- (channel != GIMP_HISTOGRAM_RGB && channel >= histogram->n_channels))
+ if (! priv->values ||
+ (channel != GIMP_HISTOGRAM_RGB && channel >= priv->n_channels))
return 0.0;
if (channel == GIMP_HISTOGRAM_RGB)
{
- for (x = 0; x < histogram->n_bins; x++)
+ for (x = 0; x < priv->n_bins; x++)
{
max = MAX (max, HISTOGRAM_VALUE (GIMP_HISTOGRAM_RED, x));
max = MAX (max, HISTOGRAM_VALUE (GIMP_HISTOGRAM_GREEN, x));
@@ -387,7 +513,7 @@ gimp_histogram_get_maximum (GimpHistogram *histogram,
}
else
{
- for (x = 0; x < histogram->n_bins; x++)
+ for (x = 0; x < priv->n_bins; x++)
{
max = MAX (max, HISTOGRAM_VALUE (channel, x));
}
@@ -401,16 +527,20 @@ gimp_histogram_get_value (GimpHistogram *histogram,
GimpHistogramChannel channel,
gint bin)
{
- g_return_val_if_fail (histogram != NULL, 0.0);
+ GimpHistogramPrivate *priv;
+
+ g_return_val_if_fail (GIMP_IS_HISTOGRAM (histogram), 0.0);
+
+ priv = histogram->priv;
/* the gray alpha channel is in slot 1 */
- if (histogram->n_channels == 3 && channel == GIMP_HISTOGRAM_ALPHA)
+ if (priv->n_channels == 3 && channel == GIMP_HISTOGRAM_ALPHA)
channel = 1;
- if (! histogram->values ||
- bin < 0 || bin >= histogram->n_bins ||
- (channel == GIMP_HISTOGRAM_RGB && histogram->n_channels < 4) ||
- (channel != GIMP_HISTOGRAM_RGB && channel >= histogram->n_channels))
+ if (! priv->values ||
+ bin < 0 || bin >= priv->n_bins ||
+ (channel == GIMP_HISTOGRAM_RGB && priv->n_channels < 4) ||
+ (channel != GIMP_HISTOGRAM_RGB && channel >= priv->n_channels))
return 0.0;
if (channel == GIMP_HISTOGRAM_RGB)
@@ -432,9 +562,9 @@ gimp_histogram_get_channel (GimpHistogram *histogram,
GimpHistogramChannel channel,
gint bin)
{
- g_return_val_if_fail (histogram != NULL, 0.0);
+ g_return_val_if_fail (GIMP_IS_HISTOGRAM (histogram), 0.0);
- if (histogram->n_channels > 3)
+ if (histogram->priv->n_channels > 3)
channel++;
return gimp_histogram_get_value (histogram, channel, bin);
@@ -443,17 +573,17 @@ gimp_histogram_get_channel (GimpHistogram *histogram,
gint
gimp_histogram_n_channels (GimpHistogram *histogram)
{
- g_return_val_if_fail (histogram != NULL, 0);
+ g_return_val_if_fail (GIMP_IS_HISTOGRAM (histogram), 0);
- return histogram->n_channels - 1;
+ return histogram->priv->n_channels - 1;
}
gint
gimp_histogram_n_bins (GimpHistogram *histogram)
{
- g_return_val_if_fail (histogram != NULL, 0);
+ g_return_val_if_fail (GIMP_IS_HISTOGRAM (histogram), 0);
- return histogram->n_bins;
+ return histogram->priv->n_bins;
}
gdouble
@@ -462,13 +592,16 @@ gimp_histogram_get_count (GimpHistogram *histogram,
gint start,
gint end)
{
- gint i;
- gdouble count = 0.0;
+ GimpHistogramPrivate *priv;
+ gint i;
+ gdouble count = 0.0;
- g_return_val_if_fail (histogram != NULL, 0.0);
+ g_return_val_if_fail (GIMP_IS_HISTOGRAM (histogram), 0.0);
+
+ priv = histogram->priv;
/* the gray alpha channel is in slot 1 */
- if (histogram->n_channels == 3 && channel == GIMP_HISTOGRAM_ALPHA)
+ if (priv->n_channels == 3 && channel == GIMP_HISTOGRAM_ALPHA)
channel = 1;
if (channel == GIMP_HISTOGRAM_RGB)
@@ -479,13 +612,13 @@ gimp_histogram_get_count (GimpHistogram *histogram,
gimp_histogram_get_count (histogram,
GIMP_HISTOGRAM_BLUE, start, end));
- if (! histogram->values ||
+ if (! priv->values ||
start > end ||
- channel >= histogram->n_channels)
+ channel >= priv->n_channels)
return 0.0;
- start = CLAMP (start, 0, histogram->n_bins - 1);
- end = CLAMP (end, 0, histogram->n_bins - 1);
+ start = CLAMP (start, 0, priv->n_bins - 1);
+ end = CLAMP (end, 0, priv->n_bins - 1);
for (i = start; i <= end; i++)
count += HISTOGRAM_VALUE (channel, i);
@@ -499,24 +632,27 @@ gimp_histogram_get_mean (GimpHistogram *histogram,
gint start,
gint end)
{
- gint i;
- gdouble mean = 0.0;
- gdouble count;
+ GimpHistogramPrivate *priv;
+ gint i;
+ gdouble mean = 0.0;
+ gdouble count;
+
+ g_return_val_if_fail (GIMP_IS_HISTOGRAM (histogram), 0.0);
- g_return_val_if_fail (histogram != NULL, 0.0);
+ priv = histogram->priv;
/* the gray alpha channel is in slot 1 */
- if (histogram->n_channels == 3 && channel == GIMP_HISTOGRAM_ALPHA)
+ if (priv->n_channels == 3 && channel == GIMP_HISTOGRAM_ALPHA)
channel = 1;
- if (! histogram->values ||
+ if (! priv->values ||
start > end ||
- (channel == GIMP_HISTOGRAM_RGB && histogram->n_channels < 4) ||
- (channel != GIMP_HISTOGRAM_RGB && channel >= histogram->n_channels))
+ (channel == GIMP_HISTOGRAM_RGB && priv->n_channels < 4) ||
+ (channel != GIMP_HISTOGRAM_RGB && channel >= priv->n_channels))
return 0.0;
- start = CLAMP (start, 0, histogram->n_bins - 1);
- end = CLAMP (end, 0, histogram->n_bins - 1);
+ start = CLAMP (start, 0, priv->n_bins - 1);
+ end = CLAMP (end, 0, priv->n_bins - 1);
if (channel == GIMP_HISTOGRAM_RGB)
{
@@ -545,24 +681,27 @@ gimp_histogram_get_median (GimpHistogram *histogram,
gint start,
gint end)
{
- gint i;
- gdouble sum = 0.0;
- gdouble count;
+ GimpHistogramPrivate *priv;
+ gint i;
+ gdouble sum = 0.0;
+ gdouble count;
- g_return_val_if_fail (histogram != NULL, -1);
+ g_return_val_if_fail (GIMP_IS_HISTOGRAM (histogram), -1);
+
+ priv = histogram->priv;
/* the gray alpha channel is in slot 1 */
- if (histogram->n_channels == 3 && channel == GIMP_HISTOGRAM_ALPHA)
+ if (priv->n_channels == 3 && channel == GIMP_HISTOGRAM_ALPHA)
channel = 1;
- if (! histogram->values ||
+ if (! priv->values ||
start > end ||
- (channel == GIMP_HISTOGRAM_RGB && histogram->n_channels < 4) ||
- (channel != GIMP_HISTOGRAM_RGB && channel >= histogram->n_channels))
+ (channel == GIMP_HISTOGRAM_RGB && priv->n_channels < 4) ||
+ (channel != GIMP_HISTOGRAM_RGB && channel >= priv->n_channels))
return 0;
- start = CLAMP (start, 0, histogram->n_bins - 1);
- end = CLAMP (end, 0, histogram->n_bins - 1);
+ start = CLAMP (start, 0, priv->n_bins - 1);
+ end = CLAMP (end, 0, priv->n_bins - 1);
count = gimp_histogram_get_count (histogram, channel, start, end);
@@ -604,31 +743,34 @@ gimp_histogram_get_threshold (GimpHistogram *histogram,
gint start,
gint end)
{
- gint i;
- gint maxval;
- gdouble *hist = NULL;
- gdouble *chist = NULL;
- gdouble *cmom = NULL;
- gdouble hist_max = 0.0;
- gdouble chist_max = 0.0;
- gdouble cmom_max = 0.0;
- gdouble bvar_max = 0.0;
- gint threshold = 127;
-
- g_return_val_if_fail (histogram != NULL, -1);
+ GimpHistogramPrivate *priv;
+ gint i;
+ gint maxval;
+ gdouble *hist = NULL;
+ gdouble *chist = NULL;
+ gdouble *cmom = NULL;
+ gdouble hist_max = 0.0;
+ gdouble chist_max = 0.0;
+ gdouble cmom_max = 0.0;
+ gdouble bvar_max = 0.0;
+ gint threshold = 127;
+
+ g_return_val_if_fail (GIMP_IS_HISTOGRAM (histogram), -1);
+
+ priv = histogram->priv;
/* the gray alpha channel is in slot 1 */
- if (histogram->n_channels == 3 && channel == GIMP_HISTOGRAM_ALPHA)
+ if (priv->n_channels == 3 && channel == GIMP_HISTOGRAM_ALPHA)
channel = 1;
- if (! histogram->values ||
+ if (! priv->values ||
start > end ||
- (channel == GIMP_HISTOGRAM_RGB && histogram->n_channels < 4) ||
- (channel != GIMP_HISTOGRAM_RGB && channel >= histogram->n_channels))
+ (channel == GIMP_HISTOGRAM_RGB && priv->n_channels < 4) ||
+ (channel != GIMP_HISTOGRAM_RGB && channel >= priv->n_channels))
return 0;
- start = CLAMP (start, 0, histogram->n_bins - 1);
- end = CLAMP (end, 0, histogram->n_bins - 1);
+ start = CLAMP (start, 0, priv->n_bins - 1);
+ end = CLAMP (end, 0, priv->n_bins - 1);
maxval = end - start;
@@ -695,21 +837,24 @@ gimp_histogram_get_std_dev (GimpHistogram *histogram,
gint start,
gint end)
{
- gint i;
- gdouble dev = 0.0;
- gdouble count;
- gdouble mean;
+ GimpHistogramPrivate *priv;
+ gint i;
+ gdouble dev = 0.0;
+ gdouble count;
+ gdouble mean;
+
+ g_return_val_if_fail (GIMP_IS_HISTOGRAM (histogram), 0.0);
- g_return_val_if_fail (histogram != NULL, 0.0);
+ priv = histogram->priv;
/* the gray alpha channel is in slot 1 */
- if (histogram->n_channels == 3 && channel == GIMP_HISTOGRAM_ALPHA)
+ if (priv->n_channels == 3 && channel == GIMP_HISTOGRAM_ALPHA)
channel = 1;
- if (! histogram->values ||
+ if (! priv->values ||
start > end ||
- (channel == GIMP_HISTOGRAM_RGB && histogram->n_channels < 4) ||
- (channel != GIMP_HISTOGRAM_RGB && channel >= histogram->n_channels))
+ (channel == GIMP_HISTOGRAM_RGB && priv->n_channels < 4) ||
+ (channel != GIMP_HISTOGRAM_RGB && channel >= priv->n_channels))
return 0.0;
mean = gimp_histogram_get_mean (histogram, channel, start, end);
@@ -747,20 +892,32 @@ gimp_histogram_alloc_values (GimpHistogram *histogram,
gint n_components,
gint n_bins)
{
- if (n_components + 1 != histogram->n_channels ||
- n_bins != histogram->n_bins)
+ GimpHistogramPrivate *priv = histogram->priv;
+
+ if (n_components + 1 != priv->n_channels ||
+ n_bins != priv->n_bins)
{
gimp_histogram_clear_values (histogram);
- histogram->n_channels = n_components + 1;
- histogram->n_bins = n_bins;
+ if (n_components + 1 != priv->n_channels)
+ {
+ priv->n_channels = n_components + 1;
+
+ g_object_notify (G_OBJECT (histogram), "n-channels");
+ }
+
+ if (n_bins != priv->n_bins)
+ {
+ priv->n_bins = n_bins;
+
+ g_object_notify (G_OBJECT (histogram), "n-bins");
+ }
- histogram->values = g_new0 (gdouble,
- histogram->n_channels * histogram->n_bins);
+ priv->values = g_new0 (gdouble, priv->n_channels * priv->n_bins);
}
else
{
- memset (histogram->values, 0,
- histogram->n_channels * histogram->n_bins * sizeof (gdouble));
+ memset (priv->values, 0,
+ priv->n_channels * priv->n_bins * sizeof (gdouble));
}
}
diff --git a/app/core/gimphistogram.h b/app/core/gimphistogram.h
index ed94abe..0deb200 100644
--- a/app/core/gimphistogram.h
+++ b/app/core/gimphistogram.h
@@ -21,10 +21,36 @@
#define __GIMP_HISTOGRAM_H__
-GimpHistogram * gimp_histogram_new (void);
+#include "gimpobject.h"
+
+
+#define GIMP_TYPE_HISTOGRAM (gimp_histogram_get_type ())
+#define GIMP_HISTOGRAM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_HISTOGRAM,
GimpHistogram))
+#define GIMP_HISTOGRAM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_HISTOGRAM,
GimpHistogramClass))
+#define GIMP_IS_HISTOGRAM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_HISTOGRAM))
+#define GIMP_IS_HISTOGRAM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_HISTOGRAM))
+#define GIMP_HISTOGRAM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_HISTOGRAM,
GimpHistogramClass))
+
+
+typedef struct _GimpHistogramPrivate GimpHistogramPrivate;
+typedef struct _GimpHistogramClass GimpHistogramClass;
+
+struct _GimpHistogram
+{
+ GimpObject parent_instance;
-GimpHistogram * gimp_histogram_ref (GimpHistogram *histogram);
-void gimp_histogram_unref (GimpHistogram *histogram);
+ GimpHistogramPrivate *priv;
+};
+
+struct _GimpHistogramClass
+{
+ GimpObjectClass parent_class;
+};
+
+
+GType gimp_histogram_get_type (void) G_GNUC_CONST;
+
+GimpHistogram * gimp_histogram_new (void);
GimpHistogram * gimp_histogram_duplicate (GimpHistogram *histogram);
diff --git a/app/operations/gimpoperationequalize.c b/app/operations/gimpoperationequalize.c
index 375d0d4..d0d56cf 100644
--- a/app/operations/gimpoperationequalize.c
+++ b/app/operations/gimpoperationequalize.c
@@ -85,11 +85,12 @@ gimp_operation_equalize_class_init (GimpOperationEqualizeClass *klass)
point_class->process = gimp_operation_equalize_process;
g_object_class_install_property (object_class, PROP_HISTOGRAM,
- g_param_spec_pointer ("histogram",
- "Histogram",
- "The histogram",
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY));
+ g_param_spec_object ("histogram",
+ "Histogram",
+ "The histogram",
+ GIMP_TYPE_HISTOGRAM,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY));
}
static void
@@ -104,7 +105,7 @@ gimp_operation_equalize_finalize (GObject *object)
if (self->histogram)
{
- gimp_histogram_unref (self->histogram);
+ g_object_unref (self->histogram);
self->histogram = NULL;
}
}
@@ -141,16 +142,14 @@ gimp_operation_equalize_set_property (GObject *object,
{
case PROP_HISTOGRAM:
if (self->histogram)
- gimp_histogram_unref (self->histogram);
- self->histogram = g_value_get_pointer (value);
+ g_object_unref (self->histogram);
+ self->histogram = g_value_dup_object (value);
if (self->histogram)
{
gdouble pixels;
gint max;
gint k;
- gimp_histogram_ref (self->histogram);
-
pixels = gimp_histogram_get_count (self->histogram,
GIMP_HISTOGRAM_VALUE, 0, 255);
diff --git a/app/operations/gimpoperationhistogramsink.c b/app/operations/gimpoperationhistogramsink.c
index 57f5474..f4c4a10 100644
--- a/app/operations/gimpoperationhistogramsink.c
+++ b/app/operations/gimpoperationhistogramsink.c
@@ -96,10 +96,11 @@ gimp_operation_histogram_sink_class_init (GimpOperationHistogramSinkClass *klass
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));
+ g_param_spec_object ("histogram",
+ "Histogram",
+ "The result histogram",
+ GIMP_TYPE_HISTOGRAM,
+ G_PARAM_READWRITE));
}
static void
@@ -114,7 +115,7 @@ gimp_operation_histogram_sink_finalize (GObject *object)
if (sink->histogram)
{
- gimp_histogram_unref (sink->histogram);
+ g_object_unref (sink->histogram);
sink->histogram = NULL;
}
@@ -159,10 +160,8 @@ gimp_operation_histogram_sink_set_property (GObject *object,
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);
+ g_object_unref (sink->histogram);
+ sink->histogram = g_value_dup_object (value);
break;
default:
diff --git a/app/pdb/color-cmds.c b/app/pdb/color-cmds.c
index d920881..45c4da1 100644
--- a/app/pdb/color-cmds.c
+++ b/app/pdb/color-cmds.c
@@ -638,7 +638,7 @@ histogram_invoker (GimpProcedure *procedure,
start_range, end_range);
percentile = count / pixels;
- gimp_histogram_unref (histogram);
+ g_object_unref (histogram);
}
}
diff --git a/app/tools/gimpcurvestool.c b/app/tools/gimpcurvestool.c
index 0de0e4b..24145c3 100644
--- a/app/tools/gimpcurvestool.c
+++ b/app/tools/gimpcurvestool.c
@@ -216,7 +216,7 @@ gimp_curves_tool_initialize (GimpTool *tool,
gimp_drawable_calculate_histogram (drawable, histogram);
gimp_histogram_view_set_background (GIMP_HISTOGRAM_VIEW (c_tool->graph),
histogram);
- gimp_histogram_unref (histogram);
+ g_object_unref (histogram);
return TRUE;
}
diff --git a/app/tools/gimplevelstool.c b/app/tools/gimplevelstool.c
index 5b1516a..adb24cc 100644
--- a/app/tools/gimplevelstool.c
+++ b/app/tools/gimplevelstool.c
@@ -187,7 +187,7 @@ gimp_levels_tool_finalize (GObject *object)
if (tool->histogram)
{
- gimp_histogram_unref (tool->histogram);
+ g_object_unref (tool->histogram);
tool->histogram = NULL;
}
diff --git a/app/tools/gimpthresholdtool.c b/app/tools/gimpthresholdtool.c
index 6f8fa7d..220a18b 100644
--- a/app/tools/gimpthresholdtool.c
+++ b/app/tools/gimpthresholdtool.c
@@ -126,7 +126,7 @@ gimp_threshold_tool_finalize (GObject *object)
if (t_tool->histogram)
{
- gimp_histogram_unref (t_tool->histogram);
+ g_object_unref (t_tool->histogram);
t_tool->histogram = NULL;
}
diff --git a/app/widgets/gimphistogrameditor.c b/app/widgets/gimphistogrameditor.c
index 9a45333..e5ff0eb 100644
--- a/app/widgets/gimphistogrameditor.c
+++ b/app/widgets/gimphistogrameditor.c
@@ -261,7 +261,7 @@ gimp_histogram_editor_set_image (GimpImageEditor *image_editor,
if (editor->histogram)
{
- gimp_histogram_unref (editor->histogram);
+ g_object_unref (editor->histogram);
editor->histogram = NULL;
gimp_histogram_view_set_histogram (view, NULL);
@@ -269,7 +269,7 @@ gimp_histogram_editor_set_image (GimpImageEditor *image_editor,
if (editor->bg_histogram)
{
- gimp_histogram_unref (editor->bg_histogram);
+ g_object_unref (editor->bg_histogram);
editor->bg_histogram = NULL;
gimp_histogram_view_set_background (view, NULL);
@@ -314,7 +314,7 @@ gimp_histogram_editor_layer_changed (GimpImage *image,
{
GimpHistogramView *view = GIMP_HISTOGRAM_BOX (editor->box)->view;
- gimp_histogram_unref (editor->bg_histogram);
+ g_object_unref (editor->bg_histogram);
editor->bg_histogram = NULL;
gimp_histogram_view_set_background (view, NULL);
@@ -410,7 +410,7 @@ gimp_histogram_editor_frozen_update (GimpHistogramEditor *editor,
}
else if (editor->bg_histogram)
{
- gimp_histogram_unref (editor->bg_histogram);
+ g_object_unref (editor->bg_histogram);
editor->bg_histogram = NULL;
gimp_histogram_view_set_background (view, NULL);
diff --git a/app/widgets/gimphistogramview.c b/app/widgets/gimphistogramview.c
index a3a194b..4554441 100644
--- a/app/widgets/gimphistogramview.c
+++ b/app/widgets/gimphistogramview.c
@@ -168,13 +168,13 @@ gimp_histogram_view_finalize (GObject *object)
if (view->histogram)
{
- gimp_histogram_unref (view->histogram);
+ g_object_unref (view->histogram);
view->histogram = NULL;
}
if (view->bg_histogram)
{
- gimp_histogram_unref (view->bg_histogram);
+ g_object_unref (view->bg_histogram);
view->bg_histogram = NULL;
}
@@ -630,13 +630,13 @@ gimp_histogram_view_set_histogram (GimpHistogramView *view,
if (view->histogram != histogram)
{
if (view->histogram)
- gimp_histogram_unref (view->histogram);
+ g_object_unref (view->histogram);
view->histogram = histogram;
if (histogram)
{
- gimp_histogram_ref (histogram);
+ g_object_ref (histogram);
if (view->channel >= gimp_histogram_n_channels (histogram))
gimp_histogram_view_set_channel (view, GIMP_HISTOGRAM_VALUE);
@@ -669,13 +669,13 @@ gimp_histogram_view_set_background (GimpHistogramView *view,
if (view->bg_histogram != histogram)
{
if (view->bg_histogram)
- gimp_histogram_unref (view->bg_histogram);
+ g_object_unref (view->bg_histogram);
view->bg_histogram = histogram;
if (histogram)
{
- gimp_histogram_ref (histogram);
+ g_object_ref (histogram);
if (view->channel >= gimp_histogram_n_channels (histogram))
gimp_histogram_view_set_channel (view, GIMP_HISTOGRAM_VALUE);
diff --git a/tools/pdbgen/pdb/color.pdb b/tools/pdbgen/pdb/color.pdb
index 737eba3..2ba337e 100644
--- a/tools/pdbgen/pdb/color.pdb
+++ b/tools/pdbgen/pdb/color.pdb
@@ -698,7 +698,7 @@ HELP
start_range, end_range);
percentile = count / pixels;
- gimp_histogram_unref (histogram);
+ g_object_unref (histogram);
}
}
CODE
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]