diff options
Diffstat (limited to 'pdb/groups/gradients.pdb')
-rw-r--r-- | pdb/groups/gradients.pdb | 274 |
1 files changed, 274 insertions, 0 deletions
diff --git a/pdb/groups/gradients.pdb b/pdb/groups/gradients.pdb new file mode 100644 index 0000000..ed47a15 --- /dev/null +++ b/pdb/groups/gradients.pdb @@ -0,0 +1,274 @@ +# GIMP - The GNU 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 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 gradients_refresh { + $blurb = 'Refresh current gradients. This function always succeeds.'; + + $help = <<'HELP'; +This procedure retrieves all gradients currently in the user's gradient path +and updates the gradient dialogs accordingly. +HELP + + &mitch_pdb_misc('2002'); + + %invoke = ( + code => <<'CODE' +{ + gimp_data_factory_data_refresh (gimp->gradient_factory, context); +} +CODE + ); +} + +sub gradients_get_list { + $blurb = 'Retrieve the list of loaded gradients.'; + + $help = <<'HELP'; +This procedure returns a list of the gradients that are currently loaded. +You can later use the gimp_context_set_gradient() function to +set the active gradient. +HELP + + &federico_pdb_misc('1997'); + + @inargs = ( + { name => 'filter', type => 'string', null_ok => 1, + desc => 'An optional regular expression used to filter the list' } + ); + + @outargs = ( + { name => 'gradient_list', type => 'stringarray', + desc => 'The list of gradient names', + array => { name => 'num_gradients', + desc => 'The number of loaded gradients' } } + ); + + %invoke = ( + headers => [ qw("core/gimpcontainer-filter.h") ], + code => <<'CODE' +{ + gradient_list = gimp_container_get_filtered_name_array (gimp_data_factory_get_container (gimp->gradient_factory), + filter, &num_gradients); +} +CODE + ); +} + +sub gradients_sample_uniform { + &std_pdb_deprecated ('gimp-gradient-get-uniform-samples'); + + @inargs = ( + { name => 'num_samples', type => '2 <= int32', + desc => 'The number of samples to take' }, + { name => 'reverse', type => 'boolean', + desc => 'Use the reverse gradient' } + ); + + @outargs = ( + { name => 'color_samples', type => 'floatarray', + desc => 'Color samples: { R1, G1, B1, A1, ..., Rn, Gn, Bn, An }', + array => { name => 'array_length', no_lib => 1, + desc => 'Length of the color_samples array (4 * + num_samples)' } } + ); + + %invoke = ( + code => <<'CODE' +{ + GimpGradient *gradient; + GimpGradientSegment *seg = NULL; + gdouble pos, delta; + GimpRGB color; + gdouble *pv; + + pos = 0.0; + delta = 1.0 / (num_samples - 1); + + array_length = num_samples * 4; + + pv = color_samples = g_new (gdouble, array_length); + + gradient = gimp_context_get_gradient (context); + + while (num_samples--) + { + seg = gimp_gradient_get_color_at (gradient, context, seg, + pos, reverse, + GIMP_GRADIENT_BLEND_RGB_PERCEPTUAL, + &color); + + *pv++ = color.r; + *pv++ = color.g; + *pv++ = color.b; + *pv++ = color.a; + + pos += delta; + } +} +CODE + ); +} + +sub gradients_sample_custom { + &std_pdb_deprecated ('gimp-gradient-get-custom-samples'); + + @inargs = ( + { name => 'positions', type => 'floatarray', + desc => 'The list of positions to sample along the gradient', + array => { name => 'num_samples', + desc => 'The number of samples to take' } }, + { name => 'reverse', type => 'boolean', + desc => 'Use the reverse gradient' } + ); + + @outargs = ( + { name => 'color_samples', type => 'floatarray', + desc => 'Color samples: { R1, G1, B1, A1, ..., Rn, Gn, Bn, An }', + array => { name => 'array_length', no_lib => 1, + desc => 'Length of the color_samples array (4 * + num_samples)' } } + ); + + %invoke = ( + code => <<'CODE' +{ + GimpGradient *gradient; + GimpGradientSegment *seg = NULL; + GimpRGB color; + gdouble *pv; + + array_length = num_samples * 4; + + pv = color_samples = g_new (gdouble, array_length); + + gradient = gimp_context_get_gradient (context); + + while (num_samples--) + { + seg = gimp_gradient_get_color_at (gradient, context, seg, + *positions, reverse, + GIMP_GRADIENT_BLEND_RGB_PERCEPTUAL, + &color); + + *pv++ = color.r; + *pv++ = color.g; + *pv++ = color.b; + *pv++ = color.a; + + positions++; + } +} +CODE + ); +} + +sub gradients_get_gradient_data { + &std_pdb_deprecated ('gimp-gradient-get-uniform-samples'); + + @inargs = ( + { name => 'name', type => 'string', null_ok => 1, + desc => 'The gradient name ("" means current active gradient)' }, + { name => 'sample_size', type => '1 <= int32 <= 10000', + no_validate => 1, + desc => 'Size of the sample to return when the gradient is changed' }, + { name => 'reverse', type => 'boolean', + desc => 'Use the reverse gradient' } + ); + + @outargs = ( + { name => 'actual_name', type => 'string', + desc => 'The gradient name' }, + { name => 'grad_data', type => 'floatarray', + desc => 'The gradient sample data', + array => { name => 'width', + desc => 'The gradient sample width (r,g,b,a)' } } + ); + + %invoke = ( + code => <<"CODE" +{ + GimpGradient *gradient; + + if (sample_size < 1 || sample_size > 10000) + sample_size = GIMP_GRADIENT_DEFAULT_SAMPLE_SIZE; + + if (name && strlen (name)) + gradient = gimp_pdb_get_gradient (gimp, name, FALSE, error); + else + gradient = gimp_context_get_gradient (context); + + if (gradient) + { + GimpGradientSegment *seg = NULL; + gdouble *pv; + gdouble pos, delta; + GimpRGB color; + + pos = 0.0; + delta = 1.0 / (sample_size - 1); + + actual_name = g_strdup (gimp_object_get_name (gradient)); + grad_data = g_new (gdouble, sample_size * 4); + width = sample_size * 4; + + pv = grad_data; + + while (sample_size--) + { + seg = gimp_gradient_get_color_at (gradient, context, seg, + pos, reverse, + GIMP_GRADIENT_BLEND_RGB_PERCEPTUAL, + &color); + + *pv++ = color.r; + *pv++ = color.g; + *pv++ = color.b; + *pv++ = color.a; + + pos += delta; + } + } + else + success = FALSE; +} +CODE + ); +} + + +@headers = qw(<string.h> + "core/gimp.h" + "core/gimpcontext.h" + "core/gimpdatafactory.h" + "core/gimpgradient.h" + "gimppdb-utils.h"); + +@procs = qw(gradients_refresh + gradients_get_list + gradients_sample_uniform + gradients_sample_custom + gradients_get_gradient_data); + +%exports = (app => [@procs], lib => [@procs]); + +$desc = 'Gradients'; +$doc_title = 'gimpgradients'; +$doc_short_desc = 'Operations related to gradients.'; +$doc_long_desc = 'Operations related to gradients.'; + +1; |