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"
|
|
|
|
|
1999-07-07 11:18:54 +08:00
|
|
|
#include <stdlib.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 "gimpcontext.h"
|
|
|
|
#include "gimpimage.h"
|
|
|
|
#include "gimpimage-mask.h"
|
|
|
|
#include "gimpimage-qmask.h"
|
2002-02-22 06:19:45 +08:00
|
|
|
#include "gimplayer-floating-sel.h"
|
2001-11-11 03:10:28 +08:00
|
|
|
|
1999-07-07 11:18:54 +08:00
|
|
|
#include "undo.h"
|
|
|
|
|
2000-12-17 05:37:03 +08:00
|
|
|
#include "libgimp/gimpintl.h"
|
|
|
|
|
1999-07-07 11:18:54 +08:00
|
|
|
|
2001-11-11 03:10:28 +08:00
|
|
|
/* local function prototypes */
|
|
|
|
|
2001-11-30 22:41:56 +08:00
|
|
|
static void gimp_image_qmask_removed_callback (GObject *qmask,
|
|
|
|
GimpImage *gimage);
|
2001-07-31 01:17:36 +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
|
|
|
{
|
2001-11-30 22:41:56 +08:00
|
|
|
g_return_if_fail (GIMP_IS_IMAGE (gimage));
|
1999-07-07 11:18:54 +08:00
|
|
|
|
2001-11-30 22:41:56 +08:00
|
|
|
if (qmask_state != gimage->qmask_state)
|
2001-11-30 00:44:51 +08:00
|
|
|
{
|
2001-11-30 22:41:56 +08:00
|
|
|
GimpChannel *mask;
|
|
|
|
GimpRGB color;
|
|
|
|
|
|
|
|
if (qmask_state)
|
|
|
|
{
|
|
|
|
/* Set the defaults */
|
|
|
|
color = gimage->qmask_color;
|
|
|
|
|
|
|
|
mask = gimp_image_get_channel_by_name (gimage, "Qmask");
|
|
|
|
|
|
|
|
if (! mask)
|
|
|
|
{
|
2002-02-24 01:29:19 +08:00
|
|
|
undo_push_group_start (gimage, IMAGE_QMASK_UNDO_GROUP);
|
2001-11-30 22:41:56 +08:00
|
|
|
|
|
|
|
if (gimp_image_mask_is_empty (gimage))
|
|
|
|
{
|
|
|
|
GimpLayer *layer;
|
|
|
|
|
|
|
|
/* if no selection */
|
|
|
|
|
|
|
|
if ((layer = gimp_image_floating_sel (gimage)))
|
|
|
|
{
|
|
|
|
floating_sel_to_layer (layer);
|
|
|
|
}
|
|
|
|
|
|
|
|
mask = gimp_channel_new (gimage,
|
|
|
|
gimage->width,
|
|
|
|
gimage->height,
|
|
|
|
"Qmask",
|
|
|
|
&color);
|
|
|
|
gimp_image_add_channel (gimage, mask, 0);
|
|
|
|
|
|
|
|
gimp_drawable_fill_by_type (GIMP_DRAWABLE (mask),
|
|
|
|
gimp_get_current_context (gimage->gimp),
|
2002-03-18 19:07:34 +08:00
|
|
|
GIMP_TRANSPARENT_FILL);
|
2001-11-30 22:41:56 +08:00
|
|
|
}
|
|
|
|
else /* if selection */
|
|
|
|
{
|
2003-02-11 21:52:47 +08:00
|
|
|
mask = GIMP_CHANNEL (gimp_item_duplicate (GIMP_ITEM (gimp_image_get_mask (gimage)),
|
|
|
|
G_TYPE_FROM_INSTANCE (gimp_image_get_mask (gimage)),
|
|
|
|
FALSE));
|
2002-08-20 18:22:23 +08:00
|
|
|
gimp_image_mask_clear (gimage); /* Clear the selection */
|
2001-11-30 22:41:56 +08:00
|
|
|
|
|
|
|
gimp_image_add_channel (gimage, mask, 0);
|
|
|
|
gimp_channel_set_color (mask, &color);
|
|
|
|
gimp_object_set_name (GIMP_OBJECT (mask), "Qmask");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gimage->qmask_inverted)
|
2002-06-07 03:07:59 +08:00
|
|
|
gimp_channel_invert (mask, TRUE);
|
2001-11-30 22:41:56 +08:00
|
|
|
|
2002-02-24 01:29:19 +08:00
|
|
|
undo_push_image_qmask (gimage);
|
2001-11-30 22:41:56 +08:00
|
|
|
|
|
|
|
undo_push_group_end (gimage);
|
|
|
|
|
|
|
|
/* connect to the removed signal, so the buttons get updated */
|
2003-01-06 06:07:10 +08:00
|
|
|
g_signal_connect (mask, "removed",
|
2001-11-30 22:41:56 +08:00
|
|
|
G_CALLBACK (gimp_image_qmask_removed_callback),
|
|
|
|
gimage);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mask = gimp_image_get_channel_by_name (gimage, "Qmask");
|
|
|
|
|
|
|
|
if (mask)
|
|
|
|
{
|
2002-02-24 01:29:19 +08:00
|
|
|
undo_push_group_start (gimage, IMAGE_QMASK_UNDO_GROUP);
|
2001-11-30 22:41:56 +08:00
|
|
|
|
|
|
|
/* push the undo here since removing the mask will
|
|
|
|
* call the qmask_removed_callback() which will set
|
|
|
|
* the qmask_state to FALSE
|
|
|
|
*/
|
2002-02-24 01:29:19 +08:00
|
|
|
undo_push_image_qmask (gimage);
|
2001-11-30 22:41:56 +08:00
|
|
|
|
|
|
|
if (gimage->qmask_inverted)
|
2002-06-07 03:07:59 +08:00
|
|
|
gimp_channel_invert (mask, TRUE);
|
2001-11-30 22:41:56 +08:00
|
|
|
|
|
|
|
gimp_image_mask_load (gimage, mask);
|
|
|
|
gimp_image_remove_channel (gimage, mask);
|
|
|
|
|
|
|
|
undo_push_group_end (gimage);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gimage->qmask_state = qmask_state ? TRUE : FALSE;
|
|
|
|
|
|
|
|
gimp_image_qmask_changed (gimage);
|
2001-11-30 00:44:51 +08:00
|
|
|
}
|
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
|
|
|
|
2001-11-30 22:41:56 +08:00
|
|
|
qmask = gimp_image_get_channel_by_name (gimage, "Qmask");
|
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,
|
|
|
|
GIMP_DRAWABLE (qmask)->width,
|
|
|
|
GIMP_DRAWABLE (qmask)->height);
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-30 22:41:56 +08:00
|
|
|
/* private functions */
|
2001-11-11 03:10:28 +08:00
|
|
|
|
|
|
|
static void
|
2001-11-30 22:41:56 +08:00
|
|
|
gimp_image_qmask_removed_callback (GObject *qmask,
|
|
|
|
GimpImage *gimage)
|
2001-11-11 03:10:28 +08:00
|
|
|
{
|
2001-11-30 22:41:56 +08:00
|
|
|
gimp_image_set_qmask_state (gimage, FALSE);
|
2001-11-11 03:10:28 +08:00
|
|
|
}
|