add refcounting and replace free() API by ref() and unref().

2008-02-04  Michael Natterer  <mitch@gimp.org>

	* app/base/gimphistogram.[ch]: add refcounting and replace free()
	API by ref() and unref().

	* app/core/gimpdrawable-equalize.c
	* app/core/gimpdrawable-levels.c
	* app/widgets/gimphistogrameditor.c
	* tools/pdbgen/pdb/color.pdb: replace calls to
	gimp_histogram_free() by gimp_histogram_unref().

	* app/pdb/color_cmds.c: regenerated.

	* app/widgets/gimphistogramview.c: reference the histograms so we
	don't need the widget's users to keep them around while the widget
	exists.

	* app/tools/gimpcurvestool.[ch]: remove the histogram from the
	tool struct and just create one locally to set it on the histogram
	view widget.

	Unrelated:

	* app/tools/gimplevelstool.[ch]
	* app/tools/gimpthresholdtool.[ch]: renamed "hist" members to
	"histogram" plus some cleanup.


svn path=/trunk/; revision=24792
This commit is contained in:
Michael Natterer 2008-02-04 21:41:57 +00:00 committed by Michael Natterer
parent f4033561ef
commit 50ad5cfd32
15 changed files with 147 additions and 80 deletions

View File

@ -1,3 +1,30 @@
2008-02-04 Michael Natterer <mitch@gimp.org>
* app/base/gimphistogram.[ch]: add refcounting and replace free()
API by ref() and unref().
* app/core/gimpdrawable-equalize.c
* app/core/gimpdrawable-levels.c
* app/widgets/gimphistogrameditor.c
* tools/pdbgen/pdb/color.pdb: replace calls to
gimp_histogram_free() by gimp_histogram_unref().
* app/pdb/color_cmds.c: regenerated.
* app/widgets/gimphistogramview.c: reference the histograms so we
don't need the widget's users to keep them around while the widget
exists.
* app/tools/gimpcurvestool.[ch]: remove the histogram from the
tool struct and just create one locally to set it on the histogram
view widget.
Unrelated:
* app/tools/gimplevelstool.[ch]
* app/tools/gimpthresholdtool.[ch]: renamed "hist" members to
"histogram" plus some cleanup.
2008-02-04 Michael Natterer <mitch@gimp.org>
* plug-ins/script-fu/script-fu.c: rename "Script-Fu Console" menu

View File

@ -42,6 +42,7 @@
struct _GimpHistogram
{
gint ref_count;
gint n_channels;
#ifdef ENABLE_MP
GStaticMutex mutex;
@ -68,6 +69,8 @@ gimp_histogram_new (void)
{
GimpHistogram *histogram = g_slice_new0 (GimpHistogram);
histogram->ref_count = 1;
#ifdef ENABLE_MP
g_static_mutex_init (&histogram->mutex);
#endif
@ -75,13 +78,28 @@ gimp_histogram_new (void)
return histogram;
}
GimpHistogram *
gimp_histogram_ref (GimpHistogram *histogram)
{
g_return_val_if_fail (histogram != NULL, NULL);
histogram->ref_count++;
return histogram;
}
void
gimp_histogram_free (GimpHistogram *histogram)
gimp_histogram_unref (GimpHistogram *histogram)
{
g_return_if_fail (histogram != NULL);
gimp_histogram_free_values (histogram);
g_slice_free (GimpHistogram, histogram);
histogram->ref_count--;
if (histogram->ref_count == 0)
{
gimp_histogram_free_values (histogram);
g_slice_free (GimpHistogram, histogram);
}
}
void

View File

@ -23,7 +23,8 @@
GimpHistogram * gimp_histogram_new (void);
void gimp_histogram_free (GimpHistogram *histogram);
GimpHistogram * gimp_histogram_ref (GimpHistogram *histogram);
void gimp_histogram_unref (GimpHistogram *histogram);
void gimp_histogram_calculate (GimpHistogram *histogram,
PixelRegion *region,

View File

@ -72,7 +72,7 @@ gimp_drawable_equalize (GimpDrawable *drawable,
lut, 2, &srcPR, &destPR);
gimp_lut_free (lut);
gimp_histogram_free (hist);
gimp_histogram_unref (hist);
gimp_drawable_merge_shadow (drawable, TRUE, _("Equalize"));

View File

@ -166,7 +166,7 @@ gimp_drawable_levels_stretch (GimpDrawable *drawable,
gimp_levels_config_stretch (config, histogram,
gimp_drawable_is_rgb (drawable));
gimp_histogram_free (histogram);
gimp_histogram_unref (histogram);
if (gimp_use_gegl (GIMP_ITEM (drawable)->image->gimp))
{

View File

@ -513,7 +513,7 @@ histogram_invoker (GimpProcedure *procedure,
start_range, end_range);
percentile = count / pixels;
gimp_histogram_free (histogram);
gimp_histogram_unref (histogram);
}
}

View File

@ -192,12 +192,6 @@ gimp_curves_tool_finalize (GObject *object)
gimp_lut_free (tool->lut);
if (tool->hist)
{
gimp_histogram_free (tool->hist);
tool->hist = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
}
@ -208,6 +202,7 @@ gimp_curves_tool_initialize (GimpTool *tool,
{
GimpCurvesTool *c_tool = GIMP_CURVES_TOOL (tool);
GimpDrawable *drawable = gimp_image_get_active_drawable (display->image);
GimpHistogram *histogram;
if (! drawable)
return FALSE;
@ -221,9 +216,6 @@ gimp_curves_tool_initialize (GimpTool *tool,
gimp_config_reset (GIMP_CONFIG (c_tool->config));
if (! c_tool->hist)
c_tool->hist = gimp_histogram_new ();
GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error);
/* always pick colors */
@ -233,9 +225,11 @@ gimp_curves_tool_initialize (GimpTool *tool,
gimp_int_combo_box_set_sensitivity (GIMP_INT_COMBO_BOX (c_tool->channel_menu),
curves_menu_sensitivity, drawable, NULL);
gimp_drawable_calculate_histogram (drawable, c_tool->hist);
histogram = gimp_histogram_new ();
gimp_drawable_calculate_histogram (drawable, histogram);
gimp_histogram_view_set_background (GIMP_HISTOGRAM_VIEW (c_tool->graph),
c_tool->hist);
histogram);
gimp_histogram_unref (histogram);
return TRUE;
}

View File

@ -41,8 +41,6 @@ struct _GimpCurvesTool
GimpLut *lut;
/* dialog */
GimpHistogram *hist;
gint col_value[5];
GtkWidget *channel_menu;

View File

@ -177,7 +177,7 @@ gimp_levels_tool_init (GimpLevelsTool *tool)
GimpImageMapTool *im_tool = GIMP_IMAGE_MAP_TOOL (tool);
tool->lut = gimp_lut_new ();
tool->hist = NULL;
tool->histogram = gimp_histogram_new ();
tool->active_picker = NULL;
im_tool->apply_func = (GimpImageMapApplyFunc) gimp_lut_process;
@ -191,10 +191,10 @@ gimp_levels_tool_finalize (GObject *object)
gimp_lut_free (tool->lut);
if (tool->hist)
if (tool->histogram)
{
gimp_histogram_free (tool->hist);
tool->hist = NULL;
gimp_histogram_unref (tool->histogram);
tool->histogram = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
@ -220,9 +220,6 @@ gimp_levels_tool_initialize (GimpTool *tool,
gimp_config_reset (GIMP_CONFIG (l_tool->config));
if (! l_tool->hist)
l_tool->hist = gimp_histogram_new ();
if (l_tool->active_picker)
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (l_tool->active_picker),
FALSE);
@ -232,9 +229,9 @@ gimp_levels_tool_initialize (GimpTool *tool,
gimp_int_combo_box_set_sensitivity (GIMP_INT_COMBO_BOX (l_tool->channel_menu),
levels_menu_sensitivity, drawable, NULL);
gimp_drawable_calculate_histogram (drawable, l_tool->hist);
gimp_histogram_view_set_histogram (GIMP_HISTOGRAM_VIEW (l_tool->hist_view),
l_tool->hist);
gimp_drawable_calculate_histogram (drawable, l_tool->histogram);
gimp_histogram_view_set_histogram (GIMP_HISTOGRAM_VIEW (l_tool->histogram_view),
l_tool->histogram);
return TRUE;
}
@ -416,14 +413,14 @@ gimp_levels_tool_dialog (GimpImageMapTool *image_map_tool)
gtk_container_add (GTK_CONTAINER (frame), vbox2);
gtk_widget_show (vbox2);
tool->hist_view = gimp_histogram_view_new (FALSE);
gtk_box_pack_start (GTK_BOX (vbox2), tool->hist_view, TRUE, TRUE, 0);
gtk_widget_show (GTK_WIDGET (tool->hist_view));
tool->histogram_view = gimp_histogram_view_new (FALSE);
gtk_box_pack_start (GTK_BOX (vbox2), tool->histogram_view, TRUE, TRUE, 0);
gtk_widget_show (GTK_WIDGET (tool->histogram_view));
gimp_histogram_options_connect_view (GIMP_HISTOGRAM_OPTIONS (tool_options),
GIMP_HISTOGRAM_VIEW (tool->hist_view));
GIMP_HISTOGRAM_VIEW (tool->histogram_view));
g_object_get (tool->hist_view, "border-width", &border, NULL);
g_object_get (tool->histogram_view, "border-width", &border, NULL);
vbox3 = gtk_vbox_new (FALSE, 0);
gtk_container_set_border_width (GTK_CONTAINER (vbox3), border);
@ -736,7 +733,7 @@ gimp_levels_tool_config_notify (GObject *object,
if (! strcmp (pspec->name, "channel"))
{
gimp_histogram_view_set_channel (GIMP_HISTOGRAM_VIEW (tool->hist_view),
gimp_histogram_view_set_channel (GIMP_HISTOGRAM_VIEW (tool->histogram_view),
config->channel);
gimp_color_bar_set_channel (GIMP_COLOR_BAR (tool->output_bar),
config->channel);
@ -893,7 +890,7 @@ levels_stretch_callback (GtkWidget *widget,
{
GimpDrawable *drawable = GIMP_IMAGE_MAP_TOOL (tool)->drawable;
gimp_levels_config_stretch (tool->config, tool->hist,
gimp_levels_config_stretch (tool->config, tool->histogram,
gimp_drawable_is_rgb (drawable));
}

View File

@ -42,11 +42,11 @@ struct _GimpLevelsTool
GimpLut *lut;
/* dialog */
GimpHistogram *hist;
GimpHistogram *histogram;
GtkWidget *channel_menu;
GtkWidget *hist_view;
GtkWidget *histogram_view;
GtkWidget *input_bar;
GtkWidget *input_sliders;

View File

@ -119,7 +119,7 @@ gimp_threshold_tool_init (GimpThresholdTool *t_tool)
GimpImageMapTool *im_tool = GIMP_IMAGE_MAP_TOOL (t_tool);
t_tool->threshold = g_slice_new0 (Threshold);
t_tool->hist = NULL;
t_tool->histogram = gimp_histogram_new ();
im_tool->apply_func = (GimpImageMapApplyFunc) threshold;
im_tool->apply_data = t_tool->threshold;
@ -132,10 +132,10 @@ gimp_threshold_tool_finalize (GObject *object)
g_slice_free (Threshold, t_tool->threshold);
if (t_tool->hist)
if (t_tool->histogram)
{
gimp_histogram_free (t_tool->hist);
t_tool->hist = NULL;
gimp_histogram_unref (t_tool->histogram);
t_tool->histogram = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
@ -161,24 +161,11 @@ gimp_threshold_tool_initialize (GimpTool *tool,
gimp_config_reset (GIMP_CONFIG (t_tool->config));
if (! t_tool->hist)
t_tool->hist = gimp_histogram_new ();
GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error);
gimp_drawable_calculate_histogram (drawable, t_tool->hist);
g_signal_handlers_block_by_func (t_tool->histogram_box->view,
gimp_threshold_tool_histogram_range,
t_tool);
gimp_drawable_calculate_histogram (drawable, t_tool->histogram);
gimp_histogram_view_set_histogram (t_tool->histogram_box->view,
t_tool->hist);
gimp_histogram_view_set_range (t_tool->histogram_box->view,
t_tool->config->low * 255.999,
t_tool->config->high * 255.999);
g_signal_handlers_unblock_by_func (t_tool->histogram_box->view,
gimp_threshold_tool_histogram_range,
t_tool);
t_tool->histogram);
gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (t_tool));
@ -229,13 +216,14 @@ gimp_threshold_tool_map (GimpImageMapTool *image_map_tool)
static void
gimp_threshold_tool_dialog (GimpImageMapTool *image_map_tool)
{
GimpThresholdTool *t_tool = GIMP_THRESHOLD_TOOL (image_map_tool);
GimpToolOptions *tool_options = GIMP_TOOL_GET_OPTIONS (image_map_tool);
GtkWidget *vbox;
GtkWidget *hbox;
GtkWidget *menu;
GtkWidget *box;
GtkWidget *button;
GimpThresholdTool *t_tool = GIMP_THRESHOLD_TOOL (image_map_tool);
GimpToolOptions *tool_options = GIMP_TOOL_GET_OPTIONS (image_map_tool);
GimpThresholdConfig *config = t_tool->config;
GtkWidget *vbox;
GtkWidget *hbox;
GtkWidget *menu;
GtkWidget *box;
GtkWidget *button;
vbox = image_map_tool->main_vbox;
@ -255,6 +243,10 @@ gimp_threshold_tool_dialog (GimpImageMapTool *image_map_tool)
t_tool->histogram_box = GIMP_HISTOGRAM_BOX (box);
gimp_histogram_view_set_range (t_tool->histogram_box->view,
config->low * 255.999,
config->high * 255.999);
g_signal_connect (t_tool->histogram_box->view, "range-changed",
G_CALLBACK (gimp_threshold_tool_histogram_range),
t_tool);
@ -284,10 +276,12 @@ gimp_threshold_tool_config_notify (GObject *object,
{
GimpThresholdConfig *config = GIMP_THRESHOLD_CONFIG (object);
if (t_tool->histogram_box)
gimp_histogram_view_set_range (t_tool->histogram_box->view,
config->low * 255.999,
config->high * 255.999);
if (! t_tool->histogram_box)
return;
gimp_histogram_view_set_range (t_tool->histogram_box->view,
config->low * 255.999,
config->high * 255.999);
gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (t_tool));
}
@ -318,7 +312,7 @@ gimp_threshold_tool_auto_clicked (GtkWidget *button,
GimpDrawable *drawable = GIMP_IMAGE_MAP_TOOL (t_tool)->drawable;
gdouble low;
low = gimp_histogram_get_threshold (t_tool->hist,
low = gimp_histogram_get_threshold (t_tool->histogram,
gimp_drawable_is_rgb (drawable) ?
GIMP_HISTOGRAM_RGB :
GIMP_HISTOGRAM_VALUE,

View File

@ -42,7 +42,7 @@ struct _GimpThresholdTool
Threshold *threshold;
/* dialog */
GimpHistogram *hist;
GimpHistogram *histogram;
GimpHistogramBox *histogram_box;
};

View File

@ -260,7 +260,7 @@ gimp_histogram_editor_set_image (GimpImageEditor *image_editor,
if (editor->histogram)
{
gimp_histogram_free (editor->histogram);
gimp_histogram_unref (editor->histogram);
editor->histogram = NULL;
gimp_histogram_view_set_histogram (view, NULL);
@ -268,7 +268,7 @@ gimp_histogram_editor_set_image (GimpImageEditor *image_editor,
if (editor->bg_histogram)
{
gimp_histogram_free (editor->bg_histogram);
gimp_histogram_unref (editor->bg_histogram);
editor->bg_histogram = NULL;
gimp_histogram_view_set_background (view, NULL);
@ -313,7 +313,7 @@ gimp_histogram_editor_layer_changed (GimpImage *image,
{
GimpHistogramView *view = GIMP_HISTOGRAM_BOX (editor->box)->view;
gimp_histogram_free (editor->bg_histogram);
gimp_histogram_unref (editor->bg_histogram);
editor->bg_histogram = NULL;
gimp_histogram_view_set_background (view, NULL);
@ -386,7 +386,7 @@ gimp_histogram_editor_frozen_update (GimpHistogramEditor *editor,
}
else if (editor->bg_histogram)
{
gimp_histogram_free (editor->bg_histogram);
gimp_histogram_unref (editor->bg_histogram);
editor->bg_histogram = NULL;
gimp_histogram_view_set_background (view, NULL);

View File

@ -50,6 +50,7 @@ enum
};
static void gimp_histogram_view_finalize (GObject *object);
static void gimp_histogram_view_set_property (GObject *object,
guint property_id,
const GValue *value,
@ -108,6 +109,7 @@ gimp_histogram_view_class_init (GimpHistogramViewClass *klass)
G_TYPE_INT,
G_TYPE_INT);
object_class->finalize = gimp_histogram_view_finalize;
object_class->get_property = gimp_histogram_view_get_property;
object_class->set_property = gimp_histogram_view_set_property;
@ -158,6 +160,26 @@ gimp_histogram_view_init (GimpHistogramView *view)
view->end = 255;
}
static void
gimp_histogram_view_finalize (GObject *object)
{
GimpHistogramView *view = GIMP_HISTOGRAM_VIEW (object);
if (view->histogram)
{
gimp_histogram_unref (view->histogram);
view->histogram = NULL;
}
if (view->bg_histogram)
{
gimp_histogram_unref (view->bg_histogram);
view->bg_histogram = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
gimp_histogram_view_set_property (GObject *object,
guint property_id,
@ -569,10 +591,18 @@ gimp_histogram_view_set_histogram (GimpHistogramView *view,
if (view->histogram != histogram)
{
if (view->histogram)
gimp_histogram_unref (view->histogram);
view->histogram = histogram;
if (histogram && view->channel >= gimp_histogram_n_channels (histogram))
gimp_histogram_view_set_channel (view, GIMP_HISTOGRAM_VALUE);
if (histogram)
{
gimp_histogram_ref (histogram);
if (view->channel >= gimp_histogram_n_channels (histogram))
gimp_histogram_view_set_channel (view, GIMP_HISTOGRAM_VALUE);
}
}
gtk_widget_queue_draw (GTK_WIDGET (view));
@ -600,10 +630,18 @@ gimp_histogram_view_set_background (GimpHistogramView *view,
if (view->bg_histogram != histogram)
{
if (view->bg_histogram)
gimp_histogram_ref (view->bg_histogram);
view->bg_histogram = histogram;
if (histogram && view->channel >= gimp_histogram_n_channels (histogram))
gimp_histogram_view_set_channel (view, GIMP_HISTOGRAM_VALUE);
if (histogram)
{
gimp_histogram_ref (histogram);
if (view->channel >= gimp_histogram_n_channels (histogram))
gimp_histogram_view_set_channel (view, GIMP_HISTOGRAM_VALUE);
}
}
gtk_widget_queue_draw (GTK_WIDGET (view));

View File

@ -595,7 +595,7 @@ HELP
start_range, end_range);
percentile = count / pixels;
gimp_histogram_free (histogram);
gimp_histogram_unref (histogram);
}
}
CODE