[gimp/gimp-2-10] app: add support for color picking in "show all" mode



commit 5e59e5c0025f6034a0537201e29bd39743bcfb11
Author: Ell <ell_se yahoo com>
Date:   Wed Sep 4 18:10:24 2019 +0300

    app: add support for color picking in "show all" mode
    
    Add a show_all parameter to gimp_image_pick_color(), which, when
    TRUE, allows picking colors outside the canvas bounds in sample-
    merged mode.  Forward the display's "show all" mode through this
    parameter where applicable (in particular, in the color-picker tool
    and the pointer dockable).

 app/core/gimpimage-pick-color.c      | 48 +++++++++++++++++++++++++++++++++---
 app/core/gimpimage-pick-color.h      |  1 +
 app/core/gimpimage.c                 |  9 ++++---
 app/core/gimpimage.h                 |  1 +
 app/display/gimpcursorview.c         |  1 +
 app/pdb/image-cmds.c                 |  1 +
 app/tools/gimpbucketfilltool.c       |  9 ++++---
 app/tools/gimpcolortool.c            | 10 +++++---
 app/tools/gimpperspectiveclonetool.c |  2 +-
 app/tools/gimpregionselecttool.c     |  3 ++-
 app/tools/gimptexttool.c             |  2 +-
 app/widgets/gimpsamplepointeditor.c  |  1 +
 app/widgets/gimpselectioneditor.c    |  2 +-
 pdb/groups/image.pdb                 |  1 +
 14 files changed, 74 insertions(+), 17 deletions(-)
---
diff --git a/app/core/gimpimage-pick-color.c b/app/core/gimpimage-pick-color.c
index 3154712f1b..f8168cb39a 100644
--- a/app/core/gimpimage-pick-color.c
+++ b/app/core/gimpimage-pick-color.c
@@ -20,8 +20,12 @@
 #include <gdk-pixbuf/gdk-pixbuf.h>
 #include <gegl.h>
 
+#include "libgimpmath/gimpmath.h"
+
 #include "core-types.h"
 
+#include "gegl/gimp-gegl-loops.h"
+
 #include "gimpchannel.h"
 #include "gimpdrawable.h"
 #include "gimpimage.h"
@@ -35,6 +39,7 @@ gimp_image_pick_color (GimpImage     *image,
                        GimpDrawable  *drawable,
                        gint           x,
                        gint           y,
+                       gboolean       show_all,
                        gboolean       sample_merged,
                        gboolean       sample_average,
                        gdouble        average_radius,
@@ -43,6 +48,7 @@ gimp_image_pick_color (GimpImage     *image,
                        GimpRGB       *color)
 {
   GimpPickable *pickable;
+  gboolean      result;
 
   g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
   g_return_val_if_fail (drawable == NULL || GIMP_IS_DRAWABLE (drawable), FALSE);
@@ -80,7 +86,10 @@ gimp_image_pick_color (GimpImage     *image,
 
   if (sample_merged)
     {
-      pickable = GIMP_PICKABLE (image);
+      if (! show_all)
+        pickable = GIMP_PICKABLE (image);
+      else
+        pickable = GIMP_PICKABLE (gimp_image_get_projection (image));
     }
   else
     {
@@ -101,7 +110,38 @@ gimp_image_pick_color (GimpImage     *image,
   if (sample_format)
     *sample_format = gimp_pickable_get_format (pickable);
 
-  return gimp_pickable_pick_color (pickable, x, y,
-                                   sample_average, average_radius,
-                                   pixel, color);
+  result = gimp_pickable_pick_color (pickable, x, y,
+                                     sample_average &&
+                                     ! (show_all && sample_merged),
+                                     average_radius,
+                                     pixel, color);
+
+  if (show_all && sample_merged)
+    {
+      const Babl *format    = babl_format ("RaGaBaA double");
+      gdouble     sample[4] = {};
+
+      if (! result)
+        memset (pixel, 0, babl_format_get_bytes_per_pixel (*sample_format));
+
+      if (sample_average)
+        {
+          GeglBuffer *buffer = gimp_pickable_get_buffer (pickable);
+          gint        radius = floor (average_radius);
+
+          gimp_gegl_average_color (buffer,
+                                   GEGL_RECTANGLE (x - radius,
+                                                   y - radius,
+                                                   2 * radius + 1,
+                                                   2 * radius + 1),
+                                   FALSE, GEGL_ABYSS_NONE, format, sample);
+        }
+
+      if (! result || sample_average)
+        gimp_pickable_pixel_to_srgb (pickable, format, sample, color);
+
+      result = TRUE;
+    }
+
+  return result;
 }
diff --git a/app/core/gimpimage-pick-color.h b/app/core/gimpimage-pick-color.h
index f0c33a92cb..1ca2947125 100644
--- a/app/core/gimpimage-pick-color.h
+++ b/app/core/gimpimage-pick-color.h
@@ -23,6 +23,7 @@ gboolean   gimp_image_pick_color (GimpImage     *image,
                                   GimpDrawable  *drawable,
                                   gint           x,
                                   gint           y,
+                                  gboolean       show_all,
                                   gboolean       sample_merged,
                                   gboolean       sample_average,
                                   gdouble        average_radius,
diff --git a/app/core/gimpimage.c b/app/core/gimpimage.c
index 4a6b65679e..db7a584c4d 100644
--- a/app/core/gimpimage.c
+++ b/app/core/gimpimage.c
@@ -4979,6 +4979,7 @@ gimp_image_remove_vectors (GimpImage   *image,
 gboolean
 gimp_image_coords_in_active_pickable (GimpImage        *image,
                                       const GimpCoords *coords,
+                                      gboolean          show_all,
                                       gboolean          sample_merged,
                                       gboolean          selected_only)
 {
@@ -4992,9 +4993,11 @@ gimp_image_coords_in_active_pickable (GimpImage        *image,
 
   if (sample_merged)
     {
-      if (x >= 0 && x < gimp_image_get_width  (image) &&
-          y >= 0 && y < gimp_image_get_height (image))
-        in_pickable = TRUE;
+      if (show_all || (x >= 0 && x < gimp_image_get_width  (image) &&
+                       y >= 0 && y < gimp_image_get_height (image)))
+        {
+          in_pickable = TRUE;
+        }
     }
   else
     {
diff --git a/app/core/gimpimage.h b/app/core/gimpimage.h
index 38852aeae5..526edf5805 100644
--- a/app/core/gimpimage.h
+++ b/app/core/gimpimage.h
@@ -447,6 +447,7 @@ void            gimp_image_remove_vectors        (GimpImage          *image,
 
 gboolean    gimp_image_coords_in_active_pickable (GimpImage          *image,
                                                   const GimpCoords   *coords,
+                                                  gboolean            show_all,
                                                   gboolean            sample_merged,
                                                   gboolean            selected_only);
 
diff --git a/app/display/gimpcursorview.c b/app/display/gimpcursorview.c
index 92628f286b..06d4ca688c 100644
--- a/app/display/gimpcursorview.c
+++ b/app/display/gimpcursorview.c
@@ -763,6 +763,7 @@ gimp_cursor_view_cursor_idle (GimpCursorView *view)
 
       if (gimp_image_pick_color (image, NULL,
                                  int_x, int_y,
+                                 view->priv->shell->show_all,
                                  view->priv->sample_merged,
                                  FALSE, 0.0,
                                  &sample_format, pixel, &color))
diff --git a/app/pdb/image-cmds.c b/app/pdb/image-cmds.c
index 9a6bdf680b..4b0af1427b 100644
--- a/app/pdb/image-cmds.c
+++ b/app/pdb/image-cmds.c
@@ -737,6 +737,7 @@ image_pick_color_invoker (GimpProcedure         *procedure,
           success = gimp_image_pick_color (image,
                                            drawable,
                                            (gint) x, (gint) y,
+                                           FALSE,
                                            sample_merged,
                                            sample_average,
                                            average_radius,
diff --git a/app/tools/gimpbucketfilltool.c b/app/tools/gimpbucketfilltool.c
index 6a57ce1f65..2c9fa166e5 100644
--- a/app/tools/gimpbucketfilltool.c
+++ b/app/tools/gimpbucketfilltool.c
@@ -521,7 +521,8 @@ gimp_bucket_fill_tool_button_press (GimpTool            *tool,
                    options->line_art_source == GIMP_LINE_ART_SOURCE_SAMPLE_MERGED :
                    options->sample_merged);
   if (press_type == GIMP_BUTTON_PRESS_NORMAL &&
-      gimp_image_coords_in_active_pickable (image, coords, sample_merged, TRUE))
+      gimp_image_coords_in_active_pickable (image, coords,
+                                            FALSE, sample_merged, TRUE))
     {
       GimpContext     *context  = GIMP_CONTEXT (options);
       GimpFillOptions *fill_options;
@@ -588,7 +589,8 @@ gimp_bucket_fill_tool_motion (GimpTool         *tool,
   sample_merged = (options->fill_area == GIMP_BUCKET_FILL_LINE_ART ?
                    options->line_art_source == GIMP_LINE_ART_SOURCE_SAMPLE_MERGED :
                    options->sample_merged);
-  if (gimp_image_coords_in_active_pickable (image, coords, sample_merged, TRUE) &&
+  if (gimp_image_coords_in_active_pickable (image, coords,
+                                            FALSE, sample_merged, TRUE) &&
       /* Fill selection only needs to happen once. */
       options->fill_area != GIMP_BUCKET_FILL_SELECTION)
     {
@@ -770,7 +772,8 @@ gimp_bucket_fill_tool_cursor_update (GimpTool         *tool,
   sample_merged = (options->fill_area == GIMP_BUCKET_FILL_LINE_ART ?
                    options->line_art_source == GIMP_LINE_ART_SOURCE_SAMPLE_MERGED :
                    options->sample_merged);
-  if (gimp_image_coords_in_active_pickable (image, coords, sample_merged, TRUE))
+  if (gimp_image_coords_in_active_pickable (image, coords,
+                                            FALSE, sample_merged, TRUE))
     {
       GimpDrawable *drawable = gimp_image_get_active_drawable (image);
 
diff --git a/app/tools/gimpcolortool.c b/app/tools/gimpcolortool.c
index 567efaa45e..3f7fa4b315 100644
--- a/app/tools/gimpcolortool.c
+++ b/app/tools/gimpcolortool.c
@@ -443,9 +443,11 @@ gimp_color_tool_real_can_pick (GimpColorTool    *color_tool,
                                const GimpCoords *coords,
                                GimpDisplay      *display)
 {
-  GimpImage *image = gimp_display_get_image (display);
+  GimpDisplayShell *shell = gimp_display_get_shell (display);
+  GimpImage        *image = gimp_display_get_image (display);
 
   return gimp_image_coords_in_active_pickable (image, coords,
+                                               shell->show_all,
                                                color_tool->options->sample_merged,
                                                FALSE);
 }
@@ -458,13 +460,15 @@ gimp_color_tool_real_pick (GimpColorTool     *color_tool,
                            gpointer           pixel,
                            GimpRGB           *color)
 {
-  GimpImage    *image    = gimp_display_get_image (display);
-  GimpDrawable *drawable = gimp_image_get_active_drawable (image);
+  GimpDisplayShell *shell    = gimp_display_get_shell (display);
+  GimpImage        *image    = gimp_display_get_image (display);
+  GimpDrawable     *drawable = gimp_image_get_active_drawable (image);
 
   g_return_val_if_fail (drawable != NULL, FALSE);
 
   return gimp_image_pick_color (image, drawable,
                                 coords->x, coords->y,
+                                shell->show_all,
                                 color_tool->options->sample_merged,
                                 color_tool->options->sample_average,
                                 color_tool->options->average_radius,
diff --git a/app/tools/gimpperspectiveclonetool.c b/app/tools/gimpperspectiveclonetool.c
index 308e2be643..548d26010a 100644
--- a/app/tools/gimpperspectiveclonetool.c
+++ b/app/tools/gimpperspectiveclonetool.c
@@ -526,7 +526,7 @@ gimp_perspective_clone_tool_cursor_update (GimpTool         *tool,
   image = gimp_display_get_image (display);
 
   if (gimp_image_coords_in_active_pickable (image, coords,
-                                            FALSE, TRUE))
+                                            FALSE, FALSE, TRUE))
     {
       cursor = GIMP_CURSOR_MOUSE;
     }
diff --git a/app/tools/gimpregionselecttool.c b/app/tools/gimpregionselecttool.c
index 23c7a61071..fe08533d5c 100644
--- a/app/tools/gimpregionselecttool.c
+++ b/app/tools/gimpregionselecttool.c
@@ -283,7 +283,8 @@ gimp_region_select_tool_cursor_update (GimpTool         *tool,
   GimpImage               *image    = gimp_display_get_image (display);
 
   if (! gimp_image_coords_in_active_pickable (image, coords,
-                                              options->sample_merged, FALSE))
+                                              FALSE, options->sample_merged,
+                                              FALSE))
     modifier = GIMP_CURSOR_MODIFIER_BAD;
 
   gimp_tool_control_set_cursor_modifier (tool->control, modifier);
diff --git a/app/tools/gimptexttool.c b/app/tools/gimptexttool.c
index d2d852d547..a9c4218f63 100644
--- a/app/tools/gimptexttool.c
+++ b/app/tools/gimptexttool.c
@@ -502,7 +502,7 @@ gimp_text_tool_button_press (GimpTool            *tool,
         }
     }
 
-  if (gimp_image_coords_in_active_pickable (image, coords, FALSE, FALSE))
+  if (gimp_image_coords_in_active_pickable (image, coords, FALSE, FALSE, FALSE))
     {
       GimpDrawable *drawable = gimp_image_get_active_drawable (image);
       GimpItem     *item     = GIMP_ITEM (drawable);
diff --git a/app/widgets/gimpsamplepointeditor.c b/app/widgets/gimpsamplepointeditor.c
index b9de0f21df..cffc803da9 100644
--- a/app/widgets/gimpsamplepointeditor.c
+++ b/app/widgets/gimpsamplepointeditor.c
@@ -561,6 +561,7 @@ gimp_sample_point_editor_update (GimpSamplePointEditor *editor)
 
           if (gimp_image_pick_color (image_editor->image, NULL,
                                      x, y,
+                                     FALSE,
                                      editor->sample_merged,
                                      FALSE, 0.0,
                                      &format,
diff --git a/app/widgets/gimpselectioneditor.c b/app/widgets/gimpselectioneditor.c
index d1f3d94a7e..7a9c55b364 100644
--- a/app/widgets/gimpselectioneditor.c
+++ b/app/widgets/gimpselectioneditor.c
@@ -275,7 +275,7 @@ gimp_selection_view_button_press (GtkWidget           *widget,
   y = gimp_image_get_height (image_editor->image) * bevent->y / renderer->height;
 
   if (gimp_image_pick_color (image_editor->image, drawable, x, y,
-                             options->sample_merged,
+                             FALSE, options->sample_merged,
                              FALSE, 0.0,
                              NULL,
                              NULL, &color))
diff --git a/pdb/groups/image.pdb b/pdb/groups/image.pdb
index 690ccec46d..7b25a8bc48 100644
--- a/pdb/groups/image.pdb
+++ b/pdb/groups/image.pdb
@@ -479,6 +479,7 @@ HELP
       success = gimp_image_pick_color (image,
                                        drawable,
                                        (gint) x, (gint) y,
+                                       FALSE,
                                        sample_merged,
                                        sample_average,
                                        average_radius,


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