mirror of
https://gitlab.gnome.org/GNOME/gimp.git
synced 2025-07-03 09:23:24 +00:00
app, libgimp, pdb: gimp_gradient_get_custom_samples() also returns an array of colors.
This commit is contained in:
parent
6327d1b3ef
commit
5ed3bc33e0
4 changed files with 121 additions and 153 deletions
|
@ -215,8 +215,7 @@ gradient_get_custom_samples_invoker (GimpProcedure *procedure,
|
||||||
gsize num_samples;
|
gsize num_samples;
|
||||||
const gdouble *positions;
|
const gdouble *positions;
|
||||||
gboolean reverse;
|
gboolean reverse;
|
||||||
gsize num_color_samples = 0;
|
GeglColor **color_samples = NULL;
|
||||||
gdouble *color_samples = NULL;
|
|
||||||
|
|
||||||
gradient = g_value_get_object (gimp_value_array_index (args, 0));
|
gradient = g_value_get_object (gimp_value_array_index (args, 0));
|
||||||
positions = gimp_value_get_double_array (gimp_value_array_index (args, 1), &num_samples);
|
positions = gimp_value_get_double_array (gimp_value_array_index (args, 1), &num_samples);
|
||||||
|
@ -226,30 +225,21 @@ gradient_get_custom_samples_invoker (GimpProcedure *procedure,
|
||||||
{
|
{
|
||||||
if (gradient)
|
if (gradient)
|
||||||
{
|
{
|
||||||
GimpGradientSegment *seg = NULL;
|
GimpGradientSegment *seg = NULL;
|
||||||
gdouble *sample;
|
GeglColor **sample;
|
||||||
|
|
||||||
num_color_samples = num_samples * 4;
|
sample = color_samples = g_new0 (GeglColor *, num_samples + 1);
|
||||||
|
|
||||||
sample = color_samples = g_new0 (gdouble, num_color_samples);
|
|
||||||
|
|
||||||
while (num_samples--)
|
while (num_samples--)
|
||||||
{
|
{
|
||||||
GeglColor *color = NULL;
|
|
||||||
|
|
||||||
seg = gimp_gradient_get_color_at (gradient, context,
|
seg = gimp_gradient_get_color_at (gradient, context,
|
||||||
seg, *positions,
|
seg, *positions,
|
||||||
reverse,
|
reverse,
|
||||||
GIMP_GRADIENT_BLEND_RGB_PERCEPTUAL,
|
GIMP_GRADIENT_BLEND_RGB_PERCEPTUAL,
|
||||||
&color);
|
sample);
|
||||||
|
|
||||||
if (color)
|
sample++;
|
||||||
gegl_color_get_pixel (color, babl_format ("R'G'B'A double"), sample);
|
|
||||||
|
|
||||||
sample += 4;
|
|
||||||
positions++;
|
positions++;
|
||||||
|
|
||||||
g_clear_object (&color);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -260,7 +250,7 @@ gradient_get_custom_samples_invoker (GimpProcedure *procedure,
|
||||||
error ? *error : NULL);
|
error ? *error : NULL);
|
||||||
|
|
||||||
if (success)
|
if (success)
|
||||||
gimp_value_take_double_array (gimp_value_array_index (return_vals, 1), color_samples, num_color_samples);
|
g_value_take_boxed (gimp_value_array_index (return_vals, 1), color_samples);
|
||||||
|
|
||||||
return return_vals;
|
return return_vals;
|
||||||
}
|
}
|
||||||
|
@ -1384,7 +1374,7 @@ register_gradient_procs (GimpPDB *pdb)
|
||||||
"gimp-gradient-get-custom-samples");
|
"gimp-gradient-get-custom-samples");
|
||||||
gimp_procedure_set_static_help (procedure,
|
gimp_procedure_set_static_help (procedure,
|
||||||
"Sample the gradient in custom positions.",
|
"Sample the gradient in custom positions.",
|
||||||
"Samples the color of the gradient at positions from a list. The left endpoint of the gradient corresponds to position 0.0, and the right endpoint corresponds to 1.0. Returns a list of floating-point values, four for each sample (RGBA.)",
|
"Samples the color of the gradient at positions from a list. The left endpoint of the gradient corresponds to position 0.0, and the right endpoint corresponds to 1.0. Returns a list of colors, one for each sample.",
|
||||||
NULL);
|
NULL);
|
||||||
gimp_procedure_set_static_attribution (procedure,
|
gimp_procedure_set_static_attribution (procedure,
|
||||||
"Federico Mena Quintero",
|
"Federico Mena Quintero",
|
||||||
|
@ -1410,10 +1400,11 @@ register_gradient_procs (GimpPDB *pdb)
|
||||||
FALSE,
|
FALSE,
|
||||||
GIMP_PARAM_READWRITE));
|
GIMP_PARAM_READWRITE));
|
||||||
gimp_procedure_add_return_value (procedure,
|
gimp_procedure_add_return_value (procedure,
|
||||||
gimp_param_spec_double_array ("color-samples",
|
g_param_spec_boxed ("color-samples",
|
||||||
"color samples",
|
"color samples",
|
||||||
"Color samples: { R1, G1, B1, A1, ..., Rn, Gn, Bn, An }",
|
"Color samples",
|
||||||
GIMP_PARAM_READWRITE));
|
GIMP_TYPE_COLOR_ARRAY,
|
||||||
|
GIMP_PARAM_READWRITE));
|
||||||
gimp_pdb_register_procedure (pdb, procedure);
|
gimp_pdb_register_procedure (pdb, procedure);
|
||||||
g_object_unref (procedure);
|
g_object_unref (procedure);
|
||||||
|
|
||||||
|
|
|
@ -199,33 +199,30 @@ gimp_gradient_get_uniform_samples (GimpGradient *gradient,
|
||||||
* @num_samples: The number of samples to take.
|
* @num_samples: The number of samples to take.
|
||||||
* @positions: (array length=num_samples) (element-type gdouble): The list of positions to sample along the gradient.
|
* @positions: (array length=num_samples) (element-type gdouble): The list of positions to sample along the gradient.
|
||||||
* @reverse: Use the reverse gradient.
|
* @reverse: Use the reverse gradient.
|
||||||
* @num_color_samples: (out): Length of the color_samples array (4 * num_samples).
|
|
||||||
* @color_samples: (out) (array length=num_color_samples) (element-type gdouble) (transfer full): Color samples: { R1, G1, B1, A1, ..., Rn, Gn, Bn, An }.
|
|
||||||
*
|
*
|
||||||
* Sample the gradient in custom positions.
|
* Sample the gradient in custom positions.
|
||||||
*
|
*
|
||||||
* Samples the color of the gradient at positions from a list. The left
|
* Samples the color of the gradient at positions from a list. The left
|
||||||
* endpoint of the gradient corresponds to position 0.0, and the right
|
* endpoint of the gradient corresponds to position 0.0, and the right
|
||||||
* endpoint corresponds to 1.0. Returns a list of floating-point
|
* endpoint corresponds to 1.0. Returns a list of colors, one for each
|
||||||
* values, four for each sample (RGBA.)
|
* sample.
|
||||||
*
|
*
|
||||||
* Returns: TRUE on success.
|
* Returns: (array zero-terminated=1) (transfer full): Color samples.
|
||||||
|
* The returned value must be freed with gimp_color_array_free().
|
||||||
*
|
*
|
||||||
* Since: 2.2
|
* Since: 2.2
|
||||||
**/
|
**/
|
||||||
gboolean
|
GeglColor **
|
||||||
gimp_gradient_get_custom_samples (GimpGradient *gradient,
|
gimp_gradient_get_custom_samples (GimpGradient *gradient,
|
||||||
gsize num_samples,
|
gsize num_samples,
|
||||||
const gdouble *positions,
|
const gdouble *positions,
|
||||||
gboolean reverse,
|
gboolean reverse)
|
||||||
gsize *num_color_samples,
|
|
||||||
gdouble **color_samples)
|
|
||||||
{
|
{
|
||||||
GimpValueArray *args;
|
GimpValueArray *args;
|
||||||
GimpValueArray *return_vals;
|
GimpValueArray *return_vals;
|
||||||
gboolean success = TRUE;
|
GeglColor **color_samples = NULL;
|
||||||
|
|
||||||
g_return_val_if_fail (num_samples >= 1, FALSE);
|
g_return_val_if_fail (num_samples >= 1, NULL);
|
||||||
|
|
||||||
args = gimp_value_array_new_from_types (NULL,
|
args = gimp_value_array_new_from_types (NULL,
|
||||||
GIMP_TYPE_GRADIENT, gradient,
|
GIMP_TYPE_GRADIENT, gradient,
|
||||||
|
@ -239,19 +236,12 @@ gimp_gradient_get_custom_samples (GimpGradient *gradient,
|
||||||
args);
|
args);
|
||||||
gimp_value_array_unref (args);
|
gimp_value_array_unref (args);
|
||||||
|
|
||||||
*num_color_samples = 0;
|
if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS)
|
||||||
*color_samples = NULL;
|
color_samples = gimp_color_array_copy (g_value_get_boxed (gimp_value_array_index (return_vals, 1)));
|
||||||
|
|
||||||
success = GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS;
|
|
||||||
|
|
||||||
if (success)
|
|
||||||
{
|
|
||||||
*color_samples = GIMP_VALUES_DUP_DOUBLE_ARRAY (return_vals, 1, num_color_samples);
|
|
||||||
}
|
|
||||||
|
|
||||||
gimp_value_array_unref (return_vals);
|
gimp_value_array_unref (return_vals);
|
||||||
|
|
||||||
return success;
|
return color_samples;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -32,94 +32,92 @@ G_BEGIN_DECLS
|
||||||
/* For information look into the C source or the html documentation */
|
/* For information look into the C source or the html documentation */
|
||||||
|
|
||||||
|
|
||||||
GimpGradient* gimp_gradient_new (const gchar *name);
|
GimpGradient* gimp_gradient_new (const gchar *name);
|
||||||
GimpGradient* gimp_gradient_get_by_name (const gchar *name);
|
GimpGradient* gimp_gradient_get_by_name (const gchar *name);
|
||||||
gint gimp_gradient_get_number_of_segments (GimpGradient *gradient);
|
gint gimp_gradient_get_number_of_segments (GimpGradient *gradient);
|
||||||
GeglColor** gimp_gradient_get_uniform_samples (GimpGradient *gradient,
|
GeglColor** gimp_gradient_get_uniform_samples (GimpGradient *gradient,
|
||||||
gint num_samples,
|
gint num_samples,
|
||||||
gboolean reverse);
|
gboolean reverse);
|
||||||
gboolean gimp_gradient_get_custom_samples (GimpGradient *gradient,
|
GeglColor** gimp_gradient_get_custom_samples (GimpGradient *gradient,
|
||||||
gsize num_samples,
|
gsize num_samples,
|
||||||
const gdouble *positions,
|
const gdouble *positions,
|
||||||
gboolean reverse,
|
gboolean reverse);
|
||||||
gsize *num_color_samples,
|
GeglColor* gimp_gradient_segment_get_left_color (GimpGradient *gradient,
|
||||||
gdouble **color_samples);
|
gint segment);
|
||||||
GeglColor* gimp_gradient_segment_get_left_color (GimpGradient *gradient,
|
gboolean gimp_gradient_segment_set_left_color (GimpGradient *gradient,
|
||||||
gint segment);
|
gint segment,
|
||||||
gboolean gimp_gradient_segment_set_left_color (GimpGradient *gradient,
|
GeglColor *color);
|
||||||
gint segment,
|
GeglColor* gimp_gradient_segment_get_right_color (GimpGradient *gradient,
|
||||||
GeglColor *color);
|
gint segment);
|
||||||
GeglColor* gimp_gradient_segment_get_right_color (GimpGradient *gradient,
|
gboolean gimp_gradient_segment_set_right_color (GimpGradient *gradient,
|
||||||
gint segment);
|
gint segment,
|
||||||
gboolean gimp_gradient_segment_set_right_color (GimpGradient *gradient,
|
GeglColor *color);
|
||||||
gint segment,
|
gboolean gimp_gradient_segment_get_left_pos (GimpGradient *gradient,
|
||||||
GeglColor *color);
|
gint segment,
|
||||||
gboolean gimp_gradient_segment_get_left_pos (GimpGradient *gradient,
|
gdouble *pos);
|
||||||
gint segment,
|
gboolean gimp_gradient_segment_set_left_pos (GimpGradient *gradient,
|
||||||
gdouble *pos);
|
gint segment,
|
||||||
gboolean gimp_gradient_segment_set_left_pos (GimpGradient *gradient,
|
gdouble pos,
|
||||||
gint segment,
|
gdouble *final_pos);
|
||||||
gdouble pos,
|
gboolean gimp_gradient_segment_get_middle_pos (GimpGradient *gradient,
|
||||||
gdouble *final_pos);
|
gint segment,
|
||||||
gboolean gimp_gradient_segment_get_middle_pos (GimpGradient *gradient,
|
gdouble *pos);
|
||||||
gint segment,
|
gboolean gimp_gradient_segment_set_middle_pos (GimpGradient *gradient,
|
||||||
gdouble *pos);
|
gint segment,
|
||||||
gboolean gimp_gradient_segment_set_middle_pos (GimpGradient *gradient,
|
gdouble pos,
|
||||||
gint segment,
|
gdouble *final_pos);
|
||||||
gdouble pos,
|
gboolean gimp_gradient_segment_get_right_pos (GimpGradient *gradient,
|
||||||
gdouble *final_pos);
|
gint segment,
|
||||||
gboolean gimp_gradient_segment_get_right_pos (GimpGradient *gradient,
|
gdouble *pos);
|
||||||
gint segment,
|
gboolean gimp_gradient_segment_set_right_pos (GimpGradient *gradient,
|
||||||
gdouble *pos);
|
gint segment,
|
||||||
gboolean gimp_gradient_segment_set_right_pos (GimpGradient *gradient,
|
gdouble pos,
|
||||||
gint segment,
|
gdouble *final_pos);
|
||||||
gdouble pos,
|
gboolean gimp_gradient_segment_get_blending_function (GimpGradient *gradient,
|
||||||
gdouble *final_pos);
|
gint segment,
|
||||||
gboolean gimp_gradient_segment_get_blending_function (GimpGradient *gradient,
|
GimpGradientSegmentType *blend_func);
|
||||||
gint segment,
|
gboolean gimp_gradient_segment_get_coloring_type (GimpGradient *gradient,
|
||||||
GimpGradientSegmentType *blend_func);
|
gint segment,
|
||||||
gboolean gimp_gradient_segment_get_coloring_type (GimpGradient *gradient,
|
GimpGradientSegmentColor *coloring_type);
|
||||||
gint segment,
|
gboolean gimp_gradient_segment_range_set_blending_function (GimpGradient *gradient,
|
||||||
GimpGradientSegmentColor *coloring_type);
|
gint start_segment,
|
||||||
gboolean gimp_gradient_segment_range_set_blending_function (GimpGradient *gradient,
|
gint end_segment,
|
||||||
gint start_segment,
|
GimpGradientSegmentType blending_function);
|
||||||
gint end_segment,
|
gboolean gimp_gradient_segment_range_set_coloring_type (GimpGradient *gradient,
|
||||||
GimpGradientSegmentType blending_function);
|
gint start_segment,
|
||||||
gboolean gimp_gradient_segment_range_set_coloring_type (GimpGradient *gradient,
|
gint end_segment,
|
||||||
gint start_segment,
|
GimpGradientSegmentColor coloring_type);
|
||||||
gint end_segment,
|
gboolean gimp_gradient_segment_range_flip (GimpGradient *gradient,
|
||||||
GimpGradientSegmentColor coloring_type);
|
gint start_segment,
|
||||||
gboolean gimp_gradient_segment_range_flip (GimpGradient *gradient,
|
gint end_segment);
|
||||||
gint start_segment,
|
gboolean gimp_gradient_segment_range_replicate (GimpGradient *gradient,
|
||||||
gint end_segment);
|
gint start_segment,
|
||||||
gboolean gimp_gradient_segment_range_replicate (GimpGradient *gradient,
|
gint end_segment,
|
||||||
gint start_segment,
|
gint replicate_times);
|
||||||
gint end_segment,
|
gboolean gimp_gradient_segment_range_split_midpoint (GimpGradient *gradient,
|
||||||
gint replicate_times);
|
gint start_segment,
|
||||||
gboolean gimp_gradient_segment_range_split_midpoint (GimpGradient *gradient,
|
gint end_segment);
|
||||||
gint start_segment,
|
gboolean gimp_gradient_segment_range_split_uniform (GimpGradient *gradient,
|
||||||
gint end_segment);
|
gint start_segment,
|
||||||
gboolean gimp_gradient_segment_range_split_uniform (GimpGradient *gradient,
|
gint end_segment,
|
||||||
gint start_segment,
|
gint split_parts);
|
||||||
gint end_segment,
|
gboolean gimp_gradient_segment_range_delete (GimpGradient *gradient,
|
||||||
gint split_parts);
|
gint start_segment,
|
||||||
gboolean gimp_gradient_segment_range_delete (GimpGradient *gradient,
|
gint end_segment);
|
||||||
gint start_segment,
|
gboolean gimp_gradient_segment_range_redistribute_handles (GimpGradient *gradient,
|
||||||
gint end_segment);
|
gint start_segment,
|
||||||
gboolean gimp_gradient_segment_range_redistribute_handles (GimpGradient *gradient,
|
gint end_segment);
|
||||||
gint start_segment,
|
gboolean gimp_gradient_segment_range_blend_colors (GimpGradient *gradient,
|
||||||
gint end_segment);
|
gint start_segment,
|
||||||
gboolean gimp_gradient_segment_range_blend_colors (GimpGradient *gradient,
|
gint end_segment);
|
||||||
gint start_segment,
|
gboolean gimp_gradient_segment_range_blend_opacity (GimpGradient *gradient,
|
||||||
gint end_segment);
|
gint start_segment,
|
||||||
gboolean gimp_gradient_segment_range_blend_opacity (GimpGradient *gradient,
|
gint end_segment);
|
||||||
gint start_segment,
|
gdouble gimp_gradient_segment_range_move (GimpGradient *gradient,
|
||||||
gint end_segment);
|
gint start_segment,
|
||||||
gdouble gimp_gradient_segment_range_move (GimpGradient *gradient,
|
gint end_segment,
|
||||||
gint start_segment,
|
gdouble delta,
|
||||||
gint end_segment,
|
gboolean control_compress);
|
||||||
gdouble delta,
|
|
||||||
gboolean control_compress);
|
|
||||||
|
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
|
@ -196,7 +196,7 @@ sub gradient_get_custom_samples {
|
||||||
Samples the color of the gradient at positions from a list.
|
Samples the color of the gradient at positions from a list.
|
||||||
The left endpoint of the gradient corresponds
|
The left endpoint of the gradient corresponds
|
||||||
to position 0.0, and the right endpoint corresponds to 1.0.
|
to position 0.0, and the right endpoint corresponds to 1.0.
|
||||||
Returns a list of floating-point values, four for each sample (RGBA.)
|
Returns a list of colors, one for each sample.
|
||||||
HELP
|
HELP
|
||||||
|
|
||||||
&federico_pdb_misc('1997', '2.2');
|
&federico_pdb_misc('1997', '2.2');
|
||||||
|
@ -212,10 +212,8 @@ HELP
|
||||||
);
|
);
|
||||||
|
|
||||||
@outargs = (
|
@outargs = (
|
||||||
{ name => 'color_samples', type => 'doublearray', void_ret => 1,
|
{ name => 'color_samples', type => 'colorarray',
|
||||||
desc => 'Color samples: { R1, G1, B1, A1, ..., Rn, Gn, Bn, An }',
|
desc => 'Color samples' }
|
||||||
array => { desc => 'Length of the color_samples array (4 *
|
|
||||||
num_samples)' } }
|
|
||||||
);
|
);
|
||||||
|
|
||||||
%invoke = (
|
%invoke = (
|
||||||
|
@ -223,30 +221,21 @@ HELP
|
||||||
{
|
{
|
||||||
if (gradient)
|
if (gradient)
|
||||||
{
|
{
|
||||||
GimpGradientSegment *seg = NULL;
|
GimpGradientSegment *seg = NULL;
|
||||||
gdouble *sample;
|
GeglColor **sample;
|
||||||
|
|
||||||
num_color_samples = num_samples * 4;
|
sample = color_samples = g_new0 (GeglColor *, num_samples + 1);
|
||||||
|
|
||||||
sample = color_samples = g_new0 (gdouble, num_color_samples);
|
|
||||||
|
|
||||||
while (num_samples--)
|
while (num_samples--)
|
||||||
{
|
{
|
||||||
GeglColor *color = NULL;
|
|
||||||
|
|
||||||
seg = gimp_gradient_get_color_at (gradient, context,
|
seg = gimp_gradient_get_color_at (gradient, context,
|
||||||
seg, *positions,
|
seg, *positions,
|
||||||
reverse,
|
reverse,
|
||||||
GIMP_GRADIENT_BLEND_RGB_PERCEPTUAL,
|
GIMP_GRADIENT_BLEND_RGB_PERCEPTUAL,
|
||||||
&color);
|
sample);
|
||||||
|
|
||||||
if (color)
|
sample++;
|
||||||
gegl_color_get_pixel (color, babl_format ("R'G'B'A double"), sample);
|
|
||||||
|
|
||||||
sample += 4;
|
|
||||||
positions++;
|
positions++;
|
||||||
|
|
||||||
g_clear_object (&color);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue