app: GimpSelectionEditor multi-drawable aware.

When clicking on the selection mask (in the dockable view) or when
dropping a color on this same view, we can now select by color based on
the selected layer composition (not only one single layer, nor the whole
image as sample merged, but also a specific list of composited layers).

gimp_channel_select_by_color() is made multi-drawable aware as a
consequence of this.
This commit is contained in:
Jehan 2020-08-17 18:22:19 +02:00
parent bd452d7df1
commit 84e587d255
5 changed files with 49 additions and 20 deletions

View File

@ -32,9 +32,13 @@
#include "gegl/gimp-gegl-loops.h"
#include "gegl/gimp-gegl-mask-combine.h"
#include "gimp.h"
#include "gimpchannel.h"
#include "gimpchannel-select.h"
#include "gimpchannel-combine.h"
#include "gimpcontainer.h"
#include "gimpimage.h"
#include "gimpimage-new.h"
#include "gimppickable.h"
#include "gimppickable-contiguous-region.h"
#include "gimpscanconvert.h"
@ -519,7 +523,7 @@ gimp_channel_select_fuzzy (GimpChannel *channel,
void
gimp_channel_select_by_color (GimpChannel *channel,
GimpDrawable *drawable,
GList *drawables,
gboolean sample_merged,
const GimpRGB *color,
gfloat threshold,
@ -533,18 +537,36 @@ gimp_channel_select_by_color (GimpChannel *channel,
{
GimpPickable *pickable;
GeglBuffer *add_on;
gint add_on_x = 0;
gint add_on_y = 0;
GimpImage *image;
GimpImage *sel_image = NULL;
gint add_on_x = 0;
gint add_on_y = 0;
g_return_if_fail (GIMP_IS_CHANNEL (channel));
g_return_if_fail (gimp_item_is_attached (GIMP_ITEM (channel)));
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
g_return_if_fail (drawables != NULL);
g_return_if_fail (color != NULL);
image = gimp_item_get_image (drawables->data);
if (sample_merged)
pickable = GIMP_PICKABLE (gimp_item_get_image (GIMP_ITEM (drawable)));
{
pickable = GIMP_PICKABLE (image);
}
else
pickable = GIMP_PICKABLE (drawable);
{
if (g_list_length (drawables) == 1)
{
pickable = GIMP_PICKABLE (drawables->data);
}
else
{
sel_image = gimp_image_new_from_drawables (image->gimp, drawables, FALSE);
gimp_container_remove (image->gimp->images, GIMP_OBJECT (sel_image));
pickable = GIMP_PICKABLE (sel_image);
gimp_pickable_flush (pickable);
}
}
add_on = gimp_pickable_contiguous_region_by_color (pickable,
antialias,
@ -553,8 +575,8 @@ gimp_channel_select_by_color (GimpChannel *channel,
select_criterion,
color);
if (! sample_merged)
gimp_item_get_offset (GIMP_ITEM (drawable), &add_on_x, &add_on_y);
if (! sample_merged && ! sel_image)
gimp_item_get_offset (GIMP_ITEM (drawables->data), &add_on_x, &add_on_y);
gimp_channel_select_buffer (channel, C_("undo-type", "Select by Color"),
add_on, add_on_x, add_on_y,
@ -562,7 +584,11 @@ gimp_channel_select_by_color (GimpChannel *channel,
feather,
feather_radius_x,
feather_radius_y);
g_object_unref (add_on);
if (sel_image)
g_object_unref (sel_image);
}
void

View File

@ -137,7 +137,7 @@ void gimp_channel_select_fuzzy (GimpChannel *channel,
gdouble feather_radius_x,
gdouble feather_radius_y);
void gimp_channel_select_by_color (GimpChannel *channel,
GimpDrawable *drawable,
GList *drawables,
gboolean sample_merged,
const GimpRGB *color,
gfloat threshold,

View File

@ -73,7 +73,8 @@ image_select_color_invoker (GimpProcedure *procedure,
if (pdb_context->sample_merged ||
gimp_pdb_item_is_attached (GIMP_ITEM (drawable), image, 0, error))
{
gimp_channel_select_by_color (gimp_image_get_mask (image), drawable,
GList *drawables = g_list_prepend (NULL, drawable);
gimp_channel_select_by_color (gimp_image_get_mask (image), drawables,
pdb_context->sample_merged,
&color,
pdb_context->sample_threshold,
@ -84,6 +85,7 @@ image_select_color_invoker (GimpProcedure *procedure,
pdb_context->feather,
pdb_context->feather_radius_x,
pdb_context->feather_radius_y);
g_list_free (drawables);
}
else
success = FALSE;

View File

@ -245,7 +245,6 @@ gimp_selection_view_button_press (GtkWidget *widget,
GimpToolInfo *tool_info;
GimpSelectionOptions *sel_options;
GimpRegionSelectOptions *options;
GimpDrawable *drawable;
GimpChannelOps operation;
GList *drawables;
gint x, y;
@ -265,12 +264,11 @@ gimp_selection_view_button_press (GtkWidget *widget,
sel_options = GIMP_SELECTION_OPTIONS (tool_info->tool_options);
options = GIMP_REGION_SELECT_OPTIONS (tool_info->tool_options);
drawable = gimp_image_get_active_drawable (image_editor->image);
drawables = gimp_image_get_selected_drawables (image_editor->image);
if (! drawable)
if (! drawables)
return TRUE;
drawables = g_list_prepend (NULL, drawable);
operation = gimp_modifiers_to_channel_op (bevent->state);
x = gimp_image_get_width (image_editor->image) * bevent->x / renderer->width;
@ -283,7 +281,7 @@ gimp_selection_view_button_press (GtkWidget *widget,
NULL, &color))
{
gimp_channel_select_by_color (gimp_image_get_mask (image_editor->image),
drawable,
drawables,
options->sample_merged,
&color,
options->threshold / 255.0,
@ -312,7 +310,7 @@ gimp_selection_editor_drop_color (GtkWidget *widget,
GimpToolInfo *tool_info;
GimpSelectionOptions *sel_options;
GimpRegionSelectOptions *options;
GimpDrawable *drawable;
GList *drawables;
if (! editor->image)
return;
@ -325,13 +323,13 @@ gimp_selection_editor_drop_color (GtkWidget *widget,
sel_options = GIMP_SELECTION_OPTIONS (tool_info->tool_options);
options = GIMP_REGION_SELECT_OPTIONS (tool_info->tool_options);
drawable = gimp_image_get_active_drawable (editor->image);
drawables = gimp_image_get_selected_drawables (editor->image);
if (! drawable)
if (! drawables)
return;
gimp_channel_select_by_color (gimp_image_get_mask (editor->image),
drawable,
drawables,
options->sample_merged,
color,
options->threshold / 255.0,
@ -343,6 +341,7 @@ gimp_selection_editor_drop_color (GtkWidget *widget,
sel_options->feather_radius,
sel_options->feather_radius);
gimp_image_flush (editor->image);
g_list_free (drawables);
}
static void

View File

@ -63,7 +63,8 @@ HELP
if (pdb_context->sample_merged ||
gimp_pdb_item_is_attached (GIMP_ITEM (drawable), image, 0, error))
{
gimp_channel_select_by_color (gimp_image_get_mask (image), drawable,
GList *drawables = g_list_prepend (NULL, drawable);
gimp_channel_select_by_color (gimp_image_get_mask (image), drawables,
pdb_context->sample_merged,
&color,
pdb_context->sample_threshold,
@ -74,6 +75,7 @@ HELP
pdb_context->feather,
pdb_context->feather_radius_x,
pdb_context->feather_radius_y);
g_list_free (drawables);
}
else
success = FALSE;