PIKApp/app/pdb/drawable-edit-cmds.c

631 lines
31 KiB
C

/* 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 "libpikabase/pikabase.h"
#include "pdb-types.h"
#include "core/pika-gradients.h"
#include "core/pika.h"
#include "core/pikabuffer.h"
#include "core/pikadrawable-bucket-fill.h"
#include "core/pikadrawable-edit.h"
#include "core/pikadrawable-gradient.h"
#include "core/pikadrawable.h"
#include "core/pikaimage.h"
#include "core/pikaitem.h"
#include "core/pikaparamspecs.h"
#include "core/pikaprogress.h"
#include "core/pikastrokeoptions.h"
#include "paint/pikapaintoptions.h"
#include "pikapdb.h"
#include "pikapdb-utils.h"
#include "pikapdbcontext.h"
#include "pikaprocedure.h"
#include "internal-procs.h"
#include "pika-intl.h"
static PikaValueArray *
drawable_edit_clear_invoker (PikaProcedure *procedure,
Pika *pika,
PikaContext *context,
PikaProgress *progress,
const PikaValueArray *args,
GError **error)
{
gboolean success = TRUE;
PikaDrawable *drawable;
drawable = g_value_get_object (pika_value_array_index (args, 0));
if (success)
{
if (pika_pdb_item_is_attached (PIKA_ITEM (drawable), NULL,
PIKA_PDB_ITEM_CONTENT, error) &&
pika_pdb_item_is_not_group (PIKA_ITEM (drawable), error))
{
pika_drawable_edit_clear (drawable, context);
}
else
success = FALSE;
}
return pika_procedure_get_return_values (procedure, success,
error ? *error : NULL);
}
static PikaValueArray *
drawable_edit_fill_invoker (PikaProcedure *procedure,
Pika *pika,
PikaContext *context,
PikaProgress *progress,
const PikaValueArray *args,
GError **error)
{
gboolean success = TRUE;
PikaDrawable *drawable;
gint fill_type;
drawable = g_value_get_object (pika_value_array_index (args, 0));
fill_type = g_value_get_enum (pika_value_array_index (args, 1));
if (success)
{
if (pika_pdb_item_is_attached (PIKA_ITEM (drawable), NULL,
PIKA_PDB_ITEM_CONTENT, error) &&
pika_pdb_item_is_not_group (PIKA_ITEM (drawable), error))
{
PikaFillOptions *options = pika_fill_options_new (pika, NULL, FALSE);
pika_context_set_opacity (PIKA_CONTEXT (options),
pika_context_get_opacity (context));
pika_context_set_paint_mode (PIKA_CONTEXT (options),
pika_context_get_paint_mode (context));
if (pika_fill_options_set_by_fill_type (options, context,
fill_type, error))
{
pika_drawable_edit_fill (drawable, options, NULL);
}
else
success = FALSE;
g_object_unref (options);
}
else
success = FALSE;
}
return pika_procedure_get_return_values (procedure, success,
error ? *error : NULL);
}
static PikaValueArray *
drawable_edit_bucket_fill_invoker (PikaProcedure *procedure,
Pika *pika,
PikaContext *context,
PikaProgress *progress,
const PikaValueArray *args,
GError **error)
{
gboolean success = TRUE;
PikaDrawable *drawable;
gint fill_type;
gdouble x;
gdouble y;
drawable = g_value_get_object (pika_value_array_index (args, 0));
fill_type = g_value_get_enum (pika_value_array_index (args, 1));
x = g_value_get_double (pika_value_array_index (args, 2));
y = g_value_get_double (pika_value_array_index (args, 3));
if (success)
{
if (pika_pdb_item_is_attached (PIKA_ITEM (drawable), NULL,
PIKA_PDB_ITEM_CONTENT, error) &&
pika_pdb_item_is_not_group (PIKA_ITEM (drawable), error))
{
PikaFillOptions *options = pika_fill_options_new (pika, NULL, FALSE);
pika_context_set_opacity (PIKA_CONTEXT (options),
pika_context_get_opacity (context));
pika_context_set_paint_mode (PIKA_CONTEXT (options),
pika_context_get_paint_mode (context));
pika_fill_options_set_antialias (options,
PIKA_PDB_CONTEXT (context)->antialias);
if (pika_fill_options_set_by_fill_type (options, context,
fill_type, error))
{
pika_drawable_bucket_fill (drawable, options,
PIKA_PDB_CONTEXT (context)->sample_transparent,
PIKA_PDB_CONTEXT (context)->sample_criterion,
PIKA_PDB_CONTEXT (context)->sample_threshold,
PIKA_PDB_CONTEXT (context)->sample_merged,
PIKA_PDB_CONTEXT (context)->diagonal_neighbors,
x, y);
}
else
success = FALSE;
g_object_unref (options);
}
else
success = FALSE;
}
return pika_procedure_get_return_values (procedure, success,
error ? *error : NULL);
}
static PikaValueArray *
drawable_edit_gradient_fill_invoker (PikaProcedure *procedure,
Pika *pika,
PikaContext *context,
PikaProgress *progress,
const PikaValueArray *args,
GError **error)
{
gboolean success = TRUE;
PikaDrawable *drawable;
gint gradient_type;
gdouble offset;
gboolean supersample;
gint supersample_max_depth;
gdouble supersample_threshold;
gboolean dither;
gdouble x1;
gdouble y1;
gdouble x2;
gdouble y2;
drawable = g_value_get_object (pika_value_array_index (args, 0));
gradient_type = g_value_get_enum (pika_value_array_index (args, 1));
offset = g_value_get_double (pika_value_array_index (args, 2));
supersample = g_value_get_boolean (pika_value_array_index (args, 3));
supersample_max_depth = g_value_get_int (pika_value_array_index (args, 4));
supersample_threshold = g_value_get_double (pika_value_array_index (args, 5));
dither = g_value_get_boolean (pika_value_array_index (args, 6));
x1 = g_value_get_double (pika_value_array_index (args, 7));
y1 = g_value_get_double (pika_value_array_index (args, 8));
x2 = g_value_get_double (pika_value_array_index (args, 9));
y2 = g_value_get_double (pika_value_array_index (args, 10));
if (success)
{
success = (pika_pdb_item_is_attached (PIKA_ITEM (drawable), NULL,
PIKA_PDB_ITEM_CONTENT, error) &&
pika_pdb_item_is_not_group (PIKA_ITEM (drawable), error));
if (success)
{
if (supersample)
{
if (supersample_max_depth < 1 || supersample_max_depth > 9)
success = FALSE;
if (supersample_threshold < 0.0 || supersample_threshold > 4.0)
success = FALSE;
}
else
{
supersample_max_depth = CLAMP (supersample_max_depth, 1, 9);
supersample_threshold = CLAMP (supersample_threshold, 0.0, 4.0);
}
}
if (success)
{
/* all options should have the same value, so pick a random one */
PikaPaintOptions *options =
pika_pdb_context_get_paint_options (PIKA_PDB_CONTEXT (context),
"pika-paintbrush");
if (progress)
pika_progress_start (progress, FALSE, _("Gradient"));
pika_drawable_gradient (drawable,
context,
pika_context_get_gradient (context),
PIKA_PDB_CONTEXT (context)->distance_metric,
pika_context_get_paint_mode (context),
gradient_type,
pika_context_get_opacity (context),
offset,
options->gradient_options->gradient_repeat,
options->gradient_options->gradient_reverse,
options->gradient_options->gradient_blend_color_space,
supersample,
supersample_max_depth,
supersample_threshold,
dither,
x1, y1, x2, y2,
progress);
if (progress)
pika_progress_end (progress);
}
}
return pika_procedure_get_return_values (procedure, success,
error ? *error : NULL);
}
static PikaValueArray *
drawable_edit_stroke_selection_invoker (PikaProcedure *procedure,
Pika *pika,
PikaContext *context,
PikaProgress *progress,
const PikaValueArray *args,
GError **error)
{
gboolean success = TRUE;
PikaDrawable *drawable;
drawable = g_value_get_object (pika_value_array_index (args, 0));
if (success)
{
if (pika_pdb_item_is_attached (PIKA_ITEM (drawable), NULL,
PIKA_PDB_ITEM_CONTENT, error) &&
pika_pdb_item_is_not_group (PIKA_ITEM (drawable), error))
{
PikaImage *image = pika_item_get_image (PIKA_ITEM (drawable));
PikaStrokeOptions *options;
PikaPaintOptions *paint_options;
GList *drawables = g_list_prepend (NULL, drawable);
options = pika_pdb_context_get_stroke_options (PIKA_PDB_CONTEXT (context));
paint_options =
pika_pdb_context_get_paint_options (PIKA_PDB_CONTEXT (context), NULL);
paint_options = pika_config_duplicate (PIKA_CONFIG (paint_options));
success = pika_item_stroke (PIKA_ITEM (pika_image_get_mask (image)),
drawables, context, options, paint_options,
TRUE, progress, error);
g_object_unref (paint_options);
g_list_free (drawables);
}
else
success = FALSE;
}
return pika_procedure_get_return_values (procedure, success,
error ? *error : NULL);
}
static PikaValueArray *
drawable_edit_stroke_item_invoker (PikaProcedure *procedure,
Pika *pika,
PikaContext *context,
PikaProgress *progress,
const PikaValueArray *args,
GError **error)
{
gboolean success = TRUE;
PikaDrawable *drawable;
PikaItem *item;
drawable = g_value_get_object (pika_value_array_index (args, 0));
item = g_value_get_object (pika_value_array_index (args, 1));
if (success)
{
if (pika_pdb_item_is_attached (PIKA_ITEM (drawable), NULL,
PIKA_PDB_ITEM_CONTENT, error) &&
pika_pdb_item_is_not_group (PIKA_ITEM (drawable), error) &&
pika_pdb_item_is_attached (item,
pika_item_get_image (PIKA_ITEM (drawable)),
0, error))
{
PikaStrokeOptions *options;
PikaPaintOptions *paint_options;
GList *drawables = g_list_prepend (NULL, drawable);
options = pika_pdb_context_get_stroke_options (PIKA_PDB_CONTEXT (context));
paint_options =
pika_pdb_context_get_paint_options (PIKA_PDB_CONTEXT (context), NULL);
paint_options = pika_config_duplicate (PIKA_CONFIG (paint_options));
success = pika_item_stroke (item, drawables,
context, options, paint_options,
TRUE, progress, error);
g_object_unref (paint_options);
g_list_free (drawables);
}
else
success = FALSE;
}
return pika_procedure_get_return_values (procedure, success,
error ? *error : NULL);
}
void
register_drawable_edit_procs (PikaPDB *pdb)
{
PikaProcedure *procedure;
/*
* pika-drawable-edit-clear
*/
procedure = pika_procedure_new (drawable_edit_clear_invoker);
pika_object_set_static_name (PIKA_OBJECT (procedure),
"pika-drawable-edit-clear");
pika_procedure_set_static_help (procedure,
"Clear selected area of drawable.",
"This procedure clears the specified drawable. If the drawable has an alpha channel, the cleared pixels will become transparent. If the drawable does not have an alpha channel, cleared pixels will be set to the background color. This procedure only affects regions within a selection if there is a selection active.\n"
"\n"
"This procedure is affected by the following context setters: 'pika-context-set-background'.",
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 drawable to clear from",
FALSE,
PIKA_PARAM_READWRITE));
pika_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* pika-drawable-edit-fill
*/
procedure = pika_procedure_new (drawable_edit_fill_invoker);
pika_object_set_static_name (PIKA_OBJECT (procedure),
"pika-drawable-edit-fill");
pika_procedure_set_static_help (procedure,
"Fill selected area of drawable.",
"This procedure fills the specified drawable according to fill mode. This procedure only affects regions within a selection if there is a selection active. If you want to fill the whole drawable, regardless of the selection, use 'pika-drawable-fill'.\n"
"\n"
"This procedure is affected by the following context setters: 'pika-context-set-opacity', 'pika-context-set-paint-mode', 'pika-context-set-foreground', 'pika-context-set-background', 'pika-context-set-pattern'.",
NULL);
pika_procedure_set_static_attribution (procedure,
"Spencer Kimball & Peter Mattis & Raphael Quinet",
"Spencer Kimball & Peter Mattis",
"1995-2000");
pika_procedure_add_argument (procedure,
pika_param_spec_drawable ("drawable",
"drawable",
"The drawable to fill to",
FALSE,
PIKA_PARAM_READWRITE));
pika_procedure_add_argument (procedure,
g_param_spec_enum ("fill-type",
"fill type",
"The type of fill",
PIKA_TYPE_FILL_TYPE,
PIKA_FILL_FOREGROUND,
PIKA_PARAM_READWRITE));
pika_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* pika-drawable-edit-bucket-fill
*/
procedure = pika_procedure_new (drawable_edit_bucket_fill_invoker);
pika_object_set_static_name (PIKA_OBJECT (procedure),
"pika-drawable-edit-bucket-fill");
pika_procedure_set_static_help (procedure,
"Fill the area by a seed fill starting at the specified coordinates.",
"This procedure does a seed fill at the specified coordinates, using various parameters from the current context.\n"
"In the case of merged sampling, the x and y coordinates are relative to the image's origin; otherwise, they are relative to the drawable's origin.\n"
"\n"
"This procedure is affected by the following context setters: 'pika-context-set-opacity', 'pika-context-set-paint-mode', 'pika-context-set-foreground', 'pika-context-set-background', 'pika-context-set-pattern', 'pika-context-set-sample-threshold', 'pika-context-set-sample-merged', 'pika-context-set-sample-criterion', 'pika-context-set-diagonal-neighbors', 'pika-context-set-antialias'.",
NULL);
pika_procedure_set_static_attribution (procedure,
"Michael Natterer <mitch@gimp.org>",
"Michael Natterer",
"2018");
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_enum ("fill-type",
"fill type",
"The type of fill",
PIKA_TYPE_FILL_TYPE,
PIKA_FILL_FOREGROUND,
PIKA_PARAM_READWRITE));
pika_procedure_add_argument (procedure,
g_param_spec_double ("x",
"x",
"The x coordinate of this bucket fill's application.",
-G_MAXDOUBLE, G_MAXDOUBLE, 0,
PIKA_PARAM_READWRITE));
pika_procedure_add_argument (procedure,
g_param_spec_double ("y",
"y",
"The y coordinate of this bucket fill's application.",
-G_MAXDOUBLE, G_MAXDOUBLE, 0,
PIKA_PARAM_READWRITE));
pika_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* pika-drawable-edit-gradient-fill
*/
procedure = pika_procedure_new (drawable_edit_gradient_fill_invoker);
pika_object_set_static_name (PIKA_OBJECT (procedure),
"pika-drawable-edit-gradient-fill");
pika_procedure_set_static_help (procedure,
"Draw a gradient between the starting and ending coordinates with the specified gradient type.",
"This tool requires information on the gradient type. It creates the specified variety of gradient using the starting and ending coordinates as defined for each gradient type. For shapeburst gradient types, the context's distance metric is also relevant and can be updated with 'pika-context-set-distance-metric'.\n"
"\n"
"This procedure is affected by the following context setters: 'pika-context-set-opacity', 'pika-context-set-paint-mode', 'pika-context-set-foreground', 'pika-context-set-background', 'pika-context-set-gradient' and all gradient property settings, 'pika-context-set-distance-metric'.",
NULL);
pika_procedure_set_static_attribution (procedure,
"Michael Natterer <mitch@gimp.org>",
"Michael Natterer",
"2018");
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_enum ("gradient-type",
"gradient type",
"The type of gradient",
PIKA_TYPE_GRADIENT_TYPE,
PIKA_GRADIENT_LINEAR,
PIKA_PARAM_READWRITE));
pika_procedure_add_argument (procedure,
g_param_spec_double ("offset",
"offset",
"Offset relates to the starting and ending coordinates specified for the blend. This parameter is mode dependent.",
0, G_MAXDOUBLE, 0,
PIKA_PARAM_READWRITE));
pika_procedure_add_argument (procedure,
g_param_spec_boolean ("supersample",
"supersample",
"Do adaptive supersampling",
FALSE,
PIKA_PARAM_READWRITE));
pika_procedure_add_argument (procedure,
g_param_spec_int ("supersample-max-depth",
"supersample max depth",
"Maximum recursion levels for supersampling",
1, 9, 1,
PIKA_PARAM_READWRITE | PIKA_PARAM_NO_VALIDATE));
pika_procedure_add_argument (procedure,
g_param_spec_double ("supersample-threshold",
"supersample threshold",
"Supersampling threshold",
0, 4, 0,
PIKA_PARAM_READWRITE | PIKA_PARAM_NO_VALIDATE));
pika_procedure_add_argument (procedure,
g_param_spec_boolean ("dither",
"dither",
"Use dithering to reduce banding",
FALSE,
PIKA_PARAM_READWRITE));
pika_procedure_add_argument (procedure,
g_param_spec_double ("x1",
"x1",
"The x coordinate of this gradient's starting point",
-G_MAXDOUBLE, G_MAXDOUBLE, 0,
PIKA_PARAM_READWRITE));
pika_procedure_add_argument (procedure,
g_param_spec_double ("y1",
"y1",
"The y coordinate of this gradient's starting point",
-G_MAXDOUBLE, G_MAXDOUBLE, 0,
PIKA_PARAM_READWRITE));
pika_procedure_add_argument (procedure,
g_param_spec_double ("x2",
"x2",
"The x coordinate of this gradient's ending point",
-G_MAXDOUBLE, G_MAXDOUBLE, 0,
PIKA_PARAM_READWRITE));
pika_procedure_add_argument (procedure,
g_param_spec_double ("y2",
"y2",
"The y coordinate of this gradient's ending point",
-G_MAXDOUBLE, G_MAXDOUBLE, 0,
PIKA_PARAM_READWRITE));
pika_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* pika-drawable-edit-stroke-selection
*/
procedure = pika_procedure_new (drawable_edit_stroke_selection_invoker);
pika_object_set_static_name (PIKA_OBJECT (procedure),
"pika-drawable-edit-stroke-selection");
pika_procedure_set_static_help (procedure,
"Stroke the current selection",
"This procedure strokes the current selection, painting along the selection boundary with the active paint method and brush, or using a plain line with configurable properties. The paint is applied to the specified drawable regardless of the active selection.\n"
"\n"
"This procedure is affected by the following context setters: 'pika-context-set-opacity', 'pika-context-set-paint-mode', 'pika-context-set-paint-method', 'pika-context-set-stroke-method', 'pika-context-set-foreground', 'pika-context-set-brush' and all brush property settings, 'pika-context-set-gradient' and all gradient property settings, 'pika-context-set-line-width' and all line property settings, 'pika-context-set-antialias'.",
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 drawable to stroke to",
FALSE,
PIKA_PARAM_READWRITE));
pika_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* pika-drawable-edit-stroke-item
*/
procedure = pika_procedure_new (drawable_edit_stroke_item_invoker);
pika_object_set_static_name (PIKA_OBJECT (procedure),
"pika-drawable-edit-stroke-item");
pika_procedure_set_static_help (procedure,
"Stroke the specified item",
"This procedure strokes the specified item, painting along its outline (e.g. along a path, or along a channel's boundary), with the active paint method and brush, or using a plain line with configurable properties.\n"
"\n"
"This procedure is affected by the following context setters: 'pika-context-set-opacity', 'pika-context-set-paint-mode', 'pika-context-set-paint-method', 'pika-context-set-stroke-method', 'pika-context-set-foreground', 'pika-context-set-brush' and all brush property settings, 'pika-context-set-gradient' and all gradient property settings, 'pika-context-set-line-width' and all line property settings, 'pika-context-set-antialias'.",
NULL);
pika_procedure_set_static_attribution (procedure,
"Michael Natterer <mitch@gimp.org>",
"Michael Natterer",
"2018");
pika_procedure_add_argument (procedure,
pika_param_spec_drawable ("drawable",
"drawable",
"The drawable to stroke to",
FALSE,
PIKA_PARAM_READWRITE));
pika_procedure_add_argument (procedure,
pika_param_spec_item ("item",
"item",
"The item to stroke",
FALSE,
PIKA_PARAM_READWRITE));
pika_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
}