[gimp] Issue #1788 - Inconsistency between FG color and selected color in...



commit abd7cbfc8ddc24b0b430cda99c777a91b0531dae
Author: Michael Natterer <mitch gimp org>
Date:   Wed Jan 2 01:45:41 2019 +0100

    Issue #1788 - Inconsistency between FG color and selected color in...
    
    ...palette views despite selected color being in the currently
    selected pallette
    
    As suggested by Massimo, changing the color comparison EPSILON in
    gimppalette.c from 1e-10 to 1e-6 fixes this, and is really small
    enough.
    
    Also, generally clean up color comparison epsilons:
    
    - use a #define, not hardcoded values for all uses of
      gimp_rgb[a]_distance()
    - call the #defines RGB_EPSILON and RGBA_EPSILON
    - make them all 1e-6 or larger

 app/actions/channels-commands.c   | 17 ++++++++++-------
 app/actions/quick-mask-commands.c |  5 ++++-
 app/core/gimpchannel.c            |  4 +++-
 app/core/gimpcontext.c            |  7 ++++---
 app/core/gimppalette.c            | 12 +++++++-----
 app/core/gimppalettemru.c         |  6 ++++--
 app/widgets/gimpcolorframe.c      |  4 +++-
 app/widgets/gimpcolormapeditor.c  |  8 ++++----
 app/widgets/gimpcolorpanel.c      |  4 +++-
 app/widgets/gimpviewrenderer.c    |  4 +++-
 libgimpwidgets/gimpcolorarea.c    |  3 ++-
 11 files changed, 47 insertions(+), 27 deletions(-)
---
diff --git a/app/actions/channels-commands.c b/app/actions/channels-commands.c
index d7ffc1636c..842634cd99 100644
--- a/app/actions/channels-commands.c
+++ b/app/actions/channels-commands.c
@@ -54,6 +54,9 @@
 #include "gimp-intl.h"
 
 
+#define RGBA_EPSILON 1e-6
+
+
 /*  local function prototypes  */
 
 static void   channels_new_callback             (GtkWidget     *dialog,
@@ -504,12 +507,12 @@ channels_edit_attributes_callback (GtkWidget     *dialog,
 {
   GimpItem *item = GIMP_ITEM (channel);
 
-  if (strcmp (channel_name, gimp_object_get_name (channel))        ||
-      gimp_rgba_distance (channel_color, &channel->color) > 0.0001 ||
-      channel_visible       != gimp_item_get_visible (item)        ||
-      channel_linked        != gimp_item_get_linked (item)         ||
-      channel_color_tag     != gimp_item_get_color_tag (item)      ||
-      channel_lock_content  != gimp_item_get_lock_content (item)   ||
+  if (strcmp (channel_name, gimp_object_get_name (channel))              ||
+      gimp_rgba_distance (channel_color, &channel->color) > RGBA_EPSILON ||
+      channel_visible       != gimp_item_get_visible (item)              ||
+      channel_linked        != gimp_item_get_linked (item)               ||
+      channel_color_tag     != gimp_item_get_color_tag (item)            ||
+      channel_lock_content  != gimp_item_get_lock_content (item)         ||
       channel_lock_position != gimp_item_get_lock_position (item))
     {
       gimp_image_undo_group_start (image,
@@ -519,7 +522,7 @@ channels_edit_attributes_callback (GtkWidget     *dialog,
       if (strcmp (channel_name, gimp_object_get_name (channel)))
         gimp_item_rename (GIMP_ITEM (channel), channel_name, NULL);
 
-      if (gimp_rgba_distance (channel_color, &channel->color) > 0.0001)
+      if (gimp_rgba_distance (channel_color, &channel->color) > RGBA_EPSILON)
         gimp_channel_set_color (channel, channel_color, TRUE);
 
       if (channel_visible != gimp_item_get_visible (item))
diff --git a/app/actions/quick-mask-commands.c b/app/actions/quick-mask-commands.c
index 7bf9a9adad..ef3ee25a1e 100644
--- a/app/actions/quick-mask-commands.c
+++ b/app/actions/quick-mask-commands.c
@@ -42,6 +42,9 @@
 #include "gimp-intl.h"
 
 
+#define RGBA_EPSILON 1e-6
+
+
 /*  local function prototypes  */
 
 static void   quick_mask_configure_callback (GtkWidget     *dialog,
@@ -167,7 +170,7 @@ quick_mask_configure_callback (GtkWidget     *dialog,
 
   gimp_image_get_quick_mask_color (image, &old_color);
 
-  if (gimp_rgba_distance (&old_color, channel_color) > 0.0001)
+  if (gimp_rgba_distance (&old_color, channel_color) > RGBA_EPSILON)
     {
       gimp_image_set_quick_mask_color (image, channel_color);
       gimp_image_flush (image);
diff --git a/app/core/gimpchannel.c b/app/core/gimpchannel.c
index a4af92e760..42db772027 100644
--- a/app/core/gimpchannel.c
+++ b/app/core/gimpchannel.c
@@ -60,6 +60,8 @@
 #include "gimp-intl.h"
 
 
+#define RGBA_EPSILON 1e-6
+
 enum
 {
   COLOR_CHANGED,
@@ -1698,7 +1700,7 @@ gimp_channel_set_color (GimpChannel   *channel,
   g_return_if_fail (GIMP_IS_CHANNEL (channel));
   g_return_if_fail (color != NULL);
 
-  if (gimp_rgba_distance (&channel->color, color) > 0.0001)
+  if (gimp_rgba_distance (&channel->color, color) > RGBA_EPSILON)
     {
       if (push_undo && gimp_item_is_attached (GIMP_ITEM (channel)))
         {
diff --git a/app/core/gimpcontext.c b/app/core/gimpcontext.c
index ff43700f65..37885835af 100644
--- a/app/core/gimpcontext.c
+++ b/app/core/gimpcontext.c
@@ -57,10 +57,11 @@
 #include "gimp-intl.h"
 
 
+#define RGBA_EPSILON 1e-10
+
 typedef void (* GimpContextCopyPropFunc) (GimpContext *src,
                                           GimpContext *dest);
 
-
 #define context_find_defined(context, prop)                              \
   while (!(((context)->defined_props) & (1 << (prop))) && (context)->parent) \
     (context) = (context)->parent
@@ -2319,7 +2320,7 @@ static void
 gimp_context_real_set_foreground (GimpContext   *context,
                                   const GimpRGB *color)
 {
-  if (gimp_rgba_distance (&context->foreground, color) < 0.0001)
+  if (gimp_rgba_distance (&context->foreground, color) < RGBA_EPSILON)
     return;
 
   context->foreground = *color;
@@ -2370,7 +2371,7 @@ static void
 gimp_context_real_set_background (GimpContext   *context,
                                   const GimpRGB *color)
 {
-  if (gimp_rgba_distance (&context->background, color) < 0.0001)
+  if (gimp_rgba_distance (&context->background, color) < RGBA_EPSILON)
     return;
 
   context->background = *color;
diff --git a/app/core/gimppalette.c b/app/core/gimppalette.c
index 335bda6f7c..f5b848ca41 100644
--- a/app/core/gimppalette.c
+++ b/app/core/gimppalette.c
@@ -37,7 +37,9 @@
 
 #include "gimp-intl.h"
 
-#define EPSILON 1e-10
+
+#define RGB_EPSILON 1e-6
+
 
 /*  local function prototypes  */
 
@@ -648,11 +650,11 @@ gimp_palette_find_entry (GimpPalette      *palette,
       for (list = palette->colors; list; list = g_list_next (list))
         {
           entry = (GimpPaletteEntry *) list->data;
-          if (gimp_rgb_distance (&entry->color, color) < EPSILON)
+          if (gimp_rgb_distance (&entry->color, color) < RGB_EPSILON)
             return entry;
         }
     }
-  else if (gimp_rgb_distance (&start_from->color, color) < EPSILON)
+  else if (gimp_rgb_distance (&start_from->color, color) < RGB_EPSILON)
     {
       return start_from;
     }
@@ -674,7 +676,7 @@ gimp_palette_find_entry (GimpPalette      *palette,
           if (next)
             {
               entry = (GimpPaletteEntry *) next->data;
-              if (gimp_rgb_distance (&entry->color, color) < EPSILON)
+              if (gimp_rgb_distance (&entry->color, color) < RGB_EPSILON)
                 return entry;
 
               next = next->next;
@@ -683,7 +685,7 @@ gimp_palette_find_entry (GimpPalette      *palette,
           if (prev)
             {
               entry = (GimpPaletteEntry *) prev->data;
-              if (gimp_rgb_distance (&entry->color, color) < EPSILON)
+              if (gimp_rgb_distance (&entry->color, color) < RGB_EPSILON)
                 return entry;
 
               prev = prev->prev;
diff --git a/app/core/gimppalettemru.c b/app/core/gimppalettemru.c
index 7d34e157b4..fb1157d3c0 100644
--- a/app/core/gimppalettemru.c
+++ b/app/core/gimppalettemru.c
@@ -34,6 +34,8 @@
 #include "gimp-intl.h"
 
 
+#define RGBA_EPSILON 1e-4
+
 enum
 {
   COLOR_HISTORY = 1
@@ -205,7 +207,7 @@ gimp_palette_mru_add (GimpPaletteMru *mru,
     {
       GimpPaletteEntry *entry = list->data;
 
-      if (gimp_rgba_distance (&entry->color, color) < 0.0001)
+      if (gimp_rgba_distance (&entry->color, color) < RGBA_EPSILON)
         {
           found = entry;
 
@@ -228,7 +230,7 @@ gimp_palette_mru_add (GimpPaletteMru *mru,
               GimpPaletteEntry *entry2 = list2->data;
 
               if (gimp_rgba_distance (&entry->color,
-                                      &entry2->color) < 0.0001)
+                                      &entry2->color) < RGBA_EPSILON)
                 {
                   found = entry2;
 
diff --git a/app/widgets/gimpcolorframe.c b/app/widgets/gimpcolorframe.c
index 04c513e1d9..eaddd54306 100644
--- a/app/widgets/gimpcolorframe.c
+++ b/app/widgets/gimpcolorframe.c
@@ -36,6 +36,8 @@
 #include "gimp-intl.h"
 
 
+#define RGBA_EPSILON 1e-6
+
 enum
 {
   PROP_0,
@@ -566,7 +568,7 @@ gimp_color_frame_set_color (GimpColorFrame *frame,
       frame->sample_format  == sample_format  &&
       frame->x              == x              &&
       frame->y              == y              &&
-      gimp_rgba_distance (&frame->color, color) < 0.0001)
+      gimp_rgba_distance (&frame->color, color) < RGBA_EPSILON)
     {
       frame->color = *color;
       return;
diff --git a/app/widgets/gimpcolormapeditor.c b/app/widgets/gimpcolormapeditor.c
index a4ace88345..834c18046b 100644
--- a/app/widgets/gimpcolormapeditor.c
+++ b/app/widgets/gimpcolormapeditor.c
@@ -48,8 +48,8 @@
 #include "gimp-intl.h"
 
 
-#define BORDER  6
-#define EPSILON 1e-10
+#define BORDER      6
+#define RGB_EPSILON 1e-6
 
 #define HAVE_COLORMAP(image) \
         (image != NULL && \
@@ -458,7 +458,7 @@ gimp_colormap_editor_get_index (GimpColormapEditor *editor,
 
       gimp_image_get_colormap_entry (image, index, &temp);
 
-      if (gimp_rgb_distance (&temp, search) > EPSILON)
+      if (gimp_rgb_distance (&temp, search) > RGB_EPSILON)
         {
           gint n_colors = gimp_image_get_colormap_size (image);
           gint i;
@@ -467,7 +467,7 @@ gimp_colormap_editor_get_index (GimpColormapEditor *editor,
             {
               gimp_image_get_colormap_entry (image, i, &temp);
 
-              if (gimp_rgb_distance (&temp, search) < EPSILON)
+              if (gimp_rgb_distance (&temp, search) < RGB_EPSILON)
                 {
                   index = i;
                   break;
diff --git a/app/widgets/gimpcolorpanel.c b/app/widgets/gimpcolorpanel.c
index 2cc6c27605..4bf15b20fd 100644
--- a/app/widgets/gimpcolorpanel.c
+++ b/app/widgets/gimpcolorpanel.c
@@ -36,6 +36,8 @@
 #include "gimpcolorpanel.h"
 
 
+#define RGBA_EPSILON 1e-6
+
 enum
 {
   RESPONSE,
@@ -255,7 +257,7 @@ gimp_color_panel_color_changed (GimpColorButton *button)
       gimp_color_dialog_get_color (GIMP_COLOR_DIALOG (panel->color_dialog),
                                    &dialog_color);
 
-      if (gimp_rgba_distance (&color, &dialog_color) > 0.00001 ||
+      if (gimp_rgba_distance (&color, &dialog_color) > RGBA_EPSILON ||
           color.a != dialog_color.a)
         {
           gimp_color_dialog_set_color (GIMP_COLOR_DIALOG (panel->color_dialog),
diff --git a/app/widgets/gimpviewrenderer.c b/app/widgets/gimpviewrenderer.c
index ee3fc059bf..d67ea05b25 100644
--- a/app/widgets/gimpviewrenderer.c
+++ b/app/widgets/gimpviewrenderer.c
@@ -53,6 +53,8 @@
 #include "gimp-priorities.h"
 
 
+#define RGB_EPSILON 1e-6
+
 enum
 {
   UPDATE,
@@ -502,7 +504,7 @@ gimp_view_renderer_set_border_color (GimpViewRenderer *renderer,
   g_return_if_fail (GIMP_IS_VIEW_RENDERER (renderer));
   g_return_if_fail (color != NULL);
 
-  if (gimp_rgb_distance (&renderer->border_color, color))
+  if (gimp_rgb_distance (&renderer->border_color, color) > RGB_EPSILON)
     {
       renderer->border_color = *color;
 
diff --git a/libgimpwidgets/gimpcolorarea.c b/libgimpwidgets/gimpcolorarea.c
index 062be74f0c..d0acf3dcfd 100644
--- a/libgimpwidgets/gimpcolorarea.c
+++ b/libgimpwidgets/gimpcolorarea.c
@@ -45,6 +45,7 @@
  **/
 
 
+#define RGBA_EPSILON        1e-6
 #define DRAG_PREVIEW_SIZE   32
 #define DRAG_ICON_OFFSET    -8
 
@@ -535,7 +536,7 @@ gimp_color_area_set_color (GimpColorArea *area,
 
   priv = GET_PRIVATE (area);
 
-  if (gimp_rgba_distance (&priv->color, color) < 0.000001)
+  if (gimp_rgba_distance (&priv->color, color) < RGBA_EPSILON)
     return;
 
   priv->color = *color;


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