GitLab repository storage has been migrated to hashed layout. Please contact Infrastructure team if you notice any issues with repositories or hooks.

layer-cmds.c 91.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 <gegl.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/gimppickable.h"
39
#include "core/gimpprogress.h"
40

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

46 47
#include "gimp-intl.h"

Elliot Lee's avatar
Elliot Lee committed
48

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

68 69 70 71 72 73 74
  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
75 76 77

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

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

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

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

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

94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
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)
    {
115
      GimpPickable *pickable = GIMP_PICKABLE (gimp_image_get_projection (image));
116

117
      layer = gimp_layer_new_from_tiles (gimp_pickable_get_tiles (pickable),
118
                                         dest_image,
119
                                         gimp_image_base_type_with_alpha (dest_image),
120 121 122 123
                                         name,
                                         GIMP_OPACITY_OPAQUE, GIMP_NORMAL_MODE);
    }

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

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

  return return_vals;
}

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

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

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

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

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

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

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

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

177
  return return_vals;
178 179
}

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

194 195
  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
196 197

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

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

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

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

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

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

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

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

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

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

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

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

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

279 280 281 282
  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
283

Manish Singh's avatar
Manish Singh committed
284
  if (success)
285
    {
286
      if (gimp_pdb_item_is_attached (GIMP_ITEM (layer), error))
287 288 289 290 291 292 293 294 295 296 297
        {
          if (progress)
            gimp_progress_start (progress, _("Scaling"), FALSE);

          gimp_item_scale_by_origin (GIMP_ITEM (layer), new_width, new_height,
                                     gimp->config->interpolation_type, progress,
                                     local_origin);

          if (progress)
            gimp_progress_end (progress);
        }
298
      else
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346
        {
          success = FALSE;
        }
    }

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

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

  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]);
  interpolation = g_value_get_enum (&args->values[4]);

  if (success)
    {
      if (gimp_pdb_item_is_attached (GIMP_ITEM (layer), error))
        {
          if (progress)
            gimp_progress_start (progress, _("Scaling"), FALSE);

          gimp_item_scale_by_origin (GIMP_ITEM (layer), new_width, new_height,
                                     interpolation, progress,
                                     local_origin);

          if (progress)
            gimp_progress_end (progress);
        }
      else
        {
          success = FALSE;
        }
347
    }
Elliot Lee's avatar
Elliot Lee committed
348

349 350
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
Elliot Lee's avatar
Elliot Lee committed
351 352
}

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

368 369 370 371 372
  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
373

Manish Singh's avatar
Manish Singh committed
374
  if (success)
375
    {
376
      if (gimp_pdb_item_is_attached (GIMP_ITEM (layer), error))
377 378
        gimp_item_resize (GIMP_ITEM (layer), context,
                          new_width, new_height, offx, offy);
379 380
      else
        success = FALSE;
381
    }
Elliot Lee's avatar
Elliot Lee committed
382

383 384
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
Elliot Lee's avatar
Elliot Lee committed
385 386
}

387
static GValueArray *
388 389 390 391 392 393
layer_resize_to_image_size_invoker (GimpProcedure      *procedure,
                                    Gimp               *gimp,
                                    GimpContext        *context,
                                    GimpProgress       *progress,
                                    const GValueArray  *args,
                                    GError            **error)
394 395 396 397
{
  gboolean success = TRUE;
  GimpLayer *layer;

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

  if (success)
    {
402
      if (gimp_pdb_item_is_attached (GIMP_ITEM (layer), error))
403
        gimp_layer_resize_to_image (layer, context);
404 405
      else
        success = FALSE;
406 407
    }

408 409
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
410 411
}

412
static GValueArray *
413 414 415 416 417 418
layer_translate_invoker (GimpProcedure      *procedure,
                         Gimp               *gimp,
                         GimpContext        *context,
                         GimpProgress       *progress,
                         const GValueArray  *args,
                         GError            **error)
Elliot Lee's avatar
Elliot Lee committed
419
{
Manish Singh's avatar
Manish Singh committed
420 421 422 423
  gboolean success = TRUE;
  GimpLayer *layer;
  gint32 offx;
  gint32 offy;
Elliot Lee's avatar
Elliot Lee committed
424

425 426 427
  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
428

Manish Singh's avatar
Manish Singh committed
429 430
  if (success)
    {
431
      GimpImage *image = gimp_item_get_image (GIMP_ITEM (layer));
Manish Singh's avatar
Manish Singh committed
432

433
      gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_ITEM_DISPLACE,
434
                                   _("Move Layer"));
Manish Singh's avatar
Manish Singh committed
435

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

438
      if (gimp_item_get_linked (GIMP_ITEM (layer)))
439
        gimp_item_linked_translate (GIMP_ITEM (layer), offx, offy, TRUE);
Manish Singh's avatar
Manish Singh committed
440

441
      gimp_image_undo_group_end (image);
Elliot Lee's avatar
Elliot Lee committed
442 443
    }

444 445
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
Elliot Lee's avatar
Elliot Lee committed
446 447
}

448
static GValueArray *
449 450 451 452 453 454
layer_set_offsets_invoker (GimpProcedure      *procedure,
                           Gimp               *gimp,
                           GimpContext        *context,
                           GimpProgress       *progress,
                           const GValueArray  *args,
                           GError            **error)
Elliot Lee's avatar
Elliot Lee committed
455
{
Manish Singh's avatar
Manish Singh committed
456 457 458 459 460
  gboolean success = TRUE;
  GimpLayer *layer;
  gint32 offx;
  gint32 offy;

461 462 463
  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
464 465 466

  if (success)
    {
467
      GimpImage *image = gimp_item_get_image (GIMP_ITEM (layer));
468 469
      gint       offset_x;
      gint       offset_y;
Manish Singh's avatar
Manish Singh committed
470

471
      gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_ITEM_DISPLACE,
472
                                   _("Move Layer"));
Manish Singh's avatar
Manish Singh committed
473

474 475 476
      gimp_item_get_offset (GIMP_ITEM (layer), &offset_x, &offset_y);
      offx -= offset_x;
      offy -= offset_y;
477 478

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

480
      if (gimp_item_get_linked (GIMP_ITEM (layer)))
481
        gimp_item_linked_translate (GIMP_ITEM (layer), offx, offy, TRUE);
Manish Singh's avatar
Manish Singh committed
482

483
      gimp_image_undo_group_end (image);
Elliot Lee's avatar
Elliot Lee committed
484 485
    }

486 487
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
Elliot Lee's avatar
Elliot Lee committed
488 489
}

490
static GValueArray *
491 492 493 494 495 496
layer_create_mask_invoker (GimpProcedure      *procedure,
                           Gimp               *gimp,
                           GimpContext        *context,
                           GimpProgress       *progress,
                           const GValueArray  *args,
                           GError            **error)
497 498
{
  gboolean success = TRUE;
499
  GValueArray *return_vals;
500 501 502 503
  GimpLayer *layer;
  gint32 mask_type;
  GimpLayerMask *mask = NULL;

504 505
  layer = gimp_value_get_layer (&args->values[0], gimp);
  mask_type = g_value_get_enum (&args->values[1]);
506 507

  if (success)
508
    {
509
      GimpChannel *channel = NULL;
510

511 512
      if (mask_type == GIMP_ADD_CHANNEL_MASK)
        {
513
          channel = gimp_image_get_active_channel (gimp_item_get_image (GIMP_ITEM (layer)));
514 515 516 517 518 519 520 521 522 523 524 525

          if (! channel)
            success = FALSE;
        }

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

          if (! mask)
            success = FALSE;
        }
526
    }
527

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

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

534
  return return_vals;
535 536
}

537
static GValueArray *
538 539 540 541 542 543
layer_get_mask_invoker (GimpProcedure      *procedure,
                        Gimp               *gimp,
                        GimpContext        *context,
                        GimpProgress       *progress,
                        const GValueArray  *args,
                        GError            **error)
Elliot Lee's avatar
Elliot Lee committed
544
{
Manish Singh's avatar
Manish Singh committed
545
  gboolean success = TRUE;
546
  GValueArray *return_vals;
Manish Singh's avatar
Manish Singh committed
547
  GimpLayer *layer;
548
  GimpLayerMask *mask = NULL;
Manish Singh's avatar
Manish Singh committed
549

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

552 553 554 555 556
  if (success)
    {
      mask = gimp_layer_get_mask (layer);
    }

557 558
  return_vals = gimp_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);
Manish Singh's avatar
Manish Singh committed
559

Elliot Lee's avatar
Elliot Lee committed
560
  if (success)
561
    gimp_value_set_layer_mask (&return_vals->values[1], mask);
Elliot Lee's avatar
Elliot Lee committed
562

563
  return return_vals;
Elliot Lee's avatar
Elliot Lee committed
564 565
}

566
static GValueArray *
567 568 569 570 571 572
layer_from_mask_invoker (GimpProcedure      *procedure,
                         Gimp               *gimp,
                         GimpContext        *context,
                         GimpProgress       *progress,
                         const GValueArray  *args,
                         GError            **error)
573 574
{
  gboolean success = TRUE;
575
  GValueArray *return_vals;
576 577 578
  GimpLayerMask *mask;
  GimpLayer *layer = NULL;

579
  mask = gimp_value_get_layer_mask (&args->values[0], gimp);
580 581 582 583 584 585

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

586 587
  return_vals = gimp_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);
588 589

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

592
  return return_vals;
593 594
}

595
static GValueArray *
596 597 598 599 600 601
layer_add_mask_invoker (GimpProcedure      *procedure,
                        Gimp               *gimp,
                        GimpContext        *context,
                        GimpProgress       *progress,
                        const GValueArray  *args,
                        GError            **error)
602 603 604 605 606
{
  gboolean success = TRUE;
  GimpLayer *layer;
  GimpLayerMask *mask;

607 608
  layer = gimp_value_get_layer (&args->values[0], gimp);
  mask = gimp_value_get_layer_mask (&args->values[1], gimp);
609 610 611

  if (success)
    {
612 613 614
      if (gimp_pdb_item_is_floating (GIMP_ITEM (mask),
                                     gimp_item_get_image (GIMP_ITEM (layer)),
                                     error))
615
        success = (gimp_layer_add_mask (layer, mask, TRUE, error) == mask);
616 617
      else
        success = FALSE;
618 619
    }

620 621
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
622 623
}

624
static GValueArray *
625 626 627 628 629 630
layer_remove_mask_invoker (GimpProcedure      *procedure,
                           Gimp               *gimp,
                           GimpContext        *context,
                           GimpProgress       *progress,
                           const GValueArray  *args,
                           GError            **error)
631 632 633 634 635
{
  gboolean success = TRUE;
  GimpLayer *layer;
  gint32 mode;

636 637
  layer = gimp_value_get_layer (&args->values[0], gimp);
  mode = g_value_get_enum (&args->values[1]);
638 639

  if (success)
640
    {
641 642
      if (gimp_pdb_item_is_attached (GIMP_ITEM (layer), error) &&
          gimp_layer_get_mask (layer))
643
        gimp_layer_apply_mask (layer, mode, TRUE);
644 645
      else
        success = FALSE;
646
    }
647

648 649
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
650 651
}

652
static GValueArray *
653 654 655 656 657 658
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
659
{
Manish Singh's avatar
Manish Singh committed
660
  gboolean success = TRUE;
661
  GValueArray *return_vals;
Manish Singh's avatar
Manish Singh committed
662
  GimpLayer *layer;
663
  gboolean is_floating_sel = FALSE;
Elliot Lee's avatar
Elliot Lee committed
664

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

667 668 669 670 671
  if (success)
    {
      is_floating_sel = gimp_layer_is_floating_sel (layer);
    }

672 673
  return_vals = gimp_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);
674 675 676 677 678 679 680 681

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

  return return_vals;
}

static GValueArray *
682 683 684 685 686 687
layer_get_lock_alpha_invoker (GimpProcedure      *procedure,
                              Gimp               *gimp,
                              GimpContext        *context,
                              GimpProgress       *progress,
                              const GValueArray  *args,
                              GError            **error)
688 689 690 691 692 693 694 695 696 697 698 699 700
{
  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);
    }

701 702
  return_vals = gimp_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);
703 704 705 706 707 708 709 710

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

  return return_vals;
}

static GValueArray *
711 712 713 714 715 716
layer_set_lock_alpha_invoker (GimpProcedure      *procedure,
                              Gimp               *gimp,
                              GimpContext        *context,
                              GimpProgress       *progress,
                              const GValueArray  *args,
                              GError            **error)
717 718 719 720 721 722 723 724 725 726 727 728 729
{
  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);
    }

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_apply_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 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;
    }

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], apply_mask);

  return return_vals;
}

static GValueArray *
767 768 769 770 771 772
layer_set_apply_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 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;
    }

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_show_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 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;
    }

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], show_mask);

  return return_vals;
}

static GValueArray *
826 827 828 829 830 831
layer_set_show_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 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;
    }

848 849
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
850 851 852
}

static GValueArray *
853 854 855 856 857 858
layer_get_edit_mask_invoker (GimpProcedure      *procedure,
                             Gimp               *gimp,
                             GimpContext        *context,
                             GimpProgress       *progress,
                             const GValueArray  *args,
                             GError            **error)
859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874
{
  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;
    }

875 876
  return_vals = gimp_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);
877 878 879 880 881 882 883 884

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

  return return_vals;
}

static GValueArray *
885 886 887 888 889 890
layer_set_edit_mask_invoker (GimpProcedure      *procedure,
                             Gimp               *gimp,
                             GimpContext        *context,
                             GimpProgress       *progress,
                             const GValueArray  *args,
                             GError            **error)
891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906
{
  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;
    }

907 908
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
Elliot Lee's avatar
Elliot Lee committed
909 910
}

911
static GValueArray *
912 913 914 915 916 917
layer_get_opacity_invoker (GimpProcedure      *procedure,
                           Gimp               *gimp,
                           GimpContext        *context,
                           GimpProgress       *progress,
                           const GValueArray  *args,
                           GError            **error)
Elliot Lee's avatar
Elliot Lee committed
918
{
Manish Singh's avatar
Manish Singh committed
919
  gboolean success = TRUE;
920
  GValueArray *return_vals;
Manish Singh's avatar
Manish Singh committed
921
  GimpLayer *layer;
922
  gdouble opacity = 0.0;
Elliot Lee's avatar
Elliot Lee committed
923

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

926 927
  if (success)
    {
928
      opacity = gimp_layer_get_opacity (layer) * 100.0;
929 930
    }

931 932
  return_vals = gimp_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);
Elliot Lee's avatar
Elliot Lee committed
933 934

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

937
  return return_vals;
Elliot Lee's avatar
Elliot Lee committed
938 939
}

940
static GValueArray *
941 942 943 944 945 946
layer_set_opacity_invoker (GimpProcedure      *procedure,
                           Gimp               *gimp,
                           GimpContext        *context,
                           GimpProgress       *progress,
                           const GValueArray  *args,
                           GError            **error)
Elliot Lee's avatar
Elliot Lee committed
947
{
Manish Singh's avatar
Manish Singh committed
948 949
  gboolean success = TRUE;
  GimpLayer *layer;
950
  gdouble opacity;
Manish Singh's avatar
Manish Singh committed
951

952
  layer = gimp_value_get_layer (&args->values[0], gimp);
953
  opacity = g_value_get_double (&args->values[1]);
Elliot Lee's avatar
Elliot Lee committed
954 955

  if (success)
956
    {
957
      gimp_layer_set_opacity (layer, opacity / 100.0, TRUE);
958
    }
Elliot Lee's avatar
Elliot Lee committed
959

960 961
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
Elliot Lee's avatar
Elliot Lee committed
962 963
}

964
static GValueArray *
965 966 967 968 969 970
layer_get_mode_invoker (GimpProcedure      *procedure,
                        Gimp               *gimp,
                        GimpContext        *context,
                        GimpProgress       *progress,
                        const GValueArray  *args,
                        GError            **error)
971 972
{
  gboolean success = TRUE;
973
  GValueArray *return_vals;
974
  GimpLayer *layer;
975
  gint32 mode = 0;
976

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

979 980
  if (success)
    {
981
      mode = gimp_layer_get_mode (layer);
982 983
    }

984 985
  return_vals = gimp_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);
986 987

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

990
  return return_vals;
991 992
}

993
static GValueArray *
994 995 996 997 998 999
layer_set_mode_invoker (GimpProcedure      *procedure,
                        Gimp               *gimp,
                        GimpContext        *context,
                        GimpProgress       *progress,
                        const GValueArray  *args,
                        GError            **error)
1000 1001 1002
{
  gboolean success = TRUE;
  GimpLayer *layer;
1003
  gint32 mode;
1004

1005
  layer = gimp_value_get_layer (&args->values[0], gimp);
1006
  mode = g_value_get_enum (&args->values[1]);
1007 1008

  if (success)
1009
    {
1010
      gimp_layer_set_mode (layer, mode, TRUE);
1011
    }
1012

1013 1014
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
1015 1016
}

1017
void
1018
register_layer_procs (GimpPDB *pdb)
1019
{
1020
  GimpProcedure *procedure;
1021

1022 1023 1024
  /*
   * gimp-layer-new
   */
1025
  procedure = gimp_procedure_new (layer_new_invoker);
1026 1027
  gimp_object_set_static_name (GIMP_OBJECT (procedure),
                               "gimp-layer-new");
1028 1029 1030
  gimp_procedure_set_static_strings (procedure,
                                     "gimp-layer-new",
                                     "Create a new layer.",
1031
                                     "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.",
1032 1033 1034 1035 1036 1037 1038 1039
                                     "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",
1040
                                                         pdb->gimp, FALSE,
1041 1042 1043 1044
                                                         GIMP_PARAM_READWRITE));
  gimp_procedure_add_argument (procedure,
                               gimp_param_spec_int32 ("width",
                                                      "width",
1045
                                                      "The layer width",
1046
                                                      1, GIMP_MAX_IMAGE_SIZE, 1,
1047 1048 1049 1050
                                                      GIMP_PARAM_READWRITE));
  gimp_procedure_add_argument (procedure,
                               gimp_param_spec_int32 ("height",
                                                      "height",
1051
                                                      "The layer height",
1052
                                                      1, GIMP_MAX_IMAGE_SIZE, 1,
1053 1054 1055 1056
                                                      GIMP_PARAM_READWRITE));
  gimp_procedure_add_argument (procedure,
                               g_param_spec_enum ("type",
                                                  "type",
1057
                                                  "The layer type",
1058 1059 1060 1061 1062 1063 1064
                                                  GIMP_TYPE_IMAGE_TYPE,
                                                  GIMP_RGB_IMAGE,
                                                  GIMP_PARAM_READWRITE));
  gimp_procedure_add_argument (procedure,
                               gimp_param_spec_string ("name",
                                                       "name",
                                                       "The layer name",
1065
                                                       FALSE, TRUE, FALSE,
1066 1067 1068 1069 1070
                                                       NULL,
                                                       GIMP_PARAM_READWRITE));
  gimp_procedure_add_argument (procedure,
                               g_param_spec_double ("opacity",
                                                    "opacity",
1071
                                                    "The layer opacity",
1072 1073 1074 1075 1076
                                                    0, 100, 0,
                                                    GIMP_PARAM_READWRITE));
  gimp_procedure_add_argument (procedure,
                               g_param_spec_enum ("mode",
                                                  "mode",
1077
                                                  "The layer combination mode",
1078 1079 1080
                                                  GIMP_TYPE_LAYER_MODE_EFFECTS,
                                                  GIMP_NORMAL_MODE,
                                                  GIMP_PARAM_READWRITE));
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
  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));
1123 1124 1125 1126
  gimp_procedure_add_return_value (procedure,
                                   gimp_param_spec_layer_id ("layer",
                                                             "layer",
                                                             "The newly created layer",
1127
                                                             pdb->gimp, FALSE,
1128
                                                             GIMP_PARAM_READWRITE));
1129
  gimp_pdb_register_procedure (pdb, procedure);
1130
  g_object_unref (procedure);
1131

1132 1133 1134
  /*
   * gimp-layer-new-from-drawable
   */
1135
  procedure = gimp_procedure_new (layer_new_from_drawable_invoker);
1136 1137
  gimp_object_set_static_name (GIMP_OBJECT (procedure),
                               "gimp-layer-new-from-drawable");
1138 1139 1140
  gimp_procedure_set_static_strings (procedure,
                                     "gimp-layer-new-from-drawable",
                                     "Create a new layer by copying an existing drawable.",
1141
                                     "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.",
1142 1143 1144 1145 1146 1147 1148 1149
                                     "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",
1150
                                                            pdb->gimp, FALSE,
1151 1152 1153 1154 1155
                                                            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",
1156
                                                         pdb->gimp, FALSE,