image-cmds.c 256 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

Michael Natterer's avatar
Michael Natterer committed
32
#include "base/temp-buf.h"
33
#include "core/gimp.h"
34
#include "core/gimpchannel.h"
35
#include "core/gimpcontainer.h"
Michael Natterer's avatar
Michael Natterer committed
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
{
  gboolean success = TRUE;
  if (success)
    {
    }
326 327
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
328 329 330
}

static GValueArray *
331 332 333 334 335 336
image_resize_invoker (GimpProcedure      *procedure,
                      Gimp               *gimp,
                      GimpContext        *context,
                      GimpProgress       *progress,
                      const GValueArray  *args,
                      GError            **error)
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356
{
  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);
    }

357 358
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
359 360 361
}

static GValueArray *
362 363 364 365 366 367
image_resize_to_layers_invoker (GimpProcedure      *procedure,
                                Gimp               *gimp,
                                GimpContext        *context,
                                GimpProgress       *progress,
                                const GValueArray  *args,
                                GError            **error)
368 369 370 371 372 373 374 375 376 377 378
{
  gboolean success = TRUE;
  GimpImage *image;

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

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

379 380
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
381 382 383
}

static GValueArray *
384 385 386 387 388 389
image_scale_invoker (GimpProcedure      *procedure,
                     Gimp               *gimp,
                     GimpContext        *context,
                     GimpProgress       *progress,
                     const GValueArray  *args,
                     GError            **error)
390 391 392 393 394 395 396 397 398 399 400 401
{
  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)
    {
402 403
      GimpPDBContext *pdb_context = GIMP_PDB_CONTEXT (context);

404 405 406
      if (progress)
        gimp_progress_start (progress, _("Scaling"), FALSE);

407
      gimp_image_scale (image, new_width, new_height,
408
                        pdb_context->interpolation,
409 410 411 412 413 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
                        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);
447 448
    }

449 450
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
451 452 453
}

static GValueArray *
454 455 456 457 458 459
image_crop_invoker (GimpProcedure      *procedure,
                    Gimp               *gimp,
                    GimpContext        *context,
                    GimpProgress       *progress,
                    const GValueArray  *args,
                    GError            **error)
460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475
{
  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)
    {
476 477 478 479
      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))
480 481 482 483 484 485 486
        success = FALSE;
      else
        gimp_image_crop (image, context,
                         offx, offy, offx + new_width, offy + new_height,
                         FALSE, TRUE);
    }

487 488
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
489 490 491
}

static GValueArray *
492 493 494 495 496 497
image_flip_invoker (GimpProcedure      *procedure,
                    Gimp               *gimp,
                    GimpContext        *context,
                    GimpProgress       *progress,
                    const GValueArray  *args,
                    GError            **error)
498 499 500 501 502 503 504 505 506 507 508 509 510
{
  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);
    }

511 512
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
513 514 515
}

static GValueArray *
516 517 518 519 520 521
image_rotate_invoker (GimpProcedure      *procedure,
                      Gimp               *gimp,
                      GimpContext        *context,
                      GimpProgress       *progress,
                      const GValueArray  *args,
                      GError            **error)
522 523 524 525 526 527 528 529 530 531
{
  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)
    {
532 533 534 535 536 537
      if (progress)
        gimp_progress_start (progress, _("Rotating"), FALSE);

      gimp_image_rotate (image, context, rotate_type, progress);

      if (progress)
538
        gimp_progress_end (progress);
539 540
    }

541 542
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
543 544 545
}

static GValueArray *
546 547 548 549 550 551
image_get_layers_invoker (GimpProcedure      *procedure,
                          Gimp               *gimp,
                          GimpContext        *context,
                          GimpProgress       *progress,
                          const GValueArray  *args,
                          GError            **error)
552 553 554 555 556 557 558 559 560 561 562
{
  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)
    {
563
      GList *list = gimp_image_get_layer_iter (image);
564 565

      num_layers = g_list_length (list);
566

567 568 569
      if (num_layers)
        {
          gint i;
570

571
          layer_ids = g_new (gint32, num_layers);
572

573 574 575 576
          for (i = 0; i < num_layers; i++, list = g_list_next (list))
            layer_ids[i] = gimp_item_get_ID (GIMP_ITEM (list->data));
        }
    }
577

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

581 582 583 584 585
  if (success)
    {
      g_value_set_int (&return_vals->values[1], num_layers);
      gimp_value_take_int32array (&return_vals->values[2], layer_ids, num_layers);
    }
586

587 588
  return return_vals;
}
589

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

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

606 607
  if (success)
    {
608
      GList *list = gimp_image_get_channel_iter (image);
609

610
      num_channels = g_list_length (list);
611

612 613 614
      if (num_channels)
        {
          gint i;
615

616 617 618 619 620 621 622
          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));
        }
    }

623 624
  return_vals = gimp_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);
625 626 627 628 629 630

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

632 633
  return return_vals;
}
634

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

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

651 652
  if (success)
    {
653
      GList *list = gimp_image_get_vectors_iter (image);
654

655
      num_vectors = g_list_length (list);
656

657 658 659
      if (num_vectors)
        {
          gint i;
660

661
          vector_ids = g_new (gint32, num_vectors);
662

663 664 665 666
          for (i = 0; i < num_vectors; i++, list = g_list_next (list))
            vector_ids[i] = gimp_item_get_ID (GIMP_ITEM (list->data));
        }
    }
667

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

671 672 673 674 675
  if (success)
    {
      g_value_set_int (&return_vals->values[1], num_vectors);
      gimp_value_take_int32array (&return_vals->values[2], vector_ids, num_vectors);
    }
676

677 678
  return return_vals;
}
679

680
static GValueArray *
681 682 683 684 685 686
image_get_active_drawable_invoker (GimpProcedure      *procedure,
                                   Gimp               *gimp,
                                   GimpContext        *context,
                                   GimpProgress       *progress,
                                   const GValueArray  *args,
                                   GError            **error)
687 688 689 690 691
{
  gboolean success = TRUE;
  GValueArray *return_vals;
  GimpImage *image;
  GimpDrawable *drawable = NULL;
692

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

695 696
  if (success)
    {
697
      drawable = gimp_image_get_active_drawable (image);
698
    }
699

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

703 704
  if (success)
    gimp_value_set_drawable (&return_vals->values[1], drawable);
705

706 707
  return return_vals;
}
708

709
static GValueArray *
710 711 712 713 714 715
image_unset_active_channel_invoker (GimpProcedure      *procedure,
                                    Gimp               *gimp,
                                    GimpContext        *context,
                                    GimpProgress       *progress,
                                    const GValueArray  *args,
                                    GError            **error)
716 717 718
{
  gboolean success = TRUE;
  GimpImage *image;
719

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

722 723 724 725
  if (success)
    {
      gimp_image_unset_active_channel (image);
    }
726

727 728
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
729
}
730

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

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

  if (success)
    {
748
      floating_sel = gimp_image_get_floating_selection (image);
749
    }
750

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

754 755
  if (success)
    gimp_value_set_layer (&return_vals->values[1], floating_sel);
756

757 758
  return return_vals;
}
759

760
static GValueArray *
761 762 763 764 765 766
image_floating_sel_attached_to_invoker (GimpProcedure      *procedure,
                                        Gimp               *gimp,
                                        GimpContext        *context,
                                        GimpProgress       *progress,
                                        const GValueArray  *args,
                                        GError            **error)
767 768 769 770 771
{
  gboolean success = TRUE;
  GValueArray *return_vals;
  GimpImage *image;
  GimpDrawable *drawable = NULL;
772

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

775 776
  if (success)
    {
777
      GimpLayer *floating_sel = gimp_image_get_floating_selection (image);
778

779
      if (floating_sel)
780
        drawable = gimp_layer_get_floating_sel_drawable (floating_sel);
781 782 783
      else
        drawable = NULL;
    }
784

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

788 789
  if (success)
    gimp_value_set_drawable (&return_vals->values[1], drawable);
Elliot Lee's avatar
Elliot Lee committed
790

791 792
  return return_vals;
}
793

794
static GValueArray *
795 796 797 798 799 800
image_pick_color_invoker (GimpProcedure      *procedure,
                          Gimp               *gimp,
                          GimpContext        *context,
                          GimpProgress       *progress,
                          const GValueArray  *args,
                          GError            **error)
Elliot Lee's avatar
Elliot Lee committed
801
{
802
  gboolean success = TRUE;
803
  GValueArray *return_vals;
804 805 806 807 808 809 810 811
  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
812

813 814 815 816 817 818 819
  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
820

821
  if (success)
822
    {
823 824 825
      if (!sample_merged)
        if (!drawable || (gimp_item_get_image (GIMP_ITEM (drawable)) != image))
          success = FALSE;
826

827 828 829 830 831
      if (success && sample_average)
        {
          if (average_radius <= 0.0)
            success = FALSE;
        }
832

833 834 835
      if (success)
        {
          if (sample_merged)
836
            gimp_pickable_flush (GIMP_PICKABLE (gimp_image_get_projection (image)));
837 838 839 840 841 842 843 844 845 846 847 848 849
          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
850
    }
851

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

855 856
  if (success)
    gimp_value_set_rgb (&return_vals->values[1], &color);
857

858
  return return_vals;
Elliot Lee's avatar
Elliot Lee committed
859 860
}

861
static GValueArray *
862 863 864 865 866 867
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
868
{
869
  gboolean success = TRUE;
870
  GValueArray *return_vals;
871 872 873 874
  GimpImage *image;
  gint32 x;
  gint32 y;
  GimpLayer *layer = NULL;
Elliot Lee's avatar
Elliot Lee committed
875

876 877 878
  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
879 880

  if (success)
881
    {
882
      layer = gimp_image_pick_layer (image, x, y);
883
    }
Elliot Lee's avatar
Elliot Lee committed
884

885 886
  return_vals = gimp_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);
Elliot Lee's avatar
Elliot Lee committed
887 888

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

891
  return return_vals;
Elliot Lee's avatar
Elliot Lee committed
892 893
}

894
static GValueArray *
895 896 897 898 899 900
image_add_layer_invoker (GimpProcedure      *procedure,
                         Gimp               *gimp,
                         GimpContext        *context,
                         GimpProgress       *progress,
                         const GValueArray  *args,
                         GError            **error)
901 902
{
  gboolean success = TRUE;
903
  GimpImage *image;
904 905
  GimpLayer *layer;
  gint32 position;
906

907
  image = gimp_value_get_image (&args->values[0], gimp);
908 909
  layer = gimp_value_get_layer (&args->values[1], gimp);
  position = g_value_get_int (&args->values[2]);
910 911

  if (success)
912
    {
913
      if (gimp_pdb_item_is_floating (GIMP_ITEM (layer), image, error) &&
914 915 916
          gimp_pdb_image_is_base_type (image,
                                       GIMP_IMAGE_TYPE_BASE_TYPE (gimp_drawable_type (GIMP_DRAWABLE (layer))),
                                       error))
917
        {
918 919
          success = gimp_image_add_layer (image, layer,
                                          NULL, MAX (position, -1), TRUE);
920 921 922 923
        }
      else
        {
          success = FALSE;
924
        }
925
    }
926

927 928
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
929 930
}

931 932 933 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
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);
}

976
static GValueArray *
977 978 979 980 981 982
image_remove_layer_invoker (GimpProcedure      *procedure,
                            Gimp               *gimp,
                            GimpContext        *context,
                            GimpProgress       *progress,
                            const GValueArray  *args,
                            GError            **error)
983 984
{
  gboolean success = TRUE;
985
  GimpImage *image;
986
  GimpLayer *layer;
987

988
  image = gimp_value_get_image (&args->values[0], gimp);
989
  layer = gimp_value_get_layer (&args->values[1], gimp);
990 991 992

  if (success)
    {
993
      if (gimp_pdb_item_is_attached (GIMP_ITEM (layer), image, FALSE, error))
994
        gimp_image_remove_layer (image, layer, TRUE, NULL);
995 996
      else
        success = FALSE;
997 998
    }

999 1000
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
1001 1002
}

1003 1004 1005 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
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);
}

1037 1038 1039 1040 1041 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
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);
}

1079 1080 1081 1082 1083 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
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);
}

1140 1141 1142 1143 1144 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
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);
}

1182 1183 1184 1185 1186 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
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);
}

1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373
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 ||
1374 1375 1376
           (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))))
1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388
        {