2006-12-09 13:33:38 -08:00
|
|
|
# GIMP - The GNU Image Manipulation Program
|
1998-10-23 22:21:56 -07:00
|
|
|
# Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
|
|
2009-01-17 14:28:01 -08:00
|
|
|
# This program is free software: you can redistribute it and/or modify
|
1998-10-23 22:21:56 -07:00
|
|
|
# it under the terms of the GNU General Public License as published by
|
2009-01-17 14:28:01 -08:00
|
|
|
# the Free Software Foundation; either version 3 of the License, or
|
1998-10-23 22:21:56 -07:00
|
|
|
# (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
|
2018-07-11 14:47:19 -07:00
|
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
1998-10-23 22:21:56 -07:00
|
|
|
|
|
|
|
|
# "Perlized" from C source by Manish Singh <yosh@gimp.org>
|
|
|
|
|
|
2002-02-21 03:16:00 -08:00
|
|
|
sub gradients_refresh {
|
2003-12-08 03:58:45 -08:00
|
|
|
$blurb = 'Refresh current gradients. This function always succeeds.';
|
2002-02-21 03:16:00 -08:00
|
|
|
|
|
|
|
|
$help = <<'HELP';
|
|
|
|
|
This procedure retrieves all gradients currently in the user's gradient path
|
|
|
|
|
and updates the gradient dialogs accordingly.
|
|
|
|
|
HELP
|
|
|
|
|
|
2006-03-14 13:35:50 -08:00
|
|
|
&mitch_pdb_misc('2002');
|
2002-02-21 03:16:00 -08:00
|
|
|
|
|
|
|
|
%invoke = (
|
2006-03-22 01:58:08 -08:00
|
|
|
code => <<'CODE'
|
|
|
|
|
{
|
2010-04-11 04:12:41 -07:00
|
|
|
gimp_data_factory_data_refresh (gimp->gradient_factory, context);
|
2006-03-22 01:58:08 -08:00
|
|
|
}
|
|
|
|
|
CODE
|
|
|
|
|
);
|
2002-02-21 03:16:00 -08:00
|
|
|
}
|
|
|
|
|
|
1998-10-23 22:21:56 -07:00
|
|
|
sub gradients_get_list {
|
|
|
|
|
$blurb = 'Retrieve the list of loaded gradients.';
|
|
|
|
|
|
|
|
|
|
$help = <<'HELP';
|
2004-09-23 08:05:48 -07:00
|
|
|
This procedure returns a list of the gradients that are currently loaded.
|
2006-06-14 01:32:08 -07:00
|
|
|
You can later use the gimp_context_set_gradient() function to
|
1998-10-23 22:21:56 -07:00
|
|
|
set the active gradient.
|
|
|
|
|
HELP
|
|
|
|
|
|
2006-03-14 13:35:50 -08:00
|
|
|
&federico_pdb_misc('1997');
|
1998-10-23 22:21:56 -07:00
|
|
|
|
2003-09-04 10:04:36 -07:00
|
|
|
@inargs = (
|
2004-09-23 08:05:48 -07:00
|
|
|
{ name => 'filter', type => 'string', null_ok => 1,
|
2003-09-04 10:04:36 -07:00
|
|
|
desc => 'An optional regular expression used to filter the list' }
|
|
|
|
|
);
|
|
|
|
|
|
1998-10-23 22:21:56 -07:00
|
|
|
@outargs = (
|
2003-09-04 05:02:31 -07:00
|
|
|
{ name => 'gradient_list', type => 'stringarray',
|
2012-12-03 14:16:16 -08:00
|
|
|
desc => 'The list of gradient names',
|
1999-03-10 10:56:56 -08:00
|
|
|
array => { name => 'num_gradients',
|
2006-03-15 07:32:39 -08:00
|
|
|
desc => 'The number of loaded gradients' } }
|
1998-10-23 22:21:56 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
%invoke = (
|
2003-09-04 10:04:36 -07:00
|
|
|
headers => [ qw("core/gimpcontainer-filter.h") ],
|
2006-03-22 01:58:08 -08:00
|
|
|
code => <<'CODE'
|
|
|
|
|
{
|
2008-12-19 13:58:17 -08:00
|
|
|
gradient_list = gimp_container_get_filtered_name_array (gimp_data_factory_get_container (gimp->gradient_factory),
|
2006-03-22 01:58:08 -08:00
|
|
|
filter, &num_gradients);
|
|
|
|
|
}
|
|
|
|
|
CODE
|
1998-10-23 22:21:56 -07:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2006-03-14 13:35:50 -08:00
|
|
|
sub gradients_sample_uniform {
|
|
|
|
|
&std_pdb_deprecated ('gimp-gradient-get-uniform-samples');
|
1998-10-23 22:21:56 -07:00
|
|
|
|
2006-03-14 13:35:50 -08:00
|
|
|
@inargs = (
|
|
|
|
|
{ name => 'num_samples', type => '2 <= int32',
|
2006-03-15 07:00:01 -08:00
|
|
|
desc => 'The number of samples to take' },
|
2006-03-14 13:35:50 -08:00
|
|
|
{ name => 'reverse', type => 'boolean',
|
2006-05-18 10:25:15 -07:00
|
|
|
desc => 'Use the reverse gradient' }
|
2006-03-14 13:35:50 -08:00
|
|
|
);
|
2003-08-18 05:17:21 -07:00
|
|
|
|
1998-10-23 22:21:56 -07:00
|
|
|
@outargs = (
|
2006-03-15 07:32:39 -08:00
|
|
|
{ name => 'color_samples', type => 'floatarray',
|
1998-10-23 22:21:56 -07:00
|
|
|
desc => 'Color samples: { R1, G1, B1, A1, ..., Rn, Gn, Bn, An }',
|
2006-03-15 07:32:39 -08:00
|
|
|
array => { name => 'array_length', no_lib => 1,
|
1999-03-10 10:56:56 -08:00
|
|
|
desc => 'Length of the color_samples array (4 *
|
|
|
|
|
num_samples)' } }
|
1998-10-23 22:21:56 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
%invoke = (
|
|
|
|
|
code => <<'CODE'
|
|
|
|
|
{
|
2006-03-14 13:35:50 -08:00
|
|
|
GimpGradient *gradient;
|
2005-02-26 15:55:50 -08:00
|
|
|
GimpGradientSegment *seg = NULL;
|
2006-03-14 13:35:50 -08:00
|
|
|
gdouble pos, delta;
|
|
|
|
|
GimpRGB color;
|
|
|
|
|
gdouble *pv;
|
2005-02-26 15:55:50 -08:00
|
|
|
|
2004-09-23 08:05:48 -07:00
|
|
|
pos = 0.0;
|
2006-03-15 07:00:01 -08:00
|
|
|
delta = 1.0 / (num_samples - 1);
|
1998-10-23 22:21:56 -07:00
|
|
|
|
2006-03-15 07:00:01 -08:00
|
|
|
array_length = num_samples * 4;
|
1998-10-23 22:21:56 -07:00
|
|
|
|
1999-03-10 10:56:56 -08:00
|
|
|
pv = color_samples = g_new (gdouble, array_length);
|
1998-10-23 22:21:56 -07:00
|
|
|
|
2004-04-14 16:37:34 -07:00
|
|
|
gradient = gimp_context_get_gradient (context);
|
1999-10-26 11:27:27 -07:00
|
|
|
|
2006-03-15 07:00:01 -08:00
|
|
|
while (num_samples--)
|
1999-03-10 10:56:56 -08:00
|
|
|
{
|
2006-08-29 14:44:51 -07:00
|
|
|
seg = gimp_gradient_get_color_at (gradient, context, seg,
|
2018-04-13 13:33:16 -07:00
|
|
|
pos, reverse,
|
|
|
|
|
GIMP_GRADIENT_BLEND_RGB_PERCEPTUAL,
|
|
|
|
|
&color);
|
1998-10-23 22:21:56 -07:00
|
|
|
|
2001-01-20 08:28:05 -08:00
|
|
|
*pv++ = color.r;
|
|
|
|
|
*pv++ = color.g;
|
|
|
|
|
*pv++ = color.b;
|
|
|
|
|
*pv++ = color.a;
|
1998-10-23 22:21:56 -07:00
|
|
|
|
1999-03-10 10:56:56 -08:00
|
|
|
pos += delta;
|
1998-10-23 22:21:56 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
CODE
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub gradients_sample_custom {
|
2005-08-02 15:52:23 -07:00
|
|
|
&std_pdb_deprecated ('gimp-gradient-get-custom-samples');
|
1998-10-23 22:21:56 -07:00
|
|
|
|
|
|
|
|
@inargs = (
|
2006-03-15 07:00:01 -08:00
|
|
|
{ name => 'positions', type => 'floatarray',
|
2003-08-18 05:17:21 -07:00
|
|
|
desc => 'The list of positions to sample along the gradient',
|
2010-06-05 09:26:53 -07:00
|
|
|
array => { name => 'num_samples',
|
2006-03-15 07:00:01 -08:00
|
|
|
desc => 'The number of samples to take' } },
|
2006-03-14 13:35:50 -08:00
|
|
|
{ name => 'reverse', type => 'boolean',
|
2006-05-18 10:25:15 -07:00
|
|
|
desc => 'Use the reverse gradient' }
|
1998-10-23 22:21:56 -07:00
|
|
|
);
|
|
|
|
|
|
2006-03-14 13:35:50 -08:00
|
|
|
@outargs = (
|
2006-03-15 07:32:39 -08:00
|
|
|
{ name => 'color_samples', type => 'floatarray',
|
2006-03-14 13:35:50 -08:00
|
|
|
desc => 'Color samples: { R1, G1, B1, A1, ..., Rn, Gn, Bn, An }',
|
2006-03-15 07:32:39 -08:00
|
|
|
array => { name => 'array_length', no_lib => 1,
|
2006-03-14 13:35:50 -08:00
|
|
|
desc => 'Length of the color_samples array (4 *
|
|
|
|
|
num_samples)' } }
|
|
|
|
|
);
|
1998-10-23 22:21:56 -07:00
|
|
|
|
|
|
|
|
%invoke = (
|
|
|
|
|
code => <<'CODE'
|
|
|
|
|
{
|
2006-03-14 13:35:50 -08:00
|
|
|
GimpGradient *gradient;
|
2005-02-26 15:55:50 -08:00
|
|
|
GimpGradientSegment *seg = NULL;
|
2006-03-14 13:35:50 -08:00
|
|
|
GimpRGB color;
|
|
|
|
|
gdouble *pv;
|
2005-02-26 15:55:50 -08:00
|
|
|
|
2006-03-15 07:00:01 -08:00
|
|
|
array_length = num_samples * 4;
|
1998-10-23 22:21:56 -07:00
|
|
|
|
1999-03-10 10:56:56 -08:00
|
|
|
pv = color_samples = g_new (gdouble, array_length);
|
1998-10-23 22:21:56 -07:00
|
|
|
|
2004-04-14 16:37:34 -07:00
|
|
|
gradient = gimp_context_get_gradient (context);
|
1999-10-26 11:27:27 -07:00
|
|
|
|
2006-03-15 07:00:01 -08:00
|
|
|
while (num_samples--)
|
1999-03-10 10:56:56 -08:00
|
|
|
{
|
2006-08-29 14:44:51 -07:00
|
|
|
seg = gimp_gradient_get_color_at (gradient, context, seg,
|
2018-04-13 13:33:16 -07:00
|
|
|
*positions, reverse,
|
|
|
|
|
GIMP_GRADIENT_BLEND_RGB_PERCEPTUAL,
|
|
|
|
|
&color);
|
1998-10-23 22:21:56 -07:00
|
|
|
|
2001-01-20 08:28:05 -08:00
|
|
|
*pv++ = color.r;
|
|
|
|
|
*pv++ = color.g;
|
|
|
|
|
*pv++ = color.b;
|
|
|
|
|
*pv++ = color.a;
|
1998-10-23 22:21:56 -07:00
|
|
|
|
2006-03-15 07:00:01 -08:00
|
|
|
positions++;
|
1998-10-23 22:21:56 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
CODE
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2001-10-25 14:59:52 -07:00
|
|
|
sub gradients_get_gradient_data {
|
2005-08-02 15:52:23 -07:00
|
|
|
&std_pdb_deprecated ('gimp-gradient-get-uniform-samples');
|
2001-10-25 14:59:52 -07:00
|
|
|
|
|
|
|
|
@inargs = (
|
2007-04-26 10:43:18 -07:00
|
|
|
{ name => 'name', type => 'string', null_ok => 1,
|
|
|
|
|
desc => 'The gradient name ("" means current active gradient)' },
|
2006-03-18 02:28:39 -08:00
|
|
|
{ name => 'sample_size', type => '1 <= int32 <= 10000',
|
2007-04-26 12:10:23 -07:00
|
|
|
no_validate => 1,
|
|
|
|
|
desc => 'Size of the sample to return when the gradient is changed' },
|
2006-03-14 13:35:50 -08:00
|
|
|
{ name => 'reverse', type => 'boolean',
|
2006-05-18 10:25:15 -07:00
|
|
|
desc => 'Use the reverse gradient' }
|
2001-10-25 14:59:52 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
@outargs = (
|
2006-03-15 07:32:39 -08:00
|
|
|
{ name => 'actual_name', type => 'string',
|
2006-03-15 04:49:25 -08:00
|
|
|
desc => 'The gradient name' },
|
2006-03-15 07:00:01 -08:00
|
|
|
{ name => 'grad_data', type => 'floatarray',
|
2006-03-15 07:32:39 -08:00
|
|
|
desc => 'The gradient sample data',
|
|
|
|
|
array => { name => 'width',
|
2006-03-15 04:49:25 -08:00
|
|
|
desc => 'The gradient sample width (r,g,b,a)' } }
|
2001-10-25 14:59:52 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
%invoke = (
|
2004-09-28 15:01:21 -07:00
|
|
|
code => <<"CODE"
|
2001-10-25 14:59:52 -07:00
|
|
|
{
|
2006-03-15 04:49:25 -08:00
|
|
|
GimpGradient *gradient;
|
|
|
|
|
|
2006-03-18 02:28:39 -08:00
|
|
|
if (sample_size < 1 || sample_size > 10000)
|
|
|
|
|
sample_size = GIMP_GRADIENT_DEFAULT_SAMPLE_SIZE;
|
|
|
|
|
|
2004-10-05 16:28:17 -07:00
|
|
|
if (name && strlen (name))
|
2007-12-11 01:54:41 -08:00
|
|
|
gradient = gimp_pdb_get_gradient (gimp, name, FALSE, error);
|
2004-10-05 16:28:17 -07:00
|
|
|
else
|
2007-12-11 01:54:41 -08:00
|
|
|
gradient = gimp_context_get_gradient (context);
|
2003-07-22 07:24:11 -07:00
|
|
|
|
|
|
|
|
if (gradient)
|
2001-10-25 14:59:52 -07:00
|
|
|
{
|
2005-02-26 15:55:50 -08:00
|
|
|
GimpGradientSegment *seg = NULL;
|
|
|
|
|
gdouble *pv;
|
|
|
|
|
gdouble pos, delta;
|
|
|
|
|
GimpRGB color;
|
2001-10-25 14:59:52 -07:00
|
|
|
|
|
|
|
|
pos = 0.0;
|
2006-03-15 04:49:25 -08:00
|
|
|
delta = 1.0 / (sample_size - 1);
|
|
|
|
|
|
2009-08-31 13:47:18 -07:00
|
|
|
actual_name = g_strdup (gimp_object_get_name (gradient));
|
2006-03-15 07:00:01 -08:00
|
|
|
grad_data = g_new (gdouble, sample_size * 4);
|
2006-03-15 04:49:25 -08:00
|
|
|
width = sample_size * 4;
|
2001-10-25 14:59:52 -07:00
|
|
|
|
2006-03-15 07:00:01 -08:00
|
|
|
pv = grad_data;
|
2001-10-25 14:59:52 -07:00
|
|
|
|
2010-10-15 09:57:01 -07:00
|
|
|
while (sample_size--)
|
2001-10-25 14:59:52 -07:00
|
|
|
{
|
2006-08-29 14:44:51 -07:00
|
|
|
seg = gimp_gradient_get_color_at (gradient, context, seg,
|
2018-04-13 13:33:16 -07:00
|
|
|
pos, reverse,
|
|
|
|
|
GIMP_GRADIENT_BLEND_RGB_PERCEPTUAL,
|
|
|
|
|
&color);
|
2001-10-25 14:59:52 -07:00
|
|
|
|
|
|
|
|
*pv++ = color.r;
|
|
|
|
|
*pv++ = color.g;
|
|
|
|
|
*pv++ = color.b;
|
|
|
|
|
*pv++ = color.a;
|
|
|
|
|
|
|
|
|
|
pos += delta;
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-12-08 03:58:45 -08:00
|
|
|
else
|
|
|
|
|
success = FALSE;
|
2001-10-25 14:59:52 -07:00
|
|
|
}
|
|
|
|
|
CODE
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2004-06-01 14:37:36 -07:00
|
|
|
|
2006-06-14 01:32:08 -07:00
|
|
|
@headers = qw(<string.h>
|
|
|
|
|
"core/gimp.h"
|
|
|
|
|
"core/gimpcontext.h"
|
|
|
|
|
"core/gimpdatafactory.h"
|
|
|
|
|
"core/gimpgradient.h"
|
2007-12-11 01:54:41 -08:00
|
|
|
"gimppdb-utils.h");
|
1999-03-27 22:36:11 -08:00
|
|
|
|
2008-02-07 09:08:54 -08:00
|
|
|
@procs = qw(gradients_refresh
|
|
|
|
|
gradients_get_list
|
|
|
|
|
gradients_sample_uniform
|
|
|
|
|
gradients_sample_custom
|
2004-09-28 15:01:21 -07:00
|
|
|
gradients_get_gradient_data);
|
2006-03-23 13:17:16 -08:00
|
|
|
|
1998-10-23 22:21:56 -07:00
|
|
|
%exports = (app => [@procs], lib => [@procs]);
|
|
|
|
|
|
|
|
|
|
$desc = 'Gradients';
|
2010-07-07 02:43:10 -07:00
|
|
|
$doc_title = 'gimpgradients';
|
|
|
|
|
$doc_short_desc = 'Operations related to gradients.';
|
|
|
|
|
$doc_long_desc = 'Operations related to gradients.';
|
1998-10-23 22:21:56 -07:00
|
|
|
|
|
|
|
|
1;
|