2001-10-22 20:13:44 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <glib-object.h>
|
|
|
|
|
|
|
|
#include "core-types.h"
|
|
|
|
|
|
|
|
#include "gimpchannel.h"
|
|
|
|
#include "gimpimage.h"
|
|
|
|
#include "gimpimage-contiguous-region.h"
|
|
|
|
#include "gimpimage-mask.h"
|
|
|
|
#include "gimpimage-mask-select.h"
|
|
|
|
#include "gimpscanconvert.h"
|
|
|
|
|
2002-02-26 13:42:14 +08:00
|
|
|
#include "vectors/gimpstroke.h"
|
|
|
|
#include "vectors/gimpvectors.h"
|
|
|
|
|
2003-02-14 22:14:29 +08:00
|
|
|
#include "libgimp/gimpintl.h"
|
|
|
|
|
2001-10-22 20:13:44 +08:00
|
|
|
|
|
|
|
void
|
2002-03-19 00:22:14 +08:00
|
|
|
gimp_image_mask_select_rectangle (GimpImage *gimage,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h,
|
|
|
|
GimpChannelOps op,
|
|
|
|
gboolean feather,
|
|
|
|
gdouble feather_radius_x,
|
|
|
|
gdouble feather_radius_y)
|
2001-10-22 20:13:44 +08:00
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_IMAGE (gimage));
|
|
|
|
|
|
|
|
/* if applicable, replace the current selection */
|
2002-03-19 00:22:14 +08:00
|
|
|
if (op == GIMP_CHANNEL_OP_REPLACE)
|
2003-02-14 22:14:29 +08:00
|
|
|
gimp_image_mask_clear (gimage, _("Rectangular Selection"));
|
2001-10-22 20:13:44 +08:00
|
|
|
else
|
2003-02-14 22:14:29 +08:00
|
|
|
gimp_image_mask_push_undo (gimage, _("Rectangular Selection"));
|
2001-10-22 20:13:44 +08:00
|
|
|
|
|
|
|
/* if feathering for rect, make a new mask with the
|
|
|
|
* rectangle and feather that with the old mask
|
|
|
|
*/
|
2002-03-19 00:22:14 +08:00
|
|
|
if (feather || op == GIMP_CHANNEL_OP_INTERSECT)
|
2001-10-22 20:13:44 +08:00
|
|
|
{
|
2001-11-09 03:14:51 +08:00
|
|
|
GimpChannel *mask;
|
|
|
|
|
|
|
|
mask = gimp_channel_new_mask (gimage, gimage->width, gimage->height);
|
2002-03-19 00:22:14 +08:00
|
|
|
gimp_channel_combine_rect (mask, GIMP_CHANNEL_OP_ADD, x, y, w, h);
|
2001-11-09 03:14:51 +08:00
|
|
|
|
|
|
|
if (feather)
|
|
|
|
gimp_channel_feather (mask,
|
|
|
|
feather_radius_x,
|
|
|
|
feather_radius_y,
|
|
|
|
FALSE /* no undo */);
|
|
|
|
|
|
|
|
gimp_channel_combine_mask (gimp_image_get_mask (gimage), mask, op, 0, 0);
|
2003-01-06 06:07:10 +08:00
|
|
|
g_object_unref (mask);
|
2001-10-22 20:13:44 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gimp_channel_combine_rect (gimp_image_get_mask (gimage), op, x, y, w, h);
|
|
|
|
}
|
2002-08-21 18:59:26 +08:00
|
|
|
|
|
|
|
gimp_image_mask_changed (gimage);
|
2001-10-22 20:13:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-03-19 00:22:14 +08:00
|
|
|
gimp_image_mask_select_ellipse (GimpImage *gimage,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h,
|
|
|
|
GimpChannelOps op,
|
|
|
|
gboolean antialias,
|
|
|
|
gboolean feather,
|
|
|
|
gdouble feather_radius_x,
|
|
|
|
gdouble feather_radius_y)
|
2001-10-22 20:13:44 +08:00
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_IMAGE (gimage));
|
|
|
|
|
|
|
|
/* if applicable, replace the current selection */
|
2002-03-19 00:22:14 +08:00
|
|
|
if (op == GIMP_CHANNEL_OP_REPLACE)
|
2003-02-14 22:14:29 +08:00
|
|
|
gimp_image_mask_clear (gimage, _("Ellipse Selection"));
|
2001-10-22 20:13:44 +08:00
|
|
|
else
|
2003-02-14 22:14:29 +08:00
|
|
|
gimp_image_mask_push_undo (gimage, _("Ellipse Selection"));
|
2001-10-22 20:13:44 +08:00
|
|
|
|
|
|
|
/* if feathering for rect, make a new mask with the
|
|
|
|
* rectangle and feather that with the old mask
|
|
|
|
*/
|
2002-03-19 00:22:14 +08:00
|
|
|
if (feather || op == GIMP_CHANNEL_OP_INTERSECT)
|
2001-10-22 20:13:44 +08:00
|
|
|
{
|
2001-11-09 03:14:51 +08:00
|
|
|
GimpChannel *mask;
|
|
|
|
|
|
|
|
mask = gimp_channel_new_mask (gimage, gimage->width, gimage->height);
|
2002-03-19 00:22:14 +08:00
|
|
|
gimp_channel_combine_ellipse (mask, GIMP_CHANNEL_OP_ADD,
|
|
|
|
x, y, w, h, antialias);
|
2001-11-09 03:14:51 +08:00
|
|
|
|
|
|
|
if (feather)
|
|
|
|
gimp_channel_feather (mask,
|
|
|
|
feather_radius_x,
|
|
|
|
feather_radius_y,
|
|
|
|
FALSE /* no undo */);
|
|
|
|
|
|
|
|
gimp_channel_combine_mask (gimp_image_get_mask (gimage), mask, op, 0, 0);
|
2003-01-06 06:07:10 +08:00
|
|
|
g_object_unref (mask);
|
2001-10-22 20:13:44 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gimp_channel_combine_ellipse (gimp_image_get_mask (gimage), op,
|
|
|
|
x, y, w, h, antialias);
|
|
|
|
}
|
2002-08-21 18:59:26 +08:00
|
|
|
|
|
|
|
gimp_image_mask_changed (gimage);
|
2001-10-22 20:13:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-02-14 22:14:29 +08:00
|
|
|
gimp_image_mask_select_polygon (GimpImage *gimage,
|
|
|
|
const gchar *undo_name,
|
|
|
|
gint n_points,
|
|
|
|
GimpVector2 *points,
|
|
|
|
GimpChannelOps op,
|
|
|
|
gboolean antialias,
|
|
|
|
gboolean feather,
|
|
|
|
gdouble feather_radius_x,
|
|
|
|
gdouble feather_radius_y)
|
2001-10-22 20:13:44 +08:00
|
|
|
{
|
|
|
|
GimpScanConvert *scan_convert;
|
2001-11-09 03:14:51 +08:00
|
|
|
GimpChannel *mask;
|
2001-10-22 20:13:44 +08:00
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_IMAGE (gimage));
|
|
|
|
|
2001-11-09 03:14:51 +08:00
|
|
|
/* if applicable, replace the current selection
|
|
|
|
* or insure that a floating selection is anchored down...
|
|
|
|
*/
|
2002-03-19 00:22:14 +08:00
|
|
|
if (op == GIMP_CHANNEL_OP_REPLACE)
|
2003-02-14 22:14:29 +08:00
|
|
|
gimp_image_mask_clear (gimage, undo_name);
|
2001-10-22 20:13:44 +08:00
|
|
|
else
|
2003-02-14 22:14:29 +08:00
|
|
|
gimp_image_mask_push_undo (gimage, undo_name);
|
2001-10-22 20:13:44 +08:00
|
|
|
|
|
|
|
#define SUPERSAMPLE 3
|
|
|
|
|
|
|
|
scan_convert = gimp_scan_convert_new (gimage->width,
|
|
|
|
gimage->height,
|
|
|
|
antialias ? SUPERSAMPLE : 1);
|
|
|
|
gimp_scan_convert_add_points (scan_convert, n_points, points);
|
|
|
|
|
|
|
|
mask = gimp_scan_convert_to_channel (scan_convert, gimage);
|
|
|
|
|
|
|
|
gimp_scan_convert_free (scan_convert);
|
|
|
|
|
|
|
|
#undef SUPERSAMPLE
|
|
|
|
|
|
|
|
if (mask)
|
|
|
|
{
|
|
|
|
if (feather)
|
|
|
|
gimp_channel_feather (mask,
|
|
|
|
feather_radius_x,
|
|
|
|
feather_radius_y,
|
|
|
|
FALSE /* no undo */);
|
|
|
|
|
2001-11-09 03:14:51 +08:00
|
|
|
gimp_channel_combine_mask (gimp_image_get_mask (gimage), mask, op, 0, 0);
|
2003-01-06 06:07:10 +08:00
|
|
|
g_object_unref (mask);
|
2001-10-22 20:13:44 +08:00
|
|
|
}
|
2002-08-21 18:59:26 +08:00
|
|
|
|
|
|
|
gimp_image_mask_changed (gimage);
|
2001-10-22 20:13:44 +08:00
|
|
|
}
|
|
|
|
|
2002-02-26 13:42:14 +08:00
|
|
|
void
|
2002-03-19 00:22:14 +08:00
|
|
|
gimp_image_mask_select_vectors (GimpImage *gimage,
|
|
|
|
GimpVectors *vectors,
|
|
|
|
GimpChannelOps op,
|
|
|
|
gboolean antialias,
|
|
|
|
gboolean feather,
|
|
|
|
gdouble feather_radius_x,
|
|
|
|
gdouble feather_radius_y)
|
2002-02-26 13:42:14 +08:00
|
|
|
{
|
|
|
|
GimpStroke *stroke;
|
2002-12-29 07:52:29 +08:00
|
|
|
GArray *coords = NULL;
|
2002-02-26 13:42:14 +08:00
|
|
|
gboolean closed;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_IMAGE (gimage));
|
|
|
|
|
|
|
|
/* gimp_stroke_interpolate() may return NULL, so iterate over the
|
|
|
|
* list of strokes until one returns coords
|
|
|
|
*/
|
|
|
|
for (stroke = vectors->strokes; stroke; stroke = stroke->next)
|
|
|
|
{
|
2002-12-29 07:52:29 +08:00
|
|
|
coords = gimp_stroke_interpolate (stroke, 1.0, &closed);
|
2002-02-26 13:42:14 +08:00
|
|
|
|
|
|
|
if (coords)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (coords)
|
|
|
|
{
|
|
|
|
GimpVector2 *points;
|
|
|
|
gint i;
|
|
|
|
|
2002-12-29 07:52:29 +08:00
|
|
|
points = g_new0 (GimpVector2, coords->len);
|
2002-02-26 13:42:14 +08:00
|
|
|
|
2002-12-29 07:52:29 +08:00
|
|
|
for (i = 0; i < coords->len; i++)
|
2002-02-26 13:42:14 +08:00
|
|
|
{
|
2002-12-29 07:52:29 +08:00
|
|
|
points[i].x = g_array_index (coords, GimpCoords, i).x;
|
|
|
|
points[i].y = g_array_index (coords, GimpCoords, i).y;
|
2002-02-26 13:42:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
gimp_image_mask_select_polygon (GIMP_ITEM (vectors)->gimage,
|
2003-02-14 22:14:29 +08:00
|
|
|
_("Selection from Path"),
|
2002-12-29 07:52:29 +08:00
|
|
|
coords->len,
|
2002-02-26 13:42:14 +08:00
|
|
|
points,
|
|
|
|
op,
|
|
|
|
antialias,
|
|
|
|
feather,
|
|
|
|
feather_radius_x,
|
|
|
|
feather_radius_y);
|
|
|
|
|
2002-12-29 07:52:29 +08:00
|
|
|
g_array_free (coords, TRUE);
|
2002-02-26 13:42:14 +08:00
|
|
|
g_free (points);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-10-22 20:13:44 +08:00
|
|
|
void
|
2002-03-19 00:22:14 +08:00
|
|
|
gimp_image_mask_select_channel (GimpImage *gimage,
|
2003-02-14 22:14:29 +08:00
|
|
|
const gchar *undo_desc,
|
2002-03-19 00:22:14 +08:00
|
|
|
GimpChannel *channel,
|
|
|
|
gint offset_x,
|
|
|
|
gint offset_y,
|
|
|
|
GimpChannelOps op,
|
|
|
|
gboolean feather,
|
|
|
|
gdouble feather_radius_x,
|
|
|
|
gdouble feather_radius_y)
|
2001-10-22 20:13:44 +08:00
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_IMAGE (gimage));
|
|
|
|
g_return_if_fail (GIMP_IS_CHANNEL (channel));
|
|
|
|
|
|
|
|
/* if applicable, replace the current selection */
|
2002-03-19 00:22:14 +08:00
|
|
|
if (op == GIMP_CHANNEL_OP_REPLACE)
|
2003-02-14 22:14:29 +08:00
|
|
|
gimp_image_mask_clear (gimage, undo_desc);
|
2001-10-22 20:13:44 +08:00
|
|
|
else
|
2003-02-14 22:14:29 +08:00
|
|
|
gimp_image_mask_push_undo (gimage, undo_desc);
|
2001-10-22 20:13:44 +08:00
|
|
|
|
|
|
|
if (feather)
|
|
|
|
gimp_channel_feather (channel,
|
|
|
|
feather_radius_x,
|
|
|
|
feather_radius_y,
|
|
|
|
FALSE /* no undo */);
|
|
|
|
|
2001-11-09 03:14:51 +08:00
|
|
|
gimp_channel_combine_mask (gimp_image_get_mask (gimage), channel,
|
2002-03-03 18:38:37 +08:00
|
|
|
op, offset_x, offset_y);
|
2002-08-21 18:59:26 +08:00
|
|
|
|
|
|
|
gimp_image_mask_changed (gimage);
|
2001-10-22 20:13:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-03-19 00:22:14 +08:00
|
|
|
gimp_image_mask_select_fuzzy (GimpImage *gimage,
|
|
|
|
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)
|
2001-10-22 20:13:44 +08:00
|
|
|
{
|
|
|
|
GimpChannel *mask;
|
2002-03-03 18:38:37 +08:00
|
|
|
gint mask_x;
|
|
|
|
gint mask_y;
|
2001-10-22 20:13:44 +08:00
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_IMAGE (gimage));
|
|
|
|
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
|
|
|
|
|
|
|
|
mask = gimp_image_contiguous_region_by_seed (gimage, drawable,
|
|
|
|
sample_merged,
|
|
|
|
antialias,
|
|
|
|
threshold,
|
2002-02-10 23:18:08 +08:00
|
|
|
select_transparent,
|
2001-10-22 20:13:44 +08:00
|
|
|
x, y);
|
|
|
|
|
2002-03-03 18:38:37 +08:00
|
|
|
if (sample_merged)
|
|
|
|
{
|
|
|
|
mask_x = 0;
|
|
|
|
mask_y = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gimp_drawable_offsets (drawable, &mask_x, &mask_y);
|
|
|
|
}
|
|
|
|
|
2001-10-22 20:13:44 +08:00
|
|
|
gimp_image_mask_select_channel (gimage,
|
2003-02-14 22:14:29 +08:00
|
|
|
_("Select Fuzzy"),
|
2001-10-22 20:13:44 +08:00
|
|
|
mask,
|
2002-03-03 18:38:37 +08:00
|
|
|
mask_x,
|
|
|
|
mask_y,
|
2001-10-22 20:13:44 +08:00
|
|
|
op,
|
|
|
|
feather,
|
|
|
|
feather_radius_x,
|
|
|
|
feather_radius_y);
|
|
|
|
|
2003-01-06 06:07:10 +08:00
|
|
|
g_object_unref (mask);
|
2001-10-22 20:13:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-03-19 00:22:14 +08:00
|
|
|
gimp_image_mask_select_by_color (GimpImage *gimage,
|
|
|
|
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)
|
2001-10-22 20:13:44 +08:00
|
|
|
{
|
|
|
|
GimpChannel *mask;
|
2002-03-03 18:38:37 +08:00
|
|
|
gint mask_x;
|
|
|
|
gint mask_y;
|
2001-10-22 20:13:44 +08:00
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_IMAGE (gimage));
|
|
|
|
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
|
|
|
|
g_return_if_fail (color != NULL);
|
|
|
|
|
|
|
|
mask = gimp_image_contiguous_region_by_color (gimage, drawable,
|
|
|
|
sample_merged,
|
|
|
|
antialias,
|
|
|
|
threshold,
|
2002-02-10 23:18:08 +08:00
|
|
|
select_transparent,
|
2001-10-22 20:13:44 +08:00
|
|
|
color);
|
|
|
|
|
2002-03-03 18:38:37 +08:00
|
|
|
if (sample_merged)
|
|
|
|
{
|
|
|
|
mask_x = 0;
|
|
|
|
mask_y = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gimp_drawable_offsets (drawable, &mask_x, &mask_y);
|
|
|
|
}
|
|
|
|
|
2001-10-22 20:13:44 +08:00
|
|
|
gimp_image_mask_select_channel (gimage,
|
2003-02-14 22:14:29 +08:00
|
|
|
_("Select by Color"),
|
2001-10-22 20:13:44 +08:00
|
|
|
mask,
|
2002-03-03 18:38:37 +08:00
|
|
|
mask_x,
|
|
|
|
mask_y,
|
2001-10-22 20:13:44 +08:00
|
|
|
op,
|
|
|
|
feather,
|
|
|
|
feather_radius_x,
|
|
|
|
feather_radius_y);
|
|
|
|
|
2003-01-06 06:07:10 +08:00
|
|
|
g_object_unref (mask);
|
2001-10-22 20:13:44 +08:00
|
|
|
}
|