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"
|
|
|
|
#include "gimpimage-qmask.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"
|
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
|
2001-11-30 22:41:56 +08:00
|
|
|
gimp_image_set_qmask_state (GimpImage *gimage,
|
|
|
|
gboolean qmask_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
|
|
|
|
2003-03-25 11:29:11 +08:00
|
|
|
if (qmask_state == gimage->qmask_state)
|
|
|
|
return;
|
|
|
|
|
2004-02-14 23:37:23 +08:00
|
|
|
/* set image->qmask_state early so we can return early when
|
|
|
|
* being called recursively
|
|
|
|
*/
|
|
|
|
gimage->qmask_state = qmask_state ? TRUE : FALSE;
|
|
|
|
|
2003-09-03 22:22:38 +08:00
|
|
|
selection = gimp_image_get_mask (gimage);
|
2004-02-14 23:37:23 +08:00
|
|
|
mask = gimp_image_get_channel_by_name (gimage, GIMP_IMAGE_QMASK_NAME);
|
2003-09-03 22:22:38 +08:00
|
|
|
|
2003-03-25 11:29:11 +08:00
|
|
|
if (qmask_state)
|
2001-11-30 00:44:51 +08:00
|
|
|
{
|
2003-03-25 11:29:11 +08:00
|
|
|
if (! mask)
|
|
|
|
{
|
|
|
|
gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_IMAGE_QMASK,
|
|
|
|
_("Enable QuickMask"));
|
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,
|
2004-02-14 23:37:23 +08:00
|
|
|
GIMP_IMAGE_QMASK_NAME,
|
|
|
|
&gimage->qmask_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
|
|
|
|
2004-02-14 23:37:23 +08:00
|
|
|
gimp_channel_set_color (mask, &gimage->qmask_color, FALSE);
|
|
|
|
gimp_item_rename (GIMP_ITEM (mask), GIMP_IMAGE_QMASK_NAME);
|
2003-03-25 11:29:11 +08:00
|
|
|
}
|
2003-03-17 10:25:39 +08:00
|
|
|
|
2003-03-25 11:29:11 +08:00
|
|
|
if (gimage->qmask_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
|
|
|
{
|
2003-03-25 11:29:11 +08:00
|
|
|
gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_IMAGE_QMASK,
|
|
|
|
_("Disable QuickMask"));
|
2001-11-30 22:41:56 +08:00
|
|
|
|
2003-03-25 11:29:11 +08:00
|
|
|
if (gimage->qmask_inverted)
|
|
|
|
gimp_channel_invert (mask, TRUE);
|
2001-11-30 22:41:56 +08:00
|
|
|
|
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
|
|
|
|
2003-03-25 11:29:11 +08:00
|
|
|
gimp_image_qmask_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
|
|
|
|
gimp_image_get_qmask_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);
|
|
|
|
|
|
|
|
return gimage->qmask_state;
|
1999-08-08 04:55:26 +08:00
|
|
|
}
|
|
|
|
|
2001-11-30 22:41:56 +08:00
|
|
|
void
|
|
|
|
gimp_image_qmask_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
|
|
|
|
2001-11-30 22:41:56 +08:00
|
|
|
if (gimage->qmask_state)
|
2001-01-15 12:37:01 +08:00
|
|
|
{
|
2001-11-30 22:41:56 +08:00
|
|
|
GimpChannel *qmask;
|
1999-08-08 04:55:26 +08:00
|
|
|
|
2004-02-14 23:37:23 +08:00
|
|
|
qmask = gimp_image_get_channel_by_name (gimage, GIMP_IMAGE_QMASK_NAME);
|
1999-08-08 04:55:26 +08:00
|
|
|
|
2001-11-30 22:41:56 +08:00
|
|
|
if (qmask)
|
|
|
|
{
|
2002-06-07 03:07:59 +08:00
|
|
|
gimp_channel_invert (qmask, TRUE);
|
2001-11-11 03:10:28 +08:00
|
|
|
|
2001-11-30 22:41:56 +08:00
|
|
|
gimp_drawable_update (GIMP_DRAWABLE (qmask),
|
|
|
|
0, 0,
|
2003-05-08 19:52:31 +08:00
|
|
|
GIMP_ITEM (qmask)->width,
|
|
|
|
GIMP_ITEM (qmask)->height);
|
2001-11-30 22:41:56 +08:00
|
|
|
}
|
|
|
|
}
|
2001-11-11 03:10:28 +08:00
|
|
|
|
2001-11-30 22:41:56 +08:00
|
|
|
gimage->qmask_inverted = ! gimage->qmask_inverted;
|
2001-11-11 03:10:28 +08:00
|
|
|
}
|