[gimp/goat-invasion: 495/526] app: add gimp_histogram_clear_values() and use it



commit 6498e39ede185b2c383d4075e4e84e9f2c9a201b
Author: Michael Natterer <mitch gimp org>
Date:   Sun Apr 15 19:09:35 2012 +0200

    app: add gimp_histogram_clear_values() and use it
    
    instead of abusing gimp_histogram_calculate() with a NULL region for
    that purpose; calculate() is about to go away.

 app/core/gimphistogram.c          |   44 ++++++++++++++++--------------------
 app/core/gimphistogram.h          |    2 +
 app/widgets/gimphistogrameditor.c |    2 +-
 3 files changed, 23 insertions(+), 25 deletions(-)
---
diff --git a/app/core/gimphistogram.c b/app/core/gimphistogram.c
index da5c913..0133378 100644
--- a/app/core/gimphistogram.c
+++ b/app/core/gimphistogram.c
@@ -57,7 +57,6 @@ struct _GimpHistogram
 
 static void  gimp_histogram_alloc_values         (GimpHistogram *histogram,
                                                   gint           bytes);
-static void  gimp_histogram_free_values          (GimpHistogram *histogram);
 static void  gimp_histogram_calculate_sub_region (GimpHistogram *histogram,
                                                   PixelRegion   *region,
                                                   PixelRegion   *mask);
@@ -98,7 +97,7 @@ gimp_histogram_unref (GimpHistogram *histogram)
 
   if (histogram->ref_count == 0)
     {
-      gimp_histogram_free_values (histogram);
+      gimp_histogram_clear_values (histogram);
       g_slice_free (GimpHistogram, histogram);
     }
 }
@@ -144,12 +143,7 @@ gimp_histogram_calculate (GimpHistogram *histogram,
   gint i;
 
   g_return_if_fail (histogram != NULL);
-
-  if (! region)
-    {
-      gimp_histogram_free_values (histogram);
-      return;
-    }
+  g_return_if_fail (region != NULL);
 
   gimp_histogram_alloc_values (histogram, region->bytes);
 
@@ -175,6 +169,23 @@ gimp_histogram_calculate (GimpHistogram *histogram,
 #endif
 }
 
+void
+gimp_histogram_clear_values (GimpHistogram *histogram)
+{
+  gint i;
+
+  g_return_if_fail (histogram != NULL);
+
+  for (i = 0; i < NUM_SLOTS; i++)
+    if (histogram->values[i])
+      {
+        g_free (histogram->values[i]);
+        histogram->values[i] = NULL;
+      }
+
+  histogram->n_channels = 0;
+}
+
 
 #define HISTOGRAM_VALUE(c,i) (histogram->values[0][(c) * 256 + (i)])
 
@@ -550,7 +561,7 @@ gimp_histogram_alloc_values (GimpHistogram *histogram,
 {
   if (bytes + 1 != histogram->n_channels)
     {
-      gimp_histogram_free_values (histogram);
+      gimp_histogram_clear_values (histogram);
 
       histogram->n_channels = bytes + 1;
 
@@ -559,21 +570,6 @@ gimp_histogram_alloc_values (GimpHistogram *histogram,
 }
 
 static void
-gimp_histogram_free_values (GimpHistogram *histogram)
-{
-  gint i;
-
-  for (i = 0; i < NUM_SLOTS; i++)
-    if (histogram->values[i])
-      {
-        g_free (histogram->values[i]);
-        histogram->values[i] = NULL;
-      }
-
-  histogram->n_channels = 0;
-}
-
-static void
 gimp_histogram_calculate_sub_region (GimpHistogram *histogram,
                                      PixelRegion   *region,
                                      PixelRegion   *mask)
diff --git a/app/core/gimphistogram.h b/app/core/gimphistogram.h
index 57ff200..2174122 100644
--- a/app/core/gimphistogram.h
+++ b/app/core/gimphistogram.h
@@ -32,6 +32,8 @@ void            gimp_histogram_calculate     (GimpHistogram        *histogram,
                                               PixelRegion          *region,
                                               PixelRegion          *mask);
 
+void            gimp_histogram_clear_values  (GimpHistogram        *histogram);
+
 gdouble         gimp_histogram_get_maximum   (GimpHistogram        *histogram,
                                               GimpHistogramChannel  channel);
 gdouble         gimp_histogram_get_count     (GimpHistogram        *histogram,
diff --git a/app/widgets/gimphistogrameditor.c b/app/widgets/gimphistogrameditor.c
index 1ab9dee..1657d22 100644
--- a/app/widgets/gimphistogrameditor.c
+++ b/app/widgets/gimphistogrameditor.c
@@ -372,7 +372,7 @@ gimp_histogram_editor_validate (GimpHistogramEditor *editor)
       if (editor->drawable)
         gimp_drawable_calculate_histogram (editor->drawable, editor->histogram);
       else
-        gimp_histogram_calculate (editor->histogram, NULL, NULL);
+        gimp_histogram_clear_values (editor->histogram);
 
       gimp_histogram_editor_info_update (editor);
 



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