layer-cmds.c 86.1 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 5 6 7 8 9 10 11 12 13 14 15
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (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
 * along with this program; if not, write to the Free Software
16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Elliot Lee's avatar
Elliot Lee committed
17 18
 */

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

21 22
#include "config.h"

23
#include <glib-object.h>
Elliot Lee's avatar
Elliot Lee committed
24

25 26
#include "libgimpbase/gimpbase.h"

27
#include "pdb-types.h"
28

29
#include "config/gimpcoreconfig.h"
30
#include "core/gimp.h"
31
#include "core/gimpdrawable.h"
32
#include "core/gimpimage-undo.h"
33
#include "core/gimpimage.h"
34
#include "core/gimpitem-linked.h"
35 36
#include "core/gimplayer.h"
#include "core/gimplayermask.h"
37
#include "core/gimpparamspecs.h"
38
#include "core/gimpprojection.h"
39

40 41 42
#include "gimppdb.h"
#include "gimppdb-utils.h"
#include "gimpprocedure.h"
43
#include "internal-procs.h"
44

45 46
#include "gimp-intl.h"

Elliot Lee's avatar
Elliot Lee committed
47

48
static GValueArray *
49 50 51 52 53 54
layer_new_invoker (GimpProcedure      *procedure,
                   Gimp               *gimp,
                   GimpContext        *context,
                   GimpProgress       *progress,
                   const GValueArray  *args,
                   GError            **error)
Elliot Lee's avatar
Elliot Lee committed
55
{
Manish Singh's avatar
Manish Singh committed
56
  gboolean success = TRUE;
57
  GValueArray *return_vals;
58
  GimpImage *image;
Manish Singh's avatar
Manish Singh committed
59 60 61
  gint32 width;
  gint32 height;
  gint32 type;
62
  const gchar *name;
63
  gdouble opacity;
Manish Singh's avatar
Manish Singh committed
64 65
  gint32 mode;
  GimpLayer *layer = NULL;
Elliot Lee's avatar
Elliot Lee committed
66

67 68 69 70 71 72 73
  image = gimp_value_get_image (&args->values[0], gimp);
  width = g_value_get_int (&args->values[1]);
  height = g_value_get_int (&args->values[2]);
  type = g_value_get_enum (&args->values[3]);
  name = g_value_get_string (&args->values[4]);
  opacity = g_value_get_double (&args->values[5]);
  mode = g_value_get_enum (&args->values[6]);
Elliot Lee's avatar
Elliot Lee committed
74 75 76

  if (success)
    {
77
      layer = gimp_layer_new (image, width, height, type, name,
Manish Singh's avatar
Manish Singh committed
78
                              opacity / 100.0, mode);
79 80 81

      if (! layer)
        success = FALSE;
Elliot Lee's avatar
Elliot Lee committed
82 83
    }

84 85
  return_vals = gimp_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);
Elliot Lee's avatar
Elliot Lee committed
86 87

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

90
  return return_vals;
Elliot Lee's avatar
Elliot Lee committed
91 92
}

93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
static GValueArray *
layer_new_from_visible_invoker (GimpProcedure      *procedure,
                                Gimp               *gimp,
                                GimpContext        *context,
                                GimpProgress       *progress,
                                const GValueArray  *args,
                                GError            **error)
{
  gboolean success = TRUE;
  GValueArray *return_vals;
  GimpImage *image;
  GimpImage *dest_image;
  const gchar *name;
  GimpLayer *layer = NULL;

  image = gimp_value_get_image (&args->values[0], gimp);
  dest_image = gimp_value_get_image (&args->values[1], gimp);
  name = g_value_get_string (&args->values[2]);

  if (success)
    {
      GimpProjection *projection = gimp_image_get_projection (image);

      layer = gimp_layer_new_from_tiles (gimp_projection_get_tiles (projection),
                                         dest_image,
118
                                         gimp_image_base_type_with_alpha (dest_image),
119 120 121 122
                                         name,
                                         GIMP_OPACITY_OPAQUE, GIMP_NORMAL_MODE);
    }

123 124
  return_vals = gimp_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);
125 126 127 128 129 130 131

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

  return return_vals;
}

132
static GValueArray *
133 134 135 136 137 138
layer_new_from_drawable_invoker (GimpProcedure      *procedure,
                                 Gimp               *gimp,
                                 GimpContext        *context,
                                 GimpProgress       *progress,
                                 const GValueArray  *args,
                                 GError            **error)
139 140
{
  gboolean success = TRUE;
141
  GValueArray *return_vals;
142 143 144 145
  GimpDrawable *drawable;
  GimpImage *dest_image;
  GimpLayer *layer_copy = NULL;

146 147
  drawable = gimp_value_get_drawable (&args->values[0], gimp);
  dest_image = gimp_value_get_image (&args->values[1], gimp);
148 149 150 151 152

  if (success)
    {
      GType     new_type;
      GimpItem *new_item;
Manish Singh's avatar
Manish Singh committed
153

154
      if (GIMP_IS_LAYER (drawable))
Manish Singh's avatar
Manish Singh committed
155
        new_type = G_TYPE_FROM_INSTANCE (drawable);
156
      else
Manish Singh's avatar
Manish Singh committed
157
        new_type = GIMP_TYPE_LAYER;
Manish Singh's avatar
Manish Singh committed
158

159
      if (dest_image == gimp_item_get_image (GIMP_ITEM (drawable)))
160
        new_item = gimp_item_duplicate (GIMP_ITEM (drawable), new_type);
161
      else
162
        new_item = gimp_item_convert (GIMP_ITEM (drawable), dest_image, new_type);
Manish Singh's avatar
Manish Singh committed
163

164
      if (new_item)
Manish Singh's avatar
Manish Singh committed
165
        layer_copy = GIMP_LAYER (new_item);
166
      else
Manish Singh's avatar
Manish Singh committed
167
        success = FALSE;
168 169
    }

170 171
  return_vals = gimp_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);
172 173

  if (success)
174
    gimp_value_set_layer (&return_vals->values[1], layer_copy);
175

176
  return return_vals;
177 178
}

179
static GValueArray *
180 181 182 183 184 185
layer_copy_invoker (GimpProcedure      *procedure,
                    Gimp               *gimp,
                    GimpContext        *context,
                    GimpProgress       *progress,
                    const GValueArray  *args,
                    GError            **error)
Elliot Lee's avatar
Elliot Lee committed
186
{
Manish Singh's avatar
Manish Singh committed
187
  gboolean success = TRUE;
188
  GValueArray *return_vals;
Manish Singh's avatar
Manish Singh committed
189 190
  GimpLayer *layer;
  gboolean add_alpha;
191
  GimpLayer *layer_copy = NULL;
Elliot Lee's avatar
Elliot Lee committed
192

193 194
  layer = gimp_value_get_layer (&args->values[0], gimp);
  add_alpha = g_value_get_boolean (&args->values[1]);
Elliot Lee's avatar
Elliot Lee committed
195 196

  if (success)
197 198
    {
      layer_copy = GIMP_LAYER (gimp_item_duplicate (GIMP_ITEM (layer),
199 200 201 202 203 204 205 206 207 208
                                                    G_TYPE_FROM_INSTANCE (layer)));
      if (layer_copy)
        {
          if (add_alpha)
            gimp_layer_add_alpha (layer_copy);
        }
      else
        {
          success = FALSE;
        }
209
    }
Elliot Lee's avatar
Elliot Lee committed
210

211 212
  return_vals = gimp_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);
Elliot Lee's avatar
Elliot Lee committed
213 214

  if (success)
215
    gimp_value_set_layer (&return_vals->values[1], layer_copy);
Elliot Lee's avatar
Elliot Lee committed
216

217
  return return_vals;
Elliot Lee's avatar
Elliot Lee committed
218 219
}

220
static GValueArray *
221 222 223 224 225 226
layer_add_alpha_invoker (GimpProcedure      *procedure,
                         Gimp               *gimp,
                         GimpContext        *context,
                         GimpProgress       *progress,
                         const GValueArray  *args,
                         GError            **error)
Elliot Lee's avatar
Elliot Lee committed
227
{
Manish Singh's avatar
Manish Singh committed
228 229
  gboolean success = TRUE;
  GimpLayer *layer;
Elliot Lee's avatar
Elliot Lee committed
230

231
  layer = gimp_value_get_layer (&args->values[0], gimp);
Elliot Lee's avatar
Elliot Lee committed
232 233

  if (success)
234 235 236
    {
      gimp_layer_add_alpha (layer);
    }
Elliot Lee's avatar
Elliot Lee committed
237

238 239
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
Elliot Lee's avatar
Elliot Lee committed
240 241
}

242
static GValueArray *
243 244 245 246 247 248
layer_flatten_invoker (GimpProcedure      *procedure,
                       Gimp               *gimp,
                       GimpContext        *context,
                       GimpProgress       *progress,
                       const GValueArray  *args,
                       GError            **error)
249 250 251 252 253 254 255 256 257 258 259
{
  gboolean success = TRUE;
  GimpLayer *layer;

  layer = gimp_value_get_layer (&args->values[0], gimp);

  if (success)
    {
      gimp_layer_flatten (layer, context);
    }

260 261
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
262 263
}

264
static GValueArray *
265 266 267 268 269 270
layer_scale_invoker (GimpProcedure      *procedure,
                     Gimp               *gimp,
                     GimpContext        *context,
                     GimpProgress       *progress,
                     const GValueArray  *args,
                     GError            **error)
Elliot Lee's avatar
Elliot Lee committed
271
{
Manish Singh's avatar
Manish Singh committed
272 273 274 275 276
  gboolean success = TRUE;
  GimpLayer *layer;
  gint32 new_width;
  gint32 new_height;
  gboolean local_origin;
Elliot Lee's avatar
Elliot Lee committed
277

278 279 280 281
  layer = gimp_value_get_layer (&args->values[0], gimp);
  new_width = g_value_get_int (&args->values[1]);
  new_height = g_value_get_int (&args->values[2]);
  local_origin = g_value_get_boolean (&args->values[3]);
Elliot Lee's avatar
Elliot Lee committed
282

Manish Singh's avatar
Manish Singh committed
283
  if (success)
284
    {
285
      if (gimp_pdb_item_is_attached (GIMP_ITEM (layer), error))
286 287 288
        gimp_item_scale_by_origin (GIMP_ITEM (layer), new_width, new_height,
                                   gimp->config->interpolation_type, NULL,
                                   local_origin);
289 290
      else
        success = FALSE;
291
    }
Elliot Lee's avatar
Elliot Lee committed
292

293 294
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
Elliot Lee's avatar
Elliot Lee committed
295 296
}

297
static GValueArray *
298 299 300 301 302 303
layer_resize_invoker (GimpProcedure      *procedure,
                      Gimp               *gimp,
                      GimpContext        *context,
                      GimpProgress       *progress,
                      const GValueArray  *args,
                      GError            **error)
Elliot Lee's avatar
Elliot Lee committed
304
{
Manish Singh's avatar
Manish Singh committed
305 306 307 308 309 310
  gboolean success = TRUE;
  GimpLayer *layer;
  gint32 new_width;
  gint32 new_height;
  gint32 offx;
  gint32 offy;
Elliot Lee's avatar
Elliot Lee committed
311

312 313 314 315 316
  layer = gimp_value_get_layer (&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]);
Elliot Lee's avatar
Elliot Lee committed
317

Manish Singh's avatar
Manish Singh committed
318
  if (success)
319
    {
320
      if (gimp_pdb_item_is_attached (GIMP_ITEM (layer), error))
321 322
        gimp_item_resize (GIMP_ITEM (layer), context,
                          new_width, new_height, offx, offy);
323 324
      else
        success = FALSE;
325
    }
Elliot Lee's avatar
Elliot Lee committed
326

327 328
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
Elliot Lee's avatar
Elliot Lee committed
329 330
}

331
static GValueArray *
332 333 334 335 336 337
layer_resize_to_image_size_invoker (GimpProcedure      *procedure,
                                    Gimp               *gimp,
                                    GimpContext        *context,
                                    GimpProgress       *progress,
                                    const GValueArray  *args,
                                    GError            **error)
338 339 340 341
{
  gboolean success = TRUE;
  GimpLayer *layer;

342
  layer = gimp_value_get_layer (&args->values[0], gimp);
343 344 345

  if (success)
    {
346
      if (gimp_pdb_item_is_attached (GIMP_ITEM (layer), error))
347
        gimp_layer_resize_to_image (layer, context);
348 349
      else
        success = FALSE;
350 351
    }

352 353
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
354 355
}

356
static GValueArray *
357 358 359 360 361 362
layer_translate_invoker (GimpProcedure      *procedure,
                         Gimp               *gimp,
                         GimpContext        *context,
                         GimpProgress       *progress,
                         const GValueArray  *args,
                         GError            **error)
Elliot Lee's avatar
Elliot Lee committed
363
{
Manish Singh's avatar
Manish Singh committed
364 365 366 367
  gboolean success = TRUE;
  GimpLayer *layer;
  gint32 offx;
  gint32 offy;
Elliot Lee's avatar
Elliot Lee committed
368

369 370 371
  layer = gimp_value_get_layer (&args->values[0], gimp);
  offx = g_value_get_int (&args->values[1]);
  offy = g_value_get_int (&args->values[2]);
Elliot Lee's avatar
Elliot Lee committed
372

Manish Singh's avatar
Manish Singh committed
373 374
  if (success)
    {
375
      GimpImage *image = gimp_item_get_image (GIMP_ITEM (layer));
Manish Singh's avatar
Manish Singh committed
376

377
      gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_ITEM_DISPLACE,
378
                                   _("Move Layer"));
Manish Singh's avatar
Manish Singh committed
379

380
      gimp_item_translate (GIMP_ITEM (layer), offx, offy, TRUE);
Manish Singh's avatar
Manish Singh committed
381

382
      if (gimp_item_get_linked (GIMP_ITEM (layer)))
383
        gimp_item_linked_translate (GIMP_ITEM (layer), offx, offy, TRUE);
Manish Singh's avatar
Manish Singh committed
384

385
      gimp_image_undo_group_end (image);
Elliot Lee's avatar
Elliot Lee committed
386 387
    }

388 389
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
Elliot Lee's avatar
Elliot Lee committed
390 391
}

392
static GValueArray *
393 394 395 396 397 398
layer_set_offsets_invoker (GimpProcedure      *procedure,
                           Gimp               *gimp,
                           GimpContext        *context,
                           GimpProgress       *progress,
                           const GValueArray  *args,
                           GError            **error)
Elliot Lee's avatar
Elliot Lee committed
399
{
Manish Singh's avatar
Manish Singh committed
400 401 402 403 404
  gboolean success = TRUE;
  GimpLayer *layer;
  gint32 offx;
  gint32 offy;

405 406 407
  layer = gimp_value_get_layer (&args->values[0], gimp);
  offx = g_value_get_int (&args->values[1]);
  offy = g_value_get_int (&args->values[2]);
Elliot Lee's avatar
Elliot Lee committed
408 409 410

  if (success)
    {
411
      GimpImage *image = gimp_item_get_image (GIMP_ITEM (layer));
Manish Singh's avatar
Manish Singh committed
412

413
      gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_ITEM_DISPLACE,
414
                                   _("Move Layer"));
Manish Singh's avatar
Manish Singh committed
415

416 417 418 419
      offx -= GIMP_ITEM (layer)->offset_x;
      offy -= GIMP_ITEM (layer)->offset_y;

      gimp_item_translate (GIMP_ITEM (layer), offx, offy, TRUE);
Manish Singh's avatar
Manish Singh committed
420

421
      if (gimp_item_get_linked (GIMP_ITEM (layer)))
422
        gimp_item_linked_translate (GIMP_ITEM (layer), offx, offy, TRUE);
Manish Singh's avatar
Manish Singh committed
423

424
      gimp_image_undo_group_end (image);
Elliot Lee's avatar
Elliot Lee committed
425 426
    }

427 428
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
Elliot Lee's avatar
Elliot Lee committed
429 430
}

431
static GValueArray *
432 433 434 435 436 437
layer_create_mask_invoker (GimpProcedure      *procedure,
                           Gimp               *gimp,
                           GimpContext        *context,
                           GimpProgress       *progress,
                           const GValueArray  *args,
                           GError            **error)
438 439
{
  gboolean success = TRUE;
440
  GValueArray *return_vals;
441 442 443 444
  GimpLayer *layer;
  gint32 mask_type;
  GimpLayerMask *mask = NULL;

445 446
  layer = gimp_value_get_layer (&args->values[0], gimp);
  mask_type = g_value_get_enum (&args->values[1]);
447 448

  if (success)
449
    {
450
      GimpChannel *channel = NULL;
451

452 453 454 455 456 457 458 459 460 461 462 463 464 465 466
      if (mask_type == GIMP_ADD_CHANNEL_MASK)
        {
          channel = gimp_image_get_active_channel (GIMP_ITEM (layer)->image);

          if (! channel)
            success = FALSE;
        }

      if (success)
        {
          mask = gimp_layer_create_mask (layer, mask_type, channel);

          if (! mask)
            success = FALSE;
        }
467
    }
468

469 470
  return_vals = gimp_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);
471 472

  if (success)
473
    gimp_value_set_layer_mask (&return_vals->values[1], mask);
474

475
  return return_vals;
476 477
}

478
static GValueArray *
479 480 481 482 483 484
layer_get_mask_invoker (GimpProcedure      *procedure,
                        Gimp               *gimp,
                        GimpContext        *context,
                        GimpProgress       *progress,
                        const GValueArray  *args,
                        GError            **error)
Elliot Lee's avatar
Elliot Lee committed
485
{
Manish Singh's avatar
Manish Singh committed
486
  gboolean success = TRUE;
487
  GValueArray *return_vals;
Manish Singh's avatar
Manish Singh committed
488
  GimpLayer *layer;
489
  GimpLayerMask *mask = NULL;
Manish Singh's avatar
Manish Singh committed
490

491
  layer = gimp_value_get_layer (&args->values[0], gimp);
Elliot Lee's avatar
Elliot Lee committed
492

493 494 495 496 497
  if (success)
    {
      mask = gimp_layer_get_mask (layer);
    }

498 499
  return_vals = gimp_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);
Manish Singh's avatar
Manish Singh committed
500

Elliot Lee's avatar
Elliot Lee committed
501
  if (success)
502
    gimp_value_set_layer_mask (&return_vals->values[1], mask);
Elliot Lee's avatar
Elliot Lee committed
503

504
  return return_vals;
Elliot Lee's avatar
Elliot Lee committed
505 506
}

507
static GValueArray *
508 509 510 511 512 513
layer_from_mask_invoker (GimpProcedure      *procedure,
                         Gimp               *gimp,
                         GimpContext        *context,
                         GimpProgress       *progress,
                         const GValueArray  *args,
                         GError            **error)
514 515
{
  gboolean success = TRUE;
516
  GValueArray *return_vals;
517 518 519
  GimpLayerMask *mask;
  GimpLayer *layer = NULL;

520
  mask = gimp_value_get_layer_mask (&args->values[0], gimp);
521 522 523 524 525 526

  if (success)
    {
      layer = gimp_layer_mask_get_layer (mask);
    }

527 528
  return_vals = gimp_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);
529 530

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

533
  return return_vals;
534 535
}

536
static GValueArray *
537 538 539 540 541 542
layer_add_mask_invoker (GimpProcedure      *procedure,
                        Gimp               *gimp,
                        GimpContext        *context,
                        GimpProgress       *progress,
                        const GValueArray  *args,
                        GError            **error)
543 544 545 546 547
{
  gboolean success = TRUE;
  GimpLayer *layer;
  GimpLayerMask *mask;

548 549
  layer = gimp_value_get_layer (&args->values[0], gimp);
  mask = gimp_value_get_layer_mask (&args->values[1], gimp);
550 551 552

  if (success)
    {
553 554 555
      if (gimp_pdb_item_is_floating (GIMP_ITEM (mask),
                                     gimp_item_get_image (GIMP_ITEM (layer)),
                                     error))
556
        success = (gimp_layer_add_mask (layer, mask, TRUE, error) == mask);
557 558
      else
        success = FALSE;
559 560
    }

561 562
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
563 564
}

565
static GValueArray *
566 567 568 569 570 571
layer_remove_mask_invoker (GimpProcedure      *procedure,
                           Gimp               *gimp,
                           GimpContext        *context,
                           GimpProgress       *progress,
                           const GValueArray  *args,
                           GError            **error)
572 573 574 575 576
{
  gboolean success = TRUE;
  GimpLayer *layer;
  gint32 mode;

577 578
  layer = gimp_value_get_layer (&args->values[0], gimp);
  mode = g_value_get_enum (&args->values[1]);
579 580

  if (success)
581
    {
582 583
      if (gimp_pdb_item_is_attached (GIMP_ITEM (layer), error) &&
          gimp_layer_get_mask (layer))
584
        gimp_layer_apply_mask (layer, mode, TRUE);
585 586
      else
        success = FALSE;
587
    }
588

589 590
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
591 592
}

593
static GValueArray *
594 595 596 597 598 599
layer_is_floating_sel_invoker (GimpProcedure      *procedure,
                               Gimp               *gimp,
                               GimpContext        *context,
                               GimpProgress       *progress,
                               const GValueArray  *args,
                               GError            **error)
Elliot Lee's avatar
Elliot Lee committed
600
{
Manish Singh's avatar
Manish Singh committed
601
  gboolean success = TRUE;
602
  GValueArray *return_vals;
Manish Singh's avatar
Manish Singh committed
603
  GimpLayer *layer;
604
  gboolean is_floating_sel = FALSE;
Elliot Lee's avatar
Elliot Lee committed
605

606
  layer = gimp_value_get_layer (&args->values[0], gimp);
Elliot Lee's avatar
Elliot Lee committed
607

608 609 610 611 612
  if (success)
    {
      is_floating_sel = gimp_layer_is_floating_sel (layer);
    }

613 614
  return_vals = gimp_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);
615 616 617 618 619 620 621 622

  if (success)
    g_value_set_boolean (&return_vals->values[1], is_floating_sel);

  return return_vals;
}

static GValueArray *
623 624 625 626 627 628
layer_get_lock_alpha_invoker (GimpProcedure      *procedure,
                              Gimp               *gimp,
                              GimpContext        *context,
                              GimpProgress       *progress,
                              const GValueArray  *args,
                              GError            **error)
629 630 631 632 633 634 635 636 637 638 639 640 641
{
  gboolean success = TRUE;
  GValueArray *return_vals;
  GimpLayer *layer;
  gboolean lock_alpha = FALSE;

  layer = gimp_value_get_layer (&args->values[0], gimp);

  if (success)
    {
      lock_alpha = gimp_layer_get_lock_alpha (layer);
    }

642 643
  return_vals = gimp_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);
644 645 646 647 648 649 650 651

  if (success)
    g_value_set_boolean (&return_vals->values[1], lock_alpha);

  return return_vals;
}

static GValueArray *
652 653 654 655 656 657
layer_set_lock_alpha_invoker (GimpProcedure      *procedure,
                              Gimp               *gimp,
                              GimpContext        *context,
                              GimpProgress       *progress,
                              const GValueArray  *args,
                              GError            **error)
658 659 660 661 662 663 664 665 666 667 668 669 670
{
  gboolean success = TRUE;
  GimpLayer *layer;
  gboolean lock_alpha;

  layer = gimp_value_get_layer (&args->values[0], gimp);
  lock_alpha = g_value_get_boolean (&args->values[1]);

  if (success)
    {
      gimp_layer_set_lock_alpha (layer, lock_alpha, TRUE);
    }

671 672
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
673 674 675
}

static GValueArray *
676 677 678 679 680 681
layer_get_apply_mask_invoker (GimpProcedure      *procedure,
                              Gimp               *gimp,
                              GimpContext        *context,
                              GimpProgress       *progress,
                              const GValueArray  *args,
                              GError            **error)
682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697
{
  gboolean success = TRUE;
  GValueArray *return_vals;
  GimpLayer *layer;
  gboolean apply_mask = FALSE;

  layer = gimp_value_get_layer (&args->values[0], gimp);

  if (success)
    {
      if (layer->mask)
        apply_mask = gimp_layer_mask_get_apply (layer->mask);
      else
        apply_mask = FALSE;
    }

698 699
  return_vals = gimp_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);
700 701 702 703 704 705 706 707

  if (success)
    g_value_set_boolean (&return_vals->values[1], apply_mask);

  return return_vals;
}

static GValueArray *
708 709 710 711 712 713
layer_set_apply_mask_invoker (GimpProcedure      *procedure,
                              Gimp               *gimp,
                              GimpContext        *context,
                              GimpProgress       *progress,
                              const GValueArray  *args,
                              GError            **error)
714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729
{
  gboolean success = TRUE;
  GimpLayer *layer;
  gboolean apply_mask;

  layer = gimp_value_get_layer (&args->values[0], gimp);
  apply_mask = g_value_get_boolean (&args->values[1]);

  if (success)
    {
      if (layer->mask)
        gimp_layer_mask_set_apply (layer->mask, apply_mask, TRUE);
      else
        success = FALSE;
    }

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

static GValueArray *
735 736 737 738 739 740
layer_get_show_mask_invoker (GimpProcedure      *procedure,
                             Gimp               *gimp,
                             GimpContext        *context,
                             GimpProgress       *progress,
                             const GValueArray  *args,
                             GError            **error)
741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756
{
  gboolean success = TRUE;
  GValueArray *return_vals;
  GimpLayer *layer;
  gboolean show_mask = FALSE;

  layer = gimp_value_get_layer (&args->values[0], gimp);

  if (success)
    {
      if (layer->mask)
        show_mask = gimp_layer_mask_get_show (layer->mask);
      else
        show_mask = FALSE;
    }

757 758
  return_vals = gimp_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);
759 760 761 762 763 764 765 766

  if (success)
    g_value_set_boolean (&return_vals->values[1], show_mask);

  return return_vals;
}

static GValueArray *
767 768 769 770 771 772
layer_set_show_mask_invoker (GimpProcedure      *procedure,
                             Gimp               *gimp,
                             GimpContext        *context,
                             GimpProgress       *progress,
                             const GValueArray  *args,
                             GError            **error)
773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788
{
  gboolean success = TRUE;
  GimpLayer *layer;
  gboolean show_mask;

  layer = gimp_value_get_layer (&args->values[0], gimp);
  show_mask = g_value_get_boolean (&args->values[1]);

  if (success)
    {
      if (layer->mask)
        gimp_layer_mask_set_show (layer->mask, show_mask, TRUE);
      else
        success = FALSE;
    }

789 790
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
791 792 793
}

static GValueArray *
794 795 796 797 798 799
layer_get_edit_mask_invoker (GimpProcedure      *procedure,
                             Gimp               *gimp,
                             GimpContext        *context,
                             GimpProgress       *progress,
                             const GValueArray  *args,
                             GError            **error)
800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815
{
  gboolean success = TRUE;
  GValueArray *return_vals;
  GimpLayer *layer;
  gboolean edit_mask = FALSE;

  layer = gimp_value_get_layer (&args->values[0], gimp);

  if (success)
    {
      if (layer->mask)
        edit_mask = gimp_layer_mask_get_edit (layer->mask);
      else
        edit_mask = FALSE;
    }

816 817
  return_vals = gimp_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);
818 819 820 821 822 823 824 825

  if (success)
    g_value_set_boolean (&return_vals->values[1], edit_mask);

  return return_vals;
}

static GValueArray *
826 827 828 829 830 831
layer_set_edit_mask_invoker (GimpProcedure      *procedure,
                             Gimp               *gimp,
                             GimpContext        *context,
                             GimpProgress       *progress,
                             const GValueArray  *args,
                             GError            **error)
832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847
{
  gboolean success = TRUE;
  GimpLayer *layer;
  gboolean edit_mask;

  layer = gimp_value_get_layer (&args->values[0], gimp);
  edit_mask = g_value_get_boolean (&args->values[1]);

  if (success)
    {
      if (layer->mask)
        gimp_layer_mask_set_edit (layer->mask, edit_mask);
      else
        success = FALSE;
    }

848 849
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
Elliot Lee's avatar
Elliot Lee committed
850 851
}

852
static GValueArray *
853 854 855 856 857 858
layer_get_opacity_invoker (GimpProcedure      *procedure,
                           Gimp               *gimp,
                           GimpContext        *context,
                           GimpProgress       *progress,
                           const GValueArray  *args,
                           GError            **error)
Elliot Lee's avatar
Elliot Lee committed
859
{
Manish Singh's avatar
Manish Singh committed
860
  gboolean success = TRUE;
861
  GValueArray *return_vals;
Manish Singh's avatar
Manish Singh committed
862
  GimpLayer *layer;
863
  gdouble opacity = 0.0;
Elliot Lee's avatar
Elliot Lee committed
864

865
  layer = gimp_value_get_layer (&args->values[0], gimp);
Elliot Lee's avatar
Elliot Lee committed
866

867 868
  if (success)
    {
869
      opacity = gimp_layer_get_opacity (layer) * 100.0;
870 871
    }

872 873
  return_vals = gimp_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);
Elliot Lee's avatar
Elliot Lee committed
874 875

  if (success)
876
    g_value_set_double (&return_vals->values[1], opacity);
Elliot Lee's avatar
Elliot Lee committed
877

878
  return return_vals;
Elliot Lee's avatar
Elliot Lee committed
879 880
}

881
static GValueArray *
882 883 884 885 886 887
layer_set_opacity_invoker (GimpProcedure      *procedure,
                           Gimp               *gimp,
                           GimpContext        *context,
                           GimpProgress       *progress,
                           const GValueArray  *args,
                           GError            **error)
Elliot Lee's avatar
Elliot Lee committed
888
{
Manish Singh's avatar
Manish Singh committed
889 890
  gboolean success = TRUE;
  GimpLayer *layer;
891
  gdouble opacity;
Manish Singh's avatar
Manish Singh committed
892

893
  layer = gimp_value_get_layer (&args->values[0], gimp);
894
  opacity = g_value_get_double (&args->values[1]);
Elliot Lee's avatar
Elliot Lee committed
895 896

  if (success)
897
    {
898
      gimp_layer_set_opacity (layer, opacity / 100.0, TRUE);
899
    }
Elliot Lee's avatar
Elliot Lee committed
900

901 902
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
Elliot Lee's avatar
Elliot Lee committed
903 904
}

905
static GValueArray *
906 907 908 909 910 911
layer_get_mode_invoker (GimpProcedure      *procedure,
                        Gimp               *gimp,
                        GimpContext        *context,
                        GimpProgress       *progress,
                        const GValueArray  *args,
                        GError            **error)
912 913
{
  gboolean success = TRUE;
914
  GValueArray *return_vals;
915
  GimpLayer *layer;
916
  gint32 mode = 0;
917

918
  layer = gimp_value_get_layer (&args->values[0], gimp);
919

920 921
  if (success)
    {
922
      mode = gimp_layer_get_mode (layer);
923 924
    }

925 926
  return_vals = gimp_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);
927 928

  if (success)
929
    g_value_set_enum (&return_vals->values[1], mode);
930

931
  return return_vals;
932 933
}

934
static GValueArray *
935 936 937 938 939 940
layer_set_mode_invoker (GimpProcedure      *procedure,
                        Gimp               *gimp,
                        GimpContext        *context,
                        GimpProgress       *progress,
                        const GValueArray  *args,
                        GError            **error)
941 942 943
{
  gboolean success = TRUE;
  GimpLayer *layer;
944
  gint32 mode;
945

946
  layer = gimp_value_get_layer (&args->values[0], gimp);
947
  mode = g_value_get_enum (&args->values[1]);
948 949

  if (success)
950
    {
951
      gimp_layer_set_mode (layer, mode, TRUE);
952
    }
953

954 955
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
956 957
}

958
void
959
register_layer_procs (GimpPDB *pdb)
960
{
961
  GimpProcedure *procedure;
962

963 964 965
  /*
   * gimp-layer-new
   */
966
  procedure = gimp_procedure_new (layer_new_invoker);
967 968
  gimp_object_set_static_name (GIMP_OBJECT (procedure),
                               "gimp-layer-new");
969 970 971
  gimp_procedure_set_static_strings (procedure,
                                     "gimp-layer-new",
                                     "Create a new layer.",
972
                                     "This procedure creates a new layer with the specified width, height, and type. Name, opacity, and mode are also supplied parameters. The new layer still needs to be added to the image, as this is not automatic. Add the new layer with the 'gimp-image-add-layer' command. Other attributes such as layer mask modes, and offsets should be set with explicit procedure calls.",
973 974 975 976 977 978 979 980
                                     "Spencer Kimball & Peter Mattis",
                                     "Spencer Kimball & Peter Mattis",
                                     "1995-1996",
                                     NULL);
  gimp_procedure_add_argument (procedure,
                               gimp_param_spec_image_id ("image",
                                                         "image",
                                                         "The image to which to add the layer",
981
                                                         pdb->gimp, FALSE,
982 983 984 985
                                                         GIMP_PARAM_READWRITE));
  gimp_procedure_add_argument (procedure,
                               gimp_param_spec_int32 ("width",
                                                      "width",
986
                                                      "The layer width",
987
                                                      1, GIMP_MAX_IMAGE_SIZE, 1,
988 989 990 991
                                                      GIMP_PARAM_READWRITE));
  gimp_procedure_add_argument (procedure,
                               gimp_param_spec_int32 ("height",
                                                      "height",
992
                                                      "The layer height",
993
                                                      1, GIMP_MAX_IMAGE_SIZE, 1,
994 995 996 997
                                                      GIMP_PARAM_READWRITE));
  gimp_procedure_add_argument (procedure,
                               g_param_spec_enum ("type",
                                                  "type",
998
                                                  "The layer type",
999 1000 1001 1002 1003 1004 1005
                                                  GIMP_TYPE_IMAGE_TYPE,
                                                  GIMP_RGB_IMAGE,
                                                  GIMP_PARAM_READWRITE));
  gimp_procedure_add_argument (procedure,
                               gimp_param_spec_string ("name",
                                                       "name",
                                                       "The layer name",
1006
                                                       FALSE, TRUE, FALSE,
1007 1008 1009 1010 1011
                                                       NULL,
                                                       GIMP_PARAM_READWRITE));
  gimp_procedure_add_argument (procedure,
                               g_param_spec_double ("opacity",
                                                    "opacity",
1012
                                                    "The layer opacity",
1013 1014 1015 1016 1017
                                                    0, 100, 0,
                                                    GIMP_PARAM_READWRITE));
  gimp_procedure_add_argument (procedure,
                               g_param_spec_enum ("mode",
                                                  "mode",
1018
                                                  "The layer combination mode",
1019 1020 1021
                                                  GIMP_TYPE_LAYER_MODE_EFFECTS,
                                                  GIMP_NORMAL_MODE,
                                                  GIMP_PARAM_READWRITE));
1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 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
  gimp_procedure_add_return_value (procedure,
                                   gimp_param_spec_layer_id ("layer",
                                                             "layer",
                                                             "The newly created layer",
                                                             pdb->gimp, FALSE,
                                                             GIMP_PARAM_READWRITE));
  gimp_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

  /*
   * gimp-layer-new-from-visible
   */
  procedure = gimp_procedure_new (layer_new_from_visible_invoker);
  gimp_object_set_static_name (GIMP_OBJECT (procedure),
                               "gimp-layer-new-from-visible");
  gimp_procedure_set_static_strings (procedure,
                                     "gimp-layer-new-from-visible",
                                     "Create a new layer from what is visible in an image.",
                                     "This procedure creates a new layer from what is visible in the given image. The new layer still needs to be added to the destination image, as this is not automatic. Add the new layer with the 'gimp-image-add-layer' command. Other attributes such as layer mask modes, and offsets should be set with explicit procedure calls.",
                                     "Sven Neumann <sven@gimp.org>",
                                     "Sven Neumann",
                                     "2008",
                                     NULL);
  gimp_procedure_add_argument (procedure,
                               gimp_param_spec_image_id ("image",
                                                         "image",
                                                         "The source image from where the content is copied",
                                                         pdb->gimp, FALSE,
                                                         GIMP_PARAM_READWRITE));
  gimp_procedure_add_argument (procedure,
                               gimp_param_spec_image_id ("dest-image",
                                                         "dest image",
                                                         "The destination image to which to add the layer",
                                                         pdb->gimp, FALSE,
                                                         GIMP_PARAM_READWRITE));
  gimp_procedure_add_argument (procedure,
                               gimp_param_spec_string ("name",
                                                       "name",
                                                       "The layer name",
                                                       FALSE, TRUE, FALSE,
                                                       NULL,
                                                       GIMP_PARAM_READWRITE));
1064 1065 1066 1067
  gimp_procedure_add_return_value (procedure,
                                   gimp_param_spec_layer_id ("layer",
                                                             "layer",
                                                             "The newly created layer",
1068
                                                             pdb->gimp, FALSE,
1069
                                                             GIMP_PARAM_READWRITE));
1070
  gimp_pdb_register_procedure (pdb, procedure);
1071
  g_object_unref (procedure);
1072

1073 1074 1075
  /*
   * gimp-layer-new-from-drawable
   */
1076
  procedure = gimp_procedure_new (layer_new_from_drawable_invoker);
1077 1078
  gimp_object_set_static_name (GIMP_OBJECT (procedure),
                               "gimp-layer-new-from-drawable");
1079 1080 1081
  gimp_procedure_set_static_strings (procedure,
                                     "gimp-layer-new-from-drawable",
                                     "Create a new layer by copying an existing drawable.",
1082
                                     "This procedure creates a new layer as a copy of the specified drawable. The new layer still needs to be added to the image, as this is not automatic. Add the new layer with the 'gimp-image-add-layer' command. Other attributes such as layer mask modes, and offsets should be set with explicit procedure calls.",
1083 1084 1085 1086 1087 1088 1089 1090
                                     "Spencer Kimball & Peter Mattis",
                                     "Spencer Kimball & Peter Mattis",
                                     "1995-1996",
                                     NULL);
  gimp_procedure_add_argument (procedure,
                               gimp_param_spec_drawable_id ("drawable",
                                                            "drawable",
                                                            "The source drawable from where the new layer is copied",
1091
                                                            pdb->gimp, FALSE,
1092 1093 1094 1095 1096
                                                            GIMP_PARAM_READWRITE));
  gimp_procedure_add_argument (procedure,
                               gimp_param_spec_image_id ("dest-image",
                                                         "dest image",
                                                         "The destination image to which to add the layer",
1097
                                                         pdb->gimp, FALSE,
1098 1099 1100 1101 1102
                                                         GIMP_PARAM_READWRITE));
  gimp_procedure_add_return_value (procedure,
                                   gimp_param_spec_layer_id ("layer-copy",
                                                             "layer copy",
                                                             "The newly copied layer",
1103
                                                             pdb->gimp, FALSE,
1104
                                                             GIMP_PARAM_READWRITE));
1105
  gimp_pdb_register_procedure (pdb, procedure);
1106
  g_object_unref (procedure);
1107 1108 1109 1110

  /*
   * gimp-layer-copy
   */
1111
  procedure = gimp_procedure_new (layer_copy_invoker);
1112 1113
  gimp_object_set_static_name (GIMP_OBJECT (procedure),
                               "gimp-layer-copy");
1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125
  gimp_procedure_set_static_strings (procedure,
                                     "gimp-layer-copy",
                                     "Copy a layer.",
                                     "This procedure copies the specified layer and returns the copy. The newly copied layer is for use within the original layer's image. It should not be subsequently added to any other image. The copied layer can optionally have an added alpha channel. This is useful if the background layer in an image is being copied and added to the same image.",
                                     "Spencer Kimball & Peter Mattis",
                                     "Spencer Kimball & Peter Mattis",
                                     "1995-1996",
                                     NULL);
  gimp_procedure_add_argument (procedure,
                               gimp_param_spec_layer_id ("layer",
                                                         "layer",
                                                         "The layer to copy",
1126
                                                         pdb->gimp, FALSE,
1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137
                                                         GIMP_PARAM_READWRITE));
  gimp_procedure_add_argument (procedure,
                               g_param_spec_boolean ("add-alpha",
                                                     "add alpha",
                                                     "Add an alpha channel to the copied layer",
                                                     FALSE,
                                                     GIMP_PARAM_READWRITE));
  gimp_procedure_add_return_value (procedure,
                                   gimp_param_spec_layer_id ("layer-copy",
                                                             "layer copy",
                                                             "The newly copied layer",
1138
                                                             pdb->gimp, FALSE,
1139
                                                             GIMP_PARAM_READWRITE));
1140