/* PIKA - Photo and Image Kooker Application
 * a rebranding of The GNU Image Manipulation Program (created with heckimp)
 * A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
 *
 * Original copyright, applying to most contents (license remains unchanged): 
 * Copyright (C) 1995-2003 Spencer Kimball and Peter Mattis
 *
 * 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 3 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, see <https://www.gnu.org/licenses/>.
 */

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

#include "config.h"

#include "stamp-pdbgen.h"

#include <cairo.h>

#include <gegl.h>

#include <gdk-pixbuf/gdk-pixbuf.h>

#include "libpikabase/pikabase.h"
#include "libpikacolor/pikacolor.h"

#include "libpikabase/pikabase.h"

#include "pdb-types.h"

#include "core/pika.h"
#include "core/pikadrawable.h"
#include "core/pikagrouplayer.h"
#include "core/pikaimage-color-profile.h"
#include "core/pikaimage-undo.h"
#include "core/pikaimage.h"
#include "core/pikalayer-new.h"
#include "core/pikalayer.h"
#include "core/pikalayermask.h"
#include "core/pikaparamspecs.h"
#include "core/pikapickable.h"
#include "core/pikaprogress.h"
#include "operations/layer-modes/pika-layer-modes.h"

#include "pikapdb.h"
#include "pikapdb-utils.h"
#include "pikapdbcontext.h"
#include "pikaprocedure.h"
#include "internal-procs.h"

#include "pika-intl.h"


static PikaValueArray *
layer_new_invoker (PikaProcedure         *procedure,
                   Pika                  *pika,
                   PikaContext           *context,
                   PikaProgress          *progress,
                   const PikaValueArray  *args,
                   GError               **error)
{
  gboolean success = TRUE;
  PikaValueArray *return_vals;
  PikaImage *image;
  gint width;
  gint height;
  gint type;
  const gchar *name;
  gdouble opacity;
  gint mode;
  PikaLayer *layer = NULL;

  image = g_value_get_object (pika_value_array_index (args, 0));
  width = g_value_get_int (pika_value_array_index (args, 1));
  height = g_value_get_int (pika_value_array_index (args, 2));
  type = g_value_get_enum (pika_value_array_index (args, 3));
  name = g_value_get_string (pika_value_array_index (args, 4));
  opacity = g_value_get_double (pika_value_array_index (args, 5));
  mode = g_value_get_enum (pika_value_array_index (args, 6));

  if (success)
    {
      PikaImageBaseType  base_type = PIKA_RGB;
      gboolean           has_alpha = FALSE;
      const Babl        *format;

      if (mode == PIKA_LAYER_MODE_OVERLAY_LEGACY)
        mode = PIKA_LAYER_MODE_SOFTLIGHT_LEGACY;

      switch (type)
        {
        case PIKA_RGB_IMAGE:
          base_type = PIKA_RGB;
          has_alpha = FALSE;
          break;

        case PIKA_RGBA_IMAGE:
          base_type = PIKA_RGB;
          has_alpha = TRUE;
          break;

        case PIKA_GRAY_IMAGE:
          base_type = PIKA_GRAY;
          has_alpha = FALSE;
          break;

        case PIKA_GRAYA_IMAGE:
          base_type = PIKA_GRAY;
          has_alpha = TRUE;
          break;

        case PIKA_INDEXED_IMAGE:
          base_type = PIKA_INDEXED;
          has_alpha = FALSE;
          break;

        case PIKA_INDEXEDA_IMAGE:
          base_type = PIKA_INDEXED;
          has_alpha = TRUE;
          break;
        }

      if (base_type == PIKA_GRAY)
        {
          /* do not use pika_image_get_layer_format() because it might
           * be the floating selection of a channel or mask, we will
           * fix the format in image-add-layer and floating-sel-attach
           */
          format = pika_image_get_format (image, base_type,
                                          pika_image_get_precision (image),
                                          has_alpha,
                                          NULL /* will fix later */);
        }
      else
        {
          format = pika_image_get_layer_format (image, has_alpha);
        }

      layer = pika_layer_new (image, width, height,
                              format, name, opacity / 100.0, mode);

      if (! layer)
        success = FALSE;
    }

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

  if (success)
    g_value_set_object (pika_value_array_index (return_vals, 1), layer);

  return return_vals;
}

static PikaValueArray *
layer_new_from_visible_invoker (PikaProcedure         *procedure,
                                Pika                  *pika,
                                PikaContext           *context,
                                PikaProgress          *progress,
                                const PikaValueArray  *args,
                                GError               **error)
{
  gboolean success = TRUE;
  PikaValueArray *return_vals;
  PikaImage *image;
  PikaImage *dest_image;
  const gchar *name;
  PikaLayer *layer = NULL;

  image = g_value_get_object (pika_value_array_index (args, 0));
  dest_image = g_value_get_object (pika_value_array_index (args, 1));
  name = g_value_get_string (pika_value_array_index (args, 2));

  if (success)
    {
      PikaPickable     *pickable = PIKA_PICKABLE (image);
      PikaColorProfile *profile;

      pika_pickable_flush (pickable);

      profile = pika_color_managed_get_color_profile (PIKA_COLOR_MANAGED (image));

      layer = pika_layer_new_from_gegl_buffer (pika_pickable_get_buffer (pickable),
                                               dest_image,
                                               pika_image_get_layer_format (dest_image,
                                                                            TRUE),
                                               name,
                                               PIKA_OPACITY_OPAQUE,
                                               pika_image_get_default_new_layer_mode (dest_image),
                                               profile);
    }

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

  if (success)
    g_value_set_object (pika_value_array_index (return_vals, 1), layer);

  return return_vals;
}

static PikaValueArray *
layer_new_from_drawable_invoker (PikaProcedure         *procedure,
                                 Pika                  *pika,
                                 PikaContext           *context,
                                 PikaProgress          *progress,
                                 const PikaValueArray  *args,
                                 GError               **error)
{
  gboolean success = TRUE;
  PikaValueArray *return_vals;
  PikaDrawable *drawable;
  PikaImage *dest_image;
  PikaLayer *layer_copy = NULL;

  drawable = g_value_get_object (pika_value_array_index (args, 0));
  dest_image = g_value_get_object (pika_value_array_index (args, 1));

  if (success)
    {
      GType     new_type;
      PikaItem *new_item;

      if (PIKA_IS_LAYER (drawable))
        new_type = G_TYPE_FROM_INSTANCE (drawable);
      else
        new_type = PIKA_TYPE_LAYER;

      new_item = pika_item_convert (PIKA_ITEM (drawable), dest_image, new_type);

      if (new_item)
        layer_copy = PIKA_LAYER (new_item);
      else
        success = FALSE;
    }

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

  if (success)
    g_value_set_object (pika_value_array_index (return_vals, 1), layer_copy);

  return return_vals;
}

static PikaValueArray *
layer_group_new_invoker (PikaProcedure         *procedure,
                         Pika                  *pika,
                         PikaContext           *context,
                         PikaProgress          *progress,
                         const PikaValueArray  *args,
                         GError               **error)
{
  gboolean success = TRUE;
  PikaValueArray *return_vals;
  PikaImage *image;
  PikaLayer *layer_group = NULL;

  image = g_value_get_object (pika_value_array_index (args, 0));

  if (success)
    {
      layer_group = pika_group_layer_new (image);

      if (! layer_group)
        success = FALSE;
    }

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

  if (success)
    g_value_set_object (pika_value_array_index (return_vals, 1), layer_group);

  return return_vals;
}

static PikaValueArray *
layer_copy_invoker (PikaProcedure         *procedure,
                    Pika                  *pika,
                    PikaContext           *context,
                    PikaProgress          *progress,
                    const PikaValueArray  *args,
                    GError               **error)
{
  gboolean success = TRUE;
  PikaValueArray *return_vals;
  PikaLayer *layer;
  gboolean add_alpha;
  PikaLayer *layer_copy = NULL;

  layer = g_value_get_object (pika_value_array_index (args, 0));
  add_alpha = g_value_get_boolean (pika_value_array_index (args, 1));

  if (success)
    {
      layer_copy = PIKA_LAYER (pika_item_duplicate (PIKA_ITEM (layer),
                                                    G_TYPE_FROM_INSTANCE (layer)));
      if (layer_copy)
        {
          if (add_alpha)
            pika_layer_add_alpha (layer_copy);
        }
      else
        {
          success = FALSE;
        }
    }

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

  if (success)
    g_value_set_object (pika_value_array_index (return_vals, 1), layer_copy);

  return return_vals;
}

static PikaValueArray *
layer_add_alpha_invoker (PikaProcedure         *procedure,
                         Pika                  *pika,
                         PikaContext           *context,
                         PikaProgress          *progress,
                         const PikaValueArray  *args,
                         GError               **error)
{
  gboolean success = TRUE;
  PikaLayer *layer;

  layer = g_value_get_object (pika_value_array_index (args, 0));

  if (success)
    {
      if (pika_pdb_item_is_modifiable (PIKA_ITEM (layer),
                                       PIKA_PDB_ITEM_CONTENT, error) &&
          pika_pdb_item_is_not_group (PIKA_ITEM (layer), error))
        {
          pika_layer_add_alpha (layer);
        }
      else
       success = FALSE;
    }

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

static PikaValueArray *
layer_flatten_invoker (PikaProcedure         *procedure,
                       Pika                  *pika,
                       PikaContext           *context,
                       PikaProgress          *progress,
                       const PikaValueArray  *args,
                       GError               **error)
{
  gboolean success = TRUE;
  PikaLayer *layer;

  layer = g_value_get_object (pika_value_array_index (args, 0));

  if (success)
    {
      if (pika_pdb_item_is_modifiable (PIKA_ITEM (layer),
                                       PIKA_PDB_ITEM_CONTENT, error) &&
          pika_pdb_item_is_not_group (PIKA_ITEM (layer), error))
        {
          pika_layer_remove_alpha (layer, context);
        }
      else
       success = FALSE;
    }

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

static PikaValueArray *
layer_scale_invoker (PikaProcedure         *procedure,
                     Pika                  *pika,
                     PikaContext           *context,
                     PikaProgress          *progress,
                     const PikaValueArray  *args,
                     GError               **error)
{
  gboolean success = TRUE;
  PikaLayer *layer;
  gint new_width;
  gint new_height;
  gboolean local_origin;

  layer = g_value_get_object (pika_value_array_index (args, 0));
  new_width = g_value_get_int (pika_value_array_index (args, 1));
  new_height = g_value_get_int (pika_value_array_index (args, 2));
  local_origin = g_value_get_boolean (pika_value_array_index (args, 3));

  if (success)
    {
      if (pika_pdb_item_is_attached (PIKA_ITEM (layer), NULL,
                                     PIKA_PDB_ITEM_CONTENT | PIKA_PDB_ITEM_POSITION,
                                     error))
        {
          PikaPDBContext *pdb_context = PIKA_PDB_CONTEXT (context);

          if (progress)
            pika_progress_start (progress, FALSE, _("Scaling"));

          pika_item_scale_by_origin (PIKA_ITEM (layer), new_width, new_height,
                                     pdb_context->interpolation, progress,
                                     local_origin);

          if (progress)
            pika_progress_end (progress);
        }
      else
        {
          success = FALSE;
        }
    }

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

static PikaValueArray *
layer_resize_invoker (PikaProcedure         *procedure,
                      Pika                  *pika,
                      PikaContext           *context,
                      PikaProgress          *progress,
                      const PikaValueArray  *args,
                      GError               **error)
{
  gboolean success = TRUE;
  PikaLayer *layer;
  gint new_width;
  gint new_height;
  gint offx;
  gint offy;

  layer = g_value_get_object (pika_value_array_index (args, 0));
  new_width = g_value_get_int (pika_value_array_index (args, 1));
  new_height = g_value_get_int (pika_value_array_index (args, 2));
  offx = g_value_get_int (pika_value_array_index (args, 3));
  offy = g_value_get_int (pika_value_array_index (args, 4));

  if (success)
    {
      if (pika_pdb_item_is_attached (PIKA_ITEM (layer), NULL,
                                     PIKA_PDB_ITEM_CONTENT | PIKA_PDB_ITEM_POSITION,
                                     error))
        pika_item_resize (PIKA_ITEM (layer), context, PIKA_FILL_TRANSPARENT,
                          new_width, new_height, offx, offy);
      else
        success = FALSE;
    }

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

static PikaValueArray *
layer_resize_to_image_size_invoker (PikaProcedure         *procedure,
                                    Pika                  *pika,
                                    PikaContext           *context,
                                    PikaProgress          *progress,
                                    const PikaValueArray  *args,
                                    GError               **error)
{
  gboolean success = TRUE;
  PikaLayer *layer;

  layer = g_value_get_object (pika_value_array_index (args, 0));

  if (success)
    {
      if (pika_pdb_item_is_attached (PIKA_ITEM (layer), NULL,
                                     PIKA_PDB_ITEM_CONTENT | PIKA_PDB_ITEM_POSITION,
                                     error))
        pika_layer_resize_to_image (layer, context, PIKA_FILL_TRANSPARENT);
      else
        success = FALSE;
    }

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

static PikaValueArray *
layer_set_offsets_invoker (PikaProcedure         *procedure,
                           Pika                  *pika,
                           PikaContext           *context,
                           PikaProgress          *progress,
                           const PikaValueArray  *args,
                           GError               **error)
{
  gboolean success = TRUE;
  PikaLayer *layer;
  gint offx;
  gint offy;

  layer = g_value_get_object (pika_value_array_index (args, 0));
  offx = g_value_get_int (pika_value_array_index (args, 1));
  offy = g_value_get_int (pika_value_array_index (args, 2));

  if (success)
    {
      if (pika_pdb_item_is_modifiable (PIKA_ITEM (layer),
                                       PIKA_PDB_ITEM_POSITION, error))
        {
          gint offset_x;
          gint offset_y;

          pika_item_get_offset (PIKA_ITEM (layer), &offset_x, &offset_y);
          offx -= offset_x;
          offy -= offset_y;

          pika_item_translate (PIKA_ITEM (layer), offx, offy, TRUE);
        }
      else
        success = FALSE;
    }

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

static PikaValueArray *
layer_create_mask_invoker (PikaProcedure         *procedure,
                           Pika                  *pika,
                           PikaContext           *context,
                           PikaProgress          *progress,
                           const PikaValueArray  *args,
                           GError               **error)
{
  gboolean success = TRUE;
  PikaValueArray *return_vals;
  PikaLayer *layer;
  gint mask_type;
  PikaLayerMask *mask = NULL;

  layer = g_value_get_object (pika_value_array_index (args, 0));
  mask_type = g_value_get_enum (pika_value_array_index (args, 1));

  if (success)
    {
      PikaChannel *channel = NULL;

      if (mask_type == PIKA_ADD_MASK_CHANNEL)
        {
          GList *channels;

          channels = pika_image_get_selected_channels (pika_item_get_image (PIKA_ITEM (layer)));

          if (! channels)
            success = FALSE;
          else
            channel = channels->data;
        }

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

          if (! mask)
            success = FALSE;
        }
    }

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

  if (success)
    g_value_set_object (pika_value_array_index (return_vals, 1), mask);

  return return_vals;
}

static PikaValueArray *
layer_get_mask_invoker (PikaProcedure         *procedure,
                        Pika                  *pika,
                        PikaContext           *context,
                        PikaProgress          *progress,
                        const PikaValueArray  *args,
                        GError               **error)
{
  gboolean success = TRUE;
  PikaValueArray *return_vals;
  PikaLayer *layer;
  PikaLayerMask *mask = NULL;

  layer = g_value_get_object (pika_value_array_index (args, 0));

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

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

  if (success)
    g_value_set_object (pika_value_array_index (return_vals, 1), mask);

  return return_vals;
}

static PikaValueArray *
layer_from_mask_invoker (PikaProcedure         *procedure,
                         Pika                  *pika,
                         PikaContext           *context,
                         PikaProgress          *progress,
                         const PikaValueArray  *args,
                         GError               **error)
{
  gboolean success = TRUE;
  PikaValueArray *return_vals;
  PikaLayerMask *mask;
  PikaLayer *layer = NULL;

  mask = g_value_get_object (pika_value_array_index (args, 0));

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

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

  if (success)
    g_value_set_object (pika_value_array_index (return_vals, 1), layer);

  return return_vals;
}

static PikaValueArray *
layer_add_mask_invoker (PikaProcedure         *procedure,
                        Pika                  *pika,
                        PikaContext           *context,
                        PikaProgress          *progress,
                        const PikaValueArray  *args,
                        GError               **error)
{
  gboolean success = TRUE;
  PikaLayer *layer;
  PikaLayerMask *mask;

  layer = g_value_get_object (pika_value_array_index (args, 0));
  mask = g_value_get_object (pika_value_array_index (args, 1));

  if (success)
    {
      if (pika_pdb_item_is_floating (PIKA_ITEM (mask),
                                     pika_item_get_image (PIKA_ITEM (layer)),
                                     error))
        success = (pika_layer_add_mask (layer, mask, TRUE, error) == mask);
      else
        success = FALSE;
    }

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

static PikaValueArray *
layer_remove_mask_invoker (PikaProcedure         *procedure,
                           Pika                  *pika,
                           PikaContext           *context,
                           PikaProgress          *progress,
                           const PikaValueArray  *args,
                           GError               **error)
{
  gboolean success = TRUE;
  PikaLayer *layer;
  gint mode;

  layer = g_value_get_object (pika_value_array_index (args, 0));
  mode = g_value_get_enum (pika_value_array_index (args, 1));

  if (success)
    {
      PikaPDBItemModify modify = 0;

      if (mode == PIKA_MASK_APPLY)
        modify |= PIKA_PDB_ITEM_CONTENT;

      if (pika_pdb_item_is_attached (PIKA_ITEM (layer), NULL, modify, error) &&
          pika_layer_get_mask (layer) &&
          (mode == PIKA_MASK_DISCARD ||
           pika_pdb_item_is_not_group (PIKA_ITEM (layer), error)))
        pika_layer_apply_mask (layer, mode, TRUE);
      else
        success = FALSE;
    }

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

static PikaValueArray *
layer_is_floating_sel_invoker (PikaProcedure         *procedure,
                               Pika                  *pika,
                               PikaContext           *context,
                               PikaProgress          *progress,
                               const PikaValueArray  *args,
                               GError               **error)
{
  gboolean success = TRUE;
  PikaValueArray *return_vals;
  PikaLayer *layer;
  gboolean is_floating_sel = FALSE;

  layer = g_value_get_object (pika_value_array_index (args, 0));

  if (success)
    {
      is_floating_sel = pika_layer_is_floating_sel (layer);
    }

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

  if (success)
    g_value_set_boolean (pika_value_array_index (return_vals, 1), is_floating_sel);

  return return_vals;
}

static PikaValueArray *
layer_get_lock_alpha_invoker (PikaProcedure         *procedure,
                              Pika                  *pika,
                              PikaContext           *context,
                              PikaProgress          *progress,
                              const PikaValueArray  *args,
                              GError               **error)
{
  gboolean success = TRUE;
  PikaValueArray *return_vals;
  PikaLayer *layer;
  gboolean lock_alpha = FALSE;

  layer = g_value_get_object (pika_value_array_index (args, 0));

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

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

  if (success)
    g_value_set_boolean (pika_value_array_index (return_vals, 1), lock_alpha);

  return return_vals;
}

static PikaValueArray *
layer_set_lock_alpha_invoker (PikaProcedure         *procedure,
                              Pika                  *pika,
                              PikaContext           *context,
                              PikaProgress          *progress,
                              const PikaValueArray  *args,
                              GError               **error)
{
  gboolean success = TRUE;
  PikaLayer *layer;
  gboolean lock_alpha;

  layer = g_value_get_object (pika_value_array_index (args, 0));
  lock_alpha = g_value_get_boolean (pika_value_array_index (args, 1));

  if (success)
    {
      if (pika_layer_can_lock_alpha (layer))
        pika_layer_set_lock_alpha (layer, lock_alpha, TRUE);
      else
        success = FALSE;
    }

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

static PikaValueArray *
layer_get_apply_mask_invoker (PikaProcedure         *procedure,
                              Pika                  *pika,
                              PikaContext           *context,
                              PikaProgress          *progress,
                              const PikaValueArray  *args,
                              GError               **error)
{
  gboolean success = TRUE;
  PikaValueArray *return_vals;
  PikaLayer *layer;
  gboolean apply_mask = FALSE;

  layer = g_value_get_object (pika_value_array_index (args, 0));

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

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

  if (success)
    g_value_set_boolean (pika_value_array_index (return_vals, 1), apply_mask);

  return return_vals;
}

static PikaValueArray *
layer_set_apply_mask_invoker (PikaProcedure         *procedure,
                              Pika                  *pika,
                              PikaContext           *context,
                              PikaProgress          *progress,
                              const PikaValueArray  *args,
                              GError               **error)
{
  gboolean success = TRUE;
  PikaLayer *layer;
  gboolean apply_mask;

  layer = g_value_get_object (pika_value_array_index (args, 0));
  apply_mask = g_value_get_boolean (pika_value_array_index (args, 1));

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

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

static PikaValueArray *
layer_get_show_mask_invoker (PikaProcedure         *procedure,
                             Pika                  *pika,
                             PikaContext           *context,
                             PikaProgress          *progress,
                             const PikaValueArray  *args,
                             GError               **error)
{
  gboolean success = TRUE;
  PikaValueArray *return_vals;
  PikaLayer *layer;
  gboolean show_mask = FALSE;

  layer = g_value_get_object (pika_value_array_index (args, 0));

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

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

  if (success)
    g_value_set_boolean (pika_value_array_index (return_vals, 1), show_mask);

  return return_vals;
}

static PikaValueArray *
layer_set_show_mask_invoker (PikaProcedure         *procedure,
                             Pika                  *pika,
                             PikaContext           *context,
                             PikaProgress          *progress,
                             const PikaValueArray  *args,
                             GError               **error)
{
  gboolean success = TRUE;
  PikaLayer *layer;
  gboolean show_mask;

  layer = g_value_get_object (pika_value_array_index (args, 0));
  show_mask = g_value_get_boolean (pika_value_array_index (args, 1));

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

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

static PikaValueArray *
layer_get_edit_mask_invoker (PikaProcedure         *procedure,
                             Pika                  *pika,
                             PikaContext           *context,
                             PikaProgress          *progress,
                             const PikaValueArray  *args,
                             GError               **error)
{
  gboolean success = TRUE;
  PikaValueArray *return_vals;
  PikaLayer *layer;
  gboolean edit_mask = FALSE;

  layer = g_value_get_object (pika_value_array_index (args, 0));

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

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

  if (success)
    g_value_set_boolean (pika_value_array_index (return_vals, 1), edit_mask);

  return return_vals;
}

static PikaValueArray *
layer_set_edit_mask_invoker (PikaProcedure         *procedure,
                             Pika                  *pika,
                             PikaContext           *context,
                             PikaProgress          *progress,
                             const PikaValueArray  *args,
                             GError               **error)
{
  gboolean success = TRUE;
  PikaLayer *layer;
  gboolean edit_mask;

  layer = g_value_get_object (pika_value_array_index (args, 0));
  edit_mask = g_value_get_boolean (pika_value_array_index (args, 1));

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

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

static PikaValueArray *
layer_get_opacity_invoker (PikaProcedure         *procedure,
                           Pika                  *pika,
                           PikaContext           *context,
                           PikaProgress          *progress,
                           const PikaValueArray  *args,
                           GError               **error)
{
  gboolean success = TRUE;
  PikaValueArray *return_vals;
  PikaLayer *layer;
  gdouble opacity = 0.0;

  layer = g_value_get_object (pika_value_array_index (args, 0));

  if (success)
    {
      opacity = pika_layer_get_opacity (layer) * 100.0;
    }

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

  if (success)
    g_value_set_double (pika_value_array_index (return_vals, 1), opacity);

  return return_vals;
}

static PikaValueArray *
layer_set_opacity_invoker (PikaProcedure         *procedure,
                           Pika                  *pika,
                           PikaContext           *context,
                           PikaProgress          *progress,
                           const PikaValueArray  *args,
                           GError               **error)
{
  gboolean success = TRUE;
  PikaLayer *layer;
  gdouble opacity;

  layer = g_value_get_object (pika_value_array_index (args, 0));
  opacity = g_value_get_double (pika_value_array_index (args, 1));

  if (success)
    {
      pika_layer_set_opacity (layer, opacity / 100.0, TRUE);
    }

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

static PikaValueArray *
layer_get_mode_invoker (PikaProcedure         *procedure,
                        Pika                  *pika,
                        PikaContext           *context,
                        PikaProgress          *progress,
                        const PikaValueArray  *args,
                        GError               **error)
{
  gboolean success = TRUE;
  PikaValueArray *return_vals;
  PikaLayer *layer;
  gint mode = 0;

  layer = g_value_get_object (pika_value_array_index (args, 0));

  if (success)
    {
      mode = pika_layer_get_mode (layer);
    }

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

  if (success)
    g_value_set_enum (pika_value_array_index (return_vals, 1), mode);

  return return_vals;
}

static PikaValueArray *
layer_set_mode_invoker (PikaProcedure         *procedure,
                        Pika                  *pika,
                        PikaContext           *context,
                        PikaProgress          *progress,
                        const PikaValueArray  *args,
                        GError               **error)
{
  gboolean success = TRUE;
  PikaLayer *layer;
  gint mode;

  layer = g_value_get_object (pika_value_array_index (args, 0));
  mode = g_value_get_enum (pika_value_array_index (args, 1));

  if (success)
    {
      if (mode == PIKA_LAYER_MODE_OVERLAY_LEGACY)
        mode = PIKA_LAYER_MODE_SOFTLIGHT_LEGACY;

      if (pika_viewable_get_children (PIKA_VIEWABLE (layer)) == NULL)
        {
          if (! (pika_layer_mode_get_context (mode) & PIKA_LAYER_MODE_CONTEXT_LAYER))
            success = FALSE;
        }
      else
        {
          if (! (pika_layer_mode_get_context (mode) & PIKA_LAYER_MODE_CONTEXT_GROUP))
            success = FALSE;
        }

      if (success)
        pika_layer_set_mode (layer, mode, TRUE);
    }

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

static PikaValueArray *
layer_get_blend_space_invoker (PikaProcedure         *procedure,
                               Pika                  *pika,
                               PikaContext           *context,
                               PikaProgress          *progress,
                               const PikaValueArray  *args,
                               GError               **error)
{
  gboolean success = TRUE;
  PikaValueArray *return_vals;
  PikaLayer *layer;
  gint blend_space = 0;

  layer = g_value_get_object (pika_value_array_index (args, 0));

  if (success)
    {
      blend_space = pika_layer_get_blend_space (layer);
    }

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

  if (success)
    g_value_set_enum (pika_value_array_index (return_vals, 1), blend_space);

  return return_vals;
}

static PikaValueArray *
layer_set_blend_space_invoker (PikaProcedure         *procedure,
                               Pika                  *pika,
                               PikaContext           *context,
                               PikaProgress          *progress,
                               const PikaValueArray  *args,
                               GError               **error)
{
  gboolean success = TRUE;
  PikaLayer *layer;
  gint blend_space;

  layer = g_value_get_object (pika_value_array_index (args, 0));
  blend_space = g_value_get_enum (pika_value_array_index (args, 1));

  if (success)
    {
      pika_layer_set_blend_space (layer, blend_space, TRUE);
    }

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

static PikaValueArray *
layer_get_composite_space_invoker (PikaProcedure         *procedure,
                                   Pika                  *pika,
                                   PikaContext           *context,
                                   PikaProgress          *progress,
                                   const PikaValueArray  *args,
                                   GError               **error)
{
  gboolean success = TRUE;
  PikaValueArray *return_vals;
  PikaLayer *layer;
  gint composite_space = 0;

  layer = g_value_get_object (pika_value_array_index (args, 0));

  if (success)
    {
      composite_space = pika_layer_get_composite_space (layer);
    }

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

  if (success)
    g_value_set_enum (pika_value_array_index (return_vals, 1), composite_space);

  return return_vals;
}

static PikaValueArray *
layer_set_composite_space_invoker (PikaProcedure         *procedure,
                                   Pika                  *pika,
                                   PikaContext           *context,
                                   PikaProgress          *progress,
                                   const PikaValueArray  *args,
                                   GError               **error)
{
  gboolean success = TRUE;
  PikaLayer *layer;
  gint composite_space;

  layer = g_value_get_object (pika_value_array_index (args, 0));
  composite_space = g_value_get_enum (pika_value_array_index (args, 1));

  if (success)
    {
      pika_layer_set_composite_space (layer, composite_space, TRUE);
    }

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

static PikaValueArray *
layer_get_composite_mode_invoker (PikaProcedure         *procedure,
                                  Pika                  *pika,
                                  PikaContext           *context,
                                  PikaProgress          *progress,
                                  const PikaValueArray  *args,
                                  GError               **error)
{
  gboolean success = TRUE;
  PikaValueArray *return_vals;
  PikaLayer *layer;
  gint composite_mode = 0;

  layer = g_value_get_object (pika_value_array_index (args, 0));

  if (success)
    {
      composite_mode = pika_layer_get_composite_mode (layer);
    }

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

  if (success)
    g_value_set_enum (pika_value_array_index (return_vals, 1), composite_mode);

  return return_vals;
}

static PikaValueArray *
layer_set_composite_mode_invoker (PikaProcedure         *procedure,
                                  Pika                  *pika,
                                  PikaContext           *context,
                                  PikaProgress          *progress,
                                  const PikaValueArray  *args,
                                  GError               **error)
{
  gboolean success = TRUE;
  PikaLayer *layer;
  gint composite_mode;

  layer = g_value_get_object (pika_value_array_index (args, 0));
  composite_mode = g_value_get_enum (pika_value_array_index (args, 1));

  if (success)
    {
      pika_layer_set_composite_mode (layer, composite_mode, TRUE);
    }

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

void
register_layer_procs (PikaPDB *pdb)
{
  PikaProcedure *procedure;

  /*
   * pika-layer-new
   */
  procedure = pika_procedure_new (layer_new_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-layer-new");
  pika_procedure_set_static_help (procedure,
                                  "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 automatic. Add the new layer with the 'pika-image-insert-layer' command. Other attributes such as layer mask modes, and offsets should be set with explicit procedure calls.",
                                  NULL);
  pika_procedure_set_static_attribution (procedure,
                                         "Spencer Kimball & Peter Mattis",
                                         "Spencer Kimball & Peter Mattis",
                                         "1995-1996");
  pika_procedure_add_argument (procedure,
                               pika_param_spec_image ("image",
                                                      "image",
                                                      "The image to which to add the layer",
                                                      FALSE,
                                                      PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_int ("width",
                                                 "width",
                                                 "The layer width",
                                                 1, PIKA_MAX_IMAGE_SIZE, 1,
                                                 PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_int ("height",
                                                 "height",
                                                 "The layer height",
                                                 1, PIKA_MAX_IMAGE_SIZE, 1,
                                                 PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_enum ("type",
                                                  "type",
                                                  "The layer type",
                                                  PIKA_TYPE_IMAGE_TYPE,
                                                  PIKA_RGB_IMAGE,
                                                  PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               pika_param_spec_string ("name",
                                                       "name",
                                                       "The layer name",
                                                       FALSE, TRUE, FALSE,
                                                       NULL,
                                                       PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_double ("opacity",
                                                    "opacity",
                                                    "The layer opacity",
                                                    0, 100, 0,
                                                    PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_enum ("mode",
                                                  "mode",
                                                  "The layer combination mode",
                                                  PIKA_TYPE_LAYER_MODE,
                                                  PIKA_LAYER_MODE_NORMAL,
                                                  PIKA_PARAM_READWRITE));
  pika_procedure_add_return_value (procedure,
                                   pika_param_spec_layer ("layer",
                                                          "layer",
                                                          "The newly created layer",
                                                          FALSE,
                                                          PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

  /*
   * pika-layer-new-from-visible
   */
  procedure = pika_procedure_new (layer_new_from_visible_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-layer-new-from-visible");
  pika_procedure_set_static_help (procedure,
                                  "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 'pika-image-insert-layer' command. Other attributes such as layer mask modes, and offsets should be set with explicit procedure calls.",
                                  NULL);
  pika_procedure_set_static_attribution (procedure,
                                         "Sven Neumann <sven@gimp.org>",
                                         "Sven Neumann",
                                         "2008");
  pika_procedure_add_argument (procedure,
                               pika_param_spec_image ("image",
                                                      "image",
                                                      "The source image from where the content is copied",
                                                      FALSE,
                                                      PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               pika_param_spec_image ("dest-image",
                                                      "dest image",
                                                      "The destination image to which to add the layer",
                                                      FALSE,
                                                      PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               pika_param_spec_string ("name",
                                                       "name",
                                                       "The layer name",
                                                       FALSE, TRUE, FALSE,
                                                       NULL,
                                                       PIKA_PARAM_READWRITE));
  pika_procedure_add_return_value (procedure,
                                   pika_param_spec_layer ("layer",
                                                          "layer",
                                                          "The newly created layer",
                                                          FALSE,
                                                          PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

  /*
   * pika-layer-new-from-drawable
   */
  procedure = pika_procedure_new (layer_new_from_drawable_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-layer-new-from-drawable");
  pika_procedure_set_static_help (procedure,
                                  "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 'pika-image-insert-layer' command. Other attributes such as layer mask modes, and offsets should be set with explicit procedure calls.",
                                  NULL);
  pika_procedure_set_static_attribution (procedure,
                                         "Spencer Kimball & Peter Mattis",
                                         "Spencer Kimball & Peter Mattis",
                                         "1995-1996");
  pika_procedure_add_argument (procedure,
                               pika_param_spec_drawable ("drawable",
                                                         "drawable",
                                                         "The source drawable from where the new layer is copied",
                                                         FALSE,
                                                         PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               pika_param_spec_image ("dest-image",
                                                      "dest image",
                                                      "The destination image to which to add the layer",
                                                      FALSE,
                                                      PIKA_PARAM_READWRITE));
  pika_procedure_add_return_value (procedure,
                                   pika_param_spec_layer ("layer-copy",
                                                          "layer copy",
                                                          "The newly copied layer",
                                                          FALSE,
                                                          PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

  /*
   * pika-layer-group-new
   */
  procedure = pika_procedure_new (layer_group_new_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-layer-group-new");
  pika_procedure_set_static_help (procedure,
                                  "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 'pika-image-insert-layer' command.\n"
                                  "Other procedures useful with layer groups: 'pika-image-reorder-item', 'pika-item-get-parent', 'pika-item-get-children', 'pika-item-is-group'.",
                                  NULL);
  pika_procedure_set_static_attribution (procedure,
                                         "Barak Itkin <lightningismyname@gmail.com>",
                                         "Barak Itkin",
                                         "2010");
  pika_procedure_add_argument (procedure,
                               pika_param_spec_image ("image",
                                                      "image",
                                                      "The image to which to add the layer group",
                                                      FALSE,
                                                      PIKA_PARAM_READWRITE));
  pika_procedure_add_return_value (procedure,
                                   pika_param_spec_layer ("layer-group",
                                                          "layer group",
                                                          "The newly created layer group",
                                                          FALSE,
                                                          PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

  /*
   * pika-layer-copy
   */
  procedure = pika_procedure_new (layer_copy_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-layer-copy");
  pika_procedure_set_static_help (procedure,
                                  "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.",
                                  NULL);
  pika_procedure_set_static_attribution (procedure,
                                         "Spencer Kimball & Peter Mattis",
                                         "Spencer Kimball & Peter Mattis",
                                         "1995-1996");
  pika_procedure_add_argument (procedure,
                               pika_param_spec_layer ("layer",
                                                      "layer",
                                                      "The layer to copy",
                                                      FALSE,
                                                      PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_boolean ("add-alpha",
                                                     "add alpha",
                                                     "Add an alpha channel to the copied layer",
                                                     FALSE,
                                                     PIKA_PARAM_READWRITE));
  pika_procedure_add_return_value (procedure,
                                   pika_param_spec_layer ("layer-copy",
                                                          "layer copy",
                                                          "The newly copied layer",
                                                          FALSE,
                                                          PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

  /*
   * pika-layer-add-alpha
   */
  procedure = pika_procedure_new (layer_add_alpha_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-layer-add-alpha");
  pika_procedure_set_static_help (procedure,
                                  "Add an alpha channel to the layer if it doesn't already have one.",
                                  "This procedure adds an additional component to the specified layer if it does not already possess an alpha channel. An alpha channel 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.",
                                  NULL);
  pika_procedure_set_static_attribution (procedure,
                                         "Spencer Kimball & Peter Mattis",
                                         "Spencer Kimball & Peter Mattis",
                                         "1995-1996");
  pika_procedure_add_argument (procedure,
                               pika_param_spec_layer ("layer",
                                                      "layer",
                                                      "The layer",
                                                      FALSE,
                                                      PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

  /*
   * pika-layer-flatten
   */
  procedure = pika_procedure_new (layer_flatten_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-layer-flatten");
  pika_procedure_set_static_help (procedure,
                                  "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.",
                                  NULL);
  pika_procedure_set_static_attribution (procedure,
                                         "Michael Natterer <mitch@gimp.org>",
                                         "Michael Natterer",
                                         "2007");
  pika_procedure_add_argument (procedure,
                               pika_param_spec_layer ("layer",
                                                      "layer",
                                                      "The layer",
                                                      FALSE,
                                                      PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

  /*
   * pika-layer-scale
   */
  procedure = pika_procedure_new (layer_scale_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-layer-scale");
  pika_procedure_set_static_help (procedure,
                                  "Scale the layer using the default interpolation method.",
                                  "This procedure scales the layer so that its new width and height are equal to the supplied parameters. The 'local-origin' parameter 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 to an image. The interpolation method used can be set with 'pika-context-set-interpolation'.",
                                  NULL);
  pika_procedure_set_static_attribution (procedure,
                                         "Spencer Kimball & Peter Mattis",
                                         "Spencer Kimball & Peter Mattis",
                                         "1995-1996");
  pika_procedure_add_argument (procedure,
                               pika_param_spec_layer ("layer",
                                                      "layer",
                                                      "The layer",
                                                      FALSE,
                                                      PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_int ("new-width",
                                                 "new width",
                                                 "New layer width",
                                                 1, PIKA_MAX_IMAGE_SIZE, 1,
                                                 PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_int ("new-height",
                                                 "new height",
                                                 "New layer height",
                                                 1, PIKA_MAX_IMAGE_SIZE, 1,
                                                 PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_boolean ("local-origin",
                                                     "local origin",
                                                     "Use a local origin (as opposed to the image origin)",
                                                     FALSE,
                                                     PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

  /*
   * pika-layer-resize
   */
  procedure = pika_procedure_new (layer_resize_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-layer-resize");
  pika_procedure_set_static_help (procedure,
                                  "Resize the layer to the specified extents.",
                                  "This procedure resizes the layer so that its new width and height 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.",
                                  NULL);
  pika_procedure_set_static_attribution (procedure,
                                         "Spencer Kimball & Peter Mattis",
                                         "Spencer Kimball & Peter Mattis",
                                         "1995-1996");
  pika_procedure_add_argument (procedure,
                               pika_param_spec_layer ("layer",
                                                      "layer",
                                                      "The layer",
                                                      FALSE,
                                                      PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_int ("new-width",
                                                 "new width",
                                                 "New layer width",
                                                 1, PIKA_MAX_IMAGE_SIZE, 1,
                                                 PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_int ("new-height",
                                                 "new height",
                                                 "New layer height",
                                                 1, PIKA_MAX_IMAGE_SIZE, 1,
                                                 PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_int ("offx",
                                                 "offx",
                                                 "x offset between upper left corner of old and new layers: (old - new)",
                                                 G_MININT32, G_MAXINT32, 0,
                                                 PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_int ("offy",
                                                 "offy",
                                                 "y offset between upper left corner of old and new layers: (old - new)",
                                                 G_MININT32, G_MAXINT32, 0,
                                                 PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

  /*
   * pika-layer-resize-to-image-size
   */
  procedure = pika_procedure_new (layer_resize_to_image_size_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-layer-resize-to-image-size");
  pika_procedure_set_static_help (procedure,
                                  "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.",
                                  NULL);
  pika_procedure_set_static_attribution (procedure,
                                         "Manish Singh",
                                         "Manish Singh",
                                         "2003");
  pika_procedure_add_argument (procedure,
                               pika_param_spec_layer ("layer",
                                                      "layer",
                                                      "The layer to resize",
                                                      FALSE,
                                                      PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

  /*
   * pika-layer-set-offsets
   */
  procedure = pika_procedure_new (layer_set_offsets_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-layer-set-offsets");
  pika_procedure_set_static_help (procedure,
                                  "Set the layer offsets.",
                                  "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.",
                                  NULL);
  pika_procedure_set_static_attribution (procedure,
                                         "Spencer Kimball & Peter Mattis",
                                         "Spencer Kimball & Peter Mattis",
                                         "1995-1996");
  pika_procedure_add_argument (procedure,
                               pika_param_spec_layer ("layer",
                                                      "layer",
                                                      "The layer",
                                                      FALSE,
                                                      PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_int ("offx",
                                                 "offx",
                                                 "Offset in x direction",
                                                 G_MININT32, G_MAXINT32, 0,
                                                 PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_int ("offy",
                                                 "offy",
                                                 "Offset in y direction",
                                                 G_MININT32, G_MAXINT32, 0,
                                                 PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

  /*
   * pika-layer-create-mask
   */
  procedure = pika_procedure_new (layer_create_mask_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-layer-create-mask");
  pika_procedure_set_static_help (procedure,
                                  "Create a layer mask for the specified layer.",
                                  "This procedure creates a layer mask for the specified layer.\n"
                                  "Layer masks serve as an additional alpha channel for a layer. Different types of masks are allowed for initialisation:\n"
                                  "- white mask (leaves the layer fully visible);\n"
                                  "- black mask (gives the layer complete transparency);\n"
                                  "- the layer's alpha channel (either a copy, or a transfer, which leaves the layer fully visible, but which may be more useful than a white mask);\n"
                                  "- the current selection;\n"
                                  "- a grayscale copy of the layer;\n"
                                  "- or a copy of the active channel.\n"
                                  "\n"
                                  "The layer mask still needs to be added to the layer. This can be done with a call to 'pika-layer-add-mask'.\n"
                                  "\n"
                                  "'pika-layer-create-mask' will fail if there are no active channels on the image, when called with 'ADD-CHANNEL-MASK'. It will return a black mask when called with 'ADD-ALPHA-MASK' or 'ADD-ALPHA-TRANSFER-MASK' on a layer with no alpha channels, or with 'ADD-SELECTION-MASK' when there is no selection on the image.",
                                  NULL);
  pika_procedure_set_static_attribution (procedure,
                                         "Spencer Kimball & Peter Mattis",
                                         "Spencer Kimball & Peter Mattis",
                                         "1995-1996");
  pika_procedure_add_argument (procedure,
                               pika_param_spec_layer ("layer",
                                                      "layer",
                                                      "The layer to which to add the mask",
                                                      FALSE,
                                                      PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_enum ("mask-type",
                                                  "mask type",
                                                  "The type of mask",
                                                  PIKA_TYPE_ADD_MASK_TYPE,
                                                  PIKA_ADD_MASK_WHITE,
                                                  PIKA_PARAM_READWRITE));
  pika_procedure_add_return_value (procedure,
                                   pika_param_spec_layer_mask ("mask",
                                                               "mask",
                                                               "The newly created mask",
                                                               FALSE,
                                                               PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

  /*
   * pika-layer-get-mask
   */
  procedure = pika_procedure_new (layer_get_mask_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-layer-get-mask");
  pika_procedure_set_static_help (procedure,
                                  "Get the specified layer's mask if it exists.",
                                  "This procedure returns the specified layer's mask, or -1 if none exists.",
                                  NULL);
  pika_procedure_set_static_attribution (procedure,
                                         "Spencer Kimball & Peter Mattis",
                                         "Spencer Kimball & Peter Mattis",
                                         "1995-1996");
  pika_procedure_add_argument (procedure,
                               pika_param_spec_layer ("layer",
                                                      "layer",
                                                      "The layer",
                                                      FALSE,
                                                      PIKA_PARAM_READWRITE));
  pika_procedure_add_return_value (procedure,
                                   pika_param_spec_layer_mask ("mask",
                                                               "mask",
                                                               "The layer mask",
                                                               FALSE,
                                                               PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

  /*
   * pika-layer-from-mask
   */
  procedure = pika_procedure_new (layer_from_mask_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-layer-from-mask");
  pika_procedure_set_static_help (procedure,
                                  "Get the specified mask's layer.",
                                  "This procedure returns the specified mask's layer , or -1 if none exists.",
                                  NULL);
  pika_procedure_set_static_attribution (procedure,
                                         "Geert Jordaens",
                                         "Geert Jordaens",
                                         "2004");
  pika_procedure_add_argument (procedure,
                               pika_param_spec_layer_mask ("mask",
                                                           "mask",
                                                           "Mask for which to return the layer",
                                                           FALSE,
                                                           PIKA_PARAM_READWRITE));
  pika_procedure_add_return_value (procedure,
                                   pika_param_spec_layer ("layer",
                                                          "layer",
                                                          "The mask's layer",
                                                          FALSE,
                                                          PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

  /*
   * pika-layer-add-mask
   */
  procedure = pika_procedure_new (layer_add_mask_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-layer-add-mask");
  pika_procedure_set_static_help (procedure,
                                  "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 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 'pika-layer-create-mask'.",
                                  NULL);
  pika_procedure_set_static_attribution (procedure,
                                         "Spencer Kimball & Peter Mattis",
                                         "Spencer Kimball & Peter Mattis",
                                         "1995-1996");
  pika_procedure_add_argument (procedure,
                               pika_param_spec_layer ("layer",
                                                      "layer",
                                                      "The layer to receive the mask",
                                                      FALSE,
                                                      PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               pika_param_spec_layer_mask ("mask",
                                                           "mask",
                                                           "The mask to add to the layer",
                                                           FALSE,
                                                           PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

  /*
   * pika-layer-remove-mask
   */
  procedure = pika_procedure_new (layer_remove_mask_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-layer-remove-mask");
  pika_procedure_set_static_help (procedure,
                                  "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.",
                                  NULL);
  pika_procedure_set_static_attribution (procedure,
                                         "Spencer Kimball & Peter Mattis",
                                         "Spencer Kimball & Peter Mattis",
                                         "1995-1996");
  pika_procedure_add_argument (procedure,
                               pika_param_spec_layer ("layer",
                                                      "layer",
                                                      "The layer from which to remove mask",
                                                      FALSE,
                                                      PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_enum ("mode",
                                                  "mode",
                                                  "Removal mode",
                                                  PIKA_TYPE_MASK_APPLY_MODE,
                                                  PIKA_MASK_APPLY,
                                                  PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

  /*
   * pika-layer-is-floating-sel
   */
  procedure = pika_procedure_new (layer_is_floating_sel_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-layer-is-floating-sel");
  pika_procedure_set_static_help (procedure,
                                  "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.",
                                  NULL);
  pika_procedure_set_static_attribution (procedure,
                                         "Spencer Kimball & Peter Mattis",
                                         "Spencer Kimball & Peter Mattis",
                                         "1995-1996");
  pika_procedure_add_argument (procedure,
                               pika_param_spec_layer ("layer",
                                                      "layer",
                                                      "The layer",
                                                      FALSE,
                                                      PIKA_PARAM_READWRITE));
  pika_procedure_add_return_value (procedure,
                                   g_param_spec_boolean ("is-floating-sel",
                                                         "is floating sel",
                                                         "TRUE if the layer is a floating selection",
                                                         FALSE,
                                                         PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

  /*
   * pika-layer-get-lock-alpha
   */
  procedure = pika_procedure_new (layer_get_lock_alpha_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-layer-get-lock-alpha");
  pika_procedure_set_static_help (procedure,
                                  "Get the lock alpha channel setting of the specified layer.",
                                  "This procedure returns the specified layer's lock alpha channel setting.",
                                  NULL);
  pika_procedure_set_static_attribution (procedure,
                                         "Spencer Kimball & Peter Mattis",
                                         "Spencer Kimball & Peter Mattis",
                                         "1995-1996");
  pika_procedure_add_argument (procedure,
                               pika_param_spec_layer ("layer",
                                                      "layer",
                                                      "The layer",
                                                      FALSE,
                                                      PIKA_PARAM_READWRITE));
  pika_procedure_add_return_value (procedure,
                                   g_param_spec_boolean ("lock-alpha",
                                                         "lock alpha",
                                                         "The layer's lock alpha channel setting",
                                                         FALSE,
                                                         PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

  /*
   * pika-layer-set-lock-alpha
   */
  procedure = pika_procedure_new (layer_set_lock_alpha_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-layer-set-lock-alpha");
  pika_procedure_set_static_help (procedure,
                                  "Set the lock alpha channel setting of the specified layer.",
                                  "This procedure sets the specified layer's lock alpha channel setting.",
                                  NULL);
  pika_procedure_set_static_attribution (procedure,
                                         "Spencer Kimball & Peter Mattis",
                                         "Spencer Kimball & Peter Mattis",
                                         "1995-1996");
  pika_procedure_add_argument (procedure,
                               pika_param_spec_layer ("layer",
                                                      "layer",
                                                      "The layer",
                                                      FALSE,
                                                      PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_boolean ("lock-alpha",
                                                     "lock alpha",
                                                     "The new layer's lock alpha channel setting",
                                                     FALSE,
                                                     PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

  /*
   * pika-layer-get-apply-mask
   */
  procedure = pika_procedure_new (layer_get_apply_mask_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-layer-get-apply-mask");
  pika_procedure_set_static_help (procedure,
                                  "Get the apply mask setting of the specified layer.",
                                  "This procedure returns the specified layer's apply mask setting. If the value is TRUE, then the layer mask for this layer is currently being composited with the layer's alpha channel.",
                                  NULL);
  pika_procedure_set_static_attribution (procedure,
                                         "Spencer Kimball & Peter Mattis",
                                         "Spencer Kimball & Peter Mattis",
                                         "1995-1996");
  pika_procedure_add_argument (procedure,
                               pika_param_spec_layer ("layer",
                                                      "layer",
                                                      "The layer",
                                                      FALSE,
                                                      PIKA_PARAM_READWRITE));
  pika_procedure_add_return_value (procedure,
                                   g_param_spec_boolean ("apply-mask",
                                                         "apply mask",
                                                         "The layer's apply mask setting",
                                                         FALSE,
                                                         PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

  /*
   * pika-layer-set-apply-mask
   */
  procedure = pika_procedure_new (layer_set_apply_mask_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-layer-set-apply-mask");
  pika_procedure_set_static_help (procedure,
                                  "Set the apply mask setting of the specified layer.",
                                  "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.",
                                  NULL);
  pika_procedure_set_static_attribution (procedure,
                                         "Spencer Kimball & Peter Mattis",
                                         "Spencer Kimball & Peter Mattis",
                                         "1995-1996");
  pika_procedure_add_argument (procedure,
                               pika_param_spec_layer ("layer",
                                                      "layer",
                                                      "The layer",
                                                      FALSE,
                                                      PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_boolean ("apply-mask",
                                                     "apply mask",
                                                     "The new layer's apply mask setting",
                                                     FALSE,
                                                     PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

  /*
   * pika-layer-get-show-mask
   */
  procedure = pika_procedure_new (layer_get_show_mask_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-layer-get-show-mask");
  pika_procedure_set_static_help (procedure,
                                  "Get the show mask setting of the specified layer.",
                                  "This procedure returns the specified layer's show mask setting. This 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.",
                                  NULL);
  pika_procedure_set_static_attribution (procedure,
                                         "Spencer Kimball & Peter Mattis",
                                         "Spencer Kimball & Peter Mattis",
                                         "1995-1996");
  pika_procedure_add_argument (procedure,
                               pika_param_spec_layer ("layer",
                                                      "layer",
                                                      "The layer",
                                                      FALSE,
                                                      PIKA_PARAM_READWRITE));
  pika_procedure_add_return_value (procedure,
                                   g_param_spec_boolean ("show-mask",
                                                         "show mask",
                                                         "The layer's show mask setting",
                                                         FALSE,
                                                         PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

  /*
   * pika-layer-set-show-mask
   */
  procedure = pika_procedure_new (layer_set_show_mask_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-layer-set-show-mask");
  pika_procedure_set_static_help (procedure,
                                  "Set the show mask setting of the specified layer.",
                                  "This procedure sets the specified layer's show mask setting. This 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.",
                                  NULL);
  pika_procedure_set_static_attribution (procedure,
                                         "Spencer Kimball & Peter Mattis",
                                         "Spencer Kimball & Peter Mattis",
                                         "1995-1996");
  pika_procedure_add_argument (procedure,
                               pika_param_spec_layer ("layer",
                                                      "layer",
                                                      "The layer",
                                                      FALSE,
                                                      PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_boolean ("show-mask",
                                                     "show mask",
                                                     "The new layer's show mask setting",
                                                     FALSE,
                                                     PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

  /*
   * pika-layer-get-edit-mask
   */
  procedure = pika_procedure_new (layer_get_edit_mask_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-layer-get-edit-mask");
  pika_procedure_set_static_help (procedure,
                                  "Get the edit mask setting of the specified layer.",
                                  "This procedure returns the specified layer's edit mask setting. If the value is TRUE, then the layer mask for this layer is currently active, and not the layer.",
                                  NULL);
  pika_procedure_set_static_attribution (procedure,
                                         "Spencer Kimball & Peter Mattis",
                                         "Spencer Kimball & Peter Mattis",
                                         "1995-1996");
  pika_procedure_add_argument (procedure,
                               pika_param_spec_layer ("layer",
                                                      "layer",
                                                      "The layer",
                                                      FALSE,
                                                      PIKA_PARAM_READWRITE));
  pika_procedure_add_return_value (procedure,
                                   g_param_spec_boolean ("edit-mask",
                                                         "edit mask",
                                                         "The layer's edit mask setting",
                                                         FALSE,
                                                         PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

  /*
   * pika-layer-set-edit-mask
   */
  procedure = pika_procedure_new (layer_set_edit_mask_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-layer-set-edit-mask");
  pika_procedure_set_static_help (procedure,
                                  "Set the edit mask setting of the specified layer.",
                                  "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.",
                                  NULL);
  pika_procedure_set_static_attribution (procedure,
                                         "Spencer Kimball & Peter Mattis",
                                         "Spencer Kimball & Peter Mattis",
                                         "1995-1996");
  pika_procedure_add_argument (procedure,
                               pika_param_spec_layer ("layer",
                                                      "layer",
                                                      "The layer",
                                                      FALSE,
                                                      PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_boolean ("edit-mask",
                                                     "edit mask",
                                                     "The new layer's edit mask setting",
                                                     FALSE,
                                                     PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

  /*
   * pika-layer-get-opacity
   */
  procedure = pika_procedure_new (layer_get_opacity_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-layer-get-opacity");
  pika_procedure_set_static_help (procedure,
                                  "Get the opacity of the specified layer.",
                                  "This procedure returns the specified layer's opacity.",
                                  NULL);
  pika_procedure_set_static_attribution (procedure,
                                         "Spencer Kimball & Peter Mattis",
                                         "Spencer Kimball & Peter Mattis",
                                         "1995-1996");
  pika_procedure_add_argument (procedure,
                               pika_param_spec_layer ("layer",
                                                      "layer",
                                                      "The layer",
                                                      FALSE,
                                                      PIKA_PARAM_READWRITE));
  pika_procedure_add_return_value (procedure,
                                   g_param_spec_double ("opacity",
                                                        "opacity",
                                                        "The layer opacity",
                                                        0, 100, 0,
                                                        PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

  /*
   * pika-layer-set-opacity
   */
  procedure = pika_procedure_new (layer_set_opacity_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-layer-set-opacity");
  pika_procedure_set_static_help (procedure,
                                  "Set the opacity of the specified layer.",
                                  "This procedure sets the specified layer's opacity.",
                                  NULL);
  pika_procedure_set_static_attribution (procedure,
                                         "Spencer Kimball & Peter Mattis",
                                         "Spencer Kimball & Peter Mattis",
                                         "1995-1996");
  pika_procedure_add_argument (procedure,
                               pika_param_spec_layer ("layer",
                                                      "layer",
                                                      "The layer",
                                                      FALSE,
                                                      PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_double ("opacity",
                                                    "opacity",
                                                    "The new layer opacity",
                                                    0, 100, 0,
                                                    PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

  /*
   * pika-layer-get-mode
   */
  procedure = pika_procedure_new (layer_get_mode_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-layer-get-mode");
  pika_procedure_set_static_help (procedure,
                                  "Get the combination mode of the specified layer.",
                                  "This procedure returns the specified layer's combination mode.",
                                  NULL);
  pika_procedure_set_static_attribution (procedure,
                                         "Spencer Kimball & Peter Mattis",
                                         "Spencer Kimball & Peter Mattis",
                                         "1995-1996");
  pika_procedure_add_argument (procedure,
                               pika_param_spec_layer ("layer",
                                                      "layer",
                                                      "The layer",
                                                      FALSE,
                                                      PIKA_PARAM_READWRITE));
  pika_procedure_add_return_value (procedure,
                                   g_param_spec_enum ("mode",
                                                      "mode",
                                                      "The layer combination mode",
                                                      PIKA_TYPE_LAYER_MODE,
                                                      PIKA_LAYER_MODE_NORMAL,
                                                      PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

  /*
   * pika-layer-set-mode
   */
  procedure = pika_procedure_new (layer_set_mode_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-layer-set-mode");
  pika_procedure_set_static_help (procedure,
                                  "Set the combination mode of the specified layer.",
                                  "This procedure sets the specified layer's combination mode.",
                                  NULL);
  pika_procedure_set_static_attribution (procedure,
                                         "Spencer Kimball & Peter Mattis",
                                         "Spencer Kimball & Peter Mattis",
                                         "1995-1996");
  pika_procedure_add_argument (procedure,
                               pika_param_spec_layer ("layer",
                                                      "layer",
                                                      "The layer",
                                                      FALSE,
                                                      PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_enum ("mode",
                                                  "mode",
                                                  "The new layer combination mode",
                                                  PIKA_TYPE_LAYER_MODE,
                                                  PIKA_LAYER_MODE_NORMAL,
                                                  PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

  /*
   * pika-layer-get-blend-space
   */
  procedure = pika_procedure_new (layer_get_blend_space_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-layer-get-blend-space");
  pika_procedure_set_static_help (procedure,
                                  "Get the blend space of the specified layer.",
                                  "This procedure returns the specified layer's blend space.",
                                  NULL);
  pika_procedure_set_static_attribution (procedure,
                                         "Ell",
                                         "Ell",
                                         "2017");
  pika_procedure_add_argument (procedure,
                               pika_param_spec_layer ("layer",
                                                      "layer",
                                                      "The layer",
                                                      FALSE,
                                                      PIKA_PARAM_READWRITE));
  pika_procedure_add_return_value (procedure,
                                   g_param_spec_enum ("blend-space",
                                                      "blend space",
                                                      "The layer blend space",
                                                      PIKA_TYPE_LAYER_COLOR_SPACE,
                                                      PIKA_LAYER_COLOR_SPACE_AUTO,
                                                      PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

  /*
   * pika-layer-set-blend-space
   */
  procedure = pika_procedure_new (layer_set_blend_space_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-layer-set-blend-space");
  pika_procedure_set_static_help (procedure,
                                  "Set the blend space of the specified layer.",
                                  "This procedure sets the specified layer's blend space.",
                                  NULL);
  pika_procedure_set_static_attribution (procedure,
                                         "Ell",
                                         "Ell",
                                         "2017");
  pika_procedure_add_argument (procedure,
                               pika_param_spec_layer ("layer",
                                                      "layer",
                                                      "The layer",
                                                      FALSE,
                                                      PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_enum ("blend-space",
                                                  "blend space",
                                                  "The new layer blend space",
                                                  PIKA_TYPE_LAYER_COLOR_SPACE,
                                                  PIKA_LAYER_COLOR_SPACE_AUTO,
                                                  PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

  /*
   * pika-layer-get-composite-space
   */
  procedure = pika_procedure_new (layer_get_composite_space_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-layer-get-composite-space");
  pika_procedure_set_static_help (procedure,
                                  "Get the composite space of the specified layer.",
                                  "This procedure returns the specified layer's composite space.",
                                  NULL);
  pika_procedure_set_static_attribution (procedure,
                                         "Ell",
                                         "Ell",
                                         "2017");
  pika_procedure_add_argument (procedure,
                               pika_param_spec_layer ("layer",
                                                      "layer",
                                                      "The layer",
                                                      FALSE,
                                                      PIKA_PARAM_READWRITE));
  pika_procedure_add_return_value (procedure,
                                   g_param_spec_enum ("composite-space",
                                                      "composite space",
                                                      "The layer composite space",
                                                      PIKA_TYPE_LAYER_COLOR_SPACE,
                                                      PIKA_LAYER_COLOR_SPACE_AUTO,
                                                      PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

  /*
   * pika-layer-set-composite-space
   */
  procedure = pika_procedure_new (layer_set_composite_space_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-layer-set-composite-space");
  pika_procedure_set_static_help (procedure,
                                  "Set the composite space of the specified layer.",
                                  "This procedure sets the specified layer's composite space.",
                                  NULL);
  pika_procedure_set_static_attribution (procedure,
                                         "Ell",
                                         "Ell",
                                         "2017");
  pika_procedure_add_argument (procedure,
                               pika_param_spec_layer ("layer",
                                                      "layer",
                                                      "The layer",
                                                      FALSE,
                                                      PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_enum ("composite-space",
                                                  "composite space",
                                                  "The new layer composite space",
                                                  PIKA_TYPE_LAYER_COLOR_SPACE,
                                                  PIKA_LAYER_COLOR_SPACE_AUTO,
                                                  PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

  /*
   * pika-layer-get-composite-mode
   */
  procedure = pika_procedure_new (layer_get_composite_mode_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-layer-get-composite-mode");
  pika_procedure_set_static_help (procedure,
                                  "Get the composite mode of the specified layer.",
                                  "This procedure returns the specified layer's composite mode.",
                                  NULL);
  pika_procedure_set_static_attribution (procedure,
                                         "Ell",
                                         "Ell",
                                         "2017");
  pika_procedure_add_argument (procedure,
                               pika_param_spec_layer ("layer",
                                                      "layer",
                                                      "The layer",
                                                      FALSE,
                                                      PIKA_PARAM_READWRITE));
  pika_procedure_add_return_value (procedure,
                                   g_param_spec_enum ("composite-mode",
                                                      "composite mode",
                                                      "The layer composite mode",
                                                      PIKA_TYPE_LAYER_COMPOSITE_MODE,
                                                      PIKA_LAYER_COMPOSITE_AUTO,
                                                      PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

  /*
   * pika-layer-set-composite-mode
   */
  procedure = pika_procedure_new (layer_set_composite_mode_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-layer-set-composite-mode");
  pika_procedure_set_static_help (procedure,
                                  "Set the composite mode of the specified layer.",
                                  "This procedure sets the specified layer's composite mode.",
                                  NULL);
  pika_procedure_set_static_attribution (procedure,
                                         "Ell",
                                         "Ell",
                                         "2017");
  pika_procedure_add_argument (procedure,
                               pika_param_spec_layer ("layer",
                                                      "layer",
                                                      "The layer",
                                                      FALSE,
                                                      PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_enum ("composite-mode",
                                                  "composite mode",
                                                  "The new layer composite mode",
                                                  PIKA_TYPE_LAYER_COMPOSITE_MODE,
                                                  PIKA_LAYER_COMPOSITE_AUTO,
                                                  PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);
}
