image-cmds.c 238 KB
Newer Older
1
/* GIMP - The GNU Image Manipulation Program
2
 * Copyright (C) 1995-2003 Spencer Kimball and Peter Mattis
Elliot Lee's avatar
Elliot Lee committed
3
 *
4
 * This program is free software: you can redistribute it and/or modify
Elliot Lee's avatar
Elliot Lee committed
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
Elliot Lee's avatar
Elliot Lee committed
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/>.
Elliot Lee's avatar
Elliot Lee committed
16
 */
17

18
/* NOTE: This file is auto-generated by pdbgen.pl. */
19

20 21
#include "config.h"

22 23
#include <cairo.h>

24
#include <gegl.h>
25

26 27 28 29
#include "libgimpbase/gimpbase.h"
#include "libgimpcolor/gimpcolor.h"
#include "libgimpmath/gimpmath.h"

30
#include "pdb-types.h"
31

32
#include "base/temp-buf.h"
33
#include "core/gimp.h"
34
#include "core/gimpchannel.h"
35
#include "core/gimpcontainer.h"
36
#include "core/gimpdrawable.h"
37
#include "core/gimpimage-colormap.h"
38
#include "core/gimpimage-crop.h"
39
#include "core/gimpimage-duplicate.h"
40
#include "core/gimpimage-flip.h"
41
#include "core/gimpimage-merge.h"
42
#include "core/gimpimage-pick-color.h"
43
#include "core/gimpimage-pick-layer.h"
44
#include "core/gimpimage-resize.h"
45
#include "core/gimpimage-rotate.h"
46
#include "core/gimpimage-scale.h"
47
#include "core/gimpimage.h"
48
#include "core/gimpitem.h"
49 50
#include "core/gimplayer.h"
#include "core/gimplayermask.h"
51
#include "core/gimpparamspecs.h"
52
#include "core/gimppickable.h"
53
#include "core/gimpprogress.h"
54
#include "core/gimpselection.h"
55
#include "core/gimpunit.h"
56
#include "vectors/gimpvectors.h"
57

58
#include "gimppdb.h"
59
#include "gimppdberror.h"
Sven Neumann's avatar
Sven Neumann committed
60
#include "gimppdb-utils.h"
61
#include "gimppdbcontext.h"
62
#include "gimpprocedure.h"
63
#include "internal-procs.h"
64

65 66
#include "gimp-intl.h"

67

68 69 70 71 72 73 74 75 76 77
#if defined (HAVE_FINITE)
#define FINITE(x) finite(x)
#elif defined (HAVE_ISFINITE)
#define FINITE(x) isfinite(x)
#elif defined (G_OS_WIN32)
#define FINITE(x) _finite(x)
#else
#error "no FINITE() implementation available?!"
#endif

78
static GValueArray *
79 80 81 82 83 84
image_is_valid_invoker (GimpProcedure      *procedure,
                        Gimp               *gimp,
                        GimpContext        *context,
                        GimpProgress       *progress,
                        const GValueArray  *args,
                        GError            **error)
85 86 87 88 89 90 91
{
  GValueArray *return_vals;
  GimpImage *image;
  gboolean valid = FALSE;

  image = gimp_value_get_image (&args->values[0], gimp);

92
  valid = GIMP_IS_IMAGE (image);
93

94
  return_vals = gimp_procedure_get_return_values (procedure, TRUE, NULL);
95
  g_value_set_boolean (&return_vals->values[1], valid);
96 97 98 99

  return return_vals;
}

100
static GValueArray *
101 102 103 104 105 106
image_list_invoker (GimpProcedure      *procedure,
                    Gimp               *gimp,
                    GimpContext        *context,
                    GimpProgress       *progress,
                    const GValueArray  *args,
                    GError            **error)
107
{
108 109 110
  GValueArray *return_vals;
  gint32 num_images = 0;
  gint32 *image_ids = NULL;
Michael Natterer's avatar
Michael Natterer committed
111

112
  GList *list = gimp_get_image_iter (gimp);
113

114
  num_images = g_list_length (list);
115

116 117 118
  if (num_images)
    {
      gint i;
119

120
      image_ids = g_new (gint32, num_images);
121

122 123 124
      for (i = 0; i < num_images; i++, list = g_list_next (list))
        image_ids[i] = gimp_image_get_ID (GIMP_IMAGE (list->data));
    }
125

126
  return_vals = gimp_procedure_get_return_values (procedure, TRUE, NULL);
127

128 129
  g_value_set_int (&return_vals->values[1], num_images);
  gimp_value_take_int32array (&return_vals->values[2], image_ids, num_images);
130

131 132
  return return_vals;
}
133

134
static GValueArray *
135 136 137 138 139 140
image_new_invoker (GimpProcedure      *procedure,
                   Gimp               *gimp,
                   GimpContext        *context,
                   GimpProgress       *progress,
                   const GValueArray  *args,
                   GError            **error)
141 142 143 144 145 146 147
{
  gboolean success = TRUE;
  GValueArray *return_vals;
  gint32 width;
  gint32 height;
  gint32 type;
  GimpImage *image = NULL;
148

149 150 151
  width = g_value_get_int (&args->values[0]);
  height = g_value_get_int (&args->values[1]);
  type = g_value_get_enum (&args->values[2]);
152

153 154 155
  if (success)
    {
      image = gimp_create_image (gimp, width, height, type, FALSE);
156

157 158 159
      if (! image)
        success = FALSE;
    }
160

161 162
  return_vals = gimp_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);
163

164 165
  if (success)
    gimp_value_set_image (&return_vals->values[1], image);
166

167 168
  return return_vals;
}
169

170
static GValueArray *
171 172 173 174 175 176
image_duplicate_invoker (GimpProcedure      *procedure,
                         Gimp               *gimp,
                         GimpContext        *context,
                         GimpProgress       *progress,
                         const GValueArray  *args,
                         GError            **error)
177 178 179 180 181
{
  gboolean success = TRUE;
  GValueArray *return_vals;
  GimpImage *image;
  GimpImage *new_image = NULL;
182

183
  image = gimp_value_get_image (&args->values[0], gimp);
184

185 186 187
  if (success)
    {
      new_image = gimp_image_duplicate (image);
188

189 190 191
      if (! new_image)
        success = FALSE;
    }
192

193 194
  return_vals = gimp_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);
195

196 197
  if (success)
    gimp_value_set_image (&return_vals->values[1], new_image);
198

199 200
  return return_vals;
}
201

202
static GValueArray *
203 204 205 206 207 208
image_delete_invoker (GimpProcedure      *procedure,
                      Gimp               *gimp,
                      GimpContext        *context,
                      GimpProgress       *progress,
                      const GValueArray  *args,
                      GError            **error)
209 210 211
{
  gboolean success = TRUE;
  GimpImage *image;
212

213
  image = gimp_value_get_image (&args->values[0], gimp);
214

215 216
  if (success)
    {
217
      if (gimp_image_get_display_count (image) == 0)
218 219 220 221
        g_object_unref (image);
      else
        success = FALSE;
    }
222

223 224
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
225
}
226

227
static GValueArray *
228 229 230 231 232 233
image_base_type_invoker (GimpProcedure      *procedure,
                         Gimp               *gimp,
                         GimpContext        *context,
                         GimpProgress       *progress,
                         const GValueArray  *args,
                         GError            **error)
234 235 236 237 238
{
  gboolean success = TRUE;
  GValueArray *return_vals;
  GimpImage *image;
  gint32 base_type = 0;
239

240
  image = gimp_value_get_image (&args->values[0], gimp);
241

242 243 244 245
  if (success)
    {
      base_type = gimp_image_base_type (image);
    }
246

247 248
  return_vals = gimp_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);
249 250 251 252 253 254 255 256

  if (success)
    g_value_set_enum (&return_vals->values[1], base_type);

  return return_vals;
}

static GValueArray *
257 258 259 260 261 262
image_width_invoker (GimpProcedure      *procedure,
                     Gimp               *gimp,
                     GimpContext        *context,
                     GimpProgress       *progress,
                     const GValueArray  *args,
                     GError            **error)
263 264 265 266 267 268 269 270 271 272 273 274 275
{
  gboolean success = TRUE;
  GValueArray *return_vals;
  GimpImage *image;
  gint32 width = 0;

  image = gimp_value_get_image (&args->values[0], gimp);

  if (success)
    {
      width = gimp_image_get_width (image);
    }

276 277
  return_vals = gimp_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);
278 279 280 281 282 283 284 285

  if (success)
    g_value_set_int (&return_vals->values[1], width);

  return return_vals;
}

static GValueArray *
286 287 288 289 290 291
image_height_invoker (GimpProcedure      *procedure,
                      Gimp               *gimp,
                      GimpContext        *context,
                      GimpProgress       *progress,
                      const GValueArray  *args,
                      GError            **error)
292 293 294 295 296 297 298 299 300 301 302 303 304
{
  gboolean success = TRUE;
  GValueArray *return_vals;
  GimpImage *image;
  gint32 height = 0;

  image = gimp_value_get_image (&args->values[0], gimp);

  if (success)
    {
      height = gimp_image_get_height (image);
    }

305 306
  return_vals = gimp_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);
307 308 309 310 311 312 313 314

  if (success)
    g_value_set_int (&return_vals->values[1], height);

  return return_vals;
}

static GValueArray *
315 316 317 318 319 320
image_free_shadow_invoker (GimpProcedure      *procedure,
                           Gimp               *gimp,
                           GimpContext        *context,
                           GimpProgress       *progress,
                           const GValueArray  *args,
                           GError            **error)
321 322 323 324 325 326 327 328 329 330
{
  gboolean success = TRUE;
  GimpImage *image;

  image = gimp_value_get_image (&args->values[0], gimp);

  if (success)
    {
    }

331 332
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
333 334 335
}

static GValueArray *
336 337 338 339 340 341
image_resize_invoker (GimpProcedure      *procedure,
                      Gimp               *gimp,
                      GimpContext        *context,
                      GimpProgress       *progress,
                      const GValueArray  *args,
                      GError            **error)
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
{
  gboolean success = TRUE;
  GimpImage *image;
  gint32 new_width;
  gint32 new_height;
  gint32 offx;
  gint32 offy;

  image = gimp_value_get_image (&args->values[0], gimp);
  new_width = g_value_get_int (&args->values[1]);
  new_height = g_value_get_int (&args->values[2]);
  offx = g_value_get_int (&args->values[3]);
  offy = g_value_get_int (&args->values[4]);

  if (success)
    {
      gimp_image_resize (image, context,
                         new_width, new_height, offx, offy, NULL);
    }

362 363
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
364 365 366
}

static GValueArray *
367 368 369 370 371 372
image_resize_to_layers_invoker (GimpProcedure      *procedure,
                                Gimp               *gimp,
                                GimpContext        *context,
                                GimpProgress       *progress,
                                const GValueArray  *args,
                                GError            **error)
373 374 375 376 377 378 379 380 381 382 383
{
  gboolean success = TRUE;
  GimpImage *image;

  image = gimp_value_get_image (&args->values[0], gimp);

  if (success)
    {
      gimp_image_resize_to_layers (image, context, NULL);
    }

384 385
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
386 387 388
}

static GValueArray *
389 390 391 392 393 394
image_scale_invoker (GimpProcedure      *procedure,
                     Gimp               *gimp,
                     GimpContext        *context,
                     GimpProgress       *progress,
                     const GValueArray  *args,
                     GError            **error)
395 396 397 398 399 400 401 402 403 404 405 406
{
  gboolean success = TRUE;
  GimpImage *image;
  gint32 new_width;
  gint32 new_height;

  image = gimp_value_get_image (&args->values[0], gimp);
  new_width = g_value_get_int (&args->values[1]);
  new_height = g_value_get_int (&args->values[2]);

  if (success)
    {
407 408
      GimpPDBContext *pdb_context = GIMP_PDB_CONTEXT (context);

409 410 411
      if (progress)
        gimp_progress_start (progress, _("Scaling"), FALSE);

412
      gimp_image_scale (image, new_width, new_height,
413
                        pdb_context->interpolation,
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451
                        progress);

      if (progress)
        gimp_progress_end (progress);
    }

  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
}

static GValueArray *
image_scale_full_invoker (GimpProcedure      *procedure,
                          Gimp               *gimp,
                          GimpContext        *context,
                          GimpProgress       *progress,
                          const GValueArray  *args,
                          GError            **error)
{
  gboolean success = TRUE;
  GimpImage *image;
  gint32 new_width;
  gint32 new_height;
  gint32 interpolation;

  image = gimp_value_get_image (&args->values[0], gimp);
  new_width = g_value_get_int (&args->values[1]);
  new_height = g_value_get_int (&args->values[2]);
  interpolation = g_value_get_enum (&args->values[3]);

  if (success)
    {
      if (progress)
        gimp_progress_start (progress, _("Scaling"), FALSE);

      gimp_image_scale (image, new_width, new_height, interpolation, progress);

      if (progress)
        gimp_progress_end (progress);
452 453
    }

454 455
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
456 457 458
}

static GValueArray *
459 460 461 462 463 464
image_crop_invoker (GimpProcedure      *procedure,
                    Gimp               *gimp,
                    GimpContext        *context,
                    GimpProgress       *progress,
                    const GValueArray  *args,
                    GError            **error)
465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480
{
  gboolean success = TRUE;
  GimpImage *image;
  gint32 new_width;
  gint32 new_height;
  gint32 offx;
  gint32 offy;

  image = gimp_value_get_image (&args->values[0], gimp);
  new_width = g_value_get_int (&args->values[1]);
  new_height = g_value_get_int (&args->values[2]);
  offx = g_value_get_int (&args->values[3]);
  offy = g_value_get_int (&args->values[4]);

  if (success)
    {
481 482 483 484
      if (new_width  >  gimp_image_get_width  (image)              ||
          new_height >  gimp_image_get_height (image)              ||
          offx       > (gimp_image_get_width  (image) - new_width) ||
          offy       > (gimp_image_get_height (image) - new_height))
485 486 487 488 489 490 491
        success = FALSE;
      else
        gimp_image_crop (image, context,
                         offx, offy, offx + new_width, offy + new_height,
                         FALSE, TRUE);
    }

492 493
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
494 495 496
}

static GValueArray *
497 498 499 500 501 502
image_flip_invoker (GimpProcedure      *procedure,
                    Gimp               *gimp,
                    GimpContext        *context,
                    GimpProgress       *progress,
                    const GValueArray  *args,
                    GError            **error)
503 504 505 506 507 508 509 510 511 512 513 514 515
{
  gboolean success = TRUE;
  GimpImage *image;
  gint32 flip_type;

  image = gimp_value_get_image (&args->values[0], gimp);
  flip_type = g_value_get_enum (&args->values[1]);

  if (success)
    {
      gimp_image_flip (image, context, flip_type, NULL);
    }

516 517
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
518 519 520
}

static GValueArray *
521 522 523 524 525 526
image_rotate_invoker (GimpProcedure      *procedure,
                      Gimp               *gimp,
                      GimpContext        *context,
                      GimpProgress       *progress,
                      const GValueArray  *args,
                      GError            **error)
527 528 529 530 531 532 533 534 535 536
{
  gboolean success = TRUE;
  GimpImage *image;
  gint32 rotate_type;

  image = gimp_value_get_image (&args->values[0], gimp);
  rotate_type = g_value_get_enum (&args->values[1]);

  if (success)
    {
537 538 539 540 541 542
      if (progress)
        gimp_progress_start (progress, _("Rotating"), FALSE);

      gimp_image_rotate (image, context, rotate_type, progress);

      if (progress)
543
        gimp_progress_end (progress);
544 545
    }

546 547
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
548 549 550
}

static GValueArray *
551 552 553 554 555 556
image_get_layers_invoker (GimpProcedure      *procedure,
                          Gimp               *gimp,
                          GimpContext        *context,
                          GimpProgress       *progress,
                          const GValueArray  *args,
                          GError            **error)
557 558 559 560 561 562 563 564 565 566 567
{
  gboolean success = TRUE;
  GValueArray *return_vals;
  GimpImage *image;
  gint32 num_layers = 0;
  gint32 *layer_ids = NULL;

  image = gimp_value_get_image (&args->values[0], gimp);

  if (success)
    {
568
      GList *list = gimp_image_get_layer_iter (image);
569 570

      num_layers = g_list_length (list);
571

572 573 574
      if (num_layers)
        {
          gint i;
575

576
          layer_ids = g_new (gint32, num_layers);
577

578 579 580 581
          for (i = 0; i < num_layers; i++, list = g_list_next (list))
            layer_ids[i] = gimp_item_get_ID (GIMP_ITEM (list->data));
        }
    }
582

583 584
  return_vals = gimp_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);
585

586 587 588 589 590
  if (success)
    {
      g_value_set_int (&return_vals->values[1], num_layers);
      gimp_value_take_int32array (&return_vals->values[2], layer_ids, num_layers);
    }
591

592 593
  return return_vals;
}
594

595
static GValueArray *
596 597 598 599 600 601
image_get_channels_invoker (GimpProcedure      *procedure,
                            Gimp               *gimp,
                            GimpContext        *context,
                            GimpProgress       *progress,
                            const GValueArray  *args,
                            GError            **error)
602 603 604 605 606 607
{
  gboolean success = TRUE;
  GValueArray *return_vals;
  GimpImage *image;
  gint32 num_channels = 0;
  gint32 *channel_ids = NULL;
608

609
  image = gimp_value_get_image (&args->values[0], gimp);
610

611 612
  if (success)
    {
613
      GList *list = gimp_image_get_channel_iter (image);
614

615
      num_channels = g_list_length (list);
616

617 618 619
      if (num_channels)
        {
          gint i;
620

621 622 623 624 625 626 627
          channel_ids = g_new (gint32, num_channels);

          for (i = 0; i < num_channels; i++, list = g_list_next (list))
            channel_ids[i] = gimp_item_get_ID (GIMP_ITEM (list->data));
        }
    }

628 629
  return_vals = gimp_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);
630 631 632 633 634 635

  if (success)
    {
      g_value_set_int (&return_vals->values[1], num_channels);
      gimp_value_take_int32array (&return_vals->values[2], channel_ids, num_channels);
    }
636

637 638
  return return_vals;
}
639

640
static GValueArray *
641 642 643 644 645 646
image_get_vectors_invoker (GimpProcedure      *procedure,
                           Gimp               *gimp,
                           GimpContext        *context,
                           GimpProgress       *progress,
                           const GValueArray  *args,
                           GError            **error)
647 648 649 650 651 652
{
  gboolean success = TRUE;
  GValueArray *return_vals;
  GimpImage *image;
  gint32 num_vectors = 0;
  gint32 *vector_ids = NULL;
653

654
  image = gimp_value_get_image (&args->values[0], gimp);
655

656 657
  if (success)
    {
658
      GList *list = gimp_image_get_vectors_iter (image);
659

660
      num_vectors = g_list_length (list);
661

662 663 664
      if (num_vectors)
        {
          gint i;
665

666
          vector_ids = g_new (gint32, num_vectors);
667

668 669 670 671
          for (i = 0; i < num_vectors; i++, list = g_list_next (list))
            vector_ids[i] = gimp_item_get_ID (GIMP_ITEM (list->data));
        }
    }
672

673 674
  return_vals = gimp_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);
675

676 677 678 679 680
  if (success)
    {
      g_value_set_int (&return_vals->values[1], num_vectors);
      gimp_value_take_int32array (&return_vals->values[2], vector_ids, num_vectors);
    }
681

682 683
  return return_vals;
}
684

685
static GValueArray *
686 687 688 689 690 691
image_get_active_drawable_invoker (GimpProcedure      *procedure,
                                   Gimp               *gimp,
                                   GimpContext        *context,
                                   GimpProgress       *progress,
                                   const GValueArray  *args,
                                   GError            **error)
692 693 694 695 696
{
  gboolean success = TRUE;
  GValueArray *return_vals;
  GimpImage *image;
  GimpDrawable *drawable = NULL;
697

698
  image = gimp_value_get_image (&args->values[0], gimp);
699

700 701
  if (success)
    {
702
      drawable = gimp_image_get_active_drawable (image);
703
    }
704

705 706
  return_vals = gimp_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);
707

708 709
  if (success)
    gimp_value_set_drawable (&return_vals->values[1], drawable);
710

711 712
  return return_vals;
}
713

714
static GValueArray *
715 716 717 718 719 720
image_unset_active_channel_invoker (GimpProcedure      *procedure,
                                    Gimp               *gimp,
                                    GimpContext        *context,
                                    GimpProgress       *progress,
                                    const GValueArray  *args,
                                    GError            **error)
721 722 723
{
  gboolean success = TRUE;
  GimpImage *image;
724

725
  image = gimp_value_get_image (&args->values[0], gimp);
726

727 728 729 730
  if (success)
    {
      gimp_image_unset_active_channel (image);
    }
731

732 733
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
734
}
735

736
static GValueArray *
737 738 739 740 741 742
image_get_floating_sel_invoker (GimpProcedure      *procedure,
                                Gimp               *gimp,
                                GimpContext        *context,
                                GimpProgress       *progress,
                                const GValueArray  *args,
                                GError            **error)
743 744 745 746 747 748 749 750 751 752
{
  gboolean success = TRUE;
  GValueArray *return_vals;
  GimpImage *image;
  GimpLayer *floating_sel = NULL;

  image = gimp_value_get_image (&args->values[0], gimp);

  if (success)
    {
753
      floating_sel = gimp_image_get_floating_selection (image);
754
    }
755

756 757
  return_vals = gimp_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);
758

759 760
  if (success)
    gimp_value_set_layer (&return_vals->values[1], floating_sel);
761

762 763
  return return_vals;
}
764

765
static GValueArray *
766 767 768 769 770 771
image_floating_sel_attached_to_invoker (GimpProcedure      *procedure,
                                        Gimp               *gimp,
                                        GimpContext        *context,
                                        GimpProgress       *progress,
                                        const GValueArray  *args,
                                        GError            **error)
772 773 774 775 776
{
  gboolean success = TRUE;
  GValueArray *return_vals;
  GimpImage *image;
  GimpDrawable *drawable = NULL;
777

778
  image = gimp_value_get_image (&args->values[0], gimp);
779

780 781
  if (success)
    {
782
      GimpLayer *floating_sel = gimp_image_get_floating_selection (image);
783

784
      if (floating_sel)
785
        drawable = gimp_layer_get_floating_sel_drawable (floating_sel);
786 787 788
      else
        drawable = NULL;
    }
789

790 791
  return_vals = gimp_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);
792

793 794
  if (success)
    gimp_value_set_drawable (&return_vals->values[1], drawable);
Elliot Lee's avatar
Elliot Lee committed
795

796 797
  return return_vals;
}
798

799
static GValueArray *
800 801 802 803 804 805
image_pick_color_invoker (GimpProcedure      *procedure,
                          Gimp               *gimp,
                          GimpContext        *context,
                          GimpProgress       *progress,
                          const GValueArray  *args,
                          GError            **error)
Elliot Lee's avatar
Elliot Lee committed
806
{
807
  gboolean success = TRUE;
808
  GValueArray *return_vals;
809 810 811 812 813 814 815 816
  GimpImage *image;
  GimpDrawable *drawable;
  gdouble x;
  gdouble y;
  gboolean sample_merged;
  gboolean sample_average;
  gdouble average_radius;
  GimpRGB color = { 0.0, 0.0, 0.0, 1.0 };
Elliot Lee's avatar
Elliot Lee committed
817

818 819 820 821 822 823 824
  image = gimp_value_get_image (&args->values[0], gimp);
  drawable = gimp_value_get_drawable (&args->values[1], gimp);
  x = g_value_get_double (&args->values[2]);
  y = g_value_get_double (&args->values[3]);
  sample_merged = g_value_get_boolean (&args->values[4]);
  sample_average = g_value_get_boolean (&args->values[5]);
  average_radius = g_value_get_double (&args->values[6]);
Elliot Lee's avatar
Elliot Lee committed
825

826
  if (success)
827
    {
828 829 830
      if (!sample_merged)
        if (!drawable || (gimp_item_get_image (GIMP_ITEM (drawable)) != image))
          success = FALSE;
831

832 833 834 835 836
      if (success && sample_average)
        {
          if (average_radius <= 0.0)
            success = FALSE;
        }
837

838 839 840
      if (success)
        {
          if (sample_merged)
841
            gimp_pickable_flush (GIMP_PICKABLE (gimp_image_get_projection (image)));
842 843 844 845 846 847 848 849 850 851 852 853 854
          else
            gimp_pickable_flush (GIMP_PICKABLE (drawable));

          success = gimp_image_pick_color (image,
                                           drawable,
                                           (gint) x, (gint) y,
                                           sample_merged,
                                           sample_average,
                                           average_radius,
                                           NULL,
                                           &color,
                                           NULL);
        }
Elliot Lee's avatar
Elliot Lee committed
855
    }
856

857 858
  return_vals = gimp_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);
859

860 861
  if (success)
    gimp_value_set_rgb (&return_vals->values[1], &color);
862

863
  return return_vals;
Elliot Lee's avatar
Elliot Lee committed
864 865
}

866
static GValueArray *
867 868 869 870 871 872
image_pick_correlate_layer_invoker (GimpProcedure      *procedure,
                                    Gimp               *gimp,
                                    GimpContext        *context,
                                    GimpProgress       *progress,
                                    const GValueArray  *args,
                                    GError            **error)
Elliot Lee's avatar
Elliot Lee committed
873
{
874
  gboolean success = TRUE;
875
  GValueArray *return_vals;
876 877 878 879
  GimpImage *image;
  gint32 x;
  gint32 y;
  GimpLayer *layer = NULL;
Elliot Lee's avatar
Elliot Lee committed
880

881 882 883
  image = gimp_value_get_image (&args->values[0], gimp);
  x = g_value_get_int (&args->values[1]);
  y = g_value_get_int (&args->values[2]);
Elliot Lee's avatar
Elliot Lee committed
884 885

  if (success)
886
    {
887
      layer = gimp_image_pick_layer (image, x, y);
888
    }
Elliot Lee's avatar
Elliot Lee committed
889

890 891
  return_vals = gimp_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);
Elliot Lee's avatar
Elliot Lee committed
892 893

  if (success)
894
    gimp_value_set_layer (&return_vals->values[1], layer);
Elliot Lee's avatar
Elliot Lee committed
895

896
  return return_vals;
Elliot Lee's avatar
Elliot Lee committed
897 898
}

899
static GValueArray *
900 901 902 903 904 905
image_add_layer_invoker (GimpProcedure      *procedure,
                         Gimp               *gimp,
                         GimpContext        *context,
                         GimpProgress       *progress,
                         const GValueArray  *args,
                         GError            **error)
906 907
{
  gboolean success = TRUE;
908
  GimpImage *image;
909 910
  GimpLayer *layer;
  gint32 position;
911

912
  image = gimp_value_get_image (&args->values[0], gimp);
913 914
  layer = gimp_value_get_layer (&args->values[1], gimp);
  position = g_value_get_int (&args->values[2]);
915 916

  if (success)
917
    {
918
      if (gimp_pdb_item_is_floating (GIMP_ITEM (layer), image, error) &&
919 920 921
          gimp_pdb_image_is_base_type (image,
                                       GIMP_IMAGE_TYPE_BASE_TYPE (gimp_drawable_type (GIMP_DRAWABLE (layer))),
                                       error))
922
        {
923 924
          success = gimp_image_add_layer (image, layer,
                                          NULL, MAX (position, -1), TRUE);
925 926 927 928
        }
      else
        {
          success = FALSE;
929
        }
930
    }
931

932 933
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
934 935
}

936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980
static GValueArray *
image_insert_layer_invoker (GimpProcedure      *procedure,
                            Gimp               *gimp,
                            GimpContext        *context,
                            GimpProgress       *progress,
                            const GValueArray  *args,
                            GError            **error)
{
  gboolean success = TRUE;
  GimpImage *image;
  GimpLayer *layer;
  GimpLayer *parent;
  gint32 position;

  image = gimp_value_get_image (&args->values[0], gimp);
  layer = gimp_value_get_layer (&args->values[1], gimp);
  parent = gimp_value_get_layer (&args->values[2], gimp);
  position = g_value_get_int (&args->values[3]);

  if (success)
    {
      if (gimp_pdb_item_is_floating (GIMP_ITEM (layer), image, error) &&
          gimp_pdb_image_is_base_type (image,
                                       GIMP_IMAGE_TYPE_BASE_TYPE (gimp_drawable_type (GIMP_DRAWABLE (layer))),
                                       error) &&
          (parent == NULL ||
           (gimp_pdb_item_is_in_tree (GIMP_ITEM (parent), image, FALSE, error) &&
            gimp_pdb_item_is_group (GIMP_ITEM (parent), error))))
        {
          if (position == -1 && parent == NULL)
            parent = GIMP_IMAGE_ACTIVE_PARENT;

          success = gimp_image_add_layer (image, layer,
                                          parent, MAX (position, -1), TRUE);
        }
      else
        {
          success = FALSE;
        }
    }

  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
}

981
static GValueArray *
982 983 984 985 986 987
image_remove_layer_invoker (GimpProcedure      *procedure,
                            Gimp               *gimp,
                            GimpContext        *context,
                            GimpProgress       *progress,
                            const GValueArray  *args,
                            GError            **error)
988 989
{
  gboolean success = TRUE;
990
  GimpImage *image;
991
  GimpLayer *layer;
992

993
  image = gimp_value_get_image (&args->values[0], gimp);
994
  layer = gimp_value_get_layer (&args->values[1], gimp);
995 996 997

  if (success)
    {
998
      if (gimp_pdb_item_is_attached (GIMP_ITEM (layer), image, FALSE, error))
999
        gimp_image_remove_layer (image, layer, TRUE, NULL);
1000 1001
      else
        success = FALSE;
1002 1003
    }

1004 1005
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
1006 1007
}

1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041
static GValueArray *
image_add_channel_invoker (GimpProcedure      *procedure,
                           Gimp               *gimp,
                           GimpContext        *context,
                           GimpProgress       *progress,
                           const GValueArray  *args,
                           GError            **error)
{
  gboolean success = TRUE;
  GimpImage *image;
  GimpChannel *channel;
  gint32 position;

  image = gimp_value_get_image (&args->values[0], gimp);
  channel = gimp_value_get_channel (&args->values[1], gimp);
  position = g_value_get_int (&args->values[2]);

  if (success)
    {
      if (gimp_pdb_item_is_floating (GIMP_ITEM (channel), image, error))
        {
          success = gimp_image_add_channel (image, channel,
                                            NULL, MAX (position, -1), TRUE);
        }
      else
        {
          success = FALSE;
        }
    }

  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
}

1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083
static GValueArray *
image_insert_channel_invoker (GimpProcedure      *procedure,
                              Gimp               *gimp,
                              GimpContext        *context,
                              GimpProgress       *progress,
                              const GValueArray  *args,
                              GError            **error)
{
  gboolean success = TRUE;
  GimpImage *image;
  GimpChannel *channel;
  GimpChannel *parent;
  gint32 position;

  image = gimp_value_get_image (&args->values[0], gimp);
  channel = gimp_value_get_channel (&args->values[1], gimp);
  parent = gimp_value_get_channel (&args->values[2], gimp);
  position = g_value_get_int (&args->values[3]);

  if (success)
    {
      if (gimp_pdb_item_is_floating (GIMP_ITEM (channel), image, error) &&
          (parent == NULL ||
           (gimp_pdb_item_is_in_tree (GIMP_ITEM (parent), image, FALSE, error) &&
            gimp_pdb_item_is_group (GIMP_ITEM (parent), error))))
        {
          if (position == -1 && parent == NULL)
            parent = GIMP_IMAGE_ACTIVE_PARENT;

          success = gimp_image_add_channel (image, channel,
                                            parent, MAX (position, -1), TRUE);
        }
      else
        {
          success = FALSE;
        }
    }

  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
}

1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144
static GValueArray *
image_remove_channel_invoker (GimpProcedure      *procedure,
                              Gimp               *gimp,
                              GimpContext        *context,
                              GimpProgress       *progress,
                              const GValueArray  *args,
                              GError            **error)
{
  gboolean success = TRUE;
  GimpImage *image;
  GimpChannel *channel;

  image = gimp_value_get_image (&args->values[0], gimp);
  channel = gimp_value_get_channel (&args->values[1], gimp);

  if (success)
    {
      if (gimp_pdb_item_is_attached (GIMP_ITEM (channel), image, FALSE, error))
        gimp_image_remove_channel (image, channel, TRUE, NULL);
      else
        success = FALSE;
    }

  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
}

static GValueArray *
image_add_vectors_invoker (GimpProcedure      *procedure,
                           Gimp               *gimp,
                           GimpContext        *context,
                           GimpProgress       *progress,
                           const GValueArray  *args,
                           GError            **error)
{
  gboolean success = TRUE;
  GimpImage *image;
  GimpVectors *vectors;
  gint32 position;

  image = gimp_value_get_image (&args->values[0], gimp);
  vectors = gimp_value_get_vectors (&args->values[1], gimp);
  position = g_value_get_int (&args->values[2]);

  if (success)
    {
      if (gimp_pdb_item_is_floating (GIMP_ITEM (vectors), image, error))
        {
          success = gimp_image_add_vectors (image, vectors,
                                            NULL, MAX (position, -1), TRUE);
        }
      else
        {
          success = FALSE;
        }
    }

  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
}

1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186
static GValueArray *
image_insert_vectors_invoker (GimpProcedure      *procedure,
                              Gimp               *gimp,
                              GimpContext        *context,
                              GimpProgress       *progress,
                              const GValueArray  *args,
                              GError            **error)
{
  gboolean success = TRUE;
  GimpImage *image;
  GimpVectors *vectors;
  GimpVectors *parent;
  gint32 position;

  image = gimp_value_get_image (&args->values[0], gimp);
  vectors = gimp_value_get_vectors (&args->values[1], gimp);
  parent = gimp_value_get_vectors (&args->values[2], gimp);
  position = g_value_get_int (&args->values[3]);

  if (success)
    {
      if (gimp_pdb_item_is_floating (GIMP_ITEM (vectors), image, error) &&
          (parent == NULL ||
           (gimp_pdb_item_is_in_tree (GIMP_ITEM (parent), image, FALSE, error) &&
            gimp_pdb_item_is_group (GIMP_ITEM (parent), error))))
        {
          if (position == -1 && parent == NULL)
            parent = GIMP_IMAGE_ACTIVE_PARENT;

          success = gimp_image_add_vectors (image, vectors,
                                            parent, MAX (position, -1), TRUE);
        }
      else
        {
          success = FALSE;
        }
    }

  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
}

1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355
static GValueArray *
image_remove_vectors_invoker (GimpProcedure      *procedure,
                              Gimp               *gimp,
                              GimpContext        *context,
                              GimpProgress       *progress,
                              const GValueArray  *args,
                              GError            **error)
{
  gboolean success = TRUE;
  GimpImage *image;
  GimpVectors *vectors;

  image = gimp_value_get_image (&args->values[0], gimp);
  vectors = gimp_value_get_vectors (&args->values[1], gimp);

  if (success)
    {
      if (gimp_pdb_item_is_attached (GIMP_ITEM (vectors), image, FALSE, error))
        gimp_image_remove_vectors (image, vectors, TRUE, NULL);
      else
        success = FALSE;
    }

  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
}

static GValueArray *
image_get_item_position_invoker (GimpProcedure      *procedure,
                                 Gimp               *gimp,
                                 GimpContext        *context,
                                 GimpProgress       *progress,
                                 const GValueArray  *args,
                                 GError            **error)
{
  gboolean success = TRUE;
  GValueArray *return_vals;
  GimpImage *image;
  GimpItem *item;
  gint32 position = 0;

  image = gimp_value_get_image (&args->values[0], gimp);
  item = gimp_value_get_item (&args->values[1], gimp);

  if (success)
    {
      if (gimp_pdb_item_is_in_tree (item, image, FALSE, error))
        position = gimp_item_get_index (item);
      else
        success = FALSE;
    }

  return_vals = gimp_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);

  if (success)
    g_value_set_int (&return_vals->values[1], position);

  return return_vals;
}

static GValueArray *
image_raise_item_invoker (GimpProcedure      *procedure,
                          Gimp               *gimp,
                          GimpContext        *context,
                          GimpProgress       *progress,
                          const GValueArray  *args,
                          GError            **error)
{
  gboolean success = TRUE;
  GimpImage *image;
  GimpItem *item;

  image = gimp_value_get_image (&args->values[0], gimp);
  item = gimp_value_get_item (&args->values[1], gimp);

  if (success)
    {
      if (gimp_pdb_item_is_in_tree (item, image, FALSE, error))
        success = gimp_image_raise_item (image, item, error);
      else
        success = FALSE;
    }

  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
}

static GValueArray *
image_lower_item_invoker (GimpProcedure      *procedure,
                          Gimp               *gimp,
                          GimpContext        *context,
                          GimpProgress       *progress,
                          const GValueArray  *args,
                          GError            **error)
{
  gboolean success = TRUE;
  GimpImage *image;
  GimpItem *item;

  image = gimp_value_get_image (&args->values[0], gimp);
  item = gimp_value_get_item (&args->values[1], gimp);

  if (success)
    {
      if (gimp_pdb_item_is_in_tree (item, image, FALSE, error))
        success = gimp_image_lower_item (image, item, error);
      else
        success = FALSE;
    }

  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
}

static GValueArray *
image_raise_item_to_top_invoker (GimpProcedure      *procedure,
                                 Gimp               *gimp,
                                 GimpContext        *context,
                                 GimpProgress       *progress,
                                 const GValueArray  *args,
                                 GError            **error)
{
  gboolean success = TRUE;
  GimpImage *image;
  GimpItem *item;

  image = gimp_value_get_image (&args->values[0], gimp);
  item = gimp_value_get_item (&args->values[1], gimp);

  if (success)
    {
      if (gimp_pdb_item_is_in_tree (item, image, FALSE, error))
        success = gimp_image_raise_item_to_top (image, item);
      else
        success = FALSE;
    }

  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
}

static GValueArray *
image_lower_item_to_bottom_invoker (GimpProcedure      *procedure,
                                    Gimp               *gimp,
                                    GimpContext        *context,
                                    GimpProgress       *progress,
                                    const GValueArray  *args,
                                    GError            **error)
{
  gboolean success = TRUE;
  GimpImage *image;
  GimpItem *item;

  image = gimp_value_get_image (&args->values[0], gimp);
  item = gimp_value_get_item (&args->values[1], gimp);

  if (success)
    {
      if (gimp_pdb_item_is_in_tree (item, image, FALSE, error))
        success = gimp_image_lower_item_to_bottom (image, item);
      else
        success = FALSE;
    }

  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
}

1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378
static GValueArray *
image_reorder_item_invoker (GimpProcedure      *procedure,
                            Gimp               *gimp,
                            GimpContext        *context,
                            GimpProgress       *progress,
                            const GValueArray  *args,
                            GError            **error)
{
  gboolean success = TRUE;
  GimpImage *image;
  GimpItem *item;
  GimpItem *parent;
  gint32 position;

  image = gimp_value_get_image (&args->values[0], gimp);
  item = gimp_value_get_item (&args->values[1], gimp);
  parent = gimp_value_get_item (&args->values[2], gimp);
  position = g_value_get_int (&args->values[3]);

  if (success)
    {
      if (gimp_pdb_item_is_in_tree (item, image, FALSE, error) &&
          (parent == NULL ||
1379 1380 1381
           (gimp_pdb_item_is_in_same_tree (item, parent, image, error) &&
            gimp_pdb_item_is_group (parent, error) &&
            gimp_pdb_item_is_not_ancestor (item, parent, error))))
1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393
        {
          success = gimp_image_reorder_item (image, item, parent, position,
                                             TRUE, NULL);
        }
      else
        success = FALSE;
    }

  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
}

1394
static GValueArray *
1395 1396 1397 1398 1399 1400
image_flatten_invoker (GimpProcedure      *procedure,
                       Gimp               *gimp,
                       GimpContext        *context,
                       GimpProgress       *progress,
                       const GValueArray  *args,
                       GError            **error)
1401 1402 1403 1404
{
  gboolean success = TRUE;
  GValueArray *return_vals;
  GimpImage *image;
1405
  GimpLayer *layer = NULL;
1406 1407 1408 1409 1410

  image = gimp_value_get_image (&args->values[0], gimp);

  if (success)
    {
1411
      layer = gimp_image_flatten (image, context);
1412

1413
      if (! layer)
1414 1415 1416
        success = FALSE;
    }

1417 1418
  return_vals = gimp_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);
1419 1420

  if (success)
1421
    gimp_value_set_layer (&return_vals->values[1], layer);
1422 1423 1424 1425

  return return_vals;
}

1426
static GValueArray *
1427 1428 1429 1430 1431 1432
image_merge_visible_layers_invoker (GimpProcedure      *procedure,
                                    Gimp               *gimp,
                                    GimpContext        *context,
                                    GimpProgress       *progress,
                                    const GValueArray  *args,
                                    GError            **error)
1433 1434
{
  gboolean success = TRUE;
1435
  GValueArray *return_vals;
1436
  GimpImage *image;
1437 1438
  gint32 merge_type;
  GimpLayer *layer = NULL;
1439

1440
  image = gimp_value_get_image (&args->values[0], gimp);
1441
  merge_type = g_value_get_enum (&args->values[1]);
1442 1443

  if (success)
1444
    {
1445 1446
      layer = gimp_image_merge_visible_layers (image, context, merge_type,
                                               FALSE, FALSE);
1447 1448

      if (! layer)
1449
        success = FALSE;
1450
    }
1451

1452 1453 1454 1455 1456 1457 1458
  return_vals = gimp_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);

  if (success)
    gimp_value_set_layer (&return_vals->values[1], layer);

  return return_vals;
1459 1460
}

1461
static GValueArray *
1462 1463 1464 1465 1466 1467
image_merge_down_invoker (GimpProcedure      *procedure,
                          Gimp               *gimp,
                          GimpContext        *context,
                          GimpProgress       *progress,
                          const GValueArray  *args,
                          GError            **error)
Elliot Lee's avatar
Elliot Lee committed
1468
{
1469
  gboolean success = TRUE;
1470
  GValueArray *return_vals;
1471
  GimpImage *image;
1472 1473 1474
  GimpLayer *merge_layer;
  gint32 merge_type;
  GimpLayer *layer = NULL;
Elliot Lee's avatar
Elliot Lee committed
1475

1476
  image = gimp_value_get_image (&args->values[0], gimp);
1477 1478
  merge_layer = gimp_value_get_layer (&args->values[1], gimp);
  merge_type = g_value_get_enum (&args->values[2]);
1479

1480 1481
  if (success)
    {
1482 1483 1484 1485 1486 1487 1488 1489
      if (gimp_pdb_item_is_attached (GIMP_ITEM (merge_layer), image, FALSE, error))
        {
          layer = gimp_image_merge_down (image, merge_layer, context, merge_type,
                                         error);

          if (! layer)
            success = FALSE;
        }
1490 1491
      else
        success = FALSE;
1492 1493
    }

1494 1495 1496 1497 1498 1499 1500
  return_vals = gimp_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);

  if (success)
    gimp_value_set_layer (&return_vals->values[1], layer);

  return return_vals;
Elliot Lee's avatar
Elliot Lee committed
1501 1502
}

1503
static GValueArray *
1504 1505 1506 1507 1508 1509
image_add_layer_mask_invoker (GimpProcedure      *procedure,
                              Gimp               *gimp,
                              GimpContext        *context,
                              GimpProgress       *progress,
                              const GValueArray  *args,
                              GError            **error)
Elliot Lee's avatar
Elliot Lee committed
1510
{
1511
  gboolean success = TRUE;
1512
  GimpImage *image;
1513
  GimpLayer *layer;
1514
  GimpLayerMask *mask;
Elliot Lee's avatar
Elliot Lee committed
1515

1516
  image = gimp_value_get_image (&args->values[0], gimp);
1517
  layer = gimp_value_get_layer (&args->values[1], gimp);
1518
  mask = gimp_value_get_layer_mask (&args->values[2], gimp);
Elliot Lee's avatar
Elliot Lee committed
1519

1520 1521
  if (success)
    {
1522 1523 1524
      if (gimp_pdb_item_is_floating (GIMP_ITEM (mask), image, error) &&
          gimp_pdb_item_is_not_group (GIMP_ITEM (layer), error))
        success = (gimp_layer_add_mask (layer, mask, TRUE, error) == mask);
1525 1526
      else
        success = FALSE;
1527 1528
    }