1999-07-07 11:18:54 +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.
|
|
|
|
*/
|
1999-09-06 08:07:03 +08:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2001-11-30 22:41:56 +08:00
|
|
|
#include <glib-object.h>
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2001-01-24 02:49:44 +08:00
|
|
|
#include "libgimpcolor/gimpcolor.h"
|
|
|
|
|
2001-11-30 22:41:56 +08:00
|
|
|
#include "core-types.h"
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2001-11-30 22:41:56 +08:00
|
|
|
#include "gimp.h"
|
|
|
|
#include "gimpchannel.h"
|
|
|
|
#include "gimpimage.h"
|
2005-09-19 20:44:06 +08:00
|
|
|
#include "gimpimage-quick-mask.h"
|
2003-02-13 19:23:50 +08:00
|
|
|
#include "gimpimage-undo.h"
|
2003-02-14 22:14:29 +08:00
|
|
|
#include "gimpimage-undo-push.h"
|
2004-03-21 00:43:29 +08:00
|
|
|
#include "gimplayer.h"
|
2002-02-22 06:19:45 +08:00
|
|
|
#include "gimplayer-floating-sel.h"
|
2003-09-05 04:18:08 +08:00
|
|
|
#include "gimpselection.h"
|
2001-11-11 03:10:28 +08:00
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
2000-12-17 05:37:03 +08:00
|
|
|
|
1999-07-07 11:18:54 +08:00
|
|
|
|
2001-11-30 22:41:56 +08:00
|
|
|
/* public functions */
|
1999-08-08 04:55:26 +08:00
|
|
|
|
1999-07-07 11:18:54 +08:00
|
|
|
void
|
2005-09-19 20:44:06 +08:00
|
|
|
gimp_image_set_quick_mask_state (GimpImage *gimage,
|
|
|
|
gboolean quick_mask_state)
|
1999-07-07 11:18:54 +08:00
|
|
|
{
|
2003-09-03 22:22:38 +08:00
|
|
|
GimpChannel *selection;
|
2003-03-25 11:29:11 +08:00
|
|
|
GimpChannel *mask;
|
|
|
|
|
2001-11-30 22:41:56 +08:00
|
|
|
g_return_if_fail (GIMP_IS_IMAGE (gimage));
|
1999-07-07 11:18:54 +08:00
|
|
|
|
2005-09-19 20:44:06 +08:00
|
|
|
if (quick_mask_state == gimage->quick_mask_state)
|
2003-03-25 11:29:11 +08:00
|
|
|
return;
|
|
|
|
|
2005-09-19 20:44:06 +08:00
|
|
|
/* set image->quick_mask_state early so we can return early when
|
2004-02-14 23:37:23 +08:00
|
|
|
* being called recursively
|
|
|
|
*/
|
2005-09-19 20:44:06 +08:00
|
|
|
gimage->quick_mask_state = quick_mask_state ? TRUE : FALSE;
|
2004-02-14 23:37:23 +08:00
|
|
|
|
2003-09-03 22:22:38 +08:00
|
|
|
selection = gimp_image_get_mask (gimage);
|
2005-09-19 20:44:06 +08:00
|
|
|
mask = gimp_image_get_quick_mask (gimage);
|
2003-09-03 22:22:38 +08:00
|
|
|
|
2005-09-19 20:44:06 +08:00
|
|
|
if (quick_mask_state)
|
2001-11-30 00:44:51 +08:00
|
|
|
{
|
2003-03-25 11:29:11 +08:00
|
|
|
if (! mask)
|
|
|
|
{
|
2005-09-19 20:44:06 +08:00
|
|
|
gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_IMAGE_QUICK_MASK,
|
2004-09-26 00:52:49 +08:00
|
|
|
_("Enable Quick Mask"));
|
2001-11-30 22:41:56 +08:00
|
|
|
|
2003-09-03 22:22:38 +08:00
|
|
|
if (gimp_channel_is_empty (selection))
|
2001-11-30 22:41:56 +08:00
|
|
|
{
|
2003-09-03 22:22:38 +08:00
|
|
|
/* if no selection */
|
|
|
|
|
2004-02-14 23:37:23 +08:00
|
|
|
GimpLayer *floating_sel = gimp_image_floating_sel (gimage);
|
2001-11-30 22:41:56 +08:00
|
|
|
|
2004-02-14 23:37:23 +08:00
|
|
|
if (floating_sel)
|
|
|
|
floating_sel_to_layer (floating_sel);
|
2001-11-30 22:41:56 +08:00
|
|
|
|
2003-09-05 04:18:08 +08:00
|
|
|
mask = gimp_channel_new (gimage,
|
|
|
|
gimage->width,
|
2003-03-25 11:29:11 +08:00
|
|
|
gimage->height,
|
2005-09-19 20:44:06 +08:00
|
|
|
GIMP_IMAGE_QUICK_MASK_NAME,
|
|
|
|
&gimage->quick_mask_color);
|
2001-11-30 22:41:56 +08:00
|
|
|
|
2004-02-14 23:37:23 +08:00
|
|
|
/* Clear the mask */
|
|
|
|
gimp_channel_clear (mask, NULL, FALSE);
|
2003-03-25 11:29:11 +08:00
|
|
|
}
|
2003-09-03 22:22:38 +08:00
|
|
|
else
|
2003-03-25 11:29:11 +08:00
|
|
|
{
|
2003-09-03 22:22:38 +08:00
|
|
|
/* if selection */
|
|
|
|
|
|
|
|
mask = GIMP_CHANNEL (gimp_item_duplicate (GIMP_ITEM (selection),
|
|
|
|
GIMP_TYPE_CHANNEL,
|
2003-03-25 11:29:11 +08:00
|
|
|
FALSE));
|
2003-09-03 22:22:38 +08:00
|
|
|
|
|
|
|
/* Clear the selection */
|
|
|
|
gimp_channel_clear (selection, NULL, TRUE);
|
2001-11-30 22:41:56 +08:00
|
|
|
|
2005-09-19 20:44:06 +08:00
|
|
|
gimp_channel_set_color (mask, &gimage->quick_mask_color, FALSE);
|
|
|
|
gimp_item_rename (GIMP_ITEM (mask), GIMP_IMAGE_QUICK_MASK_NAME);
|
2003-03-25 11:29:11 +08:00
|
|
|
}
|
2003-03-17 10:25:39 +08:00
|
|
|
|
2005-09-19 20:44:06 +08:00
|
|
|
if (gimage->quick_mask_inverted)
|
2004-02-14 23:37:23 +08:00
|
|
|
gimp_channel_invert (mask, FALSE);
|
2001-11-30 22:41:56 +08:00
|
|
|
|
2004-02-14 23:37:23 +08:00
|
|
|
gimp_image_add_channel (gimage, mask, 0);
|
2001-11-30 22:41:56 +08:00
|
|
|
|
2003-03-25 11:29:11 +08:00
|
|
|
gimp_image_undo_group_end (gimage);
|
2001-11-30 22:41:56 +08:00
|
|
|
}
|
2003-03-25 11:29:11 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (mask)
|
2003-09-05 04:18:08 +08:00
|
|
|
{
|
2004-03-21 00:43:29 +08:00
|
|
|
GimpLayer *floating_sel = gimp_image_floating_sel (gimage);
|
|
|
|
|
2005-09-19 20:44:06 +08:00
|
|
|
gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_IMAGE_QUICK_MASK,
|
2004-09-26 00:52:49 +08:00
|
|
|
_("Disable Quick Mask"));
|
2001-11-30 22:41:56 +08:00
|
|
|
|
2005-09-19 20:44:06 +08:00
|
|
|
if (gimage->quick_mask_inverted)
|
2003-03-25 11:29:11 +08:00
|
|
|
gimp_channel_invert (mask, TRUE);
|
2001-11-30 22:41:56 +08:00
|
|
|
|
2004-03-21 00:43:29 +08:00
|
|
|
if (floating_sel && floating_sel->fs.drawable == GIMP_DRAWABLE (mask))
|
|
|
|
floating_sel_anchor (floating_sel);
|
|
|
|
|
2003-09-05 04:18:08 +08:00
|
|
|
gimp_selection_load (gimp_image_get_mask (gimage), mask);
|
2003-03-25 11:29:11 +08:00
|
|
|
gimp_image_remove_channel (gimage, mask);
|
2001-11-30 22:41:56 +08:00
|
|
|
|
2003-03-25 11:29:11 +08:00
|
|
|
gimp_image_undo_group_end (gimage);
|
2001-11-30 22:41:56 +08:00
|
|
|
}
|
2003-03-25 11:29:11 +08:00
|
|
|
}
|
2001-11-30 22:41:56 +08:00
|
|
|
|
2005-09-19 20:44:06 +08:00
|
|
|
gimp_image_quick_mask_changed (gimage);
|
1999-07-07 11:18:54 +08:00
|
|
|
}
|
1999-08-08 04:55:26 +08:00
|
|
|
|
2001-11-30 22:41:56 +08:00
|
|
|
gboolean
|
2005-09-19 20:44:06 +08:00
|
|
|
gimp_image_get_quick_mask_state (const GimpImage *gimage)
|
1999-08-08 04:55:26 +08:00
|
|
|
{
|
2001-11-30 22:41:56 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
|
|
|
|
|
2005-09-19 20:44:06 +08:00
|
|
|
return gimage->quick_mask_state;
|
1999-08-08 04:55:26 +08:00
|
|
|
}
|
|
|
|
|
2004-07-05 19:18:34 +08:00
|
|
|
void
|
2005-09-19 20:44:06 +08:00
|
|
|
gimp_image_set_quick_mask_color (GimpImage *gimage,
|
|
|
|
const GimpRGB *color)
|
2004-07-05 19:18:34 +08:00
|
|
|
{
|
2005-09-19 20:44:06 +08:00
|
|
|
GimpChannel *quick_mask;
|
2004-07-05 19:18:34 +08:00
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_IMAGE (gimage));
|
|
|
|
g_return_if_fail (color != NULL);
|
|
|
|
|
2005-09-19 20:44:06 +08:00
|
|
|
gimage->quick_mask_color = *color;
|
2004-07-05 19:18:34 +08:00
|
|
|
|
2005-09-19 20:44:06 +08:00
|
|
|
quick_mask = gimp_image_get_quick_mask (gimage);
|
|
|
|
if (quick_mask)
|
|
|
|
gimp_channel_set_color (quick_mask, color, TRUE);
|
2004-07-05 19:18:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-09-19 20:44:06 +08:00
|
|
|
gimp_image_get_quick_mask_color (const GimpImage *gimage,
|
|
|
|
GimpRGB *color)
|
2004-07-05 19:18:34 +08:00
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_IMAGE (gimage));
|
|
|
|
g_return_if_fail (color != NULL);
|
|
|
|
|
2005-09-19 20:44:06 +08:00
|
|
|
*color = gimage->quick_mask_color;
|
2004-07-05 19:18:34 +08:00
|
|
|
}
|
|
|
|
|
2004-02-19 21:18:24 +08:00
|
|
|
GimpChannel *
|
2005-09-19 20:44:06 +08:00
|
|
|
gimp_image_get_quick_mask (const GimpImage *gimage)
|
2004-02-19 21:18:24 +08:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
|
|
|
|
|
2005-09-19 20:44:06 +08:00
|
|
|
return gimp_image_get_channel_by_name (gimage, GIMP_IMAGE_QUICK_MASK_NAME);
|
2004-02-19 21:18:24 +08:00
|
|
|
}
|
|
|
|
|
2001-11-30 22:41:56 +08:00
|
|
|
void
|
2005-09-19 20:44:06 +08:00
|
|
|
gimp_image_quick_mask_invert (GimpImage *gimage)
|
1999-08-08 04:55:26 +08:00
|
|
|
{
|
2001-11-30 22:41:56 +08:00
|
|
|
g_return_if_fail (GIMP_IS_IMAGE (gimage));
|
2001-01-20 21:21:49 +08:00
|
|
|
|
2005-09-19 20:44:06 +08:00
|
|
|
if (gimage->quick_mask_state)
|
2001-01-15 12:37:01 +08:00
|
|
|
{
|
2005-09-19 20:44:06 +08:00
|
|
|
GimpChannel *quick_mask = gimp_image_get_quick_mask (gimage);
|
1999-08-08 04:55:26 +08:00
|
|
|
|
2005-09-19 20:44:06 +08:00
|
|
|
if (quick_mask)
|
|
|
|
gimp_channel_invert (quick_mask, TRUE);
|
2001-11-30 22:41:56 +08:00
|
|
|
}
|
2001-11-11 03:10:28 +08:00
|
|
|
|
2005-09-19 20:44:06 +08:00
|
|
|
gimage->quick_mask_inverted = ! gimage->quick_mask_inverted;
|
2001-11-11 03:10:28 +08:00
|
|
|
}
|