1
/* The GIMP -- an image manipulation program
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
#include <glib-object.h>
23
#include "libgimpcolor/gimpcolor.h"
25
#include "core-types.h"
28
#include "gimpchannel.h"
29
#include "gimpimage.h"
30
#include "gimpimage-qmask.h"
31
#include "gimpimage-undo.h"
32
#include "gimpimage-undo-push.h"
33
#include "gimplayer.h"
34
#include "gimplayer-floating-sel.h"
35
#include "gimpselection.h"
37
#include "gimp-intl.h"
40
/* public functions */
43
gimp_image_set_qmask_state (GimpImage *gimage,
46
GimpChannel *selection;
49
g_return_if_fail (GIMP_IS_IMAGE (gimage));
51
if (qmask_state == gimage->qmask_state)
54
/* set image->qmask_state early so we can return early when
55
* being called recursively
57
gimage->qmask_state = qmask_state ? TRUE : FALSE;
59
selection = gimp_image_get_mask (gimage);
60
mask = gimp_image_get_qmask (gimage);
66
gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_IMAGE_QMASK,
67
_("Enable Quick Mask"));
69
if (gimp_channel_is_empty (selection))
73
GimpLayer *floating_sel = gimp_image_floating_sel (gimage);
76
floating_sel_to_layer (floating_sel);
78
mask = gimp_channel_new (gimage,
81
GIMP_IMAGE_QMASK_NAME,
82
&gimage->qmask_color);
85
gimp_channel_clear (mask, NULL, FALSE);
91
mask = GIMP_CHANNEL (gimp_item_duplicate (GIMP_ITEM (selection),
95
/* Clear the selection */
96
gimp_channel_clear (selection, NULL, TRUE);
98
gimp_channel_set_color (mask, &gimage->qmask_color, FALSE);
99
gimp_item_rename (GIMP_ITEM (mask), GIMP_IMAGE_QMASK_NAME);
102
if (gimage->qmask_inverted)
103
gimp_channel_invert (mask, FALSE);
105
gimp_image_add_channel (gimage, mask, 0);
107
gimp_image_undo_group_end (gimage);
114
GimpLayer *floating_sel = gimp_image_floating_sel (gimage);
116
gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_IMAGE_QMASK,
117
_("Disable Quick Mask"));
119
if (gimage->qmask_inverted)
120
gimp_channel_invert (mask, TRUE);
122
if (floating_sel && floating_sel->fs.drawable == GIMP_DRAWABLE (mask))
123
floating_sel_anchor (floating_sel);
125
gimp_selection_load (gimp_image_get_mask (gimage), mask);
126
gimp_image_remove_channel (gimage, mask);
128
gimp_image_undo_group_end (gimage);
132
gimp_image_qmask_changed (gimage);
136
gimp_image_get_qmask_state (const GimpImage *gimage)
138
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
140
return gimage->qmask_state;
144
gimp_image_set_qmask_color (GimpImage *gimage,
145
const GimpRGB *color)
149
g_return_if_fail (GIMP_IS_IMAGE (gimage));
150
g_return_if_fail (color != NULL);
152
gimage->qmask_color = *color;
154
qmask = gimp_image_get_qmask (gimage);
156
gimp_channel_set_color (qmask, color, TRUE);
160
gimp_image_get_qmask_color (const GimpImage *gimage,
163
g_return_if_fail (GIMP_IS_IMAGE (gimage));
164
g_return_if_fail (color != NULL);
166
*color = gimage->qmask_color;
170
gimp_image_get_qmask (const GimpImage *gimage)
172
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
174
return gimp_image_get_channel_by_name (gimage, GIMP_IMAGE_QMASK_NAME);
178
gimp_image_qmask_invert (GimpImage *gimage)
180
g_return_if_fail (GIMP_IS_IMAGE (gimage));
182
if (gimage->qmask_state)
184
GimpChannel *qmask = gimp_image_get_qmask (gimage);
187
gimp_channel_invert (qmask, TRUE);
190
gimage->qmask_inverted = ! gimage->qmask_inverted;