gimp r24792 - in trunk: . app/base app/core app/pdb app/tools app/widgets tools/pdbgen/pdb



Author: mitch
Date: Mon Feb  4 21:41:57 2008
New Revision: 24792
URL: http://svn.gnome.org/viewvc/gimp?rev=24792&view=rev

Log:
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.



Modified:
   trunk/ChangeLog
   trunk/app/base/gimphistogram.c
   trunk/app/base/gimphistogram.h
   trunk/app/core/gimpdrawable-equalize.c
   trunk/app/core/gimpdrawable-levels.c
   trunk/app/pdb/color_cmds.c
   trunk/app/tools/gimpcurvestool.c
   trunk/app/tools/gimpcurvestool.h
   trunk/app/tools/gimplevelstool.c
   trunk/app/tools/gimplevelstool.h
   trunk/app/tools/gimpthresholdtool.c
   trunk/app/tools/gimpthresholdtool.h
   trunk/app/widgets/gimphistogrameditor.c
   trunk/app/widgets/gimphistogramview.c
   trunk/tools/pdbgen/pdb/color.pdb

Modified: trunk/app/base/gimphistogram.c
==============================================================================
--- trunk/app/base/gimphistogram.c	(original)
+++ trunk/app/base/gimphistogram.c	Mon Feb  4 21:41:57 2008
@@ -42,6 +42,7 @@
 
 struct _GimpHistogram
 {
+  gint           ref_count;
   gint           n_channels;
 #ifdef ENABLE_MP
   GStaticMutex   mutex;
@@ -68,6 +69,8 @@
 {
   GimpHistogram *histogram = g_slice_new0 (GimpHistogram);
 
+  histogram->ref_count = 1;
+
 #ifdef ENABLE_MP
   g_static_mutex_init (&histogram->mutex);
 #endif
@@ -75,13 +78,28 @@
   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

Modified: trunk/app/base/gimphistogram.h
==============================================================================
--- trunk/app/base/gimphistogram.h	(original)
+++ trunk/app/base/gimphistogram.h	Mon Feb  4 21:41:57 2008
@@ -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,

Modified: trunk/app/core/gimpdrawable-equalize.c
==============================================================================
--- trunk/app/core/gimpdrawable-equalize.c	(original)
+++ trunk/app/core/gimpdrawable-equalize.c	Mon Feb  4 21:41:57 2008
@@ -72,7 +72,7 @@
                                   lut, 2, &srcPR, &destPR);
 
   gimp_lut_free (lut);
-  gimp_histogram_free (hist);
+  gimp_histogram_unref (hist);
 
   gimp_drawable_merge_shadow (drawable, TRUE, _("Equalize"));
 

Modified: trunk/app/core/gimpdrawable-levels.c
==============================================================================
--- trunk/app/core/gimpdrawable-levels.c	(original)
+++ trunk/app/core/gimpdrawable-levels.c	Mon Feb  4 21:41:57 2008
@@ -166,7 +166,7 @@
   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))
     {

Modified: trunk/app/pdb/color_cmds.c
==============================================================================
--- trunk/app/pdb/color_cmds.c	(original)
+++ trunk/app/pdb/color_cmds.c	Mon Feb  4 21:41:57 2008
@@ -513,7 +513,7 @@
                                                  start_range, end_range);
           percentile = count / pixels;
 
-          gimp_histogram_free (histogram);
+          gimp_histogram_unref (histogram);
         }
     }
 

Modified: trunk/app/tools/gimpcurvestool.c
==============================================================================
--- trunk/app/tools/gimpcurvestool.c	(original)
+++ trunk/app/tools/gimpcurvestool.c	Mon Feb  4 21:41:57 2008
@@ -192,12 +192,6 @@
 
   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 @@
 {
   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_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_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;
 }

Modified: trunk/app/tools/gimpcurvestool.h
==============================================================================
--- trunk/app/tools/gimpcurvestool.h	(original)
+++ trunk/app/tools/gimpcurvestool.h	Mon Feb  4 21:41:57 2008
@@ -41,8 +41,6 @@
   GimpLut              *lut;
 
   /* dialog */
-  GimpHistogram        *hist;
-
   gint                  col_value[5];
 
   GtkWidget            *channel_menu;

Modified: trunk/app/tools/gimplevelstool.c
==============================================================================
--- trunk/app/tools/gimplevelstool.c	(original)
+++ trunk/app/tools/gimplevelstool.c	Mon Feb  4 21:41:57 2008
@@ -177,7 +177,7 @@
   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_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_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_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 @@
   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 @@
 
   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 @@
 {
   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));
 }
 

Modified: trunk/app/tools/gimplevelstool.h
==============================================================================
--- trunk/app/tools/gimplevelstool.h	(original)
+++ trunk/app/tools/gimplevelstool.h	Mon Feb  4 21:41:57 2008
@@ -42,11 +42,11 @@
   GimpLut              *lut;
 
   /* dialog */
-  GimpHistogram        *hist;
+  GimpHistogram        *histogram;
 
   GtkWidget            *channel_menu;
 
-  GtkWidget            *hist_view;
+  GtkWidget            *histogram_view;
 
   GtkWidget            *input_bar;
   GtkWidget            *input_sliders;

Modified: trunk/app/tools/gimpthresholdtool.c
==============================================================================
--- trunk/app/tools/gimpthresholdtool.c	(original)
+++ trunk/app/tools/gimpthresholdtool.c	Mon Feb  4 21:41:57 2008
@@ -119,7 +119,7 @@
   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 @@
 
   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_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 @@
 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 @@
 
   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 @@
 {
   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 @@
   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,

Modified: trunk/app/tools/gimpthresholdtool.h
==============================================================================
--- trunk/app/tools/gimpthresholdtool.h	(original)
+++ trunk/app/tools/gimpthresholdtool.h	Mon Feb  4 21:41:57 2008
@@ -42,7 +42,7 @@
   Threshold           *threshold;
 
   /*  dialog  */
-  GimpHistogram       *hist;
+  GimpHistogram       *histogram;
   GimpHistogramBox    *histogram_box;
 };
 

Modified: trunk/app/widgets/gimphistogrameditor.c
==============================================================================
--- trunk/app/widgets/gimphistogrameditor.c	(original)
+++ trunk/app/widgets/gimphistogrameditor.c	Mon Feb  4 21:41:57 2008
@@ -260,7 +260,7 @@
 
       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 @@
 
       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 @@
         {
           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 @@
     }
   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);

Modified: trunk/app/widgets/gimphistogramview.c
==============================================================================
--- trunk/app/widgets/gimphistogramview.c	(original)
+++ trunk/app/widgets/gimphistogramview.c	Mon Feb  4 21:41:57 2008
@@ -50,6 +50,7 @@
 };
 
 
+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 @@
                   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;
 
@@ -159,6 +161,26 @@
 }
 
 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,
                                   const GValue *value,
@@ -569,10 +591,18 @@
 
   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 @@
 
   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));

Modified: trunk/tools/pdbgen/pdb/color.pdb
==============================================================================
--- trunk/tools/pdbgen/pdb/color.pdb	(original)
+++ trunk/tools/pdbgen/pdb/color.pdb	Mon Feb  4 21:41:57 2008
@@ -595,7 +595,7 @@
                                              start_range, end_range);
       percentile = count / pixels;
 
-      gimp_histogram_free (histogram);
+      gimp_histogram_unref (histogram);
     }
 }
 CODE



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