mirror of https://github.com/GNOME/gimp.git
app: turn GimpHistorgram into a GimpObject, no other changes
This commit is contained in:
parent
48d312ed94
commit
a7f42de4c0
|
@ -53,6 +53,5 @@ gimp_drawable_equalize (GimpDrawable *drawable,
|
|||
equalize);
|
||||
|
||||
g_object_unref (equalize);
|
||||
|
||||
gimp_histogram_unref (hist);
|
||||
g_object_unref (hist);
|
||||
}
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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,46 +50,144 @@ 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);
|
||||
|
||||
static void gimp_histogram_alloc_values (GimpHistogram *histogram,
|
||||
gint n_components,
|
||||
gint n_bins);
|
||||
|
||||
|
||||
G_DEFINE_TYPE (GimpHistogram, gimp_histogram, GIMP_TYPE_OBJECT)
|
||||
|
||||
#define parent_class gimp_histogram_parent_class
|
||||
|
||||
|
||||
static void
|
||||
gimp_histogram_class_init (GimpHistogramClass *klass)
|
||||
{
|
||||
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;
|
||||
|
||||
g_object_class_install_property (object_class, PROP_N_CHANNELS,
|
||||
g_param_spec_int ("n-channels", NULL, NULL,
|
||||
0, 5, 0,
|
||||
GIMP_PARAM_READABLE));
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_histogram_init (GimpHistogram *histogram)
|
||||
{
|
||||
histogram->priv = G_TYPE_INSTANCE_GET_PRIVATE (histogram,
|
||||
GIMP_TYPE_HISTOGRAM,
|
||||
GimpHistogramPrivate);
|
||||
|
||||
histogram->priv->n_bins = 256;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_histogram_finalize (GObject *object)
|
||||
{
|
||||
GimpHistogram *histogram = GIMP_HISTOGRAM (object);
|
||||
|
||||
gimp_histogram_clear_values (histogram);
|
||||
|
||||
G_OBJECT_CLASS (parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_histogram_set_property (GObject *object,
|
||||
guint property_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
switch (property_id)
|
||||
{
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_histogram_get_property (GObject *object,
|
||||
guint property_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GimpHistogram *histogram = GIMP_HISTOGRAM (object);
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
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)
|
||||
{
|
||||
GimpHistogram *histogram = g_slice_new0 (GimpHistogram);
|
||||
|
||||
histogram->ref_count = 1;
|
||||
histogram->n_bins = 256;
|
||||
|
||||
return histogram;
|
||||
}
|
||||
|
||||
GimpHistogram *
|
||||
gimp_histogram_ref (GimpHistogram *histogram)
|
||||
{
|
||||
g_return_val_if_fail (histogram != NULL, NULL);
|
||||
|
||||
histogram->ref_count++;
|
||||
|
||||
return histogram;
|
||||
}
|
||||
|
||||
void
|
||||
gimp_histogram_unref (GimpHistogram *histogram)
|
||||
{
|
||||
g_return_if_fail (histogram != NULL);
|
||||
|
||||
histogram->ref_count--;
|
||||
|
||||
if (histogram->ref_count == 0)
|
||||
{
|
||||
gimp_histogram_clear_values (histogram);
|
||||
g_slice_free (GimpHistogram, histogram);
|
||||
}
|
||||
return g_object_new (GIMP_TYPE_HISTOGRAM, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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 (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 (! 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 (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 (! 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;
|
||||
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 (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);
|
||||
|
||||
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 (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 (! 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;
|
||||
|
||||
histogram->values = g_new0 (gdouble,
|
||||
histogram->n_channels * histogram->n_bins);
|
||||
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");
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,10 +21,36 @@
|
|||
#define __GIMP_HISTOGRAM_H__
|
||||
|
||||
|
||||
GimpHistogram * gimp_histogram_new (void);
|
||||
#include "gimpobject.h"
|
||||
|
||||
GimpHistogram * gimp_histogram_ref (GimpHistogram *histogram);
|
||||
void gimp_histogram_unref (GimpHistogram *histogram);
|
||||
|
||||
#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;
|
||||
|
||||
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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -638,7 +638,7 @@ histogram_invoker (GimpProcedure *procedure,
|
|||
start_range, end_range);
|
||||
percentile = count / pixels;
|
||||
|
||||
gimp_histogram_unref (histogram);
|
||||
g_object_unref (histogram);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -698,7 +698,7 @@ HELP
|
|||
start_range, end_range);
|
||||
percentile = count / pixels;
|
||||
|
||||
gimp_histogram_unref (histogram);
|
||||
g_object_unref (histogram);
|
||||
}
|
||||
}
|
||||
CODE
|
||||
|
|
Loading…
Reference in New Issue