~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to app/core/gimpimage-qmask.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* The GIMP -- an image manipulation program
2
 
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3
 
 *
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.
8
 
 *
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.
13
 
 *
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.
17
 
 */
18
 
 
19
 
#include "config.h"
20
 
 
21
 
#include <glib-object.h>
22
 
 
23
 
#include "libgimpcolor/gimpcolor.h"
24
 
 
25
 
#include "core-types.h"
26
 
 
27
 
#include "gimp.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"
36
 
 
37
 
#include "gimp-intl.h"
38
 
 
39
 
 
40
 
/*  public functions  */
41
 
 
42
 
void
43
 
gimp_image_set_qmask_state (GimpImage *gimage,
44
 
                            gboolean   qmask_state)
45
 
{
46
 
  GimpChannel *selection;
47
 
  GimpChannel *mask;
48
 
 
49
 
  g_return_if_fail (GIMP_IS_IMAGE (gimage));
50
 
 
51
 
  if (qmask_state == gimage->qmask_state)
52
 
    return;
53
 
 
54
 
  /*  set image->qmask_state early so we can return early when
55
 
   *  being called recursively
56
 
   */
57
 
  gimage->qmask_state = qmask_state ? TRUE : FALSE;
58
 
 
59
 
  selection = gimp_image_get_mask (gimage);
60
 
  mask      = gimp_image_get_qmask (gimage);
61
 
 
62
 
  if (qmask_state)
63
 
    {
64
 
      if (! mask)
65
 
        {
66
 
          gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_IMAGE_QMASK,
67
 
                                       _("Enable Quick Mask"));
68
 
 
69
 
          if (gimp_channel_is_empty (selection))
70
 
            {
71
 
              /* if no selection */
72
 
 
73
 
              GimpLayer *floating_sel = gimp_image_floating_sel (gimage);
74
 
 
75
 
              if (floating_sel)
76
 
                floating_sel_to_layer (floating_sel);
77
 
 
78
 
              mask = gimp_channel_new (gimage,
79
 
                                       gimage->width,
80
 
                                       gimage->height,
81
 
                                       GIMP_IMAGE_QMASK_NAME,
82
 
                                       &gimage->qmask_color);
83
 
 
84
 
              /* Clear the mask */
85
 
              gimp_channel_clear (mask, NULL, FALSE);
86
 
            }
87
 
          else
88
 
            {
89
 
              /* if selection */
90
 
 
91
 
              mask = GIMP_CHANNEL (gimp_item_duplicate (GIMP_ITEM (selection),
92
 
                                                        GIMP_TYPE_CHANNEL,
93
 
                                                        FALSE));
94
 
 
95
 
              /* Clear the selection */
96
 
              gimp_channel_clear (selection, NULL, TRUE);
97
 
 
98
 
              gimp_channel_set_color (mask, &gimage->qmask_color, FALSE);
99
 
              gimp_item_rename (GIMP_ITEM (mask), GIMP_IMAGE_QMASK_NAME);
100
 
            }
101
 
 
102
 
          if (gimage->qmask_inverted)
103
 
            gimp_channel_invert (mask, FALSE);
104
 
 
105
 
          gimp_image_add_channel (gimage, mask, 0);
106
 
 
107
 
          gimp_image_undo_group_end (gimage);
108
 
        }
109
 
    }
110
 
  else
111
 
    {
112
 
      if (mask)
113
 
        {
114
 
          GimpLayer *floating_sel = gimp_image_floating_sel (gimage);
115
 
 
116
 
          gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_IMAGE_QMASK,
117
 
                                       _("Disable Quick Mask"));
118
 
 
119
 
          if (gimage->qmask_inverted)
120
 
            gimp_channel_invert (mask, TRUE);
121
 
 
122
 
          if (floating_sel && floating_sel->fs.drawable == GIMP_DRAWABLE (mask))
123
 
            floating_sel_anchor (floating_sel);
124
 
 
125
 
          gimp_selection_load (gimp_image_get_mask (gimage), mask);
126
 
          gimp_image_remove_channel (gimage, mask);
127
 
 
128
 
          gimp_image_undo_group_end (gimage);
129
 
        }
130
 
    }
131
 
 
132
 
  gimp_image_qmask_changed (gimage);
133
 
}
134
 
 
135
 
gboolean
136
 
gimp_image_get_qmask_state (const GimpImage *gimage)
137
 
{
138
 
  g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
139
 
 
140
 
  return gimage->qmask_state;
141
 
}
142
 
 
143
 
void
144
 
gimp_image_set_qmask_color (GimpImage     *gimage,
145
 
                            const GimpRGB *color)
146
 
{
147
 
  GimpChannel *qmask;
148
 
 
149
 
  g_return_if_fail (GIMP_IS_IMAGE (gimage));
150
 
  g_return_if_fail (color != NULL);
151
 
 
152
 
  gimage->qmask_color = *color;
153
 
 
154
 
  qmask = gimp_image_get_qmask (gimage);
155
 
  if (qmask)
156
 
    gimp_channel_set_color (qmask, color, TRUE);
157
 
}
158
 
 
159
 
void
160
 
gimp_image_get_qmask_color (const GimpImage *gimage,
161
 
                            GimpRGB         *color)
162
 
{
163
 
  g_return_if_fail (GIMP_IS_IMAGE (gimage));
164
 
  g_return_if_fail (color != NULL);
165
 
 
166
 
  *color = gimage->qmask_color;
167
 
}
168
 
 
169
 
GimpChannel *
170
 
gimp_image_get_qmask (const GimpImage *gimage)
171
 
{
172
 
  g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
173
 
 
174
 
  return gimp_image_get_channel_by_name (gimage, GIMP_IMAGE_QMASK_NAME);
175
 
}
176
 
 
177
 
void
178
 
gimp_image_qmask_invert (GimpImage *gimage)
179
 
{
180
 
  g_return_if_fail (GIMP_IS_IMAGE (gimage));
181
 
 
182
 
  if (gimage->qmask_state)
183
 
    {
184
 
      GimpChannel *qmask = gimp_image_get_qmask (gimage);
185
 
 
186
 
      if (qmask)
187
 
        gimp_channel_invert (qmask, TRUE);
188
 
    }
189
 
 
190
 
  gimage->qmask_inverted = ! gimage->qmask_inverted;
191
 
}