~ubuntu-branches/ubuntu/breezy/gimp/breezy

« back to all changes in this revision

Viewing changes to app/core/gimplayer-floating-sel.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2005-10-04 19:04:46 UTC
  • Revision ID: james.westby@ubuntu.com-20051004190446-ukh32kwk56s4sjhu
Tags: upstream-2.2.8
ImportĀ upstreamĀ versionĀ 2.2.8

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 "libgimpmath/gimpmath.h"
 
24
 
 
25
#include "core-types.h"
 
26
 
 
27
#include "base/boundary.h"
 
28
#include "base/pixel-region.h"
 
29
#include "base/tile-manager.h"
 
30
 
 
31
#include "paint-funcs/paint-funcs.h"
 
32
 
 
33
#include "gimpimage.h"
 
34
#include "gimpimage-undo.h"
 
35
#include "gimpimage-undo-push.h"
 
36
#include "gimplayer.h"
 
37
#include "gimplayer-floating-sel.h"
 
38
#include "gimplayermask.h"
 
39
 
 
40
#include "gimp-intl.h"
 
41
 
 
42
 
 
43
void
 
44
floating_sel_attach (GimpLayer    *layer,
 
45
                     GimpDrawable *drawable)
 
46
{
 
47
  GimpImage *gimage;
 
48
  GimpLayer *floating_sel;
 
49
 
 
50
  g_return_if_fail (GIMP_IS_LAYER (layer));
 
51
  g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
 
52
  g_return_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)));
 
53
  g_return_if_fail (drawable != GIMP_DRAWABLE (layer));
 
54
  g_return_if_fail (gimp_item_get_image (GIMP_ITEM (layer)) ==
 
55
                    gimp_item_get_image (GIMP_ITEM (drawable)));
 
56
 
 
57
  gimage = gimp_item_get_image (GIMP_ITEM (drawable));
 
58
 
 
59
  floating_sel = gimp_image_floating_sel (gimage);
 
60
 
 
61
  /*  If there is already a floating selection, anchor it  */
 
62
  if (floating_sel)
 
63
    {
 
64
      floating_sel_anchor (floating_sel);
 
65
 
 
66
      /*  if we were pasting to the old floating selection, paste now
 
67
       *  to the drawable
 
68
       */
 
69
      if (drawable == (GimpDrawable *) floating_sel)
 
70
        drawable = gimp_image_active_drawable (gimage);
 
71
    }
 
72
 
 
73
  /*  set the drawable and allocate a backing store  */
 
74
  gimp_layer_set_preserve_trans (layer, TRUE, FALSE);
 
75
  layer->fs.drawable      = drawable;
 
76
  layer->fs.backing_store = tile_manager_new (GIMP_ITEM (layer)->width,
 
77
                                              GIMP_ITEM (layer)->height,
 
78
                                              gimp_drawable_bytes (drawable));
 
79
 
 
80
  /*  add the layer to the gimage  */
 
81
  gimp_image_add_layer (gimage, layer, 0);
 
82
 
 
83
  /*  store the affected area from the drawable in the backing store  */
 
84
  floating_sel_rigor (layer, TRUE);
 
85
}
 
86
 
 
87
void
 
88
floating_sel_remove (GimpLayer *layer)
 
89
{
 
90
  GimpImage *gimage;
 
91
 
 
92
  g_return_if_fail (GIMP_IS_LAYER (layer));
 
93
  g_return_if_fail (gimp_layer_is_floating_sel (layer));
 
94
 
 
95
  gimage = gimp_item_get_image (GIMP_ITEM (layer->fs.drawable));
 
96
 
 
97
  gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_FS_REMOVE,
 
98
                               _("Remove Floating Selection"));
 
99
 
 
100
  /*  store the affected area from the drawable in the backing store  */
 
101
  floating_sel_relax (layer, TRUE);
 
102
 
 
103
  /*  Invalidate the preview of the obscured drawable.  We do this here
 
104
   *  because it will not be done until the floating selection is removed,
 
105
   *  at which point the obscured drawable's preview will not be declared
 
106
   *  invalid.
 
107
   */
 
108
  gimp_viewable_invalidate_preview (GIMP_VIEWABLE (layer));
 
109
 
 
110
  /*  remove the layer from the gimage  */
 
111
  gimp_image_remove_layer (gimage, layer);
 
112
 
 
113
  gimp_image_undo_group_end (gimage);
 
114
}
 
115
 
 
116
void
 
117
floating_sel_anchor (GimpLayer *layer)
 
118
{
 
119
  GimpImage    *gimage;
 
120
  GimpDrawable *drawable;
 
121
 
 
122
  g_return_if_fail (GIMP_IS_LAYER (layer));
 
123
  g_return_if_fail (gimp_layer_is_floating_sel (layer));
 
124
 
 
125
  gimage = gimp_item_get_image (GIMP_ITEM (layer));
 
126
 
 
127
  if (! gimp_layer_is_floating_sel (layer))
 
128
    {
 
129
      g_message (_("Cannot anchor this layer because "
 
130
                   "it is not a floating selection."));
 
131
      return;
 
132
    }
 
133
 
 
134
  /*  Start a floating selection anchoring undo  */
 
135
  gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_FS_ANCHOR,
 
136
                               _("Anchor Floating Selection"));
 
137
 
 
138
  /* Invalidate the previews of the layer that will be composited
 
139
   * with the floating section.
 
140
   */
 
141
  gimp_viewable_invalidate_preview (GIMP_VIEWABLE (layer->fs.drawable));
 
142
 
 
143
  /*  Relax the floating selection  */
 
144
  floating_sel_relax (layer, TRUE);
 
145
 
 
146
  /*  Composite the floating selection contents  */
 
147
  floating_sel_composite (layer,
 
148
                          GIMP_ITEM (layer)->offset_x,
 
149
                          GIMP_ITEM (layer)->offset_y,
 
150
                          GIMP_ITEM (layer)->width,
 
151
                          GIMP_ITEM (layer)->height, TRUE);
 
152
 
 
153
  drawable = layer->fs.drawable;
 
154
 
 
155
  /*  remove the floating selection  */
 
156
  gimp_image_remove_layer (gimage, layer);
 
157
 
 
158
  /*  end the group undo  */
 
159
  gimp_image_undo_group_end (gimage);
 
160
 
 
161
  /*  invalidate the boundaries  */
 
162
  gimp_drawable_invalidate_boundary (GIMP_DRAWABLE (gimp_image_get_mask (gimage)));
 
163
}
 
164
 
 
165
void
 
166
floating_sel_activate_drawable (GimpLayer *layer)
 
167
{
 
168
  GimpImage *gimage;
 
169
 
 
170
  g_return_if_fail (GIMP_IS_LAYER (layer));
 
171
  g_return_if_fail (gimp_layer_is_floating_sel (layer));
 
172
 
 
173
  gimage = gimp_item_get_image (GIMP_ITEM (layer));
 
174
 
 
175
  /*  set the underlying drawable to active  */
 
176
  if (GIMP_IS_LAYER_MASK (layer->fs.drawable))
 
177
    {
 
178
      GimpLayerMask *mask = GIMP_LAYER_MASK (layer->fs.drawable);
 
179
 
 
180
      gimp_image_set_active_layer (gimage, gimp_layer_mask_get_layer (mask));
 
181
    }
 
182
  else if (GIMP_IS_CHANNEL (layer->fs.drawable))
 
183
    {
 
184
      gimp_image_set_active_channel (gimage, GIMP_CHANNEL (layer->fs.drawable));
 
185
    }
 
186
  else
 
187
    {
 
188
      gimp_image_set_active_layer (gimage, GIMP_LAYER (layer->fs.drawable));
 
189
    }
 
190
}
 
191
 
 
192
void
 
193
floating_sel_to_layer (GimpLayer *layer)
 
194
{
 
195
  GimpItem  *item;
 
196
  GimpImage *gimage;
 
197
 
 
198
  g_return_if_fail (GIMP_IS_LAYER (layer));
 
199
  g_return_if_fail (gimp_layer_is_floating_sel (layer));
 
200
 
 
201
  item = GIMP_ITEM (layer);
 
202
 
 
203
  if (! (gimage = gimp_item_get_image (item)))
 
204
    return;
 
205
 
 
206
  /*  Check if the floating layer belongs to a channel...  */
 
207
  if (GIMP_IS_CHANNEL (layer->fs.drawable))
 
208
    {
 
209
      g_message (_("Cannot create a new layer from the floating selection "
 
210
                   "because it belongs to a layer mask or channel."));
 
211
      return;
 
212
    }
 
213
 
 
214
  gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_FS_TO_LAYER,
 
215
                               _("Floating Selection to Layer"));
 
216
 
 
217
  /*  restore the contents of the drawable  */
 
218
  floating_sel_restore (layer,
 
219
                        item->offset_x,
 
220
                        item->offset_y,
 
221
                        item->width,
 
222
                        item->height);
 
223
 
 
224
  gimp_image_undo_push_fs_to_layer (gimage, NULL,
 
225
                                    layer, layer->fs.drawable);
 
226
 
 
227
  /*  clear the selection  */
 
228
  gimp_drawable_invalidate_boundary (GIMP_DRAWABLE (layer));
 
229
 
 
230
  /*  Set pointers  */
 
231
  layer->fs.drawable   = NULL;
 
232
  gimage->floating_sel = NULL;
 
233
  gimp_item_set_visible (GIMP_ITEM (layer), TRUE, TRUE);
 
234
 
 
235
  gimp_image_undo_group_end (gimage);
 
236
 
 
237
  gimp_object_name_changed (GIMP_OBJECT (layer));
 
238
 
 
239
  gimp_drawable_update (GIMP_DRAWABLE (layer),
 
240
                        0, 0,
 
241
                        GIMP_ITEM (layer)->width,
 
242
                        GIMP_ITEM (layer)->height);
 
243
 
 
244
  gimp_image_floating_selection_changed (gimage);
 
245
}
 
246
 
 
247
void
 
248
floating_sel_store (GimpLayer *layer,
 
249
                    gint       x,
 
250
                    gint       y,
 
251
                    gint       w,
 
252
                    gint       h)
 
253
{
 
254
  PixelRegion srcPR, destPR;
 
255
  gint        offx, offy;
 
256
  gint        x1, y1, x2, y2;
 
257
 
 
258
  g_return_if_fail (GIMP_IS_LAYER (layer));
 
259
  g_return_if_fail (gimp_layer_is_floating_sel (layer));
 
260
 
 
261
  /*  Check the backing store & make sure it has the correct dimensions  */
 
262
  if ((tile_manager_width  (layer->fs.backing_store) !=
 
263
       gimp_item_width (GIMP_ITEM(layer)))  ||
 
264
      (tile_manager_height (layer->fs.backing_store) !=
 
265
       gimp_item_height (GIMP_ITEM(layer))) ||
 
266
      (tile_manager_bpp    (layer->fs.backing_store) !=
 
267
       gimp_drawable_bytes (layer->fs.drawable)))
 
268
    {
 
269
      /*  free the backing store and allocate anew  */
 
270
      tile_manager_unref (layer->fs.backing_store);
 
271
 
 
272
      layer->fs.backing_store =
 
273
        tile_manager_new (GIMP_ITEM (layer)->width,
 
274
                          GIMP_ITEM (layer)->height,
 
275
                          gimp_drawable_bytes (layer->fs.drawable));
 
276
    }
 
277
 
 
278
  /*  What this function does is save the specified area of the
 
279
   *  drawable that this floating selection obscures.  We do this so
 
280
   *  that it will be possible to subsequently restore the drawable's area
 
281
   */
 
282
  gimp_item_offsets (GIMP_ITEM (layer->fs.drawable), &offx, &offy);
 
283
 
 
284
  /*  Find the minimum area we need to uncover -- in gimage space  */
 
285
  x1 = MAX (GIMP_ITEM (layer)->offset_x, offx);
 
286
  y1 = MAX (GIMP_ITEM (layer)->offset_y, offy);
 
287
  x2 = MIN (GIMP_ITEM (layer)->offset_x + GIMP_ITEM (layer)->width,
 
288
            offx + gimp_item_width (GIMP_ITEM (layer->fs.drawable)));
 
289
  y2 = MIN (GIMP_ITEM (layer)->offset_y + GIMP_ITEM (layer)->height,
 
290
            offy + gimp_item_height (GIMP_ITEM (layer->fs.drawable)));
 
291
 
 
292
  x1 = CLAMP (x, x1, x2);
 
293
  y1 = CLAMP (y, y1, y2);
 
294
  x2 = CLAMP (x + w, x1, x2);
 
295
  y2 = CLAMP (y + h, y1, y2);
 
296
 
 
297
  if ((x2 - x1) > 0 && (y2 - y1) > 0)
 
298
    {
 
299
      /*  Copy the area from the drawable to the backing store  */
 
300
      pixel_region_init (&srcPR, gimp_drawable_data (layer->fs.drawable),
 
301
                         (x1 - offx), (y1 - offy), (x2 - x1), (y2 - y1), FALSE);
 
302
      pixel_region_init (&destPR, layer->fs.backing_store,
 
303
                         (x1 - GIMP_ITEM (layer)->offset_x),
 
304
                         (y1 - GIMP_ITEM (layer)->offset_y),
 
305
                         (x2 - x1), (y2 - y1), TRUE);
 
306
 
 
307
      copy_region (&srcPR, &destPR);
 
308
    }
 
309
}
 
310
 
 
311
void
 
312
floating_sel_restore (GimpLayer *layer,
 
313
                      gint       x,
 
314
                      gint       y,
 
315
                      gint       w,
 
316
                      gint       h)
 
317
{
 
318
  PixelRegion srcPR, destPR;
 
319
  gint        offx, offy;
 
320
  gint        x1, y1, x2, y2;
 
321
 
 
322
  g_return_if_fail (GIMP_IS_LAYER (layer));
 
323
  g_return_if_fail (gimp_layer_is_floating_sel (layer));
 
324
 
 
325
  /*  What this function does is "uncover" the specified area in the
 
326
   *  drawable that this floating selection obscures.  We do this so
 
327
   *  that either the floating selection can be removed or it can be
 
328
   *  translated
 
329
   */
 
330
 
 
331
  /*  Find the minimum area we need to uncover -- in gimage space  */
 
332
  gimp_item_offsets (GIMP_ITEM (layer->fs.drawable), &offx, &offy);
 
333
 
 
334
  x1 = MAX (GIMP_ITEM (layer)->offset_x, offx);
 
335
  y1 = MAX (GIMP_ITEM (layer)->offset_y, offy);
 
336
  x2 = MIN (GIMP_ITEM (layer)->offset_x + GIMP_ITEM (layer)->width,
 
337
            offx + gimp_item_width  (GIMP_ITEM (layer->fs.drawable)));
 
338
  y2 = MIN (GIMP_ITEM(layer)->offset_y + GIMP_ITEM (layer)->height,
 
339
            offy + gimp_item_height (GIMP_ITEM (layer->fs.drawable)));
 
340
 
 
341
  x1 = CLAMP (x, x1, x2);
 
342
  y1 = CLAMP (y, y1, y2);
 
343
  x2 = CLAMP (x + w, x1, x2);
 
344
  y2 = CLAMP (y + h, y1, y2);
 
345
 
 
346
  if ((x2 - x1) > 0 && (y2 - y1) > 0)
 
347
    {
 
348
      /*  Copy the area from the backing store to the drawable  */
 
349
      pixel_region_init (&srcPR, layer->fs.backing_store,
 
350
                         (x1 - GIMP_ITEM (layer)->offset_x),
 
351
                         (y1 - GIMP_ITEM (layer)->offset_y),
 
352
                         (x2 - x1), (y2 - y1), FALSE);
 
353
      pixel_region_init (&destPR, gimp_drawable_data (layer->fs.drawable),
 
354
                         (x1 - offx), (y1 - offy), (x2 - x1), (y2 - y1), TRUE);
 
355
 
 
356
      copy_region (&srcPR, &destPR);
 
357
    }
 
358
}
 
359
 
 
360
void
 
361
floating_sel_rigor (GimpLayer *layer,
 
362
                    gboolean   push_undo)
 
363
{
 
364
  g_return_if_fail (GIMP_IS_LAYER (layer));
 
365
  g_return_if_fail (gimp_layer_is_floating_sel (layer));
 
366
 
 
367
  /*  store the affected area from the drawable in the backing store  */
 
368
  floating_sel_store (layer,
 
369
                      GIMP_ITEM (layer)->offset_x,
 
370
                      GIMP_ITEM (layer)->offset_y,
 
371
                      GIMP_ITEM (layer)->width,
 
372
                      GIMP_ITEM (layer)->height);
 
373
  layer->fs.initial = TRUE;
 
374
 
 
375
  if (push_undo)
 
376
    gimp_image_undo_push_fs_rigor (gimp_item_get_image (GIMP_ITEM (layer)),
 
377
                                   NULL,
 
378
                                   layer);
 
379
}
 
380
 
 
381
void
 
382
floating_sel_relax (GimpLayer *layer,
 
383
                    gboolean   push_undo)
 
384
{
 
385
  g_return_if_fail (GIMP_IS_LAYER (layer));
 
386
  g_return_if_fail (gimp_layer_is_floating_sel (layer));
 
387
 
 
388
  /*  restore the contents of drawable the floating layer is attached to  */
 
389
  if (layer->fs.initial == FALSE)
 
390
    floating_sel_restore (layer,
 
391
                          GIMP_ITEM (layer)->offset_x,
 
392
                          GIMP_ITEM (layer)->offset_y,
 
393
                          GIMP_ITEM (layer)->width,
 
394
                          GIMP_ITEM (layer)->height);
 
395
  layer->fs.initial = TRUE;
 
396
 
 
397
  if (push_undo)
 
398
    gimp_image_undo_push_fs_relax (gimp_item_get_image (GIMP_ITEM (layer)),
 
399
                                   NULL,
 
400
                                   layer);
 
401
}
 
402
 
 
403
void
 
404
floating_sel_composite (GimpLayer *layer,
 
405
                        gint       x,
 
406
                        gint       y,
 
407
                        gint       w,
 
408
                        gint       h,
 
409
                        gboolean   push_undo)
 
410
{
 
411
  PixelRegion  fsPR;
 
412
  GimpImage   *gimage;
 
413
  GimpLayer   *d_layer = NULL;
 
414
  gint         preserve_trans;
 
415
  gint         active[MAX_CHANNELS];
 
416
  gint         offx, offy;
 
417
  gint         x1, y1, x2, y2;
 
418
  gint         i;
 
419
 
 
420
  g_return_if_fail (GIMP_IS_LAYER (layer));
 
421
  g_return_if_fail (gimp_layer_is_floating_sel (layer));
 
422
 
 
423
  if (! (gimage = gimp_item_get_image (GIMP_ITEM (layer))))
 
424
    return;
 
425
 
 
426
  /*  What this function does is composite the specified area of the
 
427
   *  drawble with the floating selection.  We do this when the gimage
 
428
   *  is constructed, before any other composition takes place.
 
429
   */
 
430
 
 
431
  /*  If this isn't the first composite,
 
432
   *  restore the image underneath
 
433
   */
 
434
  if (! layer->fs.initial)
 
435
    floating_sel_restore (layer, x, y, w, h);
 
436
  else if (gimp_item_get_visible (GIMP_ITEM (layer)))
 
437
    layer->fs.initial = FALSE;
 
438
 
 
439
  /*  First restore what's behind the image if necessary,
 
440
   *  then check for visibility
 
441
   */
 
442
  if (gimp_item_get_visible (GIMP_ITEM (layer)))
 
443
    {
 
444
      /*  Find the minimum area we need to composite -- in gimage space  */
 
445
      gimp_item_offsets (GIMP_ITEM (layer->fs.drawable), &offx, &offy);
 
446
 
 
447
      x1 = MAX (GIMP_ITEM (layer)->offset_x, offx);
 
448
      y1 = MAX (GIMP_ITEM (layer)->offset_y, offy);
 
449
      x2 = MIN (GIMP_ITEM (layer)->offset_x +
 
450
                GIMP_ITEM (layer)->width,
 
451
                offx + gimp_item_width  (GIMP_ITEM (layer->fs.drawable)));
 
452
      y2 = MIN (GIMP_ITEM (layer)->offset_y +
 
453
                GIMP_ITEM (layer)->height,
 
454
                offy + gimp_item_height (GIMP_ITEM (layer->fs.drawable)));
 
455
 
 
456
      x1 = CLAMP (x, x1, x2);
 
457
      y1 = CLAMP (y, y1, y2);
 
458
      x2 = CLAMP (x + w, x1, x2);
 
459
      y2 = CLAMP (y + h, y1, y2);
 
460
 
 
461
      if ((x2 - x1) > 0 && (y2 - y1) > 0)
 
462
        {
 
463
          /*  composite the area from the layer to the drawable  */
 
464
          pixel_region_init (&fsPR, GIMP_DRAWABLE (layer)->tiles,
 
465
                             (x1 - GIMP_ITEM (layer)->offset_x),
 
466
                             (y1 - GIMP_ITEM (layer)->offset_y),
 
467
                             (x2 - x1), (y2 - y1), FALSE);
 
468
 
 
469
          /*  a kludge here to prevent the case of the drawable
 
470
           *  underneath having preserve transparency on, and disallowing
 
471
           *  the composited floating selection from being shown
 
472
           */
 
473
          if (GIMP_IS_LAYER (layer->fs.drawable))
 
474
            {
 
475
              d_layer = GIMP_LAYER (layer->fs.drawable);
 
476
              if ((preserve_trans = gimp_layer_get_preserve_trans (d_layer)))
 
477
                gimp_layer_set_preserve_trans (d_layer, FALSE, FALSE);
 
478
            }
 
479
          else
 
480
            preserve_trans = FALSE;
 
481
 
 
482
          /*  We need to set all gimage channels to active to make sure that
 
483
           *  nothing strange happens while applying the floating selection.
 
484
           *  It wouldn't make sense for the floating selection to be affected
 
485
           *  by the active gimage channels.
 
486
           */
 
487
          for (i = 0; i < MAX_CHANNELS; i++)
 
488
            {
 
489
              active[i] = gimage->active[i];
 
490
              gimage->active[i] = 1;
 
491
            }
 
492
 
 
493
          /*  apply the fs with the undo specified by the value
 
494
           *  passed to this function
 
495
           */
 
496
          gimp_drawable_apply_region (layer->fs.drawable, &fsPR,
 
497
                                      push_undo, NULL,
 
498
                                      layer->opacity,
 
499
                                      layer->mode,
 
500
                                      NULL,
 
501
                                      (x1 - offx), (y1 - offy));
 
502
 
 
503
          /*  restore preserve transparency  */
 
504
          if (preserve_trans)
 
505
            gimp_layer_set_preserve_trans (d_layer, TRUE, FALSE);
 
506
 
 
507
          /*  restore gimage active channels  */
 
508
          for (i = 0; i < MAX_CHANNELS; i++)
 
509
            gimage->active[i] = active[i];
 
510
        }
 
511
    }
 
512
}
 
513
 
 
514
const BoundSeg *
 
515
floating_sel_boundary (GimpLayer *layer,
 
516
                       gint      *n_segs)
 
517
{
 
518
  PixelRegion bPR;
 
519
  gint        i;
 
520
 
 
521
  g_return_val_if_fail (GIMP_IS_LAYER (layer), NULL);
 
522
  g_return_val_if_fail (gimp_layer_is_floating_sel (layer), NULL);
 
523
  g_return_val_if_fail (n_segs != NULL, NULL);
 
524
 
 
525
  if (layer->fs.boundary_known == FALSE)
 
526
    {
 
527
      if (layer->fs.segs)
 
528
        g_free (layer->fs.segs);
 
529
 
 
530
      /*  find the segments  */
 
531
      pixel_region_init (&bPR, GIMP_DRAWABLE (layer)->tiles,
 
532
                         0, 0,
 
533
                         GIMP_ITEM (layer)->width,
 
534
                         GIMP_ITEM (layer)->height, FALSE);
 
535
      layer->fs.segs = find_mask_boundary (&bPR, &layer->fs.num_segs,
 
536
                                           WithinBounds, 0, 0,
 
537
                                           GIMP_ITEM (layer)->width,
 
538
                                           GIMP_ITEM (layer)->height,
 
539
                                           HALF_WAY);
 
540
 
 
541
      /*  offset the segments  */
 
542
      for (i = 0; i < layer->fs.num_segs; i++)
 
543
        {
 
544
          layer->fs.segs[i].x1 += GIMP_ITEM (layer)->offset_x;
 
545
          layer->fs.segs[i].y1 += GIMP_ITEM (layer)->offset_y;
 
546
          layer->fs.segs[i].x2 += GIMP_ITEM (layer)->offset_x;
 
547
          layer->fs.segs[i].y2 += GIMP_ITEM (layer)->offset_y;
 
548
        }
 
549
 
 
550
      layer->fs.boundary_known = TRUE;
 
551
    }
 
552
 
 
553
  *n_segs = layer->fs.num_segs;
 
554
 
 
555
  return layer->fs.segs;
 
556
}
 
557
 
 
558
void
 
559
floating_sel_invalidate (GimpLayer *layer)
 
560
{
 
561
  g_return_if_fail (GIMP_IS_LAYER (layer));
 
562
  g_return_if_fail (gimp_layer_is_floating_sel (layer));
 
563
 
 
564
  /*  Invalidate the attached-to drawable's preview  */
 
565
  gimp_viewable_invalidate_preview (GIMP_VIEWABLE (layer->fs.drawable));
 
566
 
 
567
  /*  Invalidate the boundary  */
 
568
  layer->fs.boundary_known = FALSE;
 
569
}