gimpimage-merge.c 20.6 KB
Newer Older
1
/* GIMP - The GNU Image Manipulation Program
2 3
 * 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 3 of the License, or
7 8 9 10 11 12 13 14
 * (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
15
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
 */
17

18 19
#include "config.h"

20
#include <cairo.h>
21
#include <gegl.h>
22
#include <gdk-pixbuf/gdk-pixbuf.h>
Sven Neumann's avatar
Sven Neumann committed
23

24
#include "libgimpcolor/gimpcolor.h"
25
#include "libgimpmath/gimpmath.h"
26
#include "libgimpbase/gimpbase.h"
27

28 29
#include "core-types.h"

30
#include "gegl/gimp-babl-compat.h"
31
#include "gegl/gimp-gegl-apply-operation.h"
32
#include "gegl/gimp-gegl-nodes.h"
33 34
#include "gegl/gimp-gegl-utils.h"

35 36
#include "vectors/gimpvectors.h"

37
#include "gimp.h"
38
#include "gimpcontext.h"
39
#include "gimperror.h"
40
#include "gimpgrouplayer.h"
41
#include "gimpimage.h"
42
#include "gimpimage-merge.h"
43
#include "gimpimage-undo.h"
44
#include "gimpitemstack.h"
45
#include "gimplayer-floating-selection.h"
46
#include "gimplayer-new.h"
47
#include "gimplayermask.h"
48
#include "gimpmarshal.h"
49
#include "gimpparasitelist.h"
50
#include "gimppickable.h"
51
#include "gimpprojectable.h"
52
#include "gimpundostack.h"
53

54
#include "gimp-intl.h"
55

56

57
static GimpLayer * gimp_image_merge_layers (GimpImage     *image,
58
                                            GimpContainer *container,
59 60
                                            GSList        *merge_list,
                                            GimpContext   *context,
61
                                            GimpMergeType  merge_type);
62

63

64
/*  public functions  */
65

66
GimpLayer *
67
gimp_image_merge_visible_layers (GimpImage     *image,
68
                                 GimpContext   *context,
69
                                 GimpMergeType  merge_type,
70
                                 gboolean       merge_active_group,
71
                                 gboolean       discard_invisible)
Sven Neumann's avatar
Sven Neumann committed
72
{
73 74 75 76
  GimpContainer *container;
  GList         *list;
  GSList        *merge_list     = NULL;
  GSList        *invisible_list = NULL;
77

78
  g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
79
  g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
80

81
  if (merge_active_group)
82
    {
83 84 85 86 87 88 89 90
      GimpLayer *active_layer = gimp_image_get_active_layer (image);

      /*  if the active layer is the floating selection, get the
       *  underlying drawable, but only if it is a layer
       */
      if (active_layer && gimp_layer_is_floating_sel (active_layer))
        {
          GimpDrawable *fs_drawable;
91

92
          fs_drawable = gimp_layer_get_floating_sel_drawable (active_layer);
93

94 95 96
          if (GIMP_IS_LAYER (fs_drawable))
            active_layer = GIMP_LAYER (fs_drawable);
        }
97

98 99 100 101 102
      if (active_layer)
        container = gimp_item_get_container (GIMP_ITEM (active_layer));
      else
        container = gimp_image_get_layers (image);
    }
103
  else
104 105 106
    {
      container = gimp_image_get_layers (image);
    }
107 108

  for (list = gimp_item_stack_get_item_iter (GIMP_ITEM_STACK (container));
109 110
       list;
       list = g_list_next (list))
111
    {
112 113 114 115
      GimpLayer *layer = list->data;

      if (gimp_layer_is_floating_sel (layer))
        continue;
116

117
      if (gimp_item_get_visible (GIMP_ITEM (layer)))
118 119 120 121 122 123 124
        {
          merge_list = g_slist_append (merge_list, layer);
        }
      else if (discard_invisible)
        {
          invisible_list = g_slist_append (invisible_list, layer);
        }
125
    }
126

127
  if (merge_list)
128
    {
129
      GimpLayer *layer;
130

131
      gimp_set_busy (image->gimp);
132

133 134 135 136 137 138 139
      gimp_image_undo_group_start (image,
                                   GIMP_UNDO_GROUP_IMAGE_LAYERS_MERGE,
                                   C_("undo-type", "Merge Visible Layers"));

      /* if there's a floating selection, anchor it */
      if (gimp_image_get_floating_selection (image))
        floating_sel_anchor (gimp_image_get_floating_selection (image));
140

141
      layer = gimp_image_merge_layers (image,
142
                                       container,
143
                                       merge_list, context, merge_type);
144
      g_slist_free (merge_list);
145

146 147 148 149 150
      if (invisible_list)
        {
          GSList *list;

          for (list = invisible_list; list; list = g_slist_next (list))
151
            gimp_image_remove_layer (image, list->data, TRUE, NULL);
152 153 154 155

          g_slist_free (invisible_list);
        }

156
      gimp_image_undo_group_end (image);
157

158
      gimp_unset_busy (image->gimp);
159

160
      return layer;
161
    }
162

163
  return gimp_image_get_active_layer (image);
164
}
165

166
GimpLayer *
167 168 169
gimp_image_flatten (GimpImage    *image,
                    GimpContext  *context,
                    GError      **error)
170
{
171 172 173
  GList     *list;
  GSList    *merge_list = NULL;
  GimpLayer *layer;
174

175
  g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
176
  g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
177
  g_return_val_if_fail (error == NULL || *error == NULL, NULL);
178

179
  for (list = gimp_image_get_layer_iter (image);
180 181 182
       list;
       list = g_list_next (list))
    {
Sven Neumann's avatar
Sven Neumann committed
183
      layer = list->data;
184

185 186 187
      if (gimp_layer_is_floating_sel (layer))
        continue;

188
      if (gimp_item_get_visible (GIMP_ITEM (layer)))
189
        merge_list = g_slist_append (merge_list, layer);
190
    }
191

192 193 194
  if (merge_list)
    {
      gimp_set_busy (image->gimp);
195

196 197 198
      gimp_image_undo_group_start (image,
                                   GIMP_UNDO_GROUP_IMAGE_LAYERS_MERGE,
                                   C_("undo-type", "Flatten Image"));
199

200 201 202 203 204 205 206 207 208
      /* if there's a floating selection, anchor it */
      if (gimp_image_get_floating_selection (image))
        floating_sel_anchor (gimp_image_get_floating_selection (image));

      layer = gimp_image_merge_layers (image,
                                       gimp_image_get_layers (image),
                                       merge_list, context,
                                       GIMP_FLATTEN_IMAGE);
      g_slist_free (merge_list);
209

210
      gimp_image_alpha_changed (image);
211

212 213 214
      gimp_image_undo_group_end (image);

      gimp_unset_busy (image->gimp);
215 216

      return layer;
217 218
    }

219 220 221
  g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
                       _("Cannot flatten an image without any visible layer."));
  return NULL;
222 223
}

224
GimpLayer *
225 226 227 228 229
gimp_image_merge_down (GimpImage      *image,
                       GimpLayer      *current_layer,
                       GimpContext    *context,
                       GimpMergeType   merge_type,
                       GError        **error)
230
{
231 232
  GimpLayer *layer;
  GList     *list;
233 234
  GList     *layer_list = NULL;
  GSList    *merge_list = NULL;
235

236
  g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
237 238
  g_return_val_if_fail (GIMP_IS_LAYER (current_layer), NULL);
  g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (current_layer)), NULL);
239
  g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
240 241
  g_return_val_if_fail (error == NULL || *error == NULL, NULL);

242 243
  for (list = gimp_item_get_container_iter (GIMP_ITEM (current_layer));
       list;
244
       list = g_list_next (list))
245
    {
246
      layer = list->data;
247

248
      if (layer == current_layer)
249
        break;
250
    }
251

252 253
  for (layer_list = g_list_next (list);
       layer_list;
254
       layer_list = g_list_next (layer_list))
255
    {
256
      layer = layer_list->data;
257

258
      if (gimp_item_get_visible (GIMP_ITEM (layer)))
259
        {
260 261 262
          if (gimp_viewable_get_children (GIMP_VIEWABLE (layer)))
            {
              g_set_error_literal (error, 0, 0,
263
                                   _("Cannot merge down to a layer group."));
264 265 266
              return NULL;
            }

267
          if (gimp_item_is_content_locked (GIMP_ITEM (layer)))
268 269 270 271 272
            {
              g_set_error_literal (error, 0, 0,
                                   _("The layer to merge down to is locked."));
              return NULL;
            }
273 274 275 276

          merge_list = g_slist_append (NULL, layer);
          break;
        }
277 278
    }

279 280 281 282 283 284 285
  if (! merge_list)
    {
      g_set_error_literal (error, 0, 0,
                           _("There is no visible layer to merge down to."));
      return NULL;
    }

286
  merge_list = g_slist_prepend (merge_list, current_layer);
287

288
  gimp_set_busy (image->gimp);
289

290 291 292 293
  gimp_image_undo_group_start (image,
                               GIMP_UNDO_GROUP_IMAGE_LAYERS_MERGE,
                               C_("undo-type", "Merge Down"));

294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309
  if (gimp_layer_is_floating_sel (current_layer))
    {
      /* Merging down a floating selection is basically equivalent to
       * anchoring it.
       */
      floating_sel_anchor (current_layer);
      /* layer is already set to the right layer below the floating
       * selection, on which we anchored. This will be the return value.
       */
    }
  else
    {
      layer = gimp_image_merge_layers (image,
                                       gimp_item_get_container (GIMP_ITEM (current_layer)),
                                       merge_list, context, merge_type);
    }
310
  g_slist_free (merge_list);
311

312 313
  gimp_image_undo_group_end (image);

314
  gimp_unset_busy (image->gimp);
315

316
  return layer;
317 318
}

319 320 321 322 323 324 325 326 327 328 329 330 331 332
GimpLayer *
gimp_image_merge_group_layer (GimpImage      *image,
                              GimpGroupLayer *group)
{
  GimpLayer *parent;
  GimpLayer *layer;
  gint       index;

  g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
  g_return_val_if_fail (GIMP_IS_GROUP_LAYER (group), NULL);
  g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (group)), NULL);
  g_return_val_if_fail (gimp_item_get_image (GIMP_ITEM (group)) == image, NULL);

  gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_IMAGE_LAYERS_MERGE,
333
                               C_("undo-type", "Merge Layer Group"));
334

335
  parent = gimp_layer_get_parent (GIMP_LAYER (group));
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351
  index  = gimp_item_get_index (GIMP_ITEM (group));

  layer = GIMP_LAYER (gimp_item_duplicate (GIMP_ITEM (group),
                                           GIMP_TYPE_LAYER));

  gimp_object_set_name (GIMP_OBJECT (layer), gimp_object_get_name (group));

  gimp_image_remove_layer (image, GIMP_LAYER (group), TRUE, NULL);
  gimp_image_add_layer (image, layer, parent, index, TRUE);

  gimp_image_undo_group_end (image);

  return layer;
}


352 353 354
/* merging vectors */

GimpVectors *
355 356
gimp_image_merge_visible_vectors (GimpImage  *image,
                                  GError    **error)
357
{
358 359 360
  GList       *list;
  GList       *merge_list = NULL;
  GimpVectors *vectors;
361 362

  g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
363
  g_return_val_if_fail (error == NULL || *error == NULL, NULL);
364

365
  for (list = gimp_image_get_vectors_iter (image);
366 367 368 369 370 371
       list;
       list = g_list_next (list))
    {
      vectors = list->data;

      if (gimp_item_get_visible (GIMP_ITEM (vectors)))
372
        merge_list = g_list_prepend (merge_list, vectors);
373 374
    }

375 376
  merge_list = g_list_reverse (merge_list);

377 378
  if (merge_list && merge_list->next)
    {
379 380 381 382
      GimpVectors *target_vectors;
      gchar       *name;
      gint         pos;

383 384 385
      gimp_set_busy (image->gimp);

      gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_IMAGE_VECTORS_MERGE,
386
                                   C_("undo-type", "Merge Visible Paths"));
387

388
      vectors = GIMP_VECTORS (merge_list->data);
389

390
      name = g_strdup (gimp_object_get_name (vectors));
391 392
      pos = gimp_item_get_index (GIMP_ITEM (vectors));

393 394
      target_vectors = GIMP_VECTORS (gimp_item_duplicate (GIMP_ITEM (vectors),
                                                          GIMP_TYPE_VECTORS));
395
      gimp_image_remove_vectors (image, vectors, TRUE, NULL);
396

397 398 399
      for (list = g_list_next (merge_list);
           list;
           list = g_list_next (list))
400
        {
401 402
          vectors = list->data;

403
          gimp_vectors_add_strokes (vectors, target_vectors);
404
          gimp_image_remove_vectors (image, vectors, TRUE, NULL);
405 406 407 408
        }

      gimp_object_take_name (GIMP_OBJECT (target_vectors), name);

409
      g_list_free (merge_list);
410

411 412
      /* FIXME tree */
      gimp_image_add_vectors (image, target_vectors, NULL, pos, TRUE);
413 414 415 416 417 418 419 420
      gimp_unset_busy (image->gimp);

      gimp_image_undo_group_end (image);

      return target_vectors;
    }
  else
    {
421
      g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
422 423
                           _("Not enough visible paths for a merge. "
                             "There must be at least two."));
424 425 426 427 428 429 430 431
      return NULL;
    }
}


/*  private functions  */

static GimpLayer *
432
gimp_image_merge_layers (GimpImage     *image,
433
                         GimpContainer *container,
434
                         GSList        *merge_list,
435
                         GimpContext   *context,
436
                         GimpMergeType  merge_type)
437
{
438 439 440
  GimpLayer        *parent;
  gint              x1, y1;
  gint              x2, y2;
Massimo Valentini's avatar
Massimo Valentini committed
441
  GSList           *layers;
442
  GimpLayer        *layer;
443
  GimpLayer        *top_layer;
444
  GimpLayer        *bottom_layer;
445
  GimpLayer        *merge_layer;
446
  gint              position;
447 448 449 450 451 452 453
  GeglNode         *node;
  GeglNode         *source_node;
  GeglNode         *flatten_node;
  GeglNode         *offset_node;
  GeglNode         *last_node;
  GeglNode         *last_node_source;
  GimpParasiteList *parasites;
454

455
  g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
456
  g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
457

458
  parent = gimp_layer_get_parent (merge_list->data);
459

460
  /*  Get the layer extents  */
461 462 463
  x1 = y1 = 0;
  x2 = y2 = 0;
  for (layers = merge_list; layers; layers = g_slist_next (layers))
464
    {
465 466 467
      gint off_x, off_y;

      layer = layers->data;
468

469
      gimp_item_get_offset (GIMP_ITEM (layer), &off_x, &off_y);
470

471
      switch (merge_type)
472 473 474
        {
        case GIMP_EXPAND_AS_NECESSARY:
        case GIMP_CLIP_TO_IMAGE:
475
          if (layers == merge_list)
476 477 478
            {
              x1 = off_x;
              y1 = off_y;
479 480
              x2 = off_x + gimp_item_get_width  (GIMP_ITEM (layer));
              y2 = off_y + gimp_item_get_height (GIMP_ITEM (layer));
481 482 483 484 485 486 487
            }
          else
            {
              if (off_x < x1)
                x1 = off_x;
              if (off_y < y1)
                y1 = off_y;
488 489 490 491
              if ((off_x + gimp_item_get_width (GIMP_ITEM (layer))) > x2)
                x2 = (off_x + gimp_item_get_width (GIMP_ITEM (layer)));
              if ((off_y + gimp_item_get_height (GIMP_ITEM (layer))) > y2)
                y2 = (off_y + gimp_item_get_height (GIMP_ITEM (layer)));
492
            }
493

494 495
          if (merge_type == GIMP_CLIP_TO_IMAGE)
            {
496 497 498 499
              x1 = CLAMP (x1, 0, gimp_image_get_width  (image));
              y1 = CLAMP (y1, 0, gimp_image_get_height (image));
              x2 = CLAMP (x2, 0, gimp_image_get_width  (image));
              y2 = CLAMP (y2, 0, gimp_image_get_height (image));
500 501 502 503
            }
          break;

        case GIMP_CLIP_TO_BOTTOM_LAYER:
504
          if (layers->next == NULL)
505 506 507
            {
              x1 = off_x;
              y1 = off_y;
508 509
              x2 = off_x + gimp_item_get_width  (GIMP_ITEM (layer));
              y2 = off_y + gimp_item_get_height (GIMP_ITEM (layer));
510 511 512 513
            }
          break;

        case GIMP_FLATTEN_IMAGE:
514
          if (layers->next == NULL)
515 516 517
            {
              x1 = 0;
              y1 = 0;
518 519
              x2 = gimp_image_get_width  (image);
              y2 = gimp_image_get_height (image);
520 521 522
            }
          break;
        }
523
    }
524

525
  if ((x2 - x1) == 0 || (y2 - y1) == 0)
526
    return NULL;
527

528 529
  top_layer    = merge_list->data;
  bottom_layer = layer;
530

531
  flatten_node = NULL;
532

533
  if (merge_type == GIMP_FLATTEN_IMAGE ||
534 535
      (gimp_drawable_is_indexed (GIMP_DRAWABLE (layer)) &&
       ! gimp_drawable_has_alpha (GIMP_DRAWABLE (layer))))
536
    {
537
      GimpRGB bg;
538

539
      merge_layer = gimp_layer_new (image, (x2 - x1), (y2 - y1),
540
                                    gimp_image_get_layer_format (image, FALSE),
541
                                    gimp_object_get_name (bottom_layer),
542
                                    GIMP_OPACITY_OPAQUE,
543
                                    gimp_image_get_default_new_layer_mode (image));
544

545
      if (! merge_layer)
546
        {
547 548
          g_warning ("%s: could not allocate merge layer", G_STRFUNC);

549 550
          return NULL;
        }
551

552
      /*  get the background for compositing  */
553
      gimp_context_get_background (context, &bg);
554 555
      gimp_pickable_srgb_to_image_color (GIMP_PICKABLE (layer),
                                         &bg, &bg);
556

557 558
      flatten_node = gimp_gegl_create_flatten_node (
        &bg, gimp_layer_get_real_composite_space (bottom_layer));
559

560
      position = 0;
561 562 563
    }
  else
    {
564
      /*  The final merged layer inherits the name of the bottom most layer
565 566
       *  and the resulting layer has an alpha channel whether or not the
       *  original did. Opacity is set to 100% and the MODE is set to normal.
567 568
       */

569
      merge_layer =
570
        gimp_layer_new (image, (x2 - x1), (y2 - y1),
571 572
                        gimp_drawable_get_format_with_alpha (GIMP_DRAWABLE (bottom_layer)),
                        gimp_object_get_name (bottom_layer),
573
                        GIMP_OPACITY_OPAQUE,
574
                        gimp_image_get_default_new_layer_mode (image));
575

576
      if (! merge_layer)
577 578
        {
          g_warning ("%s: could not allocate merge layer", G_STRFUNC);
579

580 581
          return NULL;
        }
582

583 584 585
      /*  Find the index in the layer list of the bottom layer--we need this
       *  in order to add the final, merged layer to the layer list correctly
       */
586
      position =
587
        gimp_container_get_n_children (container) -
588
        gimp_container_get_child_index (container, GIMP_OBJECT (bottom_layer));
589
    }
590

591
  gimp_item_set_offset (GIMP_ITEM (merge_layer), x1, y1);
592

593 594 595 596
  /*  Make sure the image's graph is constructed, so that top-level layers have
   *  a parent node.
   */
  (void) gimp_projectable_get_graph (GIMP_PROJECTABLE (image));
597

598 599
  /*  Build our graph inside the top-layer's parent node  */
  source_node = gimp_filter_get_node (GIMP_FILTER (top_layer));
600

601 602
  node = gegl_node_get_parent (source_node);
  g_assert (node != NULL);
603

604 605 606 607 608
  offset_node = gegl_node_new_child (node,
                                     "operation", "gegl:translate",
                                     "x",         (gdouble) -x1,
                                     "y",         (gdouble) -y1,
                                     NULL);
609

610 611 612 613
  if (flatten_node)
    {
      gegl_node_add_child (node, flatten_node);
      g_object_unref (flatten_node);
614

615 616 617 618 619 620
      gegl_node_link_many (source_node, flatten_node, offset_node, NULL);
    }
  else
    {
      gegl_node_link_many (source_node, offset_node, NULL);
    }
621

622 623 624
  /*  Disconnect the bottom-layer node's input  */
  last_node        = gimp_filter_get_node (GIMP_FILTER (bottom_layer));
  last_node_source = gegl_node_get_producer (last_node, "input", NULL);
625

626
  gegl_node_disconnect (last_node, "input");
627

628 629 630 631
  /*  Render the graph into the merge layer  */
  gegl_node_blit_buffer (offset_node,
                         gimp_drawable_get_buffer (GIMP_DRAWABLE (merge_layer)),
                         NULL, 0, GEGL_ABYSS_NONE);
632

633 634 635
  /*  Reconnect the bottom-layer node's input  */
  if (last_node_source)
    gegl_node_link (last_node_source, last_node);
636

637 638
  /*  Clean up the graph  */
  gegl_node_remove_child (node, offset_node);
639

640 641
  if (flatten_node)
    gegl_node_remove_child (node, flatten_node);
642

643 644 645
  /* Copy the tattoo and parasites of the bottom layer to the new layer */
  gimp_item_set_tattoo (GIMP_ITEM (merge_layer),
                        gimp_item_get_tattoo (GIMP_ITEM (bottom_layer)));
646

647 648 649 650
  parasites = gimp_item_get_parasites (GIMP_ITEM (bottom_layer));
  parasites = gimp_parasite_list_copy (parasites);
  gimp_item_set_parasites (GIMP_ITEM (merge_layer), parasites);
  g_object_unref (parasites);
651

652 653 654
  /*  Remove the merged layers from the image  */
  for (layers = merge_list; layers; layers = g_slist_next (layers))
    gimp_image_remove_layer (image, layers->data, TRUE, NULL);
655

656 657
  gimp_item_set_visible (GIMP_ITEM (merge_layer), TRUE, FALSE);

658
  /*  if the type is flatten, remove all the remaining layers  */
659
  if (merge_type == GIMP_FLATTEN_IMAGE)
660
    {
661 662
      GList *list = gimp_image_get_layer_iter (image);

663
      while (list)
664
        {
Sven Neumann's avatar
Sven Neumann committed
665
          layer = list->data;
666

667
          list = g_list_next (list);
668
          gimp_image_remove_layer (image, layer, TRUE, NULL);
669
        }
670

671 672
      gimp_image_add_layer (image, merge_layer, parent,
                            position, TRUE);
673 674 675
    }
  else
    {
676
      /*  Add the layer to the image  */
677 678 679 680
      gimp_image_add_layer (image, merge_layer, parent,
                            gimp_container_get_n_children (container) -
                            position + 1,
                            TRUE);
681 682
    }

683
  gimp_drawable_update (GIMP_DRAWABLE (merge_layer), 0, 0, -1, -1);
684 685

  return merge_layer;
686
}