/* 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 <gegl.h>

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

#include "libpikaconfig/pikaconfig.h"
#include "libpikamath/pikamath.h"

#include "libpikabase/pikabase.h"

#include "pdb-types.h"

#include "core/pikadrawable.h"
#include "core/pikadynamics.h"
#include "core/pikapaintinfo.h"
#include "core/pikaparamspecs.h"
#include "paint/pikapaintcore-stroke.h"
#include "paint/pikapaintcore.h"
#include "paint/pikapaintoptions.h"

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


static const PikaCoords default_coords = PIKA_COORDS_DEFAULT_VALUES;

static gboolean
paint_tools_stroke (Pika              *pika,
                    PikaContext       *context,
                    PikaPaintOptions  *options,
                    PikaDrawable      *drawable,
                    gint               n_strokes,
                    const gdouble     *strokes,
                    GError           **error,
                    const gchar       *first_property_name,
                    ...)
{
  PikaPaintCore *core;
  PikaCoords    *coords;
  gboolean       retval;
  gint           i;
  va_list        args;

  n_strokes /= 2;  /* #doubles -> #points */

  /*  undefine the paint-relevant context properties and get them
   *  from the current context
   */
  pika_context_define_properties (PIKA_CONTEXT (options),
                                  PIKA_CONTEXT_PROP_MASK_PAINT,
                                  FALSE);
  pika_context_set_parent (PIKA_CONTEXT (options), context);

  va_start (args, first_property_name);
  core = PIKA_PAINT_CORE (g_object_new_valist (options->paint_info->paint_type,
                                               first_property_name, args));
  va_end (args);

  coords = g_new (PikaCoords, n_strokes);

  for (i = 0; i < n_strokes; i++)
    {
      coords[i]   = default_coords;
      coords[i].x = strokes[2 * i];
      coords[i].y = strokes[2 * i + 1];
    }

  retval = pika_paint_core_stroke (core, drawable, options,
                                   coords, n_strokes, TRUE,
                                   error);

  g_free (coords);

  g_object_unref (core);
  g_object_unref (options);

  return retval;
}

static PikaValueArray *
airbrush_invoker (PikaProcedure         *procedure,
                  Pika                  *pika,
                  PikaContext           *context,
                  PikaProgress          *progress,
                  const PikaValueArray  *args,
                  GError               **error)
{
  gboolean success = TRUE;
  PikaDrawable *drawable;
  gdouble pressure;
  gint num_strokes;
  const gdouble *strokes;

  drawable = g_value_get_object (pika_value_array_index (args, 0));
  pressure = g_value_get_double (pika_value_array_index (args, 1));
  num_strokes = g_value_get_int (pika_value_array_index (args, 2));
  strokes = pika_value_get_float_array (pika_value_array_index (args, 3));

  if (success)
    {
      PikaPaintOptions *options =
        pika_pdb_context_get_paint_options (PIKA_PDB_CONTEXT (context),
                                            "pika-airbrush");

      if (options &&
          pika_pdb_item_is_attached (PIKA_ITEM (drawable), NULL,
                                     PIKA_PDB_ITEM_CONTENT, error) &&
          pika_pdb_item_is_not_group (PIKA_ITEM (drawable), error))
        {
          options = pika_config_duplicate (PIKA_CONFIG (options));

          g_object_set (options,
                        "pressure", pressure,
                        NULL);

          success = paint_tools_stroke (pika, context, options, drawable,
                                        num_strokes, strokes, error,
                                        "undo-desc", options->paint_info->blurb,
                                        NULL);
        }
      else
        success = FALSE;
    }

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

static PikaValueArray *
airbrush_default_invoker (PikaProcedure         *procedure,
                          Pika                  *pika,
                          PikaContext           *context,
                          PikaProgress          *progress,
                          const PikaValueArray  *args,
                          GError               **error)
{
  gboolean success = TRUE;
  PikaDrawable *drawable;
  gint num_strokes;
  const gdouble *strokes;

  drawable = g_value_get_object (pika_value_array_index (args, 0));
  num_strokes = g_value_get_int (pika_value_array_index (args, 1));
  strokes = pika_value_get_float_array (pika_value_array_index (args, 2));

  if (success)
    {
      PikaPaintOptions *options =
        pika_pdb_context_get_paint_options (PIKA_PDB_CONTEXT (context),
                                            "pika-airbrush");

      if (options &&
          pika_pdb_item_is_attached (PIKA_ITEM (drawable), NULL,
                                     PIKA_PDB_ITEM_CONTENT, error) &&
          pika_pdb_item_is_not_group (PIKA_ITEM (drawable), error))
        {
          options = pika_config_duplicate (PIKA_CONFIG (options));

          success = paint_tools_stroke (pika, context, options, drawable,
                                        num_strokes, strokes, error,
                                        "undo-desc", options->paint_info->blurb,
                                        NULL);
        }
      else
        success = FALSE;
    }

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

static PikaValueArray *
clone_invoker (PikaProcedure         *procedure,
               Pika                  *pika,
               PikaContext           *context,
               PikaProgress          *progress,
               const PikaValueArray  *args,
               GError               **error)
{
  gboolean success = TRUE;
  PikaDrawable *drawable;
  PikaDrawable *src_drawable;
  gint clone_type;
  gdouble src_x;
  gdouble src_y;
  gint num_strokes;
  const gdouble *strokes;

  drawable = g_value_get_object (pika_value_array_index (args, 0));
  src_drawable = g_value_get_object (pika_value_array_index (args, 1));
  clone_type = g_value_get_enum (pika_value_array_index (args, 2));
  src_x = g_value_get_double (pika_value_array_index (args, 3));
  src_y = g_value_get_double (pika_value_array_index (args, 4));
  num_strokes = g_value_get_int (pika_value_array_index (args, 5));
  strokes = pika_value_get_float_array (pika_value_array_index (args, 6));

  if (success)
    {
      PikaPaintOptions *options =
        pika_pdb_context_get_paint_options (PIKA_PDB_CONTEXT (context),
                                            "pika-clone");

      if (options &&
          pika_pdb_item_is_attached (PIKA_ITEM (drawable), NULL,
                                     PIKA_PDB_ITEM_CONTENT, error) &&
          pika_pdb_item_is_not_group (PIKA_ITEM (drawable), error))
        {
          GList *src_drawables;

          options = pika_config_duplicate (PIKA_CONFIG (options));
          src_drawables = g_list_prepend (NULL, src_drawable);

          g_object_set (options,
                        "clone-type",    clone_type,
                        "src-drawables", src_drawables,
                        NULL);

          success = paint_tools_stroke (pika, context, options, drawable,
                                        num_strokes, strokes, error,
                                        "undo-desc", options->paint_info->blurb,
                                        "src-x",     (gint) floor (src_x),
                                        "src-y",     (gint) floor (src_y),
                                        NULL);
          g_list_free (src_drawables);
        }
      else
        success = FALSE;
    }

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

static PikaValueArray *
clone_default_invoker (PikaProcedure         *procedure,
                       Pika                  *pika,
                       PikaContext           *context,
                       PikaProgress          *progress,
                       const PikaValueArray  *args,
                       GError               **error)
{
  gboolean success = TRUE;
  PikaDrawable *drawable;
  gint num_strokes;
  const gdouble *strokes;

  drawable = g_value_get_object (pika_value_array_index (args, 0));
  num_strokes = g_value_get_int (pika_value_array_index (args, 1));
  strokes = pika_value_get_float_array (pika_value_array_index (args, 2));

  if (success)
    {
      PikaPaintOptions *options =
        pika_pdb_context_get_paint_options (PIKA_PDB_CONTEXT (context),
                                            "pika-clone");

      if (options &&
          pika_pdb_item_is_attached (PIKA_ITEM (drawable), NULL,
                                     PIKA_PDB_ITEM_CONTENT, error) &&
          pika_pdb_item_is_not_group (PIKA_ITEM (drawable), error))
        {
          options = pika_config_duplicate (PIKA_CONFIG (options));

          success = paint_tools_stroke (pika, context, options, drawable,
                                        num_strokes, strokes, error,
                                        "undo-desc", options->paint_info->blurb,
                                        NULL);
        }
      else
        success = FALSE;
    }

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

static PikaValueArray *
convolve_invoker (PikaProcedure         *procedure,
                  Pika                  *pika,
                  PikaContext           *context,
                  PikaProgress          *progress,
                  const PikaValueArray  *args,
                  GError               **error)
{
  gboolean success = TRUE;
  PikaDrawable *drawable;
  gdouble pressure;
  gint convolve_type;
  gint num_strokes;
  const gdouble *strokes;

  drawable = g_value_get_object (pika_value_array_index (args, 0));
  pressure = g_value_get_double (pika_value_array_index (args, 1));
  convolve_type = g_value_get_enum (pika_value_array_index (args, 2));
  num_strokes = g_value_get_int (pika_value_array_index (args, 3));
  strokes = pika_value_get_float_array (pika_value_array_index (args, 4));

  if (success)
    {
      PikaPaintOptions *options =
        pika_pdb_context_get_paint_options (PIKA_PDB_CONTEXT (context),
                                            "pika-convolve");

      if (options &&
          pika_pdb_item_is_attached (PIKA_ITEM (drawable), NULL,
                                     PIKA_PDB_ITEM_CONTENT, error) &&
          pika_pdb_item_is_not_group (PIKA_ITEM (drawable), error))
        {
          options = pika_config_duplicate (PIKA_CONFIG (options));

          g_object_set (options,
                        "type", convolve_type,
                        "rate", pressure,
                        NULL);

          success = paint_tools_stroke (pika, context, options, drawable,
                                        num_strokes, strokes, error,
                                        "undo-desc", options->paint_info->blurb,
                                        NULL);
        }
      else
        success = FALSE;
    }

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

static PikaValueArray *
convolve_default_invoker (PikaProcedure         *procedure,
                          Pika                  *pika,
                          PikaContext           *context,
                          PikaProgress          *progress,
                          const PikaValueArray  *args,
                          GError               **error)
{
  gboolean success = TRUE;
  PikaDrawable *drawable;
  gint num_strokes;
  const gdouble *strokes;

  drawable = g_value_get_object (pika_value_array_index (args, 0));
  num_strokes = g_value_get_int (pika_value_array_index (args, 1));
  strokes = pika_value_get_float_array (pika_value_array_index (args, 2));

  if (success)
    {
      PikaPaintOptions *options =
        pika_pdb_context_get_paint_options (PIKA_PDB_CONTEXT (context),
                                            "pika-convolve");

      if (options &&
          pika_pdb_item_is_attached (PIKA_ITEM (drawable), NULL,
                                     PIKA_PDB_ITEM_CONTENT, error) &&
          pika_pdb_item_is_not_group (PIKA_ITEM (drawable), error))
        {
          options = pika_config_duplicate (PIKA_CONFIG (options));

          success = paint_tools_stroke (pika, context, options, drawable,
                                        num_strokes, strokes, error,
                                        "undo-desc", options->paint_info->blurb,
                                        NULL);
        }
      else
        success = FALSE;
    }

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

static PikaValueArray *
dodgeburn_invoker (PikaProcedure         *procedure,
                   Pika                  *pika,
                   PikaContext           *context,
                   PikaProgress          *progress,
                   const PikaValueArray  *args,
                   GError               **error)
{
  gboolean success = TRUE;
  PikaDrawable *drawable;
  gdouble exposure;
  gint dodgeburn_type;
  gint dodgeburn_mode;
  gint num_strokes;
  const gdouble *strokes;

  drawable = g_value_get_object (pika_value_array_index (args, 0));
  exposure = g_value_get_double (pika_value_array_index (args, 1));
  dodgeburn_type = g_value_get_enum (pika_value_array_index (args, 2));
  dodgeburn_mode = g_value_get_enum (pika_value_array_index (args, 3));
  num_strokes = g_value_get_int (pika_value_array_index (args, 4));
  strokes = pika_value_get_float_array (pika_value_array_index (args, 5));

  if (success)
    {
      PikaPaintOptions *options =
        pika_pdb_context_get_paint_options (PIKA_PDB_CONTEXT (context),
                                            "pika-dodge-burn");

      if (options &&
          pika_pdb_item_is_attached (PIKA_ITEM (drawable), NULL,
                                     PIKA_PDB_ITEM_CONTENT, error) &&
          pika_pdb_item_is_not_group (PIKA_ITEM (drawable), error))
        {
          options = pika_config_duplicate (PIKA_CONFIG (options));

          g_object_set (options,
                        "type",     dodgeburn_type,
                        "mode",     dodgeburn_mode,
                        "exposure", exposure,
                        NULL);

          success = paint_tools_stroke (pika, context, options, drawable,
                                        num_strokes, strokes, error,
                                        "undo-desc", options->paint_info->blurb,
                                        NULL);
        }
      else
        success = FALSE;
    }

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

static PikaValueArray *
dodgeburn_default_invoker (PikaProcedure         *procedure,
                           Pika                  *pika,
                           PikaContext           *context,
                           PikaProgress          *progress,
                           const PikaValueArray  *args,
                           GError               **error)
{
  gboolean success = TRUE;
  PikaDrawable *drawable;
  gint num_strokes;
  const gdouble *strokes;

  drawable = g_value_get_object (pika_value_array_index (args, 0));
  num_strokes = g_value_get_int (pika_value_array_index (args, 1));
  strokes = pika_value_get_float_array (pika_value_array_index (args, 2));

  if (success)
    {
      PikaPaintOptions *options =
        pika_pdb_context_get_paint_options (PIKA_PDB_CONTEXT (context),
                                            "pika-dodge-burn");

      if (options &&
          pika_pdb_item_is_attached (PIKA_ITEM (drawable), NULL,
                                     PIKA_PDB_ITEM_CONTENT, error) &&
          pika_pdb_item_is_not_group (PIKA_ITEM (drawable), error))
        {
          options = pika_config_duplicate (PIKA_CONFIG (options));

          success = paint_tools_stroke (pika, context, options, drawable,
                                        num_strokes, strokes, error,
                                        "undo-desc", options->paint_info->blurb,
                                        NULL);
        }
      else
        success = FALSE;
    }

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

static PikaValueArray *
eraser_invoker (PikaProcedure         *procedure,
                Pika                  *pika,
                PikaContext           *context,
                PikaProgress          *progress,
                const PikaValueArray  *args,
                GError               **error)
{
  gboolean success = TRUE;
  PikaDrawable *drawable;
  gint num_strokes;
  const gdouble *strokes;
  gint hardness;
  gint method;

  drawable = g_value_get_object (pika_value_array_index (args, 0));
  num_strokes = g_value_get_int (pika_value_array_index (args, 1));
  strokes = pika_value_get_float_array (pika_value_array_index (args, 2));
  hardness = g_value_get_enum (pika_value_array_index (args, 3));
  method = g_value_get_enum (pika_value_array_index (args, 4));

  if (success)
    {
      PikaPaintOptions *options =
        pika_pdb_context_get_paint_options (PIKA_PDB_CONTEXT (context),
                                            "pika-eraser");

      if (options &&
          pika_pdb_item_is_attached (PIKA_ITEM (drawable), NULL,
                                     PIKA_PDB_ITEM_CONTENT, error) &&
          pika_pdb_item_is_not_group (PIKA_ITEM (drawable), error))
        {
          options = pika_config_duplicate (PIKA_CONFIG (options));

          g_object_set (options,
                        "application-mode", method,
                        "hard",             hardness,
                        NULL);

          success = paint_tools_stroke (pika, context, options, drawable,
                                        num_strokes, strokes, error,
                                        "undo-desc", options->paint_info->blurb,
                                        NULL);
        }
      else
        success = FALSE;
    }

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

static PikaValueArray *
eraser_default_invoker (PikaProcedure         *procedure,
                        Pika                  *pika,
                        PikaContext           *context,
                        PikaProgress          *progress,
                        const PikaValueArray  *args,
                        GError               **error)
{
  gboolean success = TRUE;
  PikaDrawable *drawable;
  gint num_strokes;
  const gdouble *strokes;

  drawable = g_value_get_object (pika_value_array_index (args, 0));
  num_strokes = g_value_get_int (pika_value_array_index (args, 1));
  strokes = pika_value_get_float_array (pika_value_array_index (args, 2));

  if (success)
    {
      PikaPaintOptions *options =
        pika_pdb_context_get_paint_options (PIKA_PDB_CONTEXT (context),
                                            "pika-eraser");

      if (options &&
          pika_pdb_item_is_attached (PIKA_ITEM (drawable), NULL,
                                     PIKA_PDB_ITEM_CONTENT, error) &&
          pika_pdb_item_is_not_group (PIKA_ITEM (drawable), error))
        {
          options = pika_config_duplicate (PIKA_CONFIG (options));

          success = paint_tools_stroke (pika, context, options, drawable,
                                        num_strokes, strokes, error,
                                        "undo-desc", options->paint_info->blurb,
                                        NULL);
        }
      else
        success = FALSE;
    }

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

static PikaValueArray *
heal_invoker (PikaProcedure         *procedure,
              Pika                  *pika,
              PikaContext           *context,
              PikaProgress          *progress,
              const PikaValueArray  *args,
              GError               **error)
{
  gboolean success = TRUE;
  PikaDrawable *drawable;
  PikaDrawable *src_drawable;
  gdouble src_x;
  gdouble src_y;
  gint num_strokes;
  const gdouble *strokes;

  drawable = g_value_get_object (pika_value_array_index (args, 0));
  src_drawable = g_value_get_object (pika_value_array_index (args, 1));
  src_x = g_value_get_double (pika_value_array_index (args, 2));
  src_y = g_value_get_double (pika_value_array_index (args, 3));
  num_strokes = g_value_get_int (pika_value_array_index (args, 4));
  strokes = pika_value_get_float_array (pika_value_array_index (args, 5));

  if (success)
    {
      PikaPaintOptions *options =
        pika_pdb_context_get_paint_options (PIKA_PDB_CONTEXT (context),
                                            "pika-heal");

      if (options &&
          pika_pdb_item_is_attached (PIKA_ITEM (drawable), NULL,
                                     PIKA_PDB_ITEM_CONTENT, error) &&
          pika_pdb_item_is_not_group (PIKA_ITEM (drawable), error))
        {
          GList *src_drawables;

          options = pika_config_duplicate (PIKA_CONFIG (options));
          src_drawables = g_list_prepend (NULL, src_drawable);

          g_object_set (options,
                        "src-drawables", src_drawables,
                        NULL);

          success = paint_tools_stroke (pika, context, options, drawable,
                                        num_strokes, strokes, error,
                                        "undo-desc", options->paint_info->blurb,
                                        "src-x",     (gint) floor (src_x),
                                        "src-y",     (gint) floor (src_y),
                                        NULL);
          g_list_free (src_drawables);
        }
      else
        success = FALSE;
    }

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

static PikaValueArray *
heal_default_invoker (PikaProcedure         *procedure,
                      Pika                  *pika,
                      PikaContext           *context,
                      PikaProgress          *progress,
                      const PikaValueArray  *args,
                      GError               **error)
{
  gboolean success = TRUE;
  PikaDrawable *drawable;
  gint num_strokes;
  const gdouble *strokes;

  drawable = g_value_get_object (pika_value_array_index (args, 0));
  num_strokes = g_value_get_int (pika_value_array_index (args, 1));
  strokes = pika_value_get_float_array (pika_value_array_index (args, 2));

  if (success)
    {
      PikaPaintOptions *options =
        pika_pdb_context_get_paint_options (PIKA_PDB_CONTEXT (context),
                                            "pika-heal");

      if (options &&
          pika_pdb_item_is_attached (PIKA_ITEM (drawable), NULL,
                                     PIKA_PDB_ITEM_CONTENT, error) &&
          pika_pdb_item_is_not_group (PIKA_ITEM (drawable), error))
        {
          options = pika_config_duplicate (PIKA_CONFIG (options));

          success = paint_tools_stroke (pika, context, options, drawable,
                                        num_strokes, strokes, error,
                                        "undo-desc", options->paint_info->blurb,
                                        NULL);
        }
      else
        success = FALSE;
    }

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

static PikaValueArray *
paintbrush_invoker (PikaProcedure         *procedure,
                    Pika                  *pika,
                    PikaContext           *context,
                    PikaProgress          *progress,
                    const PikaValueArray  *args,
                    GError               **error)
{
  gboolean success = TRUE;
  PikaDrawable *drawable;
  gdouble fade_out;
  gint num_strokes;
  const gdouble *strokes;
  gint method;
  gdouble gradient_length;

  drawable = g_value_get_object (pika_value_array_index (args, 0));
  fade_out = g_value_get_double (pika_value_array_index (args, 1));
  num_strokes = g_value_get_int (pika_value_array_index (args, 2));
  strokes = pika_value_get_float_array (pika_value_array_index (args, 3));
  method = g_value_get_enum (pika_value_array_index (args, 4));
  gradient_length = g_value_get_double (pika_value_array_index (args, 5));

  if (success)
    {
      PikaPaintOptions *options =
        pika_pdb_context_get_paint_options (PIKA_PDB_CONTEXT (context),
                                            "pika-paintbrush");

      if (options &&
          pika_pdb_item_is_attached (PIKA_ITEM (drawable), NULL,
                                     PIKA_PDB_ITEM_CONTENT, error) &&
          pika_pdb_item_is_not_group (PIKA_ITEM (drawable), error))
        {
          PikaDynamics *pdb_dynamics  = PIKA_DYNAMICS (pika_dynamics_new (context, "pdb"));
          PikaDynamics *user_dynamics = pika_context_get_dynamics (context);

          options = pika_config_duplicate (PIKA_CONFIG (options));

          g_object_set (options,
                        "application-mode", method,
                        "fade-length",      MAX (fade_out, gradient_length),
                        NULL);

          if (fade_out > 0)
            {
               PikaDynamicsOutput *opacity_output =
                 pika_dynamics_get_output (pdb_dynamics,
                                           PIKA_DYNAMICS_OUTPUT_OPACITY);

               g_object_set (opacity_output,
                             "use-fade", TRUE,
                             NULL);
            }

          if (gradient_length > 0)
            {
              PikaDynamicsOutput *color_output =
                pika_dynamics_get_output (pdb_dynamics,
                                          PIKA_DYNAMICS_OUTPUT_COLOR);

              g_object_set (color_output,
                            "use-fade", TRUE,
                            NULL);
            }

          pika_context_set_dynamics (context, pdb_dynamics);

          success = paint_tools_stroke (pika, context, options, drawable,
                                        num_strokes, strokes, error,
                                        "undo-desc", options->paint_info->blurb,
                                        NULL);

          pika_context_set_dynamics (context, user_dynamics);

          g_object_unref (pdb_dynamics);
        }
      else
        success = FALSE;
    }

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

static PikaValueArray *
paintbrush_default_invoker (PikaProcedure         *procedure,
                            Pika                  *pika,
                            PikaContext           *context,
                            PikaProgress          *progress,
                            const PikaValueArray  *args,
                            GError               **error)
{
  gboolean success = TRUE;
  PikaDrawable *drawable;
  gint num_strokes;
  const gdouble *strokes;

  drawable = g_value_get_object (pika_value_array_index (args, 0));
  num_strokes = g_value_get_int (pika_value_array_index (args, 1));
  strokes = pika_value_get_float_array (pika_value_array_index (args, 2));

  if (success)
    {
      PikaPaintOptions *options =
        pika_pdb_context_get_paint_options (PIKA_PDB_CONTEXT (context),
                                            "pika-paintbrush");

      if (options &&
          pika_pdb_item_is_attached (PIKA_ITEM (drawable), NULL,
                                     PIKA_PDB_ITEM_CONTENT, error) &&
          pika_pdb_item_is_not_group (PIKA_ITEM (drawable), error))
        {
          options = pika_config_duplicate (PIKA_CONFIG (options));

          success = paint_tools_stroke (pika, context, options, drawable,
                                        num_strokes, strokes, error,
                                        "undo-desc", options->paint_info->blurb,
                                        NULL);
        }
      else
        success = FALSE;
    }

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

static PikaValueArray *
pencil_invoker (PikaProcedure         *procedure,
                Pika                  *pika,
                PikaContext           *context,
                PikaProgress          *progress,
                const PikaValueArray  *args,
                GError               **error)
{
  gboolean success = TRUE;
  PikaDrawable *drawable;
  gint num_strokes;
  const gdouble *strokes;

  drawable = g_value_get_object (pika_value_array_index (args, 0));
  num_strokes = g_value_get_int (pika_value_array_index (args, 1));
  strokes = pika_value_get_float_array (pika_value_array_index (args, 2));

  if (success)
    {
      PikaPaintOptions *options =
        pika_pdb_context_get_paint_options (PIKA_PDB_CONTEXT (context),
                                            "pika-pencil");

      if (options &&
          pika_pdb_item_is_attached (PIKA_ITEM (drawable), NULL,
                                     PIKA_PDB_ITEM_CONTENT, error) &&
          pika_pdb_item_is_not_group (PIKA_ITEM (drawable), error))
        {
          options = pika_config_duplicate (PIKA_CONFIG (options));

          success = paint_tools_stroke (pika, context, options, drawable,
                                        num_strokes, strokes, error,
                                        "undo-desc", options->paint_info->blurb,
                                        NULL);
        }
      else
        success = FALSE;
    }

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

static PikaValueArray *
smudge_invoker (PikaProcedure         *procedure,
                Pika                  *pika,
                PikaContext           *context,
                PikaProgress          *progress,
                const PikaValueArray  *args,
                GError               **error)
{
  gboolean success = TRUE;
  PikaDrawable *drawable;
  gdouble pressure;
  gint num_strokes;
  const gdouble *strokes;

  drawable = g_value_get_object (pika_value_array_index (args, 0));
  pressure = g_value_get_double (pika_value_array_index (args, 1));
  num_strokes = g_value_get_int (pika_value_array_index (args, 2));
  strokes = pika_value_get_float_array (pika_value_array_index (args, 3));

  if (success)
    {
      PikaPaintOptions *options =
        pika_pdb_context_get_paint_options (PIKA_PDB_CONTEXT (context),
                                            "pika-smudge");

      if (options &&
          pika_pdb_item_is_attached (PIKA_ITEM (drawable), NULL,
                                     PIKA_PDB_ITEM_CONTENT, error) &&
          pika_pdb_item_is_not_group (PIKA_ITEM (drawable), error))
        {
          options = pika_config_duplicate (PIKA_CONFIG (options));

          g_object_set (options,
                        "rate", pressure,
                        NULL);

          success = paint_tools_stroke (pika, context, options, drawable,
                                        num_strokes, strokes, error,
                                        "undo-desc", options->paint_info->blurb,
                                        NULL);
        }
      else
        success = FALSE;
    }

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

static PikaValueArray *
smudge_default_invoker (PikaProcedure         *procedure,
                        Pika                  *pika,
                        PikaContext           *context,
                        PikaProgress          *progress,
                        const PikaValueArray  *args,
                        GError               **error)
{
  gboolean success = TRUE;
  PikaDrawable *drawable;
  gint num_strokes;
  const gdouble *strokes;

  drawable = g_value_get_object (pika_value_array_index (args, 0));
  num_strokes = g_value_get_int (pika_value_array_index (args, 1));
  strokes = pika_value_get_float_array (pika_value_array_index (args, 2));

  if (success)
    {
      PikaPaintOptions *options =
        pika_pdb_context_get_paint_options (PIKA_PDB_CONTEXT (context),
                                            "pika-smudge");

      if (options &&
          pika_pdb_item_is_attached (PIKA_ITEM (drawable), NULL,
                                     PIKA_PDB_ITEM_CONTENT, error) &&
          pika_pdb_item_is_not_group (PIKA_ITEM (drawable), error))
        {
          options = pika_config_duplicate (PIKA_CONFIG (options));

          success = paint_tools_stroke (pika, context, options, drawable,
                                        num_strokes, strokes, error,
                                        "undo-desc", options->paint_info->blurb,
                                        NULL);
        }
      else
        success = FALSE;
    }

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

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

  /*
   * pika-airbrush
   */
  procedure = pika_procedure_new (airbrush_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-airbrush");
  pika_procedure_set_static_help (procedure,
                                  "Paint in the current brush with varying pressure. Paint application is time-dependent.",
                                  "This tool simulates the use of an airbrush. Paint pressure represents the relative intensity of the paint application. High pressure results in a thicker layer of paint while low pressure results in a thinner 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_drawable ("drawable",
                                                         "drawable",
                                                         "The affected drawable",
                                                         FALSE,
                                                         PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_double ("pressure",
                                                    "pressure",
                                                    "The pressure of the airbrush strokes",
                                                    0, 100, 0,
                                                    PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_int ("num-strokes",
                                                 "num strokes",
                                                 "Number of stroke control points (count each coordinate as 2 points)",
                                                 2, G_MAXINT32, 2,
                                                 PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               pika_param_spec_float_array ("strokes",
                                                            "strokes",
                                                            "Array of stroke coordinates: { s1.x, s1.y, s2.x, s2.y, ..., sn.x, sn.y }",
                                                            PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

  /*
   * pika-airbrush-default
   */
  procedure = pika_procedure_new (airbrush_default_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-airbrush-default");
  pika_procedure_set_static_help (procedure,
                                  "Paint in the current brush with varying pressure. Paint application is time-dependent.",
                                  "This tool simulates the use of an airbrush. It is similar to 'pika-airbrush' except that the pressure is derived from the airbrush tools options box. It the option has not been set the default for the option will be used.",
                                  NULL);
  pika_procedure_set_static_attribution (procedure,
                                         "Andy Thomas",
                                         "Andy Thomas",
                                         "1999");
  pika_procedure_add_argument (procedure,
                               pika_param_spec_drawable ("drawable",
                                                         "drawable",
                                                         "The affected drawable",
                                                         FALSE,
                                                         PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_int ("num-strokes",
                                                 "num strokes",
                                                 "Number of stroke control points (count each coordinate as 2 points)",
                                                 2, G_MAXINT32, 2,
                                                 PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               pika_param_spec_float_array ("strokes",
                                                            "strokes",
                                                            "Array of stroke coordinates: { s1.x, s1.y, s2.x, s2.y, ..., sn.x, sn.y }",
                                                            PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

  /*
   * pika-clone
   */
  procedure = pika_procedure_new (clone_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-clone");
  pika_procedure_set_static_help (procedure,
                                  "Clone from the source to the dest drawable using the current brush",
                                  "This tool clones (copies) from the source drawable starting at the specified source coordinates to the dest drawable. If the \"clone_type\" argument is set to PATTERN-CLONE, then the current pattern is used as the source and the \"src_drawable\" argument is ignored. Pattern cloning assumes a tileable pattern and mods the sum of the src coordinates and subsequent stroke offsets with the width and height of the pattern. For image cloning, if the sum of the src coordinates and subsequent stroke offsets exceeds the extents of the src drawable, then no paint is transferred. The clone tool is capable of transforming between any image types including RGB->Indexed--although converting from any type to indexed is significantly slower.",
                                  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 affected drawable",
                                                         FALSE,
                                                         PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               pika_param_spec_drawable ("src-drawable",
                                                         "src drawable",
                                                         "The source drawable",
                                                         FALSE,
                                                         PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_enum ("clone-type",
                                                  "clone type",
                                                  "The type of clone",
                                                  PIKA_TYPE_CLONE_TYPE,
                                                  PIKA_CLONE_IMAGE,
                                                  PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_double ("src-x",
                                                    "src x",
                                                    "The x coordinate in the source image",
                                                    -G_MAXDOUBLE, G_MAXDOUBLE, 0,
                                                    PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_double ("src-y",
                                                    "src y",
                                                    "The y coordinate in the source image",
                                                    -G_MAXDOUBLE, G_MAXDOUBLE, 0,
                                                    PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_int ("num-strokes",
                                                 "num strokes",
                                                 "Number of stroke control points (count each coordinate as 2 points)",
                                                 2, G_MAXINT32, 2,
                                                 PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               pika_param_spec_float_array ("strokes",
                                                            "strokes",
                                                            "Array of stroke coordinates: { s1.x, s1.y, s2.x, s2.y, ..., sn.x, sn.y }",
                                                            PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

  /*
   * pika-clone-default
   */
  procedure = pika_procedure_new (clone_default_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-clone-default");
  pika_procedure_set_static_help (procedure,
                                  "Clone from the source to the dest drawable using the current brush",
                                  "This tool clones (copies) from the source drawable starting at the specified source coordinates to the dest drawable. This function performs exactly the same as the 'pika-clone' function except that the tools arguments are obtained from the clones option dialog. It this dialog has not been activated then the dialogs default values will be used.",
                                  NULL);
  pika_procedure_set_static_attribution (procedure,
                                         "Andy Thomas",
                                         "Andy Thomas",
                                         "1999");
  pika_procedure_add_argument (procedure,
                               pika_param_spec_drawable ("drawable",
                                                         "drawable",
                                                         "The affected drawable",
                                                         FALSE,
                                                         PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_int ("num-strokes",
                                                 "num strokes",
                                                 "Number of stroke control points (count each coordinate as 2 points)",
                                                 2, G_MAXINT32, 2,
                                                 PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               pika_param_spec_float_array ("strokes",
                                                            "strokes",
                                                            "Array of stroke coordinates: { s1.x, s1.y, s2.x, s2.y, ..., sn.x, sn.y }",
                                                            PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

  /*
   * pika-convolve
   */
  procedure = pika_procedure_new (convolve_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-convolve");
  pika_procedure_set_static_help (procedure,
                                  "Convolve (Blur, Sharpen) using the current brush.",
                                  "This tool convolves the specified drawable with either a sharpening or blurring kernel. The pressure parameter controls the magnitude of the operation. Like the paintbrush, this tool linearly interpolates between the specified stroke coordinates.",
                                  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 affected drawable",
                                                         FALSE,
                                                         PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_double ("pressure",
                                                    "pressure",
                                                    "The pressure",
                                                    0, 100, 0,
                                                    PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_enum ("convolve-type",
                                                  "convolve type",
                                                  "Convolve type",
                                                  PIKA_TYPE_CONVOLVE_TYPE,
                                                  PIKA_CONVOLVE_BLUR,
                                                  PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_int ("num-strokes",
                                                 "num strokes",
                                                 "Number of stroke control points (count each coordinate as 2 points)",
                                                 2, G_MAXINT32, 2,
                                                 PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               pika_param_spec_float_array ("strokes",
                                                            "strokes",
                                                            "Array of stroke coordinates: { s1.x, s1.y, s2.x, s2.y, ..., sn.x, sn.y }",
                                                            PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

  /*
   * pika-convolve-default
   */
  procedure = pika_procedure_new (convolve_default_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-convolve-default");
  pika_procedure_set_static_help (procedure,
                                  "Convolve (Blur, Sharpen) using the current brush.",
                                  "This tool convolves the specified drawable with either a sharpening or blurring kernel. This function performs exactly the same as the 'pika-convolve' function except that the tools arguments are obtained from the convolve option dialog. It this dialog has not been activated then the dialogs default values will be used.",
                                  NULL);
  pika_procedure_set_static_attribution (procedure,
                                         "Andy Thomas",
                                         "Andy Thomas",
                                         "1999");
  pika_procedure_add_argument (procedure,
                               pika_param_spec_drawable ("drawable",
                                                         "drawable",
                                                         "The affected drawable",
                                                         FALSE,
                                                         PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_int ("num-strokes",
                                                 "num strokes",
                                                 "Number of stroke control points (count each coordinate as 2 points)",
                                                 2, G_MAXINT32, 2,
                                                 PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               pika_param_spec_float_array ("strokes",
                                                            "strokes",
                                                            "Array of stroke coordinates: { s1.x, s1.y, s2.x, s2.y, ..., sn.x, sn.y }",
                                                            PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

  /*
   * pika-dodgeburn
   */
  procedure = pika_procedure_new (dodgeburn_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-dodgeburn");
  pika_procedure_set_static_help (procedure,
                                  "Dodgeburn image with varying exposure.",
                                  "Dodgeburn. More details here later.",
                                  NULL);
  pika_procedure_set_static_attribution (procedure,
                                         "Andy Thomas",
                                         "Andy Thomas",
                                         "1999");
  pika_procedure_add_argument (procedure,
                               pika_param_spec_drawable ("drawable",
                                                         "drawable",
                                                         "The affected drawable",
                                                         FALSE,
                                                         PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_double ("exposure",
                                                    "exposure",
                                                    "The exposure of the strokes",
                                                    0, 100, 0,
                                                    PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_enum ("dodgeburn-type",
                                                  "dodgeburn type",
                                                  "The type either dodge or burn",
                                                  PIKA_TYPE_DODGE_BURN_TYPE,
                                                  PIKA_DODGE_BURN_TYPE_DODGE,
                                                  PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_enum ("dodgeburn-mode",
                                                  "dodgeburn mode",
                                                  "The mode",
                                                  PIKA_TYPE_TRANSFER_MODE,
                                                  PIKA_TRANSFER_SHADOWS,
                                                  PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_int ("num-strokes",
                                                 "num strokes",
                                                 "Number of stroke control points (count each coordinate as 2 points)",
                                                 2, G_MAXINT32, 2,
                                                 PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               pika_param_spec_float_array ("strokes",
                                                            "strokes",
                                                            "Array of stroke coordinates: { s1.x, s1.y, s2.x, s2.y, ..., sn.x, sn.y }",
                                                            PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

  /*
   * pika-dodgeburn-default
   */
  procedure = pika_procedure_new (dodgeburn_default_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-dodgeburn-default");
  pika_procedure_set_static_help (procedure,
                                  "Dodgeburn image with varying exposure. This is the same as the pika_dodgeburn() function except that the exposure, type and mode are taken from the tools option dialog. If the dialog has not been activated then the defaults as used by the dialog will be used.",
                                  "Dodgeburn. More details here later.",
                                  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 affected drawable",
                                                         FALSE,
                                                         PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_int ("num-strokes",
                                                 "num strokes",
                                                 "Number of stroke control points (count each coordinate as 2 points)",
                                                 2, G_MAXINT32, 2,
                                                 PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               pika_param_spec_float_array ("strokes",
                                                            "strokes",
                                                            "Array of stroke coordinates: { s1.x, s1.y, s2.x, s2.y, ..., sn.x, sn.y }",
                                                            PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

  /*
   * pika-eraser
   */
  procedure = pika_procedure_new (eraser_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-eraser");
  pika_procedure_set_static_help (procedure,
                                  "Erase using the current brush.",
                                  "This tool erases using the current brush mask. If the specified drawable contains an alpha channel, then the erased pixels will become transparent. Otherwise, the eraser tool replaces the contents of the drawable with the background color. Like paintbrush, this tool linearly interpolates between the specified stroke coordinates.",
                                  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 affected drawable",
                                                         FALSE,
                                                         PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_int ("num-strokes",
                                                 "num strokes",
                                                 "Number of stroke control points (count each coordinate as 2 points)",
                                                 2, G_MAXINT32, 2,
                                                 PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               pika_param_spec_float_array ("strokes",
                                                            "strokes",
                                                            "Array of stroke coordinates: { s1.x, s1.y, s2.x, s2.y, ..., sn.x, sn.y }",
                                                            PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_enum ("hardness",
                                                  "hardness",
                                                  "How to apply the brush",
                                                  PIKA_TYPE_BRUSH_APPLICATION_MODE,
                                                  PIKA_BRUSH_HARD,
                                                  PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_enum ("method",
                                                  "method",
                                                  "The paint method to use",
                                                  PIKA_TYPE_PAINT_APPLICATION_MODE,
                                                  PIKA_PAINT_CONSTANT,
                                                  PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

  /*
   * pika-eraser-default
   */
  procedure = pika_procedure_new (eraser_default_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-eraser-default");
  pika_procedure_set_static_help (procedure,
                                  "Erase using the current brush.",
                                  "This tool erases using the current brush mask. This function performs exactly the same as the 'pika-eraser' function except that the tools arguments are obtained from the eraser option dialog. It this dialog has not been activated then the dialogs default values will be used.",
                                  NULL);
  pika_procedure_set_static_attribution (procedure,
                                         "Andy Thomas",
                                         "Andy Thomas",
                                         "1999");
  pika_procedure_add_argument (procedure,
                               pika_param_spec_drawable ("drawable",
                                                         "drawable",
                                                         "The affected drawable",
                                                         FALSE,
                                                         PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_int ("num-strokes",
                                                 "num strokes",
                                                 "Number of stroke control points (count each coordinate as 2 points)",
                                                 2, G_MAXINT32, 2,
                                                 PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               pika_param_spec_float_array ("strokes",
                                                            "strokes",
                                                            "Array of stroke coordinates: { s1.x, s1.y, s2.x, s2.y, ..., sn.x, sn.y }",
                                                            PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

  /*
   * pika-heal
   */
  procedure = pika_procedure_new (heal_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-heal");
  pika_procedure_set_static_help (procedure,
                                  "Heal from the source to the dest drawable using the current brush",
                                  "This tool heals the source drawable starting at the specified source coordinates to the dest drawable. For image healing, if the sum of the src coordinates and subsequent stroke offsets exceeds the extents of the src drawable, then no paint is transferred. The healing tool is capable of transforming between any image types except RGB->Indexed.",
                                  NULL);
  pika_procedure_set_static_attribution (procedure,
                                         "Kevin Sookocheff",
                                         "Kevin Sookocheff",
                                         "2006");
  pika_procedure_add_argument (procedure,
                               pika_param_spec_drawable ("drawable",
                                                         "drawable",
                                                         "The affected drawable",
                                                         FALSE,
                                                         PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               pika_param_spec_drawable ("src-drawable",
                                                         "src drawable",
                                                         "The source drawable",
                                                         FALSE,
                                                         PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_double ("src-x",
                                                    "src x",
                                                    "The x coordinate in the source image",
                                                    -G_MAXDOUBLE, G_MAXDOUBLE, 0,
                                                    PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_double ("src-y",
                                                    "src y",
                                                    "The y coordinate in the source image",
                                                    -G_MAXDOUBLE, G_MAXDOUBLE, 0,
                                                    PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_int ("num-strokes",
                                                 "num strokes",
                                                 "Number of stroke control points (count each coordinate as 2 points)",
                                                 2, G_MAXINT32, 2,
                                                 PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               pika_param_spec_float_array ("strokes",
                                                            "strokes",
                                                            "Array of stroke coordinates: { s1.x, s1.y, s2.x, s2.y, ..., sn.x, sn.y }",
                                                            PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

  /*
   * pika-heal-default
   */
  procedure = pika_procedure_new (heal_default_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-heal-default");
  pika_procedure_set_static_help (procedure,
                                  "Heal from the source to the dest drawable using the current brush",
                                  "This tool heals from the source drawable starting at the specified source coordinates to the dest drawable. This function performs exactly the same as the 'pika-heal' function except that the tools arguments are obtained from the healing option dialog. It this dialog has not been activated then the dialogs default values will be used.",
                                  NULL);
  pika_procedure_set_static_attribution (procedure,
                                         "Kevin Sookocheff",
                                         "Kevin Sookocheff",
                                         "2006");
  pika_procedure_add_argument (procedure,
                               pika_param_spec_drawable ("drawable",
                                                         "drawable",
                                                         "The affected drawable",
                                                         FALSE,
                                                         PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_int ("num-strokes",
                                                 "num strokes",
                                                 "Number of stroke control points (count each coordinate as 2 points)",
                                                 2, G_MAXINT32, 2,
                                                 PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               pika_param_spec_float_array ("strokes",
                                                            "strokes",
                                                            "Array of stroke coordinates: { s1.x, s1.y, s2.x, s2.y, ..., sn.x, sn.y }",
                                                            PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

  /*
   * pika-paintbrush
   */
  procedure = pika_procedure_new (paintbrush_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-paintbrush");
  pika_procedure_set_static_help (procedure,
                                  "Paint in the current brush with optional fade out parameter and pull colors from a gradient.",
                                  "This tool is the standard paintbrush. It draws linearly interpolated lines through the specified stroke coordinates. It operates on the specified drawable in the foreground color with the active brush. The 'fade-out' parameter is measured in pixels and allows the brush stroke to linearly fall off. The pressure is set to the maximum at the beginning of the stroke. As the distance of the stroke nears the fade-out value, the pressure will approach zero. The gradient-length is the distance to spread the gradient over. It is measured in pixels. If the gradient-length is 0, no gradient is used.",
                                  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 affected drawable",
                                                         FALSE,
                                                         PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_double ("fade-out",
                                                    "fade out",
                                                    "Fade out parameter",
                                                    0, G_MAXDOUBLE, 0,
                                                    PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_int ("num-strokes",
                                                 "num strokes",
                                                 "Number of stroke control points (count each coordinate as 2 points)",
                                                 2, G_MAXINT32, 2,
                                                 PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               pika_param_spec_float_array ("strokes",
                                                            "strokes",
                                                            "Array of stroke coordinates: { s1.x, s1.y, s2.x, s2.y, ..., sn.x, sn.y }",
                                                            PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_enum ("method",
                                                  "method",
                                                  "The paint method to use",
                                                  PIKA_TYPE_PAINT_APPLICATION_MODE,
                                                  PIKA_PAINT_CONSTANT,
                                                  PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_double ("gradient-length",
                                                    "gradient length",
                                                    "Length of gradient to draw",
                                                    0, G_MAXDOUBLE, 0,
                                                    PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

  /*
   * pika-paintbrush-default
   */
  procedure = pika_procedure_new (paintbrush_default_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-paintbrush-default");
  pika_procedure_set_static_help (procedure,
                                  "Paint in the current brush. The fade out parameter and pull colors from a gradient parameter are set from the paintbrush options dialog. If this dialog has not been activated then the dialog defaults will be used.",
                                  "This tool is similar to the standard paintbrush. It draws linearly interpolated lines through the specified stroke coordinates. It operates on the specified drawable in the foreground color with the active brush. The 'fade-out' parameter is measured in pixels and allows the brush stroke to linearly fall off (value obtained from the option dialog). The pressure is set to the maximum at the beginning of the stroke. As the distance of the stroke nears the fade-out value, the pressure will approach zero. The gradient-length (value obtained from the option dialog) is the distance to spread the gradient over. It is measured in pixels. If the gradient-length is 0, no gradient is used.",
                                  NULL);
  pika_procedure_set_static_attribution (procedure,
                                         "Andy Thomas",
                                         "Andy Thomas",
                                         "1999");
  pika_procedure_add_argument (procedure,
                               pika_param_spec_drawable ("drawable",
                                                         "drawable",
                                                         "The affected drawable",
                                                         FALSE,
                                                         PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_int ("num-strokes",
                                                 "num strokes",
                                                 "Number of stroke control points (count each coordinate as 2 points)",
                                                 2, G_MAXINT32, 2,
                                                 PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               pika_param_spec_float_array ("strokes",
                                                            "strokes",
                                                            "Array of stroke coordinates: { s1.x, s1.y, s2.x, s2.y, ..., sn.x, sn.y }",
                                                            PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

  /*
   * pika-pencil
   */
  procedure = pika_procedure_new (pencil_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-pencil");
  pika_procedure_set_static_help (procedure,
                                  "Paint in the current brush without sub-pixel sampling.",
                                  "This tool is the standard pencil. It draws linearly interpolated lines through the specified stroke coordinates. It operates on the specified drawable in the foreground color with the active brush. The brush mask is treated as though it contains only black and white values. Any value below half is treated as black; any above half, as white.",
                                  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 affected drawable",
                                                         FALSE,
                                                         PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_int ("num-strokes",
                                                 "num strokes",
                                                 "Number of stroke control points (count each coordinate as 2 points)",
                                                 2, G_MAXINT32, 2,
                                                 PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               pika_param_spec_float_array ("strokes",
                                                            "strokes",
                                                            "Array of stroke coordinates: { s1.x, s1.y, s2.x, s2.y, ..., sn.x, sn.y }",
                                                            PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

  /*
   * pika-smudge
   */
  procedure = pika_procedure_new (smudge_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-smudge");
  pika_procedure_set_static_help (procedure,
                                  "Smudge image with varying pressure.",
                                  "This tool simulates a smudge using the current brush. High pressure results in a greater smudge of paint while low pressure results in a lesser smudge.",
                                  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 affected drawable",
                                                         FALSE,
                                                         PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_double ("pressure",
                                                    "pressure",
                                                    "The pressure of the smudge strokes",
                                                    0, 100, 0,
                                                    PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_int ("num-strokes",
                                                 "num strokes",
                                                 "Number of stroke control points (count each coordinate as 2 points)",
                                                 2, G_MAXINT32, 2,
                                                 PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               pika_param_spec_float_array ("strokes",
                                                            "strokes",
                                                            "Array of stroke coordinates: { s1.x, s1.y, s2.x, s2.y, ..., sn.x, sn.y }",
                                                            PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

  /*
   * pika-smudge-default
   */
  procedure = pika_procedure_new (smudge_default_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-smudge-default");
  pika_procedure_set_static_help (procedure,
                                  "Smudge image with varying pressure.",
                                  "This tool simulates a smudge using the current brush. It behaves exactly the same as 'pika-smudge' except that the pressure value is taken from the smudge tool options or the options default if the tools option dialog has not been activated.",
                                  NULL);
  pika_procedure_set_static_attribution (procedure,
                                         "Andy Thomas",
                                         "Andy Thomas",
                                         "1999");
  pika_procedure_add_argument (procedure,
                               pika_param_spec_drawable ("drawable",
                                                         "drawable",
                                                         "The affected drawable",
                                                         FALSE,
                                                         PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               g_param_spec_int ("num-strokes",
                                                 "num strokes",
                                                 "Number of stroke control points (count each coordinate as 2 points)",
                                                 2, G_MAXINT32, 2,
                                                 PIKA_PARAM_READWRITE));
  pika_procedure_add_argument (procedure,
                               pika_param_spec_float_array ("strokes",
                                                            "strokes",
                                                            "Array of stroke coordinates: { s1.x, s1.y, s2.x, s2.y, ..., sn.x, sn.y }",
                                                            PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);
}
