[gimp] app: avoid spurious channel switch in histogram editor when switching drawbles



commit eb6f544c1808c7a96aaf014e639a024cfe2c2b94
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.

 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 a5012f6b02..05d7944b5d 100644
--- a/app/core/gimphistogram.c
+++ b/app/core/gimphistogram.c
@@ -167,7 +167,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);
 }
@@ -369,26 +369,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);
 }
 
 
@@ -852,12 +841,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 ae75142962..56a943d490 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 64940bf7b4..656c856854 100644
--- a/app/widgets/gimphistogrameditor.c
+++ b/app/widgets/gimphistogrameditor.c
@@ -507,6 +507,11 @@ gimp_histogram_editor_validate (GimpHistogramEditor *editor)
 
               editor->histogram = gimp_histogram_new (editor->trc);
 
+              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);
             }
 
@@ -525,7 +530,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]