Commit 9dabd23e authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

Applied (modified and enhanced) patch from Chris Moller which allows tools

2006-08-05  Michael Natterer  <mitch@gimp.org>

	Applied (modified and enhanced) patch from Chris Moller which allows
	tools to distinguish similar colors not only by composite, but also
	by R, G, B, H, S and V. Fixes bug #348291.

	* app/core/core-enums.[ch]: added new enum GimpSelectCriterion
	which can be one of { COMPOSITE, R, G, B, H, S, V }.

	* app/core/gimpimage-contiguous-region.[ch]: added
	select_criterion params and create the region based on difference
	by the selected criterion.

	* app/core/gimpchannel-select.[ch]
	* app/core/gimpdrawable-bucket-fill.[ch]: take criterion params and
	pass them through to the contiguous region functions.

	* app/tools/gimpbucketfilloptions.[ch]
	* app/tools/gimpselectionoptions.[ch]: added criterion properties
	and GUI to select it.

	* app/tools/gimpbucketfilltool.c
	* app/tools/gimpbycolorselecttool.c
	* app/tools/gimpfuzzyselecttool.c: pass the selected criterion to
	the resp. core functions.

	* app/widgets/gimpdrawabletreeview.c
	* app/widgets/gimpselectioneditor.c
	* app/display/gimpdisplayshell-dnd.c
	* tools/pdbgen/pdb/edit.pdb
	* tools/pdbgen/pdb/selection_tools.pdb: changed accordingly
	(simply pass GIMP_SELECT_CRITERION_COMPOSITE in most cases).

	* app/pdb/edit_cmds.c
	* app/pdb/selection_tools_cmds.c: regenerated.
parent 5ce64ce2
2006-08-05 Michael Natterer <mitch@gimp.org>
Applied (modified and enhanced) patch from Chris Moller which allows
tools to distinguish similar colors not only by composite, but also
by R, G, B, H, S and V. Fixes bug #348291.
* app/core/core-enums.[ch]: added new enum GimpSelectCriterion
which can be one of { COMPOSITE, R, G, B, H, S, V }.
* app/core/gimpimage-contiguous-region.[ch]: added
select_criterion params and create the region based on difference
by the selected criterion.
* app/core/gimpchannel-select.[ch]
* app/core/gimpdrawable-bucket-fill.[ch]: take criterion params and
pass them through to the contiguous region functions.
* app/tools/gimpbucketfilloptions.[ch]
* app/tools/gimpselectionoptions.[ch]: added criterion properties
and GUI to select it.
* app/tools/gimpbucketfilltool.c
* app/tools/gimpbycolorselecttool.c
* app/tools/gimpfuzzyselecttool.c: pass the selected criterion to
the resp. core functions.
* app/widgets/gimpdrawabletreeview.c
* app/widgets/gimpselectioneditor.c
* app/display/gimpdisplayshell-dnd.c
* tools/pdbgen/pdb/edit.pdb
* tools/pdbgen/pdb/selection_tools.pdb: changed accordingly
(simply pass GIMP_SELECT_CRITERION_COMPOSITE in most cases).
* app/pdb/edit_cmds.c
* app/pdb/selection_tools_cmds.c: regenerated.
2006-08-05 Raphaël Quinet <raphael@gimp.org>
* app/core/gimpgradient-load.c (gimp_gradient_load): Do not crash
......
......@@ -1138,6 +1138,44 @@ gimp_merge_type_get_type (void)
return type;
}
GType
gimp_select_criterion_get_type (void)
{
static const GEnumValue values[] =
{
{ GIMP_SELECT_CRITERION_COMPOSITE, "GIMP_SELECT_CRITERION_COMPOSITE", "composite" },
{ GIMP_SELECT_CRITERION_R, "GIMP_SELECT_CRITERION_R", "r" },
{ GIMP_SELECT_CRITERION_G, "GIMP_SELECT_CRITERION_G", "g" },
{ GIMP_SELECT_CRITERION_B, "GIMP_SELECT_CRITERION_B", "b" },
{ GIMP_SELECT_CRITERION_H, "GIMP_SELECT_CRITERION_H", "h" },
{ GIMP_SELECT_CRITERION_S, "GIMP_SELECT_CRITERION_S", "s" },
{ GIMP_SELECT_CRITERION_V, "GIMP_SELECT_CRITERION_V", "v" },
{ 0, NULL, NULL }
};
static const GimpEnumDesc descs[] =
{
{ GIMP_SELECT_CRITERION_COMPOSITE, N_("Composite"), NULL },
{ GIMP_SELECT_CRITERION_R, N_("Red"), NULL },
{ GIMP_SELECT_CRITERION_G, N_("Green"), NULL },
{ GIMP_SELECT_CRITERION_B, N_("Blue"), NULL },
{ GIMP_SELECT_CRITERION_H, N_("Hue"), NULL },
{ GIMP_SELECT_CRITERION_S, N_("Saturation"), NULL },
{ GIMP_SELECT_CRITERION_V, N_("Value"), NULL },
{ 0, NULL, NULL }
};
static GType type = 0;
if (! type)
{
type = g_enum_register_static ("GimpSelectCriterion", values);
gimp_enum_set_value_descriptions (type, descs);
}
return type;
}
/* Generated data ends here */
......@@ -531,6 +531,22 @@ typedef enum
} GimpMergeType;
#define GIMP_TYPE_SELECT_CRITERION (gimp_select_criterion_get_type ())
GType gimp_select_criterion_get_type (void) G_GNUC_CONST;
typedef enum /*< pdb-skip >*/
{
GIMP_SELECT_CRITERION_COMPOSITE, /*< desc="Composite" >*/
GIMP_SELECT_CRITERION_R, /*< desc="Red" >*/
GIMP_SELECT_CRITERION_G, /*< desc="Green" >*/
GIMP_SELECT_CRITERION_B, /*< desc="Blue" >*/
GIMP_SELECT_CRITERION_H, /*< desc="Hue" >*/
GIMP_SELECT_CRITERION_S, /*< desc="Saturation" >*/
GIMP_SELECT_CRITERION_V /*< desc="Value" >*/
} GimpSelectCriterion;
/*
* non-registered enums; register them if needed
*/
......
......@@ -410,18 +410,19 @@ gimp_channel_select_component (GimpChannel *channel,
}
void
gimp_channel_select_fuzzy (GimpChannel *channel,
GimpDrawable *drawable,
gboolean sample_merged,
gint x,
gint y,
gint threshold,
gboolean select_transparent,
GimpChannelOps op,
gboolean antialias,
gboolean feather,
gdouble feather_radius_x,
gdouble feather_radius_y)
gimp_channel_select_fuzzy (GimpChannel *channel,
GimpDrawable *drawable,
gboolean sample_merged,
gint x,
gint y,
gint threshold,
gboolean select_transparent,
GimpSelectCriterion select_criterion,
GimpChannelOps op,
gboolean antialias,
gboolean feather,
gdouble feather_radius_x,
gdouble feather_radius_y)
{
GimpItem *item;
GimpChannel *add_on;
......@@ -440,6 +441,7 @@ gimp_channel_select_fuzzy (GimpChannel *channel,
antialias,
threshold,
select_transparent,
select_criterion,
x, y);
if (! sample_merged)
......@@ -455,17 +457,18 @@ gimp_channel_select_fuzzy (GimpChannel *channel,
}
void
gimp_channel_select_by_color (GimpChannel *channel,
GimpDrawable *drawable,
gboolean sample_merged,
const GimpRGB *color,
gint threshold,
gboolean select_transparent,
GimpChannelOps op,
gboolean antialias,
gboolean feather,
gdouble feather_radius_x,
gdouble feather_radius_y)
gimp_channel_select_by_color (GimpChannel *channel,
GimpDrawable *drawable,
gboolean sample_merged,
const GimpRGB *color,
gint threshold,
gboolean select_transparent,
GimpSelectCriterion select_criterion,
GimpChannelOps op,
gboolean antialias,
gboolean feather,
gdouble feather_radius_x,
gdouble feather_radius_y)
{
GimpItem *item;
GimpChannel *add_on;
......@@ -485,6 +488,7 @@ gimp_channel_select_by_color (GimpChannel *channel,
antialias,
threshold,
select_transparent,
select_criterion,
color);
if (! sample_merged)
......
......@@ -22,104 +22,106 @@
/* basic selection functions */
void gimp_channel_select_rectangle (GimpChannel *channel,
gint x,
gint y,
gint w,
gint h,
GimpChannelOps op,
gboolean feather,
gdouble feather_radius_x,
gdouble feather_radius_y);
void gimp_channel_select_ellipse (GimpChannel *channel,
gint x,
gint y,
gint w,
gint h,
GimpChannelOps op,
gboolean antialias,
gboolean feather,
gdouble feather_radius_x,
gdouble feather_radius_y);
void gimp_channel_select_rectangle (GimpChannel *channel,
gint x,
gint y,
gint w,
gint h,
GimpChannelOps op,
gboolean feather,
gdouble feather_radius_x,
gdouble feather_radius_y);
void gimp_channel_select_ellipse (GimpChannel *channel,
gint x,
gint y,
gint w,
gint h,
GimpChannelOps op,
gboolean antialias,
gboolean feather,
gdouble feather_radius_x,
gdouble feather_radius_y);
/* select by GimpScanConvert functions */
void gimp_channel_select_scan_convert (GimpChannel *channel,
const gchar *undo_desc,
GimpScanConvert *scan_convert,
gint offset_x,
gint offset_y,
GimpChannelOps op,
gboolean antialias,
gboolean feather,
gdouble feather_radius_x,
gdouble feather_radius_y);
void gimp_channel_select_polygon (GimpChannel *channel,
const gchar *undo_desc,
gint n_points,
GimpVector2 *points,
GimpChannelOps op,
gboolean antialias,
gboolean feather,
gdouble feather_radius_x,
gdouble feather_radius_y);
void gimp_channel_select_vectors (GimpChannel *channel,
const gchar *undo_desc,
GimpVectors *vectors,
GimpChannelOps op,
gboolean antialias,
gboolean feather,
gdouble feather_radius_x,
gdouble feather_radius_y);
void gimp_channel_select_scan_convert (GimpChannel *channel,
const gchar *undo_desc,
GimpScanConvert *scan_convert,
gint offset_x,
gint offset_y,
GimpChannelOps op,
gboolean antialias,
gboolean feather,
gdouble feather_radius_x,
gdouble feather_radius_y);
void gimp_channel_select_polygon (GimpChannel *channel,
const gchar *undo_desc,
gint n_points,
GimpVector2 *points,
GimpChannelOps op,
gboolean antialias,
gboolean feather,
gdouble feather_radius_x,
gdouble feather_radius_y);
void gimp_channel_select_vectors (GimpChannel *channel,
const gchar *undo_desc,
GimpVectors *vectors,
GimpChannelOps op,
gboolean antialias,
gboolean feather,
gdouble feather_radius_x,
gdouble feather_radius_y);
/* select by GimpChannel functions */
void gimp_channel_select_channel (GimpChannel *channel,
const gchar *undo_desc,
GimpChannel *add_on,
gint offset_x,
gint offset_y,
GimpChannelOps op,
gboolean feather,
gdouble feather_radius_x,
gdouble feather_radius_y);
void gimp_channel_select_alpha (GimpChannel *channel,
GimpDrawable *drawable,
GimpChannelOps op,
gboolean feather,
gdouble feather_radius_x,
gdouble feather_radius_y);
void gimp_channel_select_component (GimpChannel *channel,
GimpChannelType component,
GimpChannelOps op,
gboolean feather,
gdouble feather_radius_x,
gdouble feather_radius_y);
void gimp_channel_select_fuzzy (GimpChannel *channel,
GimpDrawable *drawable,
gboolean sample_merged,
gint x,
gint y,
gint threshold,
gboolean select_transparent,
GimpChannelOps op,
gboolean antialias,
gboolean feather,
gdouble feather_radius_x,
gdouble feather_radius_y);
void gimp_channel_select_by_color (GimpChannel *channel,
GimpDrawable *drawable,
gboolean sample_merged,
const GimpRGB *color,
gint threshold,
gboolean select_transparent,
GimpChannelOps op,
gboolean antialias,
gboolean feather,
gdouble feather_radius_x,
gdouble feather_radius_y);
void gimp_channel_select_channel (GimpChannel *channel,
const gchar *undo_desc,
GimpChannel *add_on,
gint offset_x,
gint offset_y,
GimpChannelOps op,
gboolean feather,
gdouble feather_radius_x,
gdouble feather_radius_y);
void gimp_channel_select_alpha (GimpChannel *channel,
GimpDrawable *drawable,
GimpChannelOps op,
gboolean feather,
gdouble feather_radius_x,
gdouble feather_radius_y);
void gimp_channel_select_component (GimpChannel *channel,
GimpChannelType component,
GimpChannelOps op,
gboolean feather,
gdouble feather_radius_x,
gdouble feather_radius_y);
void gimp_channel_select_fuzzy (GimpChannel *channel,
GimpDrawable *drawable,
gboolean sample_merged,
gint x,
gint y,
gint threshold,
gboolean select_transparent,
GimpSelectCriterion select_criterion,
GimpChannelOps op,
gboolean antialias,
gboolean feather,
gdouble feather_radius_x,
gdouble feather_radius_y);
void gimp_channel_select_by_color (GimpChannel *channel,
GimpDrawable *drawable,
gboolean sample_merged,
const GimpRGB *color,
gint threshold,
gboolean select_transparent,
GimpSelectCriterion select_criterion,
GimpChannelOps op,
gboolean antialias,
gboolean feather,
gdouble feather_radius_x,
gdouble feather_radius_y);
#endif /* __GIMP_CHANNEL_SELECT_H__ */
......@@ -46,17 +46,18 @@
/* public functions */
void
gimp_drawable_bucket_fill (GimpDrawable *drawable,
GimpContext *context,
GimpBucketFillMode fill_mode,
gint paint_mode,
gdouble opacity,
gboolean do_seed_fill,
gboolean fill_transparent,
gdouble threshold,
gboolean sample_merged,
gdouble x,
gdouble y)
gimp_drawable_bucket_fill (GimpDrawable *drawable,
GimpContext *context,
GimpBucketFillMode fill_mode,
gint paint_mode,
gdouble opacity,
gboolean do_seed_fill,
gboolean fill_transparent,
GimpSelectCriterion fill_criterion,
gdouble threshold,
gboolean sample_merged,
gdouble x,
gdouble y)
{
GimpImage *image;
GimpRGB color;
......@@ -96,25 +97,26 @@ gimp_drawable_bucket_fill (GimpDrawable *drawable,
fill_mode,
paint_mode, opacity,
do_seed_fill,
fill_transparent,
fill_transparent, fill_criterion,
threshold, sample_merged,
x, y,
&color, pattern);
}
void
gimp_drawable_bucket_fill_full (GimpDrawable *drawable,
GimpBucketFillMode fill_mode,
gint paint_mode,
gdouble opacity,
gboolean do_seed_fill,
gboolean fill_transparent,
gdouble threshold,
gboolean sample_merged,
gdouble x,
gdouble y,
const GimpRGB *color,
GimpPattern *pattern)
gimp_drawable_bucket_fill_full (GimpDrawable *drawable,
GimpBucketFillMode fill_mode,
gint paint_mode,
gdouble opacity,
gboolean do_seed_fill,
gboolean fill_transparent,
GimpSelectCriterion fill_criterion,
gdouble threshold,
gboolean sample_merged,
gdouble x,
gdouble y,
const GimpRGB *color,
GimpPattern *pattern)
{
GimpImage *image;
TileManager *buf_tiles;
......@@ -179,6 +181,7 @@ gimp_drawable_bucket_fill_full (GimpDrawable *drawable,
TRUE,
(gint) threshold,
fill_transparent,
fill_criterion,
(gint) x,
(gint) y);
......
......@@ -20,30 +20,32 @@
#define __GIMP_DRAWABLE_BUCKET_FILL_H__
void gimp_drawable_bucket_fill (GimpDrawable *drawable,
GimpContext *context,
GimpBucketFillMode fill_mode,
gint paint_mode,
gdouble opacity,
gboolean do_seed_fill,
gboolean fill_transparent,
gdouble threshold,
gboolean sample_merged,
gdouble x,
gdouble y);
void gimp_drawable_bucket_fill (GimpDrawable *drawable,
GimpContext *context,
GimpBucketFillMode fill_mode,
gint paint_mode,
gdouble opacity,
gboolean do_seed_fill,
gboolean fill_transparent,
GimpSelectCriterion fill_criterion,
gdouble threshold,
gboolean sample_merged,
gdouble x,
gdouble y);
void gimp_drawable_bucket_fill_full (GimpDrawable *drawable,
GimpBucketFillMode fill_mode,
gint paint_mode,
gdouble opacity,
gboolean do_seed_fill,
gboolean fill_transparent,
gdouble threshold,
gboolean sample_merged,
gdouble x,
gdouble y,
const GimpRGB *color,
GimpPattern *pattern);
void gimp_drawable_bucket_fill_full (GimpDrawable *drawable,
GimpBucketFillMode fill_mode,
gint paint_mode,
gdouble opacity,
gboolean do_seed_fill,
gboolean fill_transparent,
GimpSelectCriterion fill_criterion,
gdouble threshold,
gboolean sample_merged,
gdouble x,
gdouble y,
const GimpRGB *color,
GimpPattern *pattern);
#endif /* __GIMP_DRAWABLE_BUCKET_FILL_H__ */
......@@ -39,14 +39,15 @@
typedef struct
{
GimpImage *image;
GimpImageType type;
gboolean sample_merged;
gboolean antialias;
gint threshold;
gboolean select_transparent;
gboolean has_alpha;
guchar color[MAX_CHANNELS];
GimpImage *image;
GimpImageType type;
gboolean sample_merged;
gboolean antialias;
gint threshold;
gboolean select_transparent;
GimpSelectCriterion select_criterion;
gboolean has_alpha;
guchar color[MAX_CHANNELS];
} ContinuousRegionData;
......@@ -56,59 +57,63 @@ static void contiguous_region_by_color (ContinuousRegionData *cont,
PixelRegion *imagePR,
PixelRegion *maskPR);
static gint pixel_difference (const guchar *col1,
const guchar *col2,
gboolean antialias,
gint threshold,
gint bytes,
gboolean has_alpha,
gboolean select_transparent);
static void ref_tiles (TileManager *src,
TileManager *mask,
Tile **s_tile,
Tile **m_tile,
gint x,
gint y,
guchar **s,
guchar **m);
static gint find_contiguous_segment (GimpImage *image,
const guchar *col,
PixelRegion *src,
PixelRegion *mask,
gint width,
gint bytes,
GimpImageType src_type,
gboolean has_alpha,
gboolean select_transparent,
gboolean antialias,
gint threshold,
gint initial,
gint *start,
gint *end);
static void find_contiguous_region_helper (GimpImage *image,
PixelRegion *mask,
PixelRegion *src,
GimpImageType src_type,
gboolean has_alpha,
gboolean select_transparent,
gboolean antialias,
gint threshold,
gint x,
gint y,
const guchar *col);
static gint pixel_difference (const guchar *col1,
const guchar *col2,
gboolean antialias,
gint threshold,
gint bytes,
gboolean has_alpha,
gboolean select_transparent,
GimpSelectCriterion select_criterion);
static void ref_tiles (TileManager *src,
TileManager *mask,
Tile **s_tile,
Tile **m_tile,
gint x,
gint y,
guchar **s,
guchar **m);
static gint find_contiguous_segment (GimpImage *image,
const guchar *col,
PixelRegion *src,
PixelRegion *mask,
gint width,
gint bytes,
GimpImageType src_type,
gboolean has_alpha,
gboolean select_transparent,
GimpSelectCriterion select_criterion,
gboolean antialias,
gint threshold,
gint initial,
gint *start,
gint *end);
static void find_contiguous_region_helper (GimpImage *image,
PixelRegion *mask,
PixelRegion *src,
GimpImageType src_type,
gboolean has_alpha,
gboolean select_transparent,
GimpSelectCriterion select_criterion,
gboolean antialias,
gint threshold,
gint x,
gint y,
const guchar *col);
/* public functions */
GimpChannel *
gimp_image_contiguous_region_by_seed (GimpImage *image,
GimpDrawable *drawable,
gboolean sample_merged,
gboolean antialias,
gint threshold,
gboolean select_transparent,
gint x,
gint y)
gimp_image_contiguous_region_by_seed (GimpImage *image,
GimpDrawable *drawable,
gboolean sample_merged,
gboolean antialias,
gint threshold,
gboolean select_transparent,
GimpSelectCriterion select_criterion,
gint x,
gint y)
{
PixelRegion srcPR, maskPR;
GimpPickable *pickable;
......@@ -185,7 +190,8 @@ gimp_image_contiguous_region_by_seed (GimpImage *image,
find_contiguous_region_helper (image, &maskPR, &srcPR,
src_type, has_alpha,
select_transparent, antialias, threshold,
select_transparent, select_criterion,
antialias, threshold,
x, y, start_col);
tile_release (tile, FALSE);
......@@ -195,13 +201,14 @@ gimp_image_contiguous_region_by_seed (GimpImage *image,
}
GimpChannel *
gimp_image_contiguous_region_by_color (GimpImage *image,
GimpDrawable *drawable,
gboolean sample_merged,
gboolean antialias,
gint threshold,
gboolean select_transparent,
const GimpRGB *color)
gimp_image_contiguous_region_by_color (GimpImage *image,
GimpDrawable *drawable,
gboolean sample_merged,
gboolean antialias,
gint threshold,
gboolean select_transparent,
GimpSelectCriterion select_criterion,
const GimpRGB *color)
{
/* Scan over the image's active layer, finding pixels within the
* specified threshold from the given R, G, & B values. If
......@@ -258,10 +265,11 @@ gimp_image_contiguous_region_by_color (GimpImage *image,
select_transparent = FALSE;
}
cont.image = image;
cont.image = image;
cont.antialias = antialias;
cont.threshold = threshold;
cont.select_transparent = select_transparent;
cont.select_criterion = select_criterion;
mask = gimp_channel_new_mask (image, width, height);
......@@ -306,7 +314,8 @@ contiguous_region_by_color (ContinuousRegionData *cont,
cont->threshold,
cont->has_alpha ? 4 : 3,
cont->has_alpha,
cont->select_transparent);
cont->select_transparent,
cont->select_criterion);
i += imagePR->bytes;
}
......@@ -317,13 +326,14 @@ contiguous_region_by_color (ContinuousRegionData *cont,
}
static gint
pixel_difference (const guchar *col1,
const guchar *col2,
gboolean antialias,
gint threshold,
gint bytes,
gboolean has_alpha,
gboolean select_transparent)
pixel_difference (const guchar *col1,
const guchar *col2,
gboolean antialias,
gint threshold,
gint bytes,
gboolean has_alpha,