[gnome-builder/wip/slaf/colorpicker] gstyle-plane: fix hue with saturation == 0



commit 155d64a349dea31d14855c57e6b02756fc21781e
Author: Sebastien Lafargue <slafargue gnome org>
Date:   Thu Jul 14 19:07:08 2016 +0200

    gstyle-plane: fix hue with saturation == 0
    
    In hsv formula, when saturation == 0, we also set
    hue to 0 but in the plane hue adjustment, we need to
    keep track of the previous value.

 contrib/gstyle/gstyle-color-plane.c |   23 ++++++++++++++++++++++-
 1 files changed, 22 insertions(+), 1 deletions(-)
---
diff --git a/contrib/gstyle/gstyle-color-plane.c b/contrib/gstyle/gstyle-color-plane.c
index 93a0bc3..c47ca96 100644
--- a/contrib/gstyle/gstyle-color-plane.c
+++ b/contrib/gstyle/gstyle-color-plane.c
@@ -90,6 +90,9 @@ typedef struct
   Component               comp [N_GSTYLE_COLOR_COMPONENT];
   GstyleColorComponent    ref_comp;
   GstyleColorUnit         preferred_unit;
+  gdouble                 hue_backup;
+
+  guint                   hue_backup_set : 1;
 } GstyleColorPlanePrivate;
 
 G_DEFINE_TYPE_WITH_PRIVATE (GstyleColorPlane, gstyle_color_plane, GTK_TYPE_DRAWING_AREA)
@@ -844,6 +847,7 @@ update_adjustments (GstyleColorPlane     *self,
 {
   GstyleColorPlanePrivate *priv = gstyle_color_plane_get_instance_private (self);
   gdouble hue, saturation, value;
+  gdouble current_hue;
   GstyleCielab lab;
   ColorSpaceId color_space;
   GdkRGBA rgba = {0};
@@ -872,8 +876,25 @@ update_adjustments (GstyleColorPlane     *self,
 
       if (color_space != COLOR_SPACE_HSV)
         {
+          current_hue = priv->comp [GSTYLE_COLOR_COMPONENT_HSV_H].val;
           gstyle_color_convert_xyz_to_hsv (xyz, &hue, &saturation, &value);
-          priv->comp [GSTYLE_COLOR_COMPONENT_HSV_H].val = hue * priv->comp 
[GSTYLE_COLOR_COMPONENT_HSV_H].factor;
+          if (saturation > 1e-6)
+            {
+              if (priv->hue_backup_set)
+                {
+                  priv->comp [GSTYLE_COLOR_COMPONENT_HSV_H].val = priv->hue_backup;
+                  priv->hue_backup_set = FALSE;
+                }
+              else
+                priv->comp [GSTYLE_COLOR_COMPONENT_HSV_H].val = hue * priv->comp 
[GSTYLE_COLOR_COMPONENT_HSV_H].factor;
+            }
+          else if (!priv->hue_backup_set)
+            {
+              priv->hue_backup = current_hue;
+              priv->hue_backup_set = TRUE;
+              priv->comp [GSTYLE_COLOR_COMPONENT_HSV_H].val = hue;
+            }
+
           priv->comp [GSTYLE_COLOR_COMPONENT_HSV_S].val = saturation * priv->comp 
[GSTYLE_COLOR_COMPONENT_HSV_S].factor;
           priv->comp [GSTYLE_COLOR_COMPONENT_HSV_V].val = value * priv->comp 
[GSTYLE_COLOR_COMPONENT_HSV_V].factor;
         }


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