[gimp/gimp-2-10] app: avoid spurious channel switch in histogram editor when switching drawbles



commit 412fa7822bb7ddf53e9bd0dc7462e601aa58b1da
Author: Ell <ell_se yahoo com>
Date:   Tue Oct 22 16:08:25 2019 +0300

    app: avoid spurious channel switch in histogram editor when switching drawbles
    
    Add an n_components parameter to gimp_histogram_clear_values(),
    which allows to set the new component count when clearing the
    histogram.  This is useful to seed the histogram with the correct
    number of channels, for display purposes, before starting an async
    histogram calculation.  We use this in GimpHistogramEditor, to
    avoid resetting the view's channel back to "Value" each time the
    active drawable changes.
    
    (cherry picked from commit eb6f544c1808c7a96aaf014e639a024cfe2c2b94)

 app/core/gimphistogram.c          | 27 ++++++++++-----------------
 app/core/gimphistogram.h          |  3 ++-
 app/widgets/gimphistogrameditor.c |  7 ++++++-
 3 files changed, 18 insertions(+), 19 deletions(-)
---
diff --git a/app/core/gimphistogram.c b/app/core/gimphistogram.c
index 50f49cf683..33747c492b 100644
--- a/app/core/gimphistogram.c
+++ b/app/core/gimphistogram.c
@@ -166,7 +166,7 @@ gimp_histogram_finalize (GObject *object)
 {
   GimpHistogram *histogram = GIMP_HISTOGRAM (object);
 
-  gimp_histogram_clear_values (histogram);
+  gimp_histogram_clear_values (histogram, 0);
 
   G_OBJECT_CLASS (parent_class)->finalize (object);
 }
@@ -368,26 +368,15 @@ gimp_histogram_calculate_async (GimpHistogram       *histogram,
 }
 
 void
-gimp_histogram_clear_values (GimpHistogram *histogram)
+gimp_histogram_clear_values (GimpHistogram *histogram,
+                             gint           n_components)
 {
   g_return_if_fail (GIMP_IS_HISTOGRAM (histogram));
 
   if (histogram->priv->calculate_async)
     gimp_async_cancel_and_wait (histogram->priv->calculate_async);
 
-  if (histogram->priv->values)
-    {
-      g_clear_pointer (&histogram->priv->values, g_free);
-
-      g_object_notify (G_OBJECT (histogram), "values");
-    }
-
-  if (histogram->priv->n_channels)
-    {
-      histogram->priv->n_channels = 0;
-
-      g_object_notify (G_OBJECT (histogram), "n-components");
-    }
+  gimp_histogram_set_values (histogram, n_components, 0, NULL);
 }
 
 
@@ -851,12 +840,16 @@ gimp_histogram_set_values (GimpHistogram *histogram,
                            gdouble       *values)
 {
   GimpHistogramPrivate *priv                = histogram->priv;
+  gint                  n_channels          = n_components;
   gboolean              notify_n_components = FALSE;
   gboolean              notify_n_bins       = FALSE;
 
-  if (n_components + N_DERIVED_CHANNELS != priv->n_channels)
+  if (n_channels > 0)
+    n_channels += N_DERIVED_CHANNELS;
+
+  if (n_channels != priv->n_channels)
     {
-      priv->n_channels = n_components + N_DERIVED_CHANNELS;
+      priv->n_channels = n_channels;
 
       notify_n_components = TRUE;
     }
diff --git a/app/core/gimphistogram.h b/app/core/gimphistogram.h
index 2089d82e4e..ba1e0ef142 100644
--- a/app/core/gimphistogram.h
+++ b/app/core/gimphistogram.h
@@ -65,7 +65,8 @@ GimpAsync     * gimp_histogram_calculate_async (GimpHistogram        *histogram,
                                                 GeglBuffer           *mask,
                                                 const GeglRectangle  *mask_rect);
 
-void            gimp_histogram_clear_values    (GimpHistogram        *histogram);
+void            gimp_histogram_clear_values    (GimpHistogram        *histogram,
+                                                gint                  n_components);
 
 gdouble         gimp_histogram_get_maximum     (GimpHistogram        *histogram,
                                                 GimpHistogramChannel  channel);
diff --git a/app/widgets/gimphistogrameditor.c b/app/widgets/gimphistogrameditor.c
index 0f65f9d1a2..ae21eec5ea 100644
--- a/app/widgets/gimphistogrameditor.c
+++ b/app/widgets/gimphistogrameditor.c
@@ -510,6 +510,11 @@ gimp_histogram_editor_validate (GimpHistogramEditor *editor)
 
               editor->histogram = gimp_histogram_new (editor->linear);
 
+              gimp_histogram_clear_values (
+                editor->histogram,
+                babl_format_get_n_components (
+                  gimp_drawable_get_format (editor->drawable)));
+
               gimp_histogram_view_set_histogram (view, editor->histogram);
             }
 
@@ -528,7 +533,7 @@ gimp_histogram_editor_validate (GimpHistogramEditor *editor)
         }
       else if (editor->histogram)
         {
-          gimp_histogram_clear_values (editor->histogram);
+          gimp_histogram_clear_values (editor->histogram, 0);
 
           gimp_histogram_editor_info_update (editor);
         }


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