2004-11-16 Michael Natterer <mitch@gimp.org> * tools/pdbgen/pdb/drawable_transform.pdb: renamed the new drawable_foo_defaults() functions to drawable_foo_default() to be consistent with paintbrush_default() and friends. * tools/pdbgen/pdb/transform_tools.pdb * libgimp/gimp.def: changed accordingly. * app/pdb/drawable_transform_cmds.c * app/pdb/transform_tools_cmds.c * libgimp/gimpdrawabletransform_pdb.[ch] * libgimp/gimptransformtools_pdb.c: regenerated. * plug-ins/script-fu/scripts/coolmetal-logo.scm * plug-ins/script-fu/scripts/image-structure.scm * plug-ins/script-fu/scripts/text-circle.scm: follow the API change.
386 lines
11 KiB
Text
386 lines
11 KiB
Text
# The GIMP -- an image manipulation program
|
|
# 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 2 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, write to the Free Software
|
|
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
# "Perlized" from C source by Manish Singh <yosh@gimp.org>
|
|
|
|
# Transform Tools
|
|
|
|
# shortcuts
|
|
|
|
sub drawable_arg () {{
|
|
name => 'drawable',
|
|
type => 'drawable',
|
|
desc => 'The affected drawable',
|
|
}}
|
|
|
|
sub drawable_out_arg {
|
|
my $type = shift;
|
|
my $arg = &drawable_arg;
|
|
$arg->{desc} = "The $type drawable";
|
|
$arg->{no_declare} = 1;
|
|
$arg;
|
|
}
|
|
|
|
|
|
# The defs
|
|
|
|
sub flip {
|
|
&std_pdb_deprecated ('gimp_drawable_transform_flip_simple');
|
|
|
|
@inargs = (
|
|
&drawable_arg,
|
|
{ name => 'flip_type', type => &std_orientation_enum,
|
|
desc => 'Type of flip: %%desc%%' }
|
|
);
|
|
|
|
@outargs = ( &drawable_out_arg('flipped') );
|
|
|
|
%invoke = (
|
|
code => <<'CODE'
|
|
{
|
|
gint x, y, width, height;
|
|
|
|
success = gimp_item_is_attached (GIMP_ITEM (drawable));
|
|
|
|
if (success &&
|
|
gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height))
|
|
{
|
|
success = gimp_drawable_transform_flip (drawable, context,
|
|
flip_type, TRUE, 0.0, FALSE);
|
|
}
|
|
}
|
|
CODE
|
|
);
|
|
}
|
|
|
|
sub perspective {
|
|
&std_pdb_deprecated ('gimp_drawable_transform_perspective_default');
|
|
|
|
@inargs = (
|
|
&drawable_arg,
|
|
{ name => 'interpolation', type => 'boolean',
|
|
desc => 'Whether to use interpolation' }
|
|
);
|
|
|
|
my $pos = 0;
|
|
foreach $where (qw(upper-left upper-right lower-left lower-right)) {
|
|
foreach (qw(x y)) {
|
|
push @inargs,
|
|
{ name => "$_$pos", type => 'float',
|
|
desc => "The new $_ coordinate of $where corner of original
|
|
bounding box",
|
|
alias => "trans_info[\U$_\E$pos]", no_declare => 1 }
|
|
}
|
|
$pos++;
|
|
}
|
|
|
|
@outargs = ( &drawable_out_arg('newly mapped') );
|
|
|
|
%invoke = (
|
|
vars => [ 'gdouble trans_info[8]' ],
|
|
code => <<'CODE'
|
|
{
|
|
gint x, y, width, height;
|
|
|
|
success = gimp_item_is_attached (GIMP_ITEM (drawable));
|
|
|
|
if (success &&
|
|
gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height))
|
|
{
|
|
GimpMatrix3 matrix;
|
|
GimpInterpolationType interpolation_type = GIMP_INTERPOLATION_NONE;
|
|
|
|
/* Assemble the transformation matrix */
|
|
gimp_transform_matrix_perspective (x, y, width, height,
|
|
trans_info[X0], trans_info[Y0],
|
|
trans_info[X1], trans_info[Y1],
|
|
trans_info[X2], trans_info[Y2],
|
|
trans_info[X3], trans_info[Y3],
|
|
&matrix);
|
|
|
|
if (interpolation)
|
|
interpolation_type = gimp->config->interpolation_type;
|
|
|
|
if (progress)
|
|
gimp_progress_start (progress, _("Perspective..."), FALSE);
|
|
|
|
/* Perspective the selection */
|
|
success = gimp_drawable_transform_affine (drawable, context,
|
|
&matrix,
|
|
GIMP_TRANSFORM_FORWARD,
|
|
interpolation_type, TRUE, 3,
|
|
FALSE, progress);
|
|
|
|
if (progress)
|
|
gimp_progress_end (progress);
|
|
}
|
|
}
|
|
CODE
|
|
);
|
|
}
|
|
|
|
sub rotate {
|
|
&std_pdb_deprecated ('gimp_drawable_transform_rotate_default');
|
|
|
|
@inargs = (
|
|
&drawable_arg,
|
|
{ name => 'interpolation', type => 'boolean',
|
|
desc => 'Whether to use interpolation' },
|
|
{ name => 'angle', type => 'float',
|
|
desc => 'The angle of rotation (radians)' }
|
|
);
|
|
|
|
@outargs = ( &drawable_out_arg('rotated') );
|
|
|
|
%invoke = (
|
|
code => <<'CODE'
|
|
{
|
|
gint x, y, width, height;
|
|
|
|
success = gimp_item_is_attached (GIMP_ITEM (drawable));
|
|
|
|
if (success &&
|
|
gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height))
|
|
{
|
|
GimpMatrix3 matrix;
|
|
GimpInterpolationType interpolation_type = GIMP_INTERPOLATION_NONE;
|
|
|
|
/* Assemble the transformation matrix */
|
|
gimp_transform_matrix_rotate (x, y, width, height,
|
|
angle, &matrix);
|
|
|
|
if (interpolation)
|
|
interpolation_type = gimp->config->interpolation_type;
|
|
|
|
if (progress)
|
|
gimp_progress_start (progress, _("Rotating..."), FALSE);
|
|
|
|
/* Rotate the selection */
|
|
success = gimp_drawable_transform_affine (drawable, context,
|
|
&matrix,
|
|
GIMP_TRANSFORM_FORWARD,
|
|
interpolation_type, FALSE, 3,
|
|
FALSE, progress);
|
|
|
|
if (progress)
|
|
gimp_progress_end (progress);
|
|
}
|
|
}
|
|
CODE
|
|
);
|
|
}
|
|
|
|
sub scale {
|
|
&std_pdb_deprecated ('gimp_drawable_transform_scale_default');
|
|
|
|
@inargs = (
|
|
&drawable_arg,
|
|
{ name => 'interpolation', type => 'boolean',
|
|
desc => 'Whether to use interpolation' }
|
|
);
|
|
|
|
my $pos = 0;
|
|
foreach $where (qw(upper-left lower-right)) {
|
|
foreach (qw(x y)) {
|
|
push @inargs,
|
|
{ name => "$_$pos", type => 'float',
|
|
desc => "The new $_ coordinate of $where corner of newly
|
|
scaled region",
|
|
alias => "trans_info[\U$_\E$pos]", no_declare => 1 }
|
|
}
|
|
$pos++;
|
|
}
|
|
|
|
@outargs = ( &drawable_out_arg('scaled') );
|
|
|
|
%invoke = (
|
|
vars => [ 'gdouble trans_info[4]' ],
|
|
code => <<'CODE'
|
|
{
|
|
gint x, y, width, height;
|
|
|
|
success = (gimp_item_is_attached (GIMP_ITEM (drawable)) &&
|
|
trans_info[X0] < trans_info[X1] &&
|
|
trans_info[Y0] < trans_info[X1]);
|
|
|
|
if (success &&
|
|
gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height))
|
|
{
|
|
GimpMatrix3 matrix;
|
|
GimpInterpolationType interpolation_type = GIMP_INTERPOLATION_NONE;
|
|
|
|
/* Assemble the transformation matrix */
|
|
gimp_transform_matrix_scale (x, y, width, height,
|
|
trans_info[X0],
|
|
trans_info[Y0],
|
|
trans_info[X1] - trans_info[X0],
|
|
trans_info[Y1] - trans_info[Y0],
|
|
&matrix);
|
|
|
|
if (interpolation)
|
|
interpolation_type = gimp->config->interpolation_type;
|
|
|
|
if (progress)
|
|
gimp_progress_start (progress, _("Scaling..."), FALSE);
|
|
|
|
/* Scale the selection */
|
|
success = gimp_drawable_transform_affine (drawable, context,
|
|
&matrix,
|
|
GIMP_TRANSFORM_FORWARD,
|
|
interpolation_type, TRUE, 3,
|
|
FALSE, progress);
|
|
|
|
if (progress)
|
|
gimp_progress_end (progress);
|
|
}
|
|
}
|
|
CODE
|
|
);
|
|
}
|
|
|
|
sub shear {
|
|
&std_pdb_deprecated ('gimp_drawable_transform_shear_default');
|
|
|
|
@inargs = (
|
|
&drawable_arg,
|
|
{ name => 'interpolation', type => 'boolean',
|
|
desc => 'Whether to use interpolation' },
|
|
{ name => 'shear_type', type => &std_orientation_enum,
|
|
desc => 'Type of shear: %%desc%%' },
|
|
{ name => 'magnitude', type => 'float',
|
|
desc => 'The magnitude of the shear' }
|
|
);
|
|
|
|
@outargs = ( &drawable_out_arg('sheared') );
|
|
|
|
%invoke = (
|
|
code => <<'CODE'
|
|
{
|
|
gint x, y, width, height;
|
|
|
|
success = gimp_item_is_attached (GIMP_ITEM (drawable));
|
|
|
|
if (success &&
|
|
gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height))
|
|
{
|
|
GimpMatrix3 matrix;
|
|
GimpInterpolationType interpolation_type = GIMP_INTERPOLATION_NONE;
|
|
|
|
/* Assemble the transformation matrix */
|
|
gimp_transform_matrix_shear (x, y, width, height,
|
|
shear_type, magnitude,
|
|
&matrix);
|
|
|
|
if (interpolation)
|
|
interpolation_type = gimp->config->interpolation_type;
|
|
|
|
if (progress)
|
|
gimp_progress_start (progress, _("Shearing..."), FALSE);
|
|
|
|
/* Shear the selection */
|
|
success = gimp_drawable_transform_affine (drawable, context,
|
|
&matrix,
|
|
GIMP_TRANSFORM_FORWARD,
|
|
interpolation_type, FALSE, 3,
|
|
FALSE, progress);
|
|
|
|
if (progress)
|
|
gimp_progress_end (progress);
|
|
}
|
|
}
|
|
CODE
|
|
);
|
|
}
|
|
|
|
sub transform_2d {
|
|
&std_pdb_deprecated ('gimp_drawable_transform_2d_default');
|
|
|
|
@inargs = (
|
|
&drawable_arg,
|
|
{ name => 'interpolation', type => 'boolean',
|
|
desc => 'Whether to use interpolation' },
|
|
{ name => 'source_x', type => 'float',
|
|
desc => 'X coordinate of the transformation center' },
|
|
{ name => 'source_y', type => 'float',
|
|
desc => 'Y coordinate of the transformation center' },
|
|
{ name => 'scale_x', type => 'float',
|
|
desc => 'Amount to scale in x direction' },
|
|
{ name => 'scale_y', type => 'float',
|
|
desc => 'Amount to scale in y direction' },
|
|
{ name => 'angle', type => 'float',
|
|
desc => 'The angle of rotation (radians)' },
|
|
{ name => 'dest_x', type => 'float',
|
|
desc => 'X coordinate of where the centre goes' },
|
|
{ name => 'dest_y', type => 'float',
|
|
desc => 'Y coordinate of where the centre goes' }
|
|
);
|
|
|
|
@outargs = ( &drawable_out_arg('transformed') );
|
|
|
|
%invoke = (
|
|
code => <<'CODE'
|
|
{
|
|
gint x, y, width, height;
|
|
|
|
success = gimp_item_is_attached (GIMP_ITEM (drawable));
|
|
|
|
if (success &&
|
|
gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height))
|
|
{
|
|
GimpMatrix3 matrix;
|
|
GimpInterpolationType interpolation_type = GIMP_INTERPOLATION_NONE;
|
|
|
|
/* Assemble the transformation matrix */
|
|
gimp_matrix3_identity (&matrix);
|
|
gimp_matrix3_translate (&matrix, -source_x, -source_y);
|
|
gimp_matrix3_scale (&matrix, scale_x, scale_y);
|
|
gimp_matrix3_rotate (&matrix, angle);
|
|
gimp_matrix3_translate (&matrix, dest_x, dest_y);
|
|
|
|
if (interpolation)
|
|
interpolation_type = gimp->config->interpolation_type;
|
|
|
|
if (progress)
|
|
gimp_progress_start (progress, _("2D Transform..."), FALSE);
|
|
|
|
/* Transform the selection */
|
|
success = gimp_drawable_transform_affine (drawable, context,
|
|
&matrix, GIMP_TRANSFORM_FORWARD,
|
|
interpolation_type, TRUE, 3,
|
|
FALSE, progress);
|
|
|
|
if (progress)
|
|
gimp_progress_end (progress);
|
|
}
|
|
}
|
|
CODE
|
|
);
|
|
}
|
|
|
|
@headers = qw("libgimpmath/gimpmath.h" "config/gimpcoreconfig.h"
|
|
"core/gimp.h" "core/gimp-transform-utils.h" "core/gimpimage.h"
|
|
"core/gimpdrawable.h" "core/gimpdrawable-transform.h"
|
|
"core/gimpprogress.h"
|
|
"gimp-intl.h");
|
|
|
|
@procs = qw(flip perspective rotate scale shear transform_2d);
|
|
|
|
%exports = (app => [@procs], lib => [@procs]);
|
|
|
|
$desc = 'Transform Tool procedures';
|
|
|
|
1;
|