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-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
2003-02-14 22:14:29 +08:00
|
|
|
|
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-17 19:32:02 +08:00
|
|
|
gimp_image_mask_clear (gimage, _("Rect Select"));
|
2001-10-22 20:13:44 +08:00
|
|
|
else
|
2003-02-17 19:32:02 +08:00
|
|
|
gimp_image_mask_push_undo (gimage, _("Rect Select"));
|
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-17 19:32:02 +08:00
|
|
|
gimp_image_mask_clear (gimage, _("Ellipse Select"));
|
2001-10-22 20:13:44 +08:00
|
|
|
else
|
2003-02-17 19:32:02 +08:00
|
|
|
gimp_image_mask_push_undo (gimage, _("Ellipse Select"));
|
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,
|
2003-05-21 09:01:09 +08:00
|
|
|
x, y, w, h, antialias);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2003-05-21 09:01:09 +08:00
|
|
|
gimp_scan_convert_add_points (scan_convert, n_points, points, FALSE);
|
2001-10-22 20:13:44 +08:00
|
|
|
|
|
|
|
mask = gimp_scan_convert_to_channel (scan_convert, gimage);
|
|
|
|
|
|
|
|
gimp_scan_convert_free (scan_convert);
|
|
|
|
|
|
|
|
#undef SUPERSAMPLE
|
|
|
|
|
|
|
|
if (mask)
|
|
|
|
{
|
|
|
|
if (feather)
|
2003-05-21 09:01:09 +08:00
|
|
|
gimp_channel_feather (mask,
|
|
|
|
feather_radius_x,
|
|
|
|
feather_radius_y,
|
2001-10-22 20:13:44 +08:00
|
|
|
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
|
|
|
{
|
2003-04-14 08:37:04 +08:00
|
|
|
GList *stroke;
|
|
|
|
GArray *coords = NULL;
|
|
|
|
gboolean closed;
|
2003-05-21 09:01:09 +08:00
|
|
|
const gchar *undo_name = "Select Vectors"; /* this probably should be an
|
|
|
|
argument */
|
|
|
|
|
|
|
|
GimpScanConvert *scan_convert;
|
|
|
|
GimpChannel *mask;
|
2002-02-26 13:42:14 +08:00
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_IMAGE (gimage));
|
|
|
|
|
2003-05-21 09:01:09 +08:00
|
|
|
/* if applicable, replace the current selection
|
|
|
|
* or insure that a floating selection is anchored down...
|
2002-02-26 13:42:14 +08:00
|
|
|
*/
|
2003-05-21 09:01:09 +08:00
|
|
|
if (op == GIMP_CHANNEL_OP_REPLACE)
|
|
|
|
gimp_image_mask_clear (gimage, undo_name);
|
|
|
|
else
|
|
|
|
gimp_image_mask_push_undo (gimage, undo_name);
|
|
|
|
|
|
|
|
#define SUPERSAMPLE 3
|
|
|
|
|
|
|
|
scan_convert = gimp_scan_convert_new (gimage->width,
|
|
|
|
gimage->height,
|
|
|
|
antialias ? SUPERSAMPLE : 1);
|
|
|
|
|
|
|
|
#undef SUPERSAMPLE
|
|
|
|
|
2002-02-26 13:42:14 +08:00
|
|
|
for (stroke = vectors->strokes; stroke; stroke = stroke->next)
|
|
|
|
{
|
2003-04-14 08:37:04 +08:00
|
|
|
coords = gimp_stroke_interpolate (GIMP_STROKE (stroke->data),
|
|
|
|
1.0, &closed);
|
2003-05-21 09:01:09 +08:00
|
|
|
|
2002-02-26 13:42:14 +08:00
|
|
|
if (coords)
|
2003-05-21 09:01:09 +08:00
|
|
|
{
|
|
|
|
GimpVector2 *points;
|
|
|
|
gint i;
|
2002-02-26 13:42:14 +08:00
|
|
|
|
2003-05-21 09:01:09 +08:00
|
|
|
points = g_new0 (GimpVector2, coords->len);
|
2002-02-26 13:42:14 +08:00
|
|
|
|
2003-05-21 09:01:09 +08:00
|
|
|
for (i = 0; i < coords->len; i++)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2003-05-21 09:01:09 +08:00
|
|
|
gimp_scan_convert_add_points (scan_convert, coords->len,
|
|
|
|
points, TRUE);
|
|
|
|
|
|
|
|
g_array_free (coords, TRUE);
|
|
|
|
g_free (points);
|
2002-02-26 13:42:14 +08:00
|
|
|
}
|
2003-05-21 09:01:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
mask = gimp_scan_convert_to_channel (scan_convert, gimage);
|
|
|
|
|
|
|
|
gimp_scan_convert_free (scan_convert);
|
|
|
|
|
|
|
|
if (mask)
|
|
|
|
{
|
|
|
|
if (feather)
|
|
|
|
gimp_channel_feather (mask,
|
|
|
|
feather_radius_x,
|
|
|
|
feather_radius_y,
|
|
|
|
FALSE /* no undo */);
|
2002-02-26 13:42:14 +08:00
|
|
|
|
2003-05-21 09:01:09 +08:00
|
|
|
gimp_channel_combine_mask (gimp_image_get_mask (gimage), mask, op, 0, 0);
|
|
|
|
g_object_unref (mask);
|
2002-02-26 13:42:14 +08:00
|
|
|
}
|
2003-05-21 09:01:09 +08:00
|
|
|
|
|
|
|
gimp_image_mask_changed (gimage);
|
2002-02-26 13:42:14 +08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2003-08-21 01:14:57 +08:00
|
|
|
if (feather || op == GIMP_CHANNEL_OP_INTERSECT)
|
|
|
|
{
|
|
|
|
GimpChannel *mask;
|
|
|
|
|
|
|
|
mask = gimp_channel_new_mask (gimage, gimage->width, gimage->height);
|
|
|
|
gimp_channel_combine_mask (mask, channel, GIMP_CHANNEL_OP_ADD,
|
|
|
|
offset_x, offset_y);
|
|
|
|
|
|
|
|
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);
|
|
|
|
g_object_unref (mask);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gimp_channel_combine_mask (gimp_image_get_mask (gimage), channel,
|
|
|
|
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
|
|
|
|
{
|
2003-05-08 22:06:03 +08:00
|
|
|
gimp_item_offsets (GIMP_ITEM (drawable), &mask_x, &mask_y);
|
2002-03-03 18:38:37 +08:00
|
|
|
}
|
|
|
|
|
2001-10-22 20:13:44 +08:00
|
|
|
gimp_image_mask_select_channel (gimage,
|
2003-02-17 19:32:02 +08:00
|
|
|
_("Fuzzy Select"),
|
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
|
|
|
|
{
|
2003-05-08 22:06:03 +08:00
|
|
|
gimp_item_offsets (GIMP_ITEM (drawable), &mask_x, &mask_y);
|
2002-03-03 18:38:37 +08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|