2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
1999-07-07 11:18:54 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
1999-07-07 11:18:54 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
1999-07-07 11:18:54 +08:00
|
|
|
* (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
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
1999-07-07 11:18:54 +08:00
|
|
|
*/
|
1999-09-06 08:07:03 +08:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2008-10-10 04:24:04 +08:00
|
|
|
#include <gegl.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
|
|
|
|
2007-07-20 16:23:29 +08:00
|
|
|
#define CHANNEL_WAS_ACTIVE (0x2)
|
|
|
|
|
|
|
|
|
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
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_set_quick_mask_state (GimpImage *image,
|
2007-07-20 16:23:29 +08:00
|
|
|
gboolean active)
|
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;
|
2007-07-20 16:23:29 +08:00
|
|
|
gboolean channel_was_active;
|
2003-03-25 11:29:11 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
g_return_if_fail (GIMP_IS_IMAGE (image));
|
1999-07-07 11:18:54 +08:00
|
|
|
|
2007-07-20 16:23:29 +08:00
|
|
|
if (active == gimp_image_get_quick_mask_state (image))
|
2003-03-25 11:29:11 +08:00
|
|
|
return;
|
|
|
|
|
2007-07-20 16:23:29 +08:00
|
|
|
/* Keep track of the state so that we can make the right drawable
|
|
|
|
* active again when deactiviting quick mask (see bug #134371).
|
|
|
|
*/
|
|
|
|
if (image->quick_mask_state)
|
|
|
|
channel_was_active = (image->quick_mask_state & CHANNEL_WAS_ACTIVE) != 0;
|
|
|
|
else
|
|
|
|
channel_was_active = gimp_image_get_active_channel (image) != NULL;
|
|
|
|
|
|
|
|
/* Set image->quick_mask_state early so we can return early when
|
|
|
|
* being called recursively.
|
2004-02-14 23:37:23 +08:00
|
|
|
*/
|
2007-07-20 16:23:29 +08:00
|
|
|
image->quick_mask_state = (active
|
|
|
|
? TRUE | (channel_was_active ?
|
|
|
|
CHANNEL_WAS_ACTIVE : 0)
|
|
|
|
: FALSE);
|
2004-02-14 23:37:23 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
selection = gimp_image_get_mask (image);
|
|
|
|
mask = gimp_image_get_quick_mask (image);
|
2003-09-03 22:22:38 +08:00
|
|
|
|
2007-07-20 16:23:29 +08:00
|
|
|
if (active)
|
2001-11-30 00:44:51 +08:00
|
|
|
{
|
2003-03-25 11:29:11 +08:00
|
|
|
if (! mask)
|
|
|
|
{
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_undo_group_start (image, 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 */
|
|
|
|
|
2008-11-14 23:01:44 +08:00
|
|
|
GimpLayer *floating_sel = gimp_image_get_floating_selection (image);
|
2001-11-30 22:41:56 +08:00
|
|
|
|
2004-02-14 23:37:23 +08:00
|
|
|
if (floating_sel)
|
2007-12-07 02:00:10 +08:00
|
|
|
floating_sel_to_layer (floating_sel, NULL);
|
2001-11-30 22:41:56 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
mask = gimp_channel_new (image,
|
2007-12-26 00:21:40 +08:00
|
|
|
gimp_image_get_width (image),
|
|
|
|
gimp_image_get_height (image),
|
2005-09-19 20:44:06 +08:00
|
|
|
GIMP_IMAGE_QUICK_MASK_NAME,
|
2006-03-29 01:08:36 +08:00
|
|
|
&image->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),
|
2008-01-08 19:46:15 +08:00
|
|
|
GIMP_TYPE_CHANNEL));
|
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
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_channel_set_color (mask, &image->quick_mask_color, FALSE);
|
2007-12-12 21:57:11 +08:00
|
|
|
gimp_item_rename (GIMP_ITEM (mask), GIMP_IMAGE_QUICK_MASK_NAME,
|
|
|
|
NULL);
|
2003-03-25 11:29:11 +08:00
|
|
|
}
|
2003-03-17 10:25:39 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
if (image->quick_mask_inverted)
|
2004-02-14 23:37:23 +08:00
|
|
|
gimp_channel_invert (mask, FALSE);
|
2001-11-30 22:41:56 +08:00
|
|
|
|
2009-08-04 01:21:51 +08:00
|
|
|
gimp_image_add_channel (image, mask, NULL, 0, TRUE);
|
2001-11-30 22:41:56 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_undo_group_end (image);
|
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
|
|
|
{
|
2008-11-14 23:01:44 +08:00
|
|
|
GimpLayer *floating_sel = gimp_image_get_floating_selection (image);
|
2004-03-21 00:43:29 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_undo_group_start (image, 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
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
if (image->quick_mask_inverted)
|
2003-03-25 11:29:11 +08:00
|
|
|
gimp_channel_invert (mask, TRUE);
|
2001-11-30 22:41:56 +08:00
|
|
|
|
2009-01-27 06:47:16 +08:00
|
|
|
if (floating_sel &&
|
|
|
|
gimp_layer_get_floating_sel_drawable (floating_sel) == GIMP_DRAWABLE (mask))
|
2004-03-21 00:43:29 +08:00
|
|
|
floating_sel_anchor (floating_sel);
|
|
|
|
|
2008-11-23 06:07:55 +08:00
|
|
|
gimp_selection_load (GIMP_SELECTION (gimp_image_get_mask (image)),
|
|
|
|
mask);
|
2008-10-10 03:40:41 +08:00
|
|
|
gimp_image_remove_channel (image, mask, TRUE, NULL);
|
2001-11-30 22:41:56 +08:00
|
|
|
|
2007-07-20 16:23:29 +08:00
|
|
|
if (! channel_was_active)
|
|
|
|
gimp_image_unset_active_channel (image);
|
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_undo_group_end (image);
|
2001-11-30 22:41:56 +08:00
|
|
|
}
|
2003-03-25 11:29:11 +08:00
|
|
|
}
|
2001-11-30 22:41:56 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_quick_mask_changed (image);
|
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
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_get_quick_mask_state (const GimpImage *image)
|
1999-08-08 04:55:26 +08:00
|
|
|
{
|
2006-03-29 01:08:36 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
|
2001-11-30 22:41:56 +08:00
|
|
|
|
2008-11-20 07:34:43 +08:00
|
|
|
return image->quick_mask_state;
|
1999-08-08 04:55:26 +08:00
|
|
|
}
|
|
|
|
|
2004-07-05 19:18:34 +08:00
|
|
|
void
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_set_quick_mask_color (GimpImage *image,
|
2005-09-19 20:44:06 +08:00
|
|
|
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
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
g_return_if_fail (GIMP_IS_IMAGE (image));
|
2004-07-05 19:18:34 +08:00
|
|
|
g_return_if_fail (color != NULL);
|
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
image->quick_mask_color = *color;
|
2004-07-05 19:18:34 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
quick_mask = gimp_image_get_quick_mask (image);
|
2005-09-19 20:44:06 +08:00
|
|
|
if (quick_mask)
|
|
|
|
gimp_channel_set_color (quick_mask, color, TRUE);
|
2004-07-05 19:18:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_get_quick_mask_color (const GimpImage *image,
|
2005-09-19 20:44:06 +08:00
|
|
|
GimpRGB *color)
|
2004-07-05 19:18:34 +08:00
|
|
|
{
|
2006-03-29 01:08:36 +08:00
|
|
|
g_return_if_fail (GIMP_IS_IMAGE (image));
|
2004-07-05 19:18:34 +08:00
|
|
|
g_return_if_fail (color != NULL);
|
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
*color = image->quick_mask_color;
|
2004-07-05 19:18:34 +08:00
|
|
|
}
|
|
|
|
|
2004-02-19 21:18:24 +08:00
|
|
|
GimpChannel *
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_get_quick_mask (const GimpImage *image)
|
2004-02-19 21:18:24 +08:00
|
|
|
{
|
2006-03-29 01:08:36 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
2004-02-19 21:18:24 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
return gimp_image_get_channel_by_name (image, GIMP_IMAGE_QUICK_MASK_NAME);
|
2004-02-19 21:18:24 +08:00
|
|
|
}
|
|
|
|
|
2001-11-30 22:41:56 +08:00
|
|
|
void
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_quick_mask_invert (GimpImage *image)
|
1999-08-08 04:55:26 +08:00
|
|
|
{
|
2006-03-29 01:08:36 +08:00
|
|
|
g_return_if_fail (GIMP_IS_IMAGE (image));
|
2001-01-20 21:21:49 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
if (image->quick_mask_state)
|
2001-01-15 12:37:01 +08:00
|
|
|
{
|
2006-03-29 01:08:36 +08:00
|
|
|
GimpChannel *quick_mask = gimp_image_get_quick_mask (image);
|
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
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
image->quick_mask_inverted = ! image->quick_mask_inverted;
|
2001-11-11 03:10:28 +08:00
|
|
|
}
|