455 lines
15 KiB
Plaintext
455 lines
15 KiB
Plaintext
|
# PIKA - Photo and Image Kooker Application
|
||
|
# Copyright (C) 1995 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/>.
|
||
|
|
||
|
# "Perlized" from C source by Manish Singh <yosh@gimp.org>
|
||
|
|
||
|
sub drawable_edit_clear {
|
||
|
$blurb = 'Clear selected area of drawable.';
|
||
|
|
||
|
$help = <<'HELP';
|
||
|
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.
|
||
|
|
||
|
|
||
|
This procedure is affected by the following context setters:
|
||
|
pika_context_set_background().
|
||
|
HELP
|
||
|
|
||
|
&std_pdb_misc;
|
||
|
|
||
|
@inargs = (
|
||
|
{ name => 'drawable', type => 'drawable',
|
||
|
desc => 'The drawable to clear from' }
|
||
|
);
|
||
|
|
||
|
%invoke = (
|
||
|
code => <<CODE
|
||
|
{
|
||
|
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;
|
||
|
}
|
||
|
CODE
|
||
|
);
|
||
|
}
|
||
|
|
||
|
sub drawable_edit_fill {
|
||
|
$blurb = 'Fill selected area of drawable.';
|
||
|
|
||
|
$help = <<'HELP';
|
||
|
|
||
|
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().
|
||
|
|
||
|
|
||
|
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().
|
||
|
HELP
|
||
|
|
||
|
&std_pdb_misc;
|
||
|
$author .= ' & Raphael Quinet';
|
||
|
$date = '1995-2000';
|
||
|
|
||
|
@inargs = (
|
||
|
{ name => 'drawable', type => 'drawable',
|
||
|
desc => "The drawable to fill to" },
|
||
|
{ name => 'fill_type', type => 'enum PikaFillType',
|
||
|
desc => 'The type of fill' }
|
||
|
);
|
||
|
|
||
|
%invoke = (
|
||
|
code => <<CODE
|
||
|
{
|
||
|
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;
|
||
|
}
|
||
|
CODE
|
||
|
);
|
||
|
}
|
||
|
|
||
|
sub drawable_edit_bucket_fill {
|
||
|
$blurb = <<'BLURB';
|
||
|
Fill the area by a seed fill starting at the specified coordinates.
|
||
|
BLURB
|
||
|
|
||
|
$help = <<'HELP';
|
||
|
This procedure does a seed fill at the specified coordinates, using
|
||
|
various parameters from the current context.
|
||
|
|
||
|
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.
|
||
|
|
||
|
|
||
|
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().
|
||
|
HELP
|
||
|
|
||
|
&mitch_pdb_misc('2018', '2.10');
|
||
|
|
||
|
@inargs = (
|
||
|
{ name => 'drawable', type => 'drawable',
|
||
|
desc => 'The affected drawable' },
|
||
|
{ name => 'fill_type', type => 'enum PikaFillType',
|
||
|
desc => 'The type of fill' },
|
||
|
{ name => 'x', type => 'float',
|
||
|
desc => "The x coordinate of this bucket fill's application." },
|
||
|
{ name => 'y', type => 'float',
|
||
|
desc => "The y coordinate of this bucket fill's application." }
|
||
|
);
|
||
|
|
||
|
%invoke = (
|
||
|
headers => [ qw ("core/pikadrawable-bucket-fill.h") ],
|
||
|
code => <<'CODE'
|
||
|
{
|
||
|
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;
|
||
|
}
|
||
|
CODE
|
||
|
);
|
||
|
}
|
||
|
|
||
|
sub drawable_edit_gradient_fill {
|
||
|
$blurb = <<'BLURB';
|
||
|
Draw a gradient between the starting and ending coordinates with the
|
||
|
specified gradient type.
|
||
|
BLURB
|
||
|
|
||
|
$help = <<'HELP';
|
||
|
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().
|
||
|
|
||
|
|
||
|
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().
|
||
|
HELP
|
||
|
|
||
|
&mitch_pdb_misc('2018', '2.10');
|
||
|
|
||
|
@inargs = (
|
||
|
{ name => 'drawable', type => 'drawable',
|
||
|
desc => 'The affected drawable' },
|
||
|
{ name => 'gradient_type', type => 'enum PikaGradientType',
|
||
|
desc => 'The type of gradient' },
|
||
|
{ name => 'offset', type => '0 <= float',
|
||
|
desc => 'Offset relates to the starting and ending coordinates
|
||
|
specified for the blend. This parameter is mode dependent.' },
|
||
|
{ name => 'supersample', type => 'boolean',
|
||
|
desc => 'Do adaptive supersampling' },
|
||
|
{ name => 'supersample_max_depth', type => '1 <= int32 <= 9',
|
||
|
no_validate => 1,
|
||
|
desc => 'Maximum recursion levels for supersampling' },
|
||
|
{ name => 'supersample_threshold', type => '0 <= float <= 4',
|
||
|
no_validate => 1,
|
||
|
desc => 'Supersampling threshold' },
|
||
|
{ name => 'dither', type => 'boolean',
|
||
|
desc => 'Use dithering to reduce banding' },
|
||
|
{ name => 'x1', type => 'float',
|
||
|
desc => "The x coordinate of this gradient's starting point" },
|
||
|
{ name => 'y1', type => 'float',
|
||
|
desc => "The y coordinate of this gradient's starting point" },
|
||
|
{ name => 'x2', type => 'float',
|
||
|
desc => "The x coordinate of this gradient's ending point" },
|
||
|
{ name => 'y2', type => 'float',
|
||
|
desc => "The y coordinate of this gradient's ending point" }
|
||
|
);
|
||
|
|
||
|
%invoke = (
|
||
|
headers => [ qw("core/pika-gradients.h" "core/pikadrawable-gradient.h") ],
|
||
|
code => <<'CODE'
|
||
|
{
|
||
|
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);
|
||
|
}
|
||
|
}
|
||
|
CODE
|
||
|
);
|
||
|
}
|
||
|
|
||
|
sub drawable_edit_stroke_selection {
|
||
|
$blurb = 'Stroke the current selection';
|
||
|
|
||
|
$help = <<'HELP';
|
||
|
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.
|
||
|
|
||
|
|
||
|
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().
|
||
|
HELP
|
||
|
|
||
|
&std_pdb_misc;
|
||
|
|
||
|
@inargs = (
|
||
|
{ name => 'drawable', type => 'drawable',
|
||
|
desc => 'The drawable to stroke to' }
|
||
|
);
|
||
|
|
||
|
%invoke = (
|
||
|
headers => [ qw("core/pikastrokeoptions.h") ],
|
||
|
code => <<'CODE'
|
||
|
{
|
||
|
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;
|
||
|
}
|
||
|
CODE
|
||
|
);
|
||
|
}
|
||
|
|
||
|
sub drawable_edit_stroke_item {
|
||
|
$blurb = 'Stroke the specified item';
|
||
|
|
||
|
$help = <<'HELP';
|
||
|
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.
|
||
|
|
||
|
|
||
|
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().
|
||
|
HELP
|
||
|
|
||
|
&mitch_pdb_misc('2018', '2.10');
|
||
|
|
||
|
@inargs = (
|
||
|
{ name => 'drawable', type => 'drawable',
|
||
|
desc => 'The drawable to stroke to' },
|
||
|
{ name => 'item', type => 'item',
|
||
|
desc => 'The item to stroke' }
|
||
|
);
|
||
|
|
||
|
%invoke = (
|
||
|
headers => [ qw("core/pikastrokeoptions.h") ],
|
||
|
code => <<'CODE'
|
||
|
{
|
||
|
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;
|
||
|
}
|
||
|
CODE
|
||
|
);
|
||
|
}
|
||
|
|
||
|
|
||
|
@headers = qw("libpikaconfig/pikaconfig.h"
|
||
|
"paint/pikapaintoptions.h"
|
||
|
"core/pika.h"
|
||
|
"core/pikadrawable-edit.h"
|
||
|
"core/pikabuffer.h"
|
||
|
"core/pikaimage.h"
|
||
|
"core/pikaprogress.h"
|
||
|
"pikapdb-utils.h"
|
||
|
"pikapdbcontext.h"
|
||
|
"pika-intl.h");
|
||
|
|
||
|
@procs = qw(drawable_edit_clear
|
||
|
drawable_edit_fill
|
||
|
drawable_edit_bucket_fill
|
||
|
drawable_edit_gradient_fill
|
||
|
drawable_edit_stroke_selection
|
||
|
drawable_edit_stroke_item);
|
||
|
|
||
|
%exports = (app => [@procs], lib => [@procs]);
|
||
|
|
||
|
$desc = 'Drawable edit procedures';
|
||
|
$doc_title = 'pikadrawableedit';
|
||
|
$doc_short_desc = 'Drawable edit functions (clear, fill, gradient, stroke etc.)';
|
||
|
$doc_long_desc = 'Drawable edit functions (clear, fill, gradient, stroke etc.)';
|
||
|
|
||
|
1;
|