gimplayer_pdb.c 33.2 KB
Newer Older
1
/* LIBGIMP - The GIMP Library
2
 * Copyright (C) 1995-2003 Peter Mattis and Spencer Kimball
3 4
 *
 * gimplayer_pdb.c
Manish Singh's avatar
Manish Singh committed
5
 *
6
 * This library is free software: you can redistribute it and/or
Marc Lehmann's avatar
Marc Lehmann committed
7
 * modify it under the terms of the GNU Lesser General Public
Manish Singh's avatar
Manish Singh committed
8
 * License as published by the Free Software Foundation; either
9
 * version 3 of the License, or (at your option) any later version.
10 11 12 13
 *
 * This library 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
14
 * Lesser General Public License for more details.
Manish Singh's avatar
Manish Singh committed
15
 *
Marc Lehmann's avatar
Marc Lehmann committed
16
 * You should have received a copy of the GNU Lesser General Public
17 18
 * License along with this library.  If not, see
 * <http://www.gnu.org/licenses/>.
19 20
 */

21
/* NOTE: This file is auto-generated by pdbgen.pl */
Elliot Lee's avatar
Elliot Lee committed
22

Sven Neumann's avatar
Sven Neumann committed
23 24
#include "config.h"

25
#include "gimp.h"
Elliot Lee's avatar
Elliot Lee committed
26

27 28 29 30 31 32 33 34 35 36

/**
 * SECTION: gimplayer
 * @title: gimplayer
 * @short_description: Operations on a single layer.
 *
 * Operations on a single layer.
 **/


37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
/**
 * _gimp_layer_new:
 * @image_ID: The image to which to add the layer.
 * @width: The layer width.
 * @height: The layer height.
 * @type: The layer type.
 * @name: The layer name.
 * @opacity: The layer opacity.
 * @mode: The layer combination mode.
 *
 * Create a new layer.
 *
 * 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
52
 * automatic. Add the new layer with the gimp_image_insert_layer()
53 54 55 56
 * command. Other attributes such as layer mask modes, and offsets
 * should be set with explicit procedure calls.
 *
 * Returns: The newly created layer.
57
 **/
Elliot Lee's avatar
Elliot Lee committed
58
gint32
59
_gimp_layer_new (gint32                image_ID,
60 61 62 63 64 65
                 gint                  width,
                 gint                  height,
                 GimpImageType         type,
                 const gchar          *name,
                 gdouble               opacity,
                 GimpLayerModeEffects  mode)
Elliot Lee's avatar
Elliot Lee committed
66
{
67
  GimpParam *return_vals;
68
  gint nreturn_vals;
69
  gint32 layer_ID = -1;
Elliot Lee's avatar
Elliot Lee committed
70

71
  return_vals = gimp_run_procedure ("gimp-layer-new",
72 73 74 75 76 77 78 79 80
                                    &nreturn_vals,
                                    GIMP_PDB_IMAGE, image_ID,
                                    GIMP_PDB_INT32, width,
                                    GIMP_PDB_INT32, height,
                                    GIMP_PDB_INT32, type,
                                    GIMP_PDB_STRING, name,
                                    GIMP_PDB_FLOAT, opacity,
                                    GIMP_PDB_INT32, mode,
                                    GIMP_PDB_END);
81 82

  if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
Elliot Lee's avatar
Elliot Lee committed
83 84 85 86 87 88 89
    layer_ID = return_vals[1].data.d_layer;

  gimp_destroy_params (return_vals, nreturn_vals);

  return layer_ID;
}

90 91 92 93 94 95 96 97 98 99 100
/**
 * gimp_layer_new_from_visible:
 * @image_ID: The source image from where the content is copied.
 * @dest_image_ID: The destination image to which to add the layer.
 * @name: The layer name.
 *
 * 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
101 102
 * gimp_image_insert_layer() command. Other attributes such as layer
 * mask modes, and offsets should be set with explicit procedure calls.
103 104 105 106
 *
 * Returns: The newly created layer.
 *
 * Since: GIMP 2.6
107
 **/
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
gint32
gimp_layer_new_from_visible (gint32       image_ID,
                             gint32       dest_image_ID,
                             const gchar *name)
{
  GimpParam *return_vals;
  gint nreturn_vals;
  gint32 layer_ID = -1;

  return_vals = gimp_run_procedure ("gimp-layer-new-from-visible",
                                    &nreturn_vals,
                                    GIMP_PDB_IMAGE, image_ID,
                                    GIMP_PDB_IMAGE, dest_image_ID,
                                    GIMP_PDB_STRING, name,
                                    GIMP_PDB_END);

  if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
    layer_ID = return_vals[1].data.d_layer;

  gimp_destroy_params (return_vals, nreturn_vals);

  return layer_ID;
}

132 133 134 135 136 137 138 139 140 141
/**
 * gimp_layer_new_from_drawable:
 * @drawable_ID: The source drawable from where the new layer is copied.
 * @dest_image_ID: The destination image to which to add the layer.
 *
 * Create a new layer by copying an existing drawable.
 *
 * 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
142 143
 * gimp_image_insert_layer() command. Other attributes such as layer
 * mask modes, and offsets should be set with explicit procedure calls.
144 145
 *
 * Returns: The newly copied layer.
146
 **/
147 148
gint32
gimp_layer_new_from_drawable (gint32 drawable_ID,
149
                              gint32 dest_image_ID)
150 151 152 153 154
{
  GimpParam *return_vals;
  gint nreturn_vals;
  gint32 layer_copy_ID = -1;

155
  return_vals = gimp_run_procedure ("gimp-layer-new-from-drawable",
156 157 158 159
                                    &nreturn_vals,
                                    GIMP_PDB_DRAWABLE, drawable_ID,
                                    GIMP_PDB_IMAGE, dest_image_ID,
                                    GIMP_PDB_END);
160 161 162 163 164 165 166 167 168

  if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
    layer_copy_ID = return_vals[1].data.d_layer;

  gimp_destroy_params (return_vals, nreturn_vals);

  return layer_copy_ID;
}

169 170 171 172 173 174 175 176 177 178 179 180 181 182
/**
 * gimp_layer_group_new:
 * @image_ID: The image to which to add the layer group.
 *
 * Create a new layer group.
 *
 * This procedure creates a new layer group. Attributes such as layer
 * mode and opacity should be set with explicit procedure calls. Add
 * the new layer group (which is a kind of layer) with the
 * gimp_image_insert_layer() command.
 *
 * Returns: The newly created layer group.
 *
 * Since: GIMP 2.8
183
 **/
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
gint32
gimp_layer_group_new (gint32 image_ID)
{
  GimpParam *return_vals;
  gint nreturn_vals;
  gint32 layer_group_ID = -1;

  return_vals = gimp_run_procedure ("gimp-layer-group-new",
                                    &nreturn_vals,
                                    GIMP_PDB_IMAGE, image_ID,
                                    GIMP_PDB_END);

  if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
    layer_group_ID = return_vals[1].data.d_layer;

  gimp_destroy_params (return_vals, nreturn_vals);

  return layer_group_ID;
}

204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
/**
 * _gimp_layer_copy:
 * @layer_ID: The layer to copy.
 * @add_alpha: Add an alpha channel to the copied layer.
 *
 * 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.
 *
 * Returns: The newly copied layer.
219
 **/
Elliot Lee's avatar
Elliot Lee committed
220
gint32
221
_gimp_layer_copy (gint32   layer_ID,
222
                  gboolean add_alpha)
Elliot Lee's avatar
Elliot Lee committed
223
{
224
  GimpParam *return_vals;
225
  gint nreturn_vals;
226
  gint32 layer_copy_ID = -1;
Elliot Lee's avatar
Elliot Lee committed
227

228
  return_vals = gimp_run_procedure ("gimp-layer-copy",
229 230 231 232
                                    &nreturn_vals,
                                    GIMP_PDB_LAYER, layer_ID,
                                    GIMP_PDB_INT32, add_alpha,
                                    GIMP_PDB_END);
Elliot Lee's avatar
Elliot Lee committed
233

234
  if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
235
    layer_copy_ID = return_vals[1].data.d_layer;
Elliot Lee's avatar
Elliot Lee committed
236 237 238

  gimp_destroy_params (return_vals, nreturn_vals);

239
  return layer_copy_ID;
Elliot Lee's avatar
Elliot Lee committed
240 241
}

242
/**
243 244
 * gimp_layer_add_alpha:
 * @layer_ID: The layer.
245
 *
246
 * Add an alpha channel to the layer if it doesn't already have one.
247
 *
248 249
 * This procedure adds an additional component to the specified layer
 * if it does not already possess an alpha channel. An alpha channel
250 251 252
 * makes it possible to clear and erase to transparency, instead of the
 * background color. This transforms layers of type RGB to RGBA, GRAY
 * to GRAYA, and INDEXED to INDEXEDA.
253
 *
254
 * Returns: TRUE on success.
255
 **/
256 257
gboolean
gimp_layer_add_alpha (gint32 layer_ID)
Elliot Lee's avatar
Elliot Lee committed
258
{
259
  GimpParam *return_vals;
260
  gint nreturn_vals;
261
  gboolean success = TRUE;
Elliot Lee's avatar
Elliot Lee committed
262

263
  return_vals = gimp_run_procedure ("gimp-layer-add-alpha",
264 265 266
                                    &nreturn_vals,
                                    GIMP_PDB_LAYER, layer_ID,
                                    GIMP_PDB_END);
Elliot Lee's avatar
Elliot Lee committed
267

268
  success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
269

Elliot Lee's avatar
Elliot Lee committed
270
  gimp_destroy_params (return_vals, nreturn_vals);
271

272
  return success;
Elliot Lee's avatar
Elliot Lee committed
273 274
}

275 276 277 278 279 280 281 282 283 284 285 286 287 288
/**
 * gimp_layer_flatten:
 * @layer_ID: The layer.
 *
 * Remove the alpha channel from the layer if it has one.
 *
 * This procedure removes the alpha channel from a layer, blending all
 * (partially) transparent pixels in the layer against the background
 * color. This transforms layers of type RGBA to RGB, GRAYA to GRAY,
 * and INDEXEDA to INDEXED.
 *
 * Returns: TRUE on success.
 *
 * Since: GIMP 2.4
289
 **/
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308
gboolean
gimp_layer_flatten (gint32 layer_ID)
{
  GimpParam *return_vals;
  gint nreturn_vals;
  gboolean success = TRUE;

  return_vals = gimp_run_procedure ("gimp-layer-flatten",
                                    &nreturn_vals,
                                    GIMP_PDB_LAYER, layer_ID,
                                    GIMP_PDB_END);

  success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;

  gimp_destroy_params (return_vals, nreturn_vals);

  return success;
}

309 310 311 312 313 314 315
/**
 * gimp_layer_scale:
 * @layer_ID: The layer.
 * @new_width: New layer width.
 * @new_height: New layer height.
 * @local_origin: Use a local origin (as opposed to the image origin).
 *
316
 * Scale the layer using the default interpolation method.
317
 *
318
 * This procedure scales the layer so that its new width and height are
319
 * equal to the supplied parameters. The 'local-origin' parameter
320 321
 * specifies whether to scale from the center of the layer, or from the
 * image origin. This operation only works if the layer has been added
322 323
 * to an image. The interpolation method used can be set with
 * gimp_context_set_interpolation().
324 325
 *
 * Returns: TRUE on success.
326
 **/
327
gboolean
328
gimp_layer_scale (gint32   layer_ID,
329 330 331
                  gint     new_width,
                  gint     new_height,
                  gboolean local_origin)
Elliot Lee's avatar
Elliot Lee committed
332
{
333
  GimpParam *return_vals;
334
  gint nreturn_vals;
335
  gboolean success = TRUE;
Elliot Lee's avatar
Elliot Lee committed
336

337
  return_vals = gimp_run_procedure ("gimp-layer-scale",
338 339 340 341 342 343
                                    &nreturn_vals,
                                    GIMP_PDB_LAYER, layer_ID,
                                    GIMP_PDB_INT32, new_width,
                                    GIMP_PDB_INT32, new_height,
                                    GIMP_PDB_INT32, local_origin,
                                    GIMP_PDB_END);
Elliot Lee's avatar
Elliot Lee committed
344

345 346
  success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;

Elliot Lee's avatar
Elliot Lee committed
347
  gimp_destroy_params (return_vals, nreturn_vals);
348

349 350 351 352 353 354 355 356 357 358 359
  return success;
}

/**
 * gimp_layer_scale_full:
 * @layer_ID: The layer.
 * @new_width: New layer width.
 * @new_height: New layer height.
 * @local_origin: Use a local origin (as opposed to the image origin).
 * @interpolation: Type of interpolation.
 *
360
 * Deprecated: Use gimp_layer_scale() instead.
361 362 363 364
 *
 * Returns: TRUE on success.
 *
 * Since: GIMP 2.6
365
 **/
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389
gboolean
gimp_layer_scale_full (gint32                layer_ID,
                       gint                  new_width,
                       gint                  new_height,
                       gboolean              local_origin,
                       GimpInterpolationType interpolation)
{
  GimpParam *return_vals;
  gint nreturn_vals;
  gboolean success = TRUE;

  return_vals = gimp_run_procedure ("gimp-layer-scale-full",
                                    &nreturn_vals,
                                    GIMP_PDB_LAYER, layer_ID,
                                    GIMP_PDB_INT32, new_width,
                                    GIMP_PDB_INT32, new_height,
                                    GIMP_PDB_INT32, local_origin,
                                    GIMP_PDB_INT32, interpolation,
                                    GIMP_PDB_END);

  success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;

  gimp_destroy_params (return_vals, nreturn_vals);

390
  return success;
Elliot Lee's avatar
Elliot Lee committed
391 392
}

393 394 395 396 397
/**
 * gimp_layer_resize:
 * @layer_ID: The layer.
 * @new_width: New layer width.
 * @new_height: New layer height.
398 399
 * @offx: x offset between upper left corner of old and new layers: (old - new).
 * @offy: y offset between upper left corner of old and new layers: (old - new).
400 401 402
 *
 * Resize the layer to the specified extents.
 *
403
 * This procedure resizes the layer so that its new width and height
404 405 406 407 408
 * are equal to the supplied parameters. Offsets are also provided
 * which describe the position of the previous layer's content. This
 * operation only works if the layer has been added to an image.
 *
 * Returns: TRUE on success.
409
 **/
410
gboolean
411
gimp_layer_resize (gint32 layer_ID,
412 413 414 415
                   gint   new_width,
                   gint   new_height,
                   gint   offx,
                   gint   offy)
Elliot Lee's avatar
Elliot Lee committed
416
{
417
  GimpParam *return_vals;
418
  gint nreturn_vals;
419
  gboolean success = TRUE;
Elliot Lee's avatar
Elliot Lee committed
420

421
  return_vals = gimp_run_procedure ("gimp-layer-resize",
422 423 424 425 426 427 428
                                    &nreturn_vals,
                                    GIMP_PDB_LAYER, layer_ID,
                                    GIMP_PDB_INT32, new_width,
                                    GIMP_PDB_INT32, new_height,
                                    GIMP_PDB_INT32, offx,
                                    GIMP_PDB_INT32, offy,
                                    GIMP_PDB_END);
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446

  success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;

  gimp_destroy_params (return_vals, nreturn_vals);

  return success;
}

/**
 * gimp_layer_resize_to_image_size:
 * @layer_ID: The layer to resize.
 *
 * Resize a layer to the image size.
 *
 * This procedure resizes the layer so that it's new width and height
 * are equal to the width and height of its image container.
 *
 * Returns: TRUE on success.
447
 **/
448 449 450 451 452 453 454
gboolean
gimp_layer_resize_to_image_size (gint32 layer_ID)
{
  GimpParam *return_vals;
  gint nreturn_vals;
  gboolean success = TRUE;

455
  return_vals = gimp_run_procedure ("gimp-layer-resize-to-image-size",
456 457 458
                                    &nreturn_vals,
                                    GIMP_PDB_LAYER, layer_ID,
                                    GIMP_PDB_END);
Elliot Lee's avatar
Elliot Lee committed
459

460 461
  success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;

Elliot Lee's avatar
Elliot Lee committed
462
  gimp_destroy_params (return_vals, nreturn_vals);
463 464

  return success;
Elliot Lee's avatar
Elliot Lee committed
465 466
}

467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482
/**
 * gimp_layer_translate:
 * @layer_ID: The layer.
 * @offx: Offset in x direction.
 * @offy: Offset in y direction.
 *
 * Translate the layer by the specified offsets.
 *
 * This procedure translates the layer by the amounts specified in the
 * x and y arguments. These can be negative, and are considered offsets
 * from the current position. This command only works if the layer has
 * been added to an image. All additional layers contained in the image
 * which have the linked flag set to TRUE w ill also be translated by
 * the specified offsets.
 *
 * Returns: TRUE on success.
483
 **/
484
gboolean
485
gimp_layer_translate (gint32 layer_ID,
486 487
                      gint   offx,
                      gint   offy)
Elliot Lee's avatar
Elliot Lee committed
488
{
489
  GimpParam *return_vals;
490
  gint nreturn_vals;
491
  gboolean success = TRUE;
Elliot Lee's avatar
Elliot Lee committed
492

493
  return_vals = gimp_run_procedure ("gimp-layer-translate",
494 495 496 497 498
                                    &nreturn_vals,
                                    GIMP_PDB_LAYER, layer_ID,
                                    GIMP_PDB_INT32, offx,
                                    GIMP_PDB_INT32, offy,
                                    GIMP_PDB_END);
Elliot Lee's avatar
Elliot Lee committed
499

500 501
  success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;

Elliot Lee's avatar
Elliot Lee committed
502
  gimp_destroy_params (return_vals, nreturn_vals);
503 504

  return success;
Elliot Lee's avatar
Elliot Lee committed
505 506
}

507
/**
508
 * gimp_layer_set_offsets:
509
 * @layer_ID: The layer.
510 511
 * @offx: Offset in x direction.
 * @offy: Offset in y direction.
512
 *
513
 * Set the layer offsets.
514
 *
515 516 517
 * This procedure sets the offsets for the specified layer. The offsets
 * are relative to the image origin and can be any values. This
 * operation is valid only on layers which have been added to an image.
518 519
 *
 * Returns: TRUE on success.
520
 **/
521
gboolean
522
gimp_layer_set_offsets (gint32 layer_ID,
523 524
                        gint   offx,
                        gint   offy)
Elliot Lee's avatar
Elliot Lee committed
525
{
526
  GimpParam *return_vals;
527
  gint nreturn_vals;
528
  gboolean success = TRUE;
Elliot Lee's avatar
Elliot Lee committed
529

530
  return_vals = gimp_run_procedure ("gimp-layer-set-offsets",
531 532 533 534 535
                                    &nreturn_vals,
                                    GIMP_PDB_LAYER, layer_ID,
                                    GIMP_PDB_INT32, offx,
                                    GIMP_PDB_INT32, offy,
                                    GIMP_PDB_END);
Elliot Lee's avatar
Elliot Lee committed
536

537 538
  success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;

Elliot Lee's avatar
Elliot Lee committed
539
  gimp_destroy_params (return_vals, nreturn_vals);
540 541

  return success;
Elliot Lee's avatar
Elliot Lee committed
542 543
}

544
/**
545 546 547
 * gimp_layer_create_mask:
 * @layer_ID: The layer to which to add the mask.
 * @mask_type: The type of mask.
548
 *
549
 * Create a layer mask for the specified specified layer.
550
 *
551 552
 * This procedure creates a layer mask for the specified layer. Layer
 * masks serve as an additional alpha channel for a layer. A number of
553
 * different types of masks are allowed for initialisation: completely
554 555 556 557 558 559
 * white masks (which will leave the layer fully visible), completely
 * black masks (which will give the layer complete transparency, the
 * layer's already existing alpha channel (which will leave the layer
 * fully visible, but which may be more useful than a white mask), the
 * current selection or a grayscale copy of the layer. The layer mask
 * still needs to be added to the layer. This can be done with a call
560
 * to gimp_layer_add_mask().
561
 *
562
 * Returns: The newly created mask.
563
 **/
564 565
gint32
gimp_layer_create_mask (gint32          layer_ID,
566
                        GimpAddMaskType mask_type)
Elliot Lee's avatar
Elliot Lee committed
567
{
568
  GimpParam *return_vals;
569
  gint nreturn_vals;
570
  gint32 mask_ID = -1;
Elliot Lee's avatar
Elliot Lee committed
571

572
  return_vals = gimp_run_procedure ("gimp-layer-create-mask",
573 574 575 576
                                    &nreturn_vals,
                                    GIMP_PDB_LAYER, layer_ID,
                                    GIMP_PDB_INT32, mask_type,
                                    GIMP_PDB_END);
Elliot Lee's avatar
Elliot Lee committed
577

578 579
  if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
    mask_ID = return_vals[1].data.d_layer_mask;
580

Elliot Lee's avatar
Elliot Lee committed
581
  gimp_destroy_params (return_vals, nreturn_vals);
582

583
  return mask_ID;
Elliot Lee's avatar
Elliot Lee committed
584 585
}

586
/**
587
 * gimp_layer_get_mask:
588 589 590 591 592 593 594 595
 * @layer_ID: The layer.
 *
 * Get the specified layer's mask if it exists.
 *
 * This procedure returns the specified layer's mask, or -1 if none
 * exists.
 *
 * Returns: The layer mask.
596
 **/
Elliot Lee's avatar
Elliot Lee committed
597
gint32
598
gimp_layer_get_mask (gint32 layer_ID)
Elliot Lee's avatar
Elliot Lee committed
599
{
600
  GimpParam *return_vals;
601
  gint nreturn_vals;
602
  gint32 mask_ID = -1;
Elliot Lee's avatar
Elliot Lee committed
603

604
  return_vals = gimp_run_procedure ("gimp-layer-get-mask",
605 606 607
                                    &nreturn_vals,
                                    GIMP_PDB_LAYER, layer_ID,
                                    GIMP_PDB_END);
Elliot Lee's avatar
Elliot Lee committed
608

609
  if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
610
    mask_ID = return_vals[1].data.d_layer_mask;
Elliot Lee's avatar
Elliot Lee committed
611 612 613 614 615 616

  gimp_destroy_params (return_vals, nreturn_vals);

  return mask_ID;
}

617 618 619 620 621 622 623 624 625 626 627 628
/**
 * gimp_layer_from_mask:
 * @mask_ID: Mask for which to return the layer.
 *
 * Get the specified mask's layer.
 *
 * This procedure returns the specified mask's layer , or -1 if none
 * exists.
 *
 * Returns: The mask's layer.
 *
 * Since: GIMP 2.2
629
 **/
630 631 632 633 634 635 636
gint32
gimp_layer_from_mask (gint32 mask_ID)
{
  GimpParam *return_vals;
  gint nreturn_vals;
  gint32 layer_ID = -1;

637
  return_vals = gimp_run_procedure ("gimp-layer-from-mask",
638 639 640
                                    &nreturn_vals,
                                    GIMP_PDB_CHANNEL, mask_ID,
                                    GIMP_PDB_END);
641 642 643 644 645 646 647 648 649

  if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
    layer_ID = return_vals[1].data.d_layer;

  gimp_destroy_params (return_vals, nreturn_vals);

  return layer_ID;
}

650 651
/**
 * gimp_layer_add_mask:
652 653
 * @layer_ID: The layer to receive the mask.
 * @mask_ID: The mask to add to the layer.
654 655 656 657 658 659 660
 *
 * Add a layer mask to the specified layer.
 *
 * This procedure adds a layer mask to the specified layer. Layer masks
 * serve as an additional alpha channel for a layer. This procedure
 * will fail if a number of prerequisites aren't met. The layer cannot
 * already have a layer mask. The specified mask must exist and have
661 662 663
 * the same dimensions as the layer. The layer must have been created
 * for use with the specified image and the mask must have been created
 * with the procedure 'gimp-layer-create-mask'.
664 665
 *
 * Returns: TRUE on success.
666
 **/
667 668
gboolean
gimp_layer_add_mask (gint32 layer_ID,
669
                     gint32 mask_ID)
670 671 672 673 674
{
  GimpParam *return_vals;
  gint nreturn_vals;
  gboolean success = TRUE;

675
  return_vals = gimp_run_procedure ("gimp-layer-add-mask",
676 677 678 679
                                    &nreturn_vals,
                                    GIMP_PDB_LAYER, layer_ID,
                                    GIMP_PDB_CHANNEL, mask_ID,
                                    GIMP_PDB_END);
680 681 682 683 684 685 686 687 688 689

  success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;

  gimp_destroy_params (return_vals, nreturn_vals);

  return success;
}

/**
 * gimp_layer_remove_mask:
690 691
 * @layer_ID: The layer from which to remove mask.
 * @mode: Removal mode.
692 693 694 695 696 697 698
 *
 * Remove the specified layer mask from the layer.
 *
 * This procedure removes the specified layer mask from the layer. If
 * the mask doesn't exist, an error is returned.
 *
 * Returns: TRUE on success.
699
 **/
700 701
gboolean
gimp_layer_remove_mask (gint32            layer_ID,
702
                        GimpMaskApplyMode mode)
703 704 705 706 707
{
  GimpParam *return_vals;
  gint nreturn_vals;
  gboolean success = TRUE;

708
  return_vals = gimp_run_procedure ("gimp-layer-remove-mask",
709 710 711 712
                                    &nreturn_vals,
                                    GIMP_PDB_LAYER, layer_ID,
                                    GIMP_PDB_INT32, mode,
                                    GIMP_PDB_END);
713 714 715 716 717 718 719 720

  success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;

  gimp_destroy_params (return_vals, nreturn_vals);

  return success;
}

721 722 723 724 725 726 727 728 729 730
/**
 * gimp_layer_is_floating_sel:
 * @layer_ID: The layer.
 *
 * Is the specified layer a floating selection?
 *
 * This procedure returns whether the layer is a floating selection.
 * Floating selections are special cases of layers which are attached
 * to a specific drawable.
 *
731
 * Returns: TRUE if the layer is a floating selection.
732
 **/
733
gboolean
734
gimp_layer_is_floating_sel (gint32 layer_ID)
Elliot Lee's avatar
Elliot Lee committed
735
{
736
  GimpParam *return_vals;
737
  gint nreturn_vals;
738
  gboolean is_floating_sel = FALSE;
Elliot Lee's avatar
Elliot Lee committed
739

740
  return_vals = gimp_run_procedure ("gimp-layer-is-floating-sel",
741 742 743
                                    &nreturn_vals,
                                    GIMP_PDB_LAYER, layer_ID,
                                    GIMP_PDB_END);
Elliot Lee's avatar
Elliot Lee committed
744

745
  if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
746
    is_floating_sel = return_vals[1].data.d_int32;
Elliot Lee's avatar
Elliot Lee committed
747 748 749

  gimp_destroy_params (return_vals, nreturn_vals);

750
  return is_floating_sel;
Elliot Lee's avatar
Elliot Lee committed
751 752
}

753
/**
754
 * gimp_layer_get_lock_alpha:
755 756
 * @layer_ID: The layer.
 *
757
 * Get the lock alpha channel setting of the specified layer.
758
 *
759
 * This procedure returns the specified layer's lock alpha channel
760 761
 * setting.
 *
762
 * Returns: The layer's lock alpha channel setting.
763
 **/
764
gboolean
765
gimp_layer_get_lock_alpha (gint32 layer_ID)
Elliot Lee's avatar
Elliot Lee committed
766
{
767
  GimpParam *return_vals;
768
  gint nreturn_vals;
769
  gboolean lock_alpha = FALSE;
Elliot Lee's avatar
Elliot Lee committed
770

771
  return_vals = gimp_run_procedure ("gimp-layer-get-lock-alpha",
772 773 774
                                    &nreturn_vals,
                                    GIMP_PDB_LAYER, layer_ID,
                                    GIMP_PDB_END);
Elliot Lee's avatar
Elliot Lee committed
775

776
  if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
777
    lock_alpha = return_vals[1].data.d_int32;
Elliot Lee's avatar
Elliot Lee committed
778 779 780

  gimp_destroy_params (return_vals, nreturn_vals);

781
  return lock_alpha;
Elliot Lee's avatar
Elliot Lee committed
782 783
}

784
/**
785
 * gimp_layer_set_lock_alpha:
786
 * @layer_ID: The layer.
787
 * @lock_alpha: The new layer's lock alpha channel setting.
788
 *
789
 * Set the lock alpha channel setting of the specified layer.
790
 *
791
 * This procedure sets the specified layer's lock alpha channel
792 793 794
 * setting.
 *
 * Returns: TRUE on success.
795
 **/
796
gboolean
797
gimp_layer_set_lock_alpha (gint32   layer_ID,
798
                           gboolean lock_alpha)
Elliot Lee's avatar
Elliot Lee committed
799
{
800
  GimpParam *return_vals;
801
  gint nreturn_vals;
802
  gboolean success = TRUE;
Elliot Lee's avatar
Elliot Lee committed
803

804
  return_vals = gimp_run_procedure ("gimp-layer-set-lock-alpha",
805 806 807 808
                                    &nreturn_vals,
                                    GIMP_PDB_LAYER, layer_ID,
                                    GIMP_PDB_INT32, lock_alpha,
                                    GIMP_PDB_END);
Elliot Lee's avatar
Elliot Lee committed
809

810 811
  success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;

Elliot Lee's avatar
Elliot Lee committed
812
  gimp_destroy_params (return_vals, nreturn_vals);
813 814

  return success;
Elliot Lee's avatar
Elliot Lee committed
815 816
}

817 818 819 820
/**
 * gimp_layer_get_apply_mask:
 * @layer_ID: The layer.
 *
821
 * Get the apply mask setting of the specified layer.
822
 *
823
 * This procedure returns the specified layer's apply mask setting. If
824 825
 * the value is TRUE, then the layer mask for this layer is currently
 * being composited with the layer's alpha channel.
826
 *
827
 * Returns: The layer's apply mask setting.
828
 **/
829 830 831 832 833 834 835
gboolean
gimp_layer_get_apply_mask (gint32 layer_ID)
{
  GimpParam *return_vals;
  gint nreturn_vals;
  gboolean apply_mask = FALSE;

836
  return_vals = gimp_run_procedure ("gimp-layer-get-apply-mask",
837 838 839
                                    &nreturn_vals,
                                    GIMP_PDB_LAYER, layer_ID,
                                    GIMP_PDB_END);
840 841 842 843 844 845 846 847 848 849 850 851

  if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
    apply_mask = return_vals[1].data.d_int32;

  gimp_destroy_params (return_vals, nreturn_vals);

  return apply_mask;
}

/**
 * gimp_layer_set_apply_mask:
 * @layer_ID: The layer.
852
 * @apply_mask: The new layer's apply mask setting.
853
 *
854
 * Set the apply mask setting of the specified layer.
855
 *
856 857 858 859
 * This procedure sets the specified layer's apply mask setting. This
 * controls whether the layer's mask is currently affecting the alpha
 * channel. If there is no layer mask, this function will return an
 * error.
860 861
 *
 * Returns: TRUE on success.
862
 **/
863 864
gboolean
gimp_layer_set_apply_mask (gint32   layer_ID,
865
                           gboolean apply_mask)
866 867 868 869 870
{
  GimpParam *return_vals;
  gint nreturn_vals;
  gboolean success = TRUE;

871
  return_vals = gimp_run_procedure ("gimp-layer-set-apply-mask",
872 873 874 875
                                    &nreturn_vals,
                                    GIMP_PDB_LAYER, layer_ID,
                                    GIMP_PDB_INT32, apply_mask,
                                    GIMP_PDB_END);
876 877 878 879 880 881 882 883 884 885 886 887

  success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;

  gimp_destroy_params (return_vals, nreturn_vals);

  return success;
}

/**
 * gimp_layer_get_show_mask:
 * @layer_ID: The layer.
 *
888
 * Get the show mask setting of the specified layer.
889
 *
890
 * This procedure returns the specified layer's show mask setting. This
891 892 893
 * controls whether the layer or its mask is visible. TRUE indicates
 * that the mask should be visible. If the layer has no mask, then this
 * function returns an error.
894
 *
895
 * Returns: The layer's show mask setting.
896
 **/
897 898 899 900 901 902 903
gboolean
gimp_layer_get_show_mask (gint32 layer_ID)
{
  GimpParam *return_vals;
  gint nreturn_vals;
  gboolean show_mask = FALSE;

904
  return_vals = gimp_run_procedure ("gimp-layer-get-show-mask",
905 906 907
                                    &nreturn_vals,
                                    GIMP_PDB_LAYER, layer_ID,
                                    GIMP_PDB_END);
908 909 910 911 912 913 914 915 916 917 918 919

  if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
    show_mask = return_vals[1].data.d_int32;

  gimp_destroy_params (return_vals, nreturn_vals);

  return show_mask;
}

/**
 * gimp_layer_set_show_mask:
 * @layer_ID: The layer.
920
 * @show_mask: The new layer's show mask setting.
921
 *
922
 * Set the show mask setting of the specified layer.
923
 *
924
 * This procedure sets the specified layer's show mask setting. This
925 926 927
 * controls whether the layer or its mask is visible. TRUE indicates
 * that the mask should be visible. If there is no layer mask, this
 * function will return an error.
928 929
 *
 * Returns: TRUE on success.
930
 **/
931 932
gboolean
gimp_layer_set_show_mask (gint32   layer_ID,
933
                          gboolean show_mask)
934 935 936 937 938
{
  GimpParam *return_vals;
  gint nreturn_vals;
  gboolean success = TRUE;

939
  return_vals = gimp_run_procedure ("gimp-layer-set-show-mask",
940 941 942 943
                                    &nreturn_vals,
                                    GIMP_PDB_LAYER, layer_ID,
                                    GIMP_PDB_INT32, show_mask,
                                    GIMP_PDB_END);
944 945 946 947 948 949 950 951 952 953 954 955

  success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;

  gimp_destroy_params (return_vals, nreturn_vals);

  return success;
}

/**
 * gimp_layer_get_edit_mask:
 * @layer_ID: The layer.
 *
956
 * Get the edit mask setting of the specified layer.
957
 *
958
 * This procedure returns the specified layer's edit mask setting. If
959 960
 * the value is TRUE, then the layer mask for this layer is currently
 * active, and not the layer.
961
 *
962
 * Returns: The layer's edit mask setting.
963
 **/
964 965 966 967 968 969 970
gboolean
gimp_layer_get_edit_mask (gint32 layer_ID)
{
  GimpParam *return_vals;
  gint nreturn_vals;
  gboolean edit_mask = FALSE;

971
  return_vals = gimp_run_procedure ("gimp-layer-get-edit-mask",
972 973 974
                                    &nreturn_vals,
                                    GIMP_PDB_LAYER, layer_ID,
                                    GIMP_PDB_END);
975 976 977 978 979 980 981 982 983 984 985 986

  if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
    edit_mask = return_vals[1].data.d_int32;

  gimp_destroy_params (return_vals, nreturn_vals);

  return edit_mask;
}

/**
 * gimp_layer_set_edit_mask:
 * @layer_ID: The layer.
987
 * @edit_mask: The new layer's edit mask setting.
988
 *
989
 * Set the edit mask setting of the specified layer.
990
 *
991 992 993 994
 * This procedure sets the specified layer's edit mask setting. This
 * controls whether the layer or it's mask is currently active for
 * editing. If the specified layer has no layer mask, then this
 * procedure will return an error.
995 996
 *
 * Returns: TRUE on success.
997
 **/
998 999
gboolean
gimp_layer_set_edit_mask (gint32   layer_ID,
1000
                          gboolean edit_mask)
1001 1002 1003 1004 1005
{
  GimpParam *return_vals;
  gint nreturn_vals;
  gboolean success = TRUE;

1006
  return_vals = gimp_run_procedure ("gimp-layer-set-edit-mask",
1007 1008 1009 1010
                                    &nreturn_vals,
                                    GIMP_PDB_LAYER, layer_ID,
                                    GIMP_PDB_INT32, edit_mask,
                                    GIMP_PDB_END);
1011 1012 1013 1014 1015 1016 1017 1018

  success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;

  gimp_destroy_params (return_vals, nreturn_vals);

  return success;
}

1019 1020 1021 1022 1023 1024 1025 1026 1027
/**
 * gimp_layer_get_opacity:
 * @layer_ID: The layer.
 *
 * Get the opacity of the specified layer.
 *
 * This procedure returns the specified layer's opacity.
 *
 * Returns: The layer opacity.
1028
 **/
1029 1030 1031
gdouble
gimp_layer_get_opacity (gint32 layer_ID)
{
1032
  GimpParam *return_vals;
1033
  gint nreturn_vals;
1034
  gdouble opacity = 0.0;
1035

1036
  return_vals = gimp_run_procedure ("gimp-layer-get-opacity",
1037 1038 1039
                                    &nreturn_vals,
                                    GIMP_PDB_LAYER, layer_ID,
                                    GIMP_PDB_END);
Elliot Lee's avatar
Elliot Lee committed
1040

1041
  if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
1042 1043
    opacity = return_vals[1].data.d_float;

Elliot Lee's avatar
Elliot Lee committed
1044
  gimp_destroy_params (return_vals, nreturn_vals);
1045 1046

  return opacity;
Elliot Lee's avatar
Elliot Lee committed
1047 1048
}

1049 1050 1051 1052 1053 1054 1055 1056 1057 1058
/**
 * gimp_layer_set_opacity:
 * @layer_ID: The layer.
 * @opacity: The new layer opacity.
 *
 * Set the opacity of the specified layer.
 *
 * This procedure sets the specified layer's opacity.
 *
 * Returns: TRUE on success.
1059
 **/
1060
gboolean
Elliot Lee's avatar
Elliot Lee committed
1061
gimp_layer_set_opacity (gint32  layer_ID,
1062
                        gdouble opacity)
Elliot Lee's avatar
Elliot Lee committed
1063
{
1064
  GimpParam *return_vals;
1065
  gint nreturn_vals;
1066
  gboolean success = TRUE;
Elliot Lee's avatar
Elliot Lee committed
1067

1068
  return_vals = gimp_run_procedure ("gimp-layer-set-opacity",
1069 1070 1071 1072
                                    &nreturn_vals,
                                    GIMP_PDB_LAYER, layer_ID,
                                    GIMP_PDB_FLOAT, opacity,
                                    GIMP_PDB_END);
Elliot Lee's avatar
Elliot Lee committed
1073

1074 1075
  success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;

Elliot Lee's avatar
Elliot Lee committed
1076
  gimp_destroy_params (return_vals, nreturn_vals);
1077 1078

  return success;
Elliot Lee's avatar
Elliot Lee committed
1079 1080
}

1081 1082 1083 1084 1085 1086 1087 1088 1089
/**
 * gimp_layer_get_mode:
 * @layer_ID: The layer.
 *
 * Get the combination mode of the specified layer.
 *
 * This procedure returns the specified layer's combination mode.
 *
 * Returns: The layer combination mode.
1090
 **/
1091 1092
GimpLayerModeEffects
gimp_layer_get_mode (gint32 layer_ID)
Elliot Lee's avatar
Elliot Lee committed
1093
{
1094
  GimpParam *return_vals;
1095
  gint nreturn_vals;
1096
  GimpLayerModeEffects mode = 0;
Elliot Lee's avatar
Elliot Lee committed
1097

1098
  return_vals = gimp_run_procedure ("gimp-layer-get-mode",
1099 1100 1101
                                    &nreturn_vals,
                                    GIMP_PDB_LAYER, layer_ID,
                                    GIMP_PDB_END);
Elliot Lee's avatar
Elliot Lee committed
1102

1103
  if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
1104 1105
    mode = return_vals[1].data.d_int32;

Elliot Lee's avatar
Elliot Lee committed
1106
  gimp_destroy_params (return_vals, nreturn_vals);
1107 1108

  return mode;
Elliot Lee's avatar
Elliot Lee committed
1109 1110
}

1111 1112 1113 1114 1115 1116 1117 1118 1119 1120
/**
 * gimp_layer_set_mode:
 * @layer_ID: The layer.
 * @mode: The new layer combination mode.
 *
 * Set the combination mode of the specified layer.
 *
 * This procedure sets the specified layer's combination mode.
 *
 * Returns: TRUE on success.
1121
 **/
1122
gboolean
1123
gimp_layer_set_mode (gint32               layer_ID,
1124
                     GimpLayerModeEffects mode)
Elliot Lee's avatar
Elliot Lee committed
1125
{
1126
  GimpParam *return_vals;
1127
  gint nreturn_vals;
1128
  gboolean success = TRUE;
Elliot Lee's avatar
Elliot Lee committed
1129

1130
  return_vals = gimp_run_procedure ("gimp-layer-set-mode",
1131 1132 1133 1134
                                    &nreturn_vals,
                                    GIMP_PDB_LAYER, layer_ID,
                                    GIMP_PDB_INT32, mode,
                                    GIMP_PDB_END);
1135

1136 1137
  success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;

1138
  gimp_destroy_params (return_vals, nreturn_vals);
1139 1140

  return success;
1141
}