app, libgimp*, pdb, plug-ins: float arrays don't need size arguments too.

This commit is contained in:
Jehan 2024-10-24 22:18:20 +02:00
parent f2b9babfb4
commit 096c45599d
22 changed files with 196 additions and 179 deletions

View File

@ -784,7 +784,7 @@ context_set_line_dash_pattern_invoker (GimpProcedure *procedure,
const gdouble *dashes;
num_dashes = g_value_get_int (gimp_value_array_index (args, 0));
dashes = gimp_value_get_float_array (gimp_value_array_index (args, 1));
dashes = gimp_value_get_float_array (gimp_value_array_index (args, 1), (gsize *) &num_dashes);
if (success)
{

View File

@ -213,7 +213,7 @@ drawable_curves_explicit_invoker (GimpProcedure *procedure,
drawable = g_value_get_object (gimp_value_array_index (args, 0));
channel = g_value_get_enum (gimp_value_array_index (args, 1));
num_values = g_value_get_int (gimp_value_array_index (args, 2));
values = gimp_value_get_float_array (gimp_value_array_index (args, 3));
values = gimp_value_get_float_array (gimp_value_array_index (args, 3), (gsize *) &num_values);
if (success)
{
@ -262,7 +262,7 @@ drawable_curves_spline_invoker (GimpProcedure *procedure,
drawable = g_value_get_object (gimp_value_array_index (args, 0));
channel = g_value_get_enum (gimp_value_array_index (args, 1));
num_points = g_value_get_int (gimp_value_array_index (args, 2));
points = gimp_value_get_float_array (gimp_value_array_index (args, 3));
points = gimp_value_get_float_array (gimp_value_array_index (args, 3), (gsize *) &num_points);
if (success)
{

View File

@ -358,8 +358,6 @@ gimp_pdb_execute_procedure_by_name (GimpPDB *pdb,
GimpValueArray *args;
GimpValueArray *return_vals;
va_list va_args;
GType prev_value_type = G_TYPE_NONE;
gint prev_int_value = 0;
gint i;
g_return_val_if_fail (GIMP_IS_PDB (pdb), NULL);
@ -448,25 +446,9 @@ gimp_pdb_execute_procedure_by_name (GimpPDB *pdb,
if (GIMP_VALUE_HOLDS_INT32_ARRAY (value) ||
GIMP_VALUE_HOLDS_FLOAT_ARRAY (value) ||
GIMP_VALUE_HOLDS_CORE_OBJECT_ARRAY (value))
{
if (GIMP_VALUE_HOLDS_FLOAT_ARRAY (value))
{
/* Array arguments don't have their size information when they
* are set by core code, in C array form.
* By convention, the previous argument has to be the array
* size argument.
*/
g_return_val_if_fail (prev_value_type == G_TYPE_INT && prev_int_value >= 0, NULL);
gimp_value_set_float_array (value,
(const gdouble *) va_arg (va_args, gpointer),
prev_int_value);
}
else if (GIMP_VALUE_HOLDS_CORE_OBJECT_ARRAY (value) ||
GIMP_VALUE_HOLDS_INT32_ARRAY (value))
{
g_value_set_boxed (value, va_arg (va_args, gpointer));
}
}
else
{
G_VALUE_COLLECT (value, va_args, G_VALUE_NOCOPY_CONTENTS, &error_msg);
@ -490,10 +472,6 @@ gimp_pdb_execute_procedure_by_name (GimpPDB *pdb,
return return_vals;
}
prev_value_type = value_type;
if (prev_value_type == G_TYPE_INT)
prev_int_value = g_value_get_int (value);
}
va_end (va_args);

View File

@ -236,7 +236,7 @@ gradient_get_custom_samples_invoker (GimpProcedure *procedure,
gradient = g_value_get_object (gimp_value_array_index (args, 0));
num_samples = g_value_get_int (gimp_value_array_index (args, 1));
positions = gimp_value_get_float_array (gimp_value_array_index (args, 2));
positions = gimp_value_get_float_array (gimp_value_array_index (args, 2), (gsize *) &num_samples);
reverse = g_value_get_boolean (gimp_value_array_index (args, 3));
if (success)

View File

@ -296,7 +296,7 @@ image_select_polygon_invoker (GimpProcedure *procedure,
image = g_value_get_object (gimp_value_array_index (args, 0));
operation = g_value_get_enum (gimp_value_array_index (args, 1));
num_segs = g_value_get_int (gimp_value_array_index (args, 2));
segs = gimp_value_get_float_array (gimp_value_array_index (args, 3));
segs = gimp_value_get_float_array (gimp_value_array_index (args, 3), (gsize *) &num_segs);
if (success)
{

View File

@ -119,7 +119,7 @@ airbrush_invoker (GimpProcedure *procedure,
drawable = g_value_get_object (gimp_value_array_index (args, 0));
pressure = g_value_get_double (gimp_value_array_index (args, 1));
num_strokes = g_value_get_int (gimp_value_array_index (args, 2));
strokes = gimp_value_get_float_array (gimp_value_array_index (args, 3));
strokes = gimp_value_get_float_array (gimp_value_array_index (args, 3), (gsize *) &num_strokes);
if (success)
{
@ -166,7 +166,7 @@ airbrush_default_invoker (GimpProcedure *procedure,
drawable = g_value_get_object (gimp_value_array_index (args, 0));
num_strokes = g_value_get_int (gimp_value_array_index (args, 1));
strokes = gimp_value_get_float_array (gimp_value_array_index (args, 2));
strokes = gimp_value_get_float_array (gimp_value_array_index (args, 2), (gsize *) &num_strokes);
if (success)
{
@ -217,7 +217,7 @@ clone_invoker (GimpProcedure *procedure,
src_x = g_value_get_double (gimp_value_array_index (args, 3));
src_y = g_value_get_double (gimp_value_array_index (args, 4));
num_strokes = g_value_get_int (gimp_value_array_index (args, 5));
strokes = gimp_value_get_float_array (gimp_value_array_index (args, 6));
strokes = gimp_value_get_float_array (gimp_value_array_index (args, 6), (gsize *) &num_strokes);
if (success)
{
@ -271,7 +271,7 @@ clone_default_invoker (GimpProcedure *procedure,
drawable = g_value_get_object (gimp_value_array_index (args, 0));
num_strokes = g_value_get_int (gimp_value_array_index (args, 1));
strokes = gimp_value_get_float_array (gimp_value_array_index (args, 2));
strokes = gimp_value_get_float_array (gimp_value_array_index (args, 2), (gsize *) &num_strokes);
if (success)
{
@ -318,7 +318,7 @@ convolve_invoker (GimpProcedure *procedure,
pressure = g_value_get_double (gimp_value_array_index (args, 1));
convolve_type = g_value_get_enum (gimp_value_array_index (args, 2));
num_strokes = g_value_get_int (gimp_value_array_index (args, 3));
strokes = gimp_value_get_float_array (gimp_value_array_index (args, 4));
strokes = gimp_value_get_float_array (gimp_value_array_index (args, 4), (gsize *) &num_strokes);
if (success)
{
@ -366,7 +366,7 @@ convolve_default_invoker (GimpProcedure *procedure,
drawable = g_value_get_object (gimp_value_array_index (args, 0));
num_strokes = g_value_get_int (gimp_value_array_index (args, 1));
strokes = gimp_value_get_float_array (gimp_value_array_index (args, 2));
strokes = gimp_value_get_float_array (gimp_value_array_index (args, 2), (gsize *) &num_strokes);
if (success)
{
@ -415,7 +415,7 @@ dodgeburn_invoker (GimpProcedure *procedure,
dodgeburn_type = g_value_get_enum (gimp_value_array_index (args, 2));
dodgeburn_mode = g_value_get_enum (gimp_value_array_index (args, 3));
num_strokes = g_value_get_int (gimp_value_array_index (args, 4));
strokes = gimp_value_get_float_array (gimp_value_array_index (args, 5));
strokes = gimp_value_get_float_array (gimp_value_array_index (args, 5), (gsize *) &num_strokes);
if (success)
{
@ -464,7 +464,7 @@ dodgeburn_default_invoker (GimpProcedure *procedure,
drawable = g_value_get_object (gimp_value_array_index (args, 0));
num_strokes = g_value_get_int (gimp_value_array_index (args, 1));
strokes = gimp_value_get_float_array (gimp_value_array_index (args, 2));
strokes = gimp_value_get_float_array (gimp_value_array_index (args, 2), (gsize *) &num_strokes);
if (success)
{
@ -509,7 +509,7 @@ eraser_invoker (GimpProcedure *procedure,
drawable = g_value_get_object (gimp_value_array_index (args, 0));
num_strokes = g_value_get_int (gimp_value_array_index (args, 1));
strokes = gimp_value_get_float_array (gimp_value_array_index (args, 2));
strokes = gimp_value_get_float_array (gimp_value_array_index (args, 2), (gsize *) &num_strokes);
hardness = g_value_get_enum (gimp_value_array_index (args, 3));
method = g_value_get_enum (gimp_value_array_index (args, 4));
@ -559,7 +559,7 @@ eraser_default_invoker (GimpProcedure *procedure,
drawable = g_value_get_object (gimp_value_array_index (args, 0));
num_strokes = g_value_get_int (gimp_value_array_index (args, 1));
strokes = gimp_value_get_float_array (gimp_value_array_index (args, 2));
strokes = gimp_value_get_float_array (gimp_value_array_index (args, 2), (gsize *) &num_strokes);
if (success)
{
@ -608,7 +608,7 @@ heal_invoker (GimpProcedure *procedure,
src_x = g_value_get_double (gimp_value_array_index (args, 2));
src_y = g_value_get_double (gimp_value_array_index (args, 3));
num_strokes = g_value_get_int (gimp_value_array_index (args, 4));
strokes = gimp_value_get_float_array (gimp_value_array_index (args, 5));
strokes = gimp_value_get_float_array (gimp_value_array_index (args, 5), (gsize *) &num_strokes);
if (success)
{
@ -661,7 +661,7 @@ heal_default_invoker (GimpProcedure *procedure,
drawable = g_value_get_object (gimp_value_array_index (args, 0));
num_strokes = g_value_get_int (gimp_value_array_index (args, 1));
strokes = gimp_value_get_float_array (gimp_value_array_index (args, 2));
strokes = gimp_value_get_float_array (gimp_value_array_index (args, 2), (gsize *) &num_strokes);
if (success)
{
@ -708,7 +708,7 @@ paintbrush_invoker (GimpProcedure *procedure,
drawable = g_value_get_object (gimp_value_array_index (args, 0));
fade_out = g_value_get_double (gimp_value_array_index (args, 1));
num_strokes = g_value_get_int (gimp_value_array_index (args, 2));
strokes = gimp_value_get_float_array (gimp_value_array_index (args, 3));
strokes = gimp_value_get_float_array (gimp_value_array_index (args, 3), (gsize *) &num_strokes);
method = g_value_get_enum (gimp_value_array_index (args, 4));
gradient_length = g_value_get_double (gimp_value_array_index (args, 5));
@ -789,7 +789,7 @@ paintbrush_default_invoker (GimpProcedure *procedure,
drawable = g_value_get_object (gimp_value_array_index (args, 0));
num_strokes = g_value_get_int (gimp_value_array_index (args, 1));
strokes = gimp_value_get_float_array (gimp_value_array_index (args, 2));
strokes = gimp_value_get_float_array (gimp_value_array_index (args, 2), (gsize *) &num_strokes);
if (success)
{
@ -832,7 +832,7 @@ pencil_invoker (GimpProcedure *procedure,
drawable = g_value_get_object (gimp_value_array_index (args, 0));
num_strokes = g_value_get_int (gimp_value_array_index (args, 1));
strokes = gimp_value_get_float_array (gimp_value_array_index (args, 2));
strokes = gimp_value_get_float_array (gimp_value_array_index (args, 2), (gsize *) &num_strokes);
if (success)
{
@ -877,7 +877,7 @@ smudge_invoker (GimpProcedure *procedure,
drawable = g_value_get_object (gimp_value_array_index (args, 0));
pressure = g_value_get_double (gimp_value_array_index (args, 1));
num_strokes = g_value_get_int (gimp_value_array_index (args, 2));
strokes = gimp_value_get_float_array (gimp_value_array_index (args, 3));
strokes = gimp_value_get_float_array (gimp_value_array_index (args, 3), (gsize *) &num_strokes);
if (success)
{
@ -924,7 +924,7 @@ smudge_default_invoker (GimpProcedure *procedure,
drawable = g_value_get_object (gimp_value_array_index (args, 0));
num_strokes = g_value_get_int (gimp_value_array_index (args, 1));
strokes = gimp_value_get_float_array (gimp_value_array_index (args, 2));
strokes = gimp_value_get_float_array (gimp_value_array_index (args, 2), (gsize *) &num_strokes);
if (success)
{

View File

@ -735,7 +735,7 @@ path_stroke_new_from_points_invoker (GimpProcedure *procedure,
path = g_value_get_object (gimp_value_array_index (args, 0));
type = g_value_get_enum (gimp_value_array_index (args, 1));
num_points = g_value_get_int (gimp_value_array_index (args, 2));
controlpoints = gimp_value_get_float_array (gimp_value_array_index (args, 3));
controlpoints = gimp_value_get_float_array (gimp_value_array_index (args, 3), (gsize *) &num_points);
closed = g_value_get_boolean (gimp_value_array_index (args, 4));
if (success)

View File

@ -1137,7 +1137,7 @@ plug_in_convmatrix_invoker (GimpProcedure *procedure,
drawable = g_value_get_object (gimp_value_array_index (args, 2));
argc_matrix = g_value_get_int (gimp_value_array_index (args, 3));
matrix = gimp_value_get_float_array (gimp_value_array_index (args, 4));
matrix = gimp_value_get_float_array (gimp_value_array_index (args, 4), (gsize *) &argc_matrix);
alpha_alg = g_value_get_boolean (gimp_value_array_index (args, 5));
divisor = g_value_get_double (gimp_value_array_index (args, 6));
offset = g_value_get_double (gimp_value_array_index (args, 7));

View File

@ -722,28 +722,6 @@ gimp_plug_in_handle_proc_install (GimpPlugIn *plug_in,
return;
}
/* Sanity check for array arguments */
for (i = 1; i < proc_install->n_params; i++)
{
GPParamDef *param_def = &proc_install->params[i];
GPParamDef *prev_param_def = &proc_install->params[i - 1];
if (! strcmp (param_def->type_name, "GimpParamFloatArray") &&
strcmp (prev_param_def->type_name, "GParamInt"))
{
gimp_message (plug_in->manager->gimp, NULL, GIMP_MESSAGE_ERROR,
"Plug-in \"%s\"\n(%s)\n\n"
"attempted to install procedure \"%s\" "
"which fails to comply with the array parameter "
"passing standard. Argument %d is noncompliant.",
gimp_object_get_name (plug_in),
gimp_file_get_utf8_name (plug_in->file),
proc_install->name, i);
return;
}
}
/* Sanity check strings for UTF-8 validity */
#define VALIDATE(str) ((str) == NULL || g_utf8_validate ((str), -1, NULL))

View File

@ -1160,7 +1160,7 @@ gimp_context_get_line_dash_pattern (gint *num_dashes,
if (success)
{
*num_dashes = GIMP_VALUES_GET_INT (return_vals, 1);
*dashes = GIMP_VALUES_DUP_FLOAT_ARRAY (return_vals, 2);
*dashes = GIMP_VALUES_DUP_FLOAT_ARRAY (return_vals, 2, (gsize *) num_dashes);
}
gimp_value_array_unref (return_vals);

View File

@ -196,7 +196,7 @@ gimp_gradient_get_uniform_samples (GimpGradient *gradient,
if (success)
{
*num_color_samples = GIMP_VALUES_GET_INT (return_vals, 1);
*color_samples = GIMP_VALUES_DUP_FLOAT_ARRAY (return_vals, 2);
*color_samples = GIMP_VALUES_DUP_FLOAT_ARRAY (return_vals, 2, (gsize *) num_color_samples);
}
gimp_value_array_unref (return_vals);
@ -257,7 +257,7 @@ gimp_gradient_get_custom_samples (GimpGradient *gradient,
if (success)
{
*num_color_samples = GIMP_VALUES_GET_INT (return_vals, 1);
*color_samples = GIMP_VALUES_DUP_FLOAT_ARRAY (return_vals, 2);
*color_samples = GIMP_VALUES_DUP_FLOAT_ARRAY (return_vals, 2, (gsize *) num_color_samples);
}
gimp_value_array_unref (return_vals);

View File

@ -703,7 +703,7 @@ gimp_path_stroke_get_points (GimpPath *path,
{
type = GIMP_VALUES_GET_ENUM (return_vals, 1);
*num_points = GIMP_VALUES_GET_INT (return_vals, 2);
*controlpoints = GIMP_VALUES_DUP_FLOAT_ARRAY (return_vals, 3);
*controlpoints = GIMP_VALUES_DUP_FLOAT_ARRAY (return_vals, 3, (gsize *) num_points);
*closed = GIMP_VALUES_GET_BOOLEAN (return_vals, 4);
}
@ -812,7 +812,7 @@ gimp_path_stroke_interpolate (GimpPath *path,
if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS)
{
*num_coords = GIMP_VALUES_GET_INT (return_vals, 1);
coords = GIMP_VALUES_DUP_FLOAT_ARRAY (return_vals, 2);
coords = GIMP_VALUES_DUP_FLOAT_ARRAY (return_vals, 2, (gsize *) num_coords);
*closed = GIMP_VALUES_GET_BOOLEAN (return_vals, 3);
}

View File

@ -198,11 +198,11 @@ G_BEGIN_DECLS
/* float array */
#define GIMP_VALUES_GET_FLOAT_ARRAY(args, n) \
gimp_value_get_float_array (gimp_value_array_index (args, n))
#define GIMP_VALUES_GET_FLOAT_ARRAY(args, n, length) \
gimp_value_get_float_array (gimp_value_array_index (args, n), length)
#define GIMP_VALUES_DUP_FLOAT_ARRAY(args, n) \
gimp_value_dup_float_array (gimp_value_array_index (args, n))
#define GIMP_VALUES_DUP_FLOAT_ARRAY(args, n, length) \
gimp_value_dup_float_array (gimp_value_array_index (args, n), length)
#define GIMP_VALUES_SET_FLOAT_ARRAY(args, n, value, length) \
gimp_value_set_float_array (gimp_value_array_index (args, n), value, length)

View File

@ -71,6 +71,8 @@ EXPORTS
gimp_flags_value_get_desc
gimp_flags_value_get_help
gimp_float_array_get_type
gimp_float_array_get_values
gimp_float_array_set_values
gimp_foreground_extract_mode_get_type
gimp_gradient_blend_color_space_get_type
gimp_gradient_segment_color_get_type

View File

@ -687,6 +687,49 @@ gimp_value_take_int32_array (GValue *value,
typedef GimpArray GimpFloatArray;
G_DEFINE_BOXED_TYPE (GimpFloatArray, gimp_float_array, gimp_array_copy, gimp_array_free)
/**
* gimp_float_array_get_values:
* @array: the #GimpArray representing #float values.
* @length: the number of #float values in the returned array.
*
* Returns: (array length=length) (transfer none): a C-array of #gdouble.
*/
const gdouble *
gimp_float_array_get_values (GimpArray *array,
gsize *length)
{
g_return_val_if_fail (array->length % sizeof (gdouble) == 0, NULL);
if (length)
*length = array->length / sizeof (gdouble);
return (const gdouble *) array->data;
}
/**
* gimp_float_array_set_values:
* @array: the array to modify.
* @values: (array length=length): the C-array.
* @length: the number of #float values in @data.
* @static_data: whether @data is a static rather than allocated array.
*/
void
gimp_float_array_set_values (GimpArray *array,
const gdouble *values,
gsize length,
gboolean static_data)
{
g_return_if_fail ((values == NULL && length == 0) || (values != NULL && length > 0));
if (! array->static_data)
g_free (array->data);
array->length = length * sizeof (gdouble);
array->data = static_data ? (guint8 *) values : g_memdup2 (values, array->length);
array->static_data = static_data;
}
/*
* GIMP_TYPE_PARAM_FLOAT_ARRAY
*/
@ -763,32 +806,54 @@ gimp_param_spec_float_array (const gchar *name,
/**
* gimp_value_get_float_array:
* @value: A valid value of type %GIMP_TYPE_FLOAT_ARRAY
* @length: the number of returned #double elements.
*
* Gets the contents of a %GIMP_TYPE_FLOAT_ARRAY #GValue
*
* Returns: (transfer none) (array): The contents of @value
* Returns: (transfer none) (array length=length): The contents of @value
*/
const gdouble *
gimp_value_get_float_array (const GValue *value)
gimp_value_get_float_array (const GValue *value,
gsize *length)
{
GimpArray *array;
g_return_val_if_fail (GIMP_VALUE_HOLDS_FLOAT_ARRAY (value), NULL);
array = value->data[0].v_pointer;
g_return_val_if_fail (array->length % sizeof (gdouble) == 0, NULL);
if (length)
*length = array->length / sizeof (gdouble);
return (const gdouble *) gimp_value_get_array (value);
}
/**
* gimp_value_dup_float_array:
* @value: A valid value of type %GIMP_TYPE_FLOAT_ARRAY
* @length: the number of returned #double elements.
*
* Gets the contents of a %GIMP_TYPE_FLOAT_ARRAY #GValue
*
* Returns: (transfer full) (array): The contents of @value
* Returns: (transfer full) (array length=length): The contents of @value
*/
gdouble *
gimp_value_dup_float_array (const GValue *value)
gimp_value_dup_float_array (const GValue *value,
gsize *length)
{
GimpArray *array;
g_return_val_if_fail (GIMP_VALUE_HOLDS_FLOAT_ARRAY (value), NULL);
array = value->data[0].v_pointer;
g_return_val_if_fail (array->length % sizeof (gdouble) == 0, NULL);
if (length)
*length = array->length / sizeof (gdouble);
return (gdouble *) gimp_value_dup_array (value);
}

View File

@ -270,6 +270,13 @@ void gimp_value_take_int32_array (GValue *value,
GType gimp_float_array_get_type (void) G_GNUC_CONST;
const gdouble * gimp_float_array_get_values (GimpArray *array,
gsize *length);
void gimp_float_array_set_values (GimpArray *array,
const gdouble *values,
gsize length,
gboolean static_data);
/*
* GIMP_TYPE_PARAM_FLOAT_ARRAY
@ -293,8 +300,10 @@ GParamSpec * gimp_param_spec_float_array (const gchar *name,
const gchar *blurb,
GParamFlags flags);
const gdouble * gimp_value_get_float_array (const GValue *value);
gdouble * gimp_value_dup_float_array (const GValue *value);
const gdouble * gimp_value_get_float_array (const GValue *value,
gsize *length);
gdouble * gimp_value_dup_float_array (const GValue *value,
gsize *length);
void gimp_value_set_float_array (GValue *value,
const gdouble *data,
gsize length);

View File

@ -384,7 +384,8 @@ gimp_config_deserialize_value (GValue *value,
{
return gimp_config_deserialize_strv (value, scanner);
}
else if (prop_spec->value_type == GIMP_TYPE_INT32_ARRAY)
else if (prop_spec->value_type == GIMP_TYPE_INT32_ARRAY ||
prop_spec->value_type == GIMP_TYPE_FLOAT_ARRAY)
{
return gimp_config_deserialize_array (value, scanner);
}
@ -943,9 +944,14 @@ gimp_config_deserialize_array (GValue *value,
if (! gimp_scanner_parse_int (scanner, &n_values))
return G_TOKEN_INT;
if (GIMP_VALUE_HOLDS_INT32_ARRAY (value))
values = g_new0 (gint32, n_values);
else /* GIMP_VALUE_HOLDS_FLOAT_ARRAY (value) */
values = (gint32 *) g_new0 (gdouble, n_values);
for (gint i = 0; i < n_values; i++)
{
if (GIMP_VALUE_HOLDS_INT32_ARRAY (value))
{
gint value;
@ -957,10 +963,26 @@ gimp_config_deserialize_array (GValue *value,
values[i] = value;
}
else
{
gdouble value;
if (! gimp_scanner_parse_float (scanner, &value))
{
result_token = G_TOKEN_FLOAT;
break;
}
((gdouble *) values)[i] = value;
}
}
if (result_token == G_TOKEN_RIGHT_PAREN)
{
if (GIMP_VALUE_HOLDS_INT32_ARRAY (value))
gimp_value_take_int32_array (value, values, n_values);
else
gimp_value_take_float_array (value, (gdouble *) values, n_values);
}
else
{

View File

@ -514,7 +514,8 @@ gimp_config_serialize_value (const GValue *value,
return gimp_config_serialize_strv (value, str);
}
if (GIMP_VALUE_HOLDS_INT32_ARRAY (value))
if (GIMP_VALUE_HOLDS_INT32_ARRAY (value) ||
GIMP_VALUE_HOLDS_FLOAT_ARRAY (value))
{
return gimp_config_serialize_array (value, str);
}
@ -743,25 +744,42 @@ gimp_config_serialize_array (const GValue *value,
{
GimpArray *array;
g_return_val_if_fail (GIMP_VALUE_HOLDS_INT32_ARRAY (value), FALSE);
g_return_val_if_fail (GIMP_VALUE_HOLDS_INT32_ARRAY (value) ||
GIMP_VALUE_HOLDS_FLOAT_ARRAY (value), FALSE);
array = g_value_get_boxed (value);
if (array)
{
gint32 *values = (gint32 *) array->data;
gint length = array->length / sizeof (gint32);
gint length;
if (GIMP_VALUE_HOLDS_INT32_ARRAY (value))
length = array->length / sizeof (gint32);
else
length = array->length / sizeof (gdouble);
/* Write length */
g_string_append_printf (str, "%d", length);
for (gint i = 0; i < length; i++)
{
gchar *istr;
gchar *num_str;
istr = g_strdup_printf (" %d", values[i]);
g_string_append (str, istr);
g_free (istr);
if (GIMP_VALUE_HOLDS_INT32_ARRAY (value))
{
num_str = g_strdup_printf (" %d", values[i]);
}
else
{
gchar buf[G_ASCII_DTOSTR_BUF_SIZE];
g_ascii_dtostr (buf, sizeof (buf), ((gdouble *) values)[i]);
num_str = g_strdup_printf (" %s", buf);
}
g_string_append (str, num_str);
g_free (num_str);
}
}
else

View File

@ -92,8 +92,8 @@ package Gimp::CodeGen::pdb;
init_value => 'NULL',
in_annotate => '(element-type gdouble)',
out_annotate => '(element-type gdouble) (transfer full)',
get_value_func => '$var = gimp_value_get_float_array ($value)',
dup_value_func => '$var = GIMP_VALUES_DUP_FLOAT_ARRAY ($value)',
get_value_func => '$var = gimp_value_get_float_array ($value, (gsize *) &$var_len)',
dup_value_func => '$var = GIMP_VALUES_DUP_FLOAT_ARRAY ($value, (gsize *) $var_len)',
set_value_func => 'gimp_value_set_float_array ($value, $var, $var_len)',
take_value_func => 'gimp_value_take_float_array ($value, $var, $var_len)' },

View File

@ -466,48 +466,24 @@ bender_create_procedure (GimpPlugIn *plug_in,
"upper",
G_PARAM_READWRITE);
gimp_procedure_add_int_argument (procedure, "argc-upper-point-x",
_("Argc upper point X"),
_("Argc upper point X"),
2, 17, 2,
G_PARAM_READWRITE);
gimp_procedure_add_float_array_argument (procedure, "upper-point-x",
_("Upper point X"),
_("Array of 17 x point coords "
"{ 0.0 <= x <= 1.0 or -1 for unused point }"),
G_PARAM_READWRITE);
gimp_procedure_add_int_argument (procedure, "argc-upper-point-y",
_("Argc upper point Y"),
_("Argc upper point Y"),
2, 17, 2,
G_PARAM_READWRITE);
gimp_procedure_add_float_array_argument (procedure, "upper-point-y",
_("Upper point Y"),
_("Array of 17 y point coords "
"{ 0.0 <= y <= 1.0 or -1 for unused point }"),
G_PARAM_READWRITE);
gimp_procedure_add_int_argument (procedure, "argc-lower-point-x",
_("Argc lower point X"),
_("Argc lower point X"),
2, 17, 2,
G_PARAM_READWRITE);
gimp_procedure_add_float_array_argument (procedure, "lower-point-x",
_("Lower point X"),
_("Array of 17 x point coords "
"{ 0.0 <= x <= 1.0 or -1 for unused point }"),
G_PARAM_READWRITE);
gimp_procedure_add_int_argument (procedure, "argc-lower-point-y",
_("Argc lower point Y"),
_("Argc lower point Y"),
2, 17, 2,
G_PARAM_READWRITE);
gimp_procedure_add_float_array_argument (procedure, "lower-point-y",
_("Lower point Y"),
_("Array of 17 y point coords "

View File

@ -36,7 +36,6 @@ static pointer marshal_returned_PDB_values (scheme *sc,
static pointer marshal_returned_PDB_value (scheme *sc,
GValue *value,
guint array_length,
pointer *error);
@ -220,7 +219,7 @@ marshal_PDB_return_by_arity (scheme *sc,
{
/* Marshal to single value not wrapped in list. */
/* The value is second in the GVA, beyond the PDB status value. */
result = marshal_returned_PDB_value (sc, gimp_value_array_index (values, 1), 2, &marshalling_error);
result = marshal_returned_PDB_value (sc, gimp_value_array_index (values, 1), &marshalling_error);
}
else
{
@ -278,27 +277,16 @@ marshal_returned_PDB_values (scheme *sc,
*error = NULL;
/* Counting down, i.e. traversing in reverse.
* i+1 is the current index. i is the preceding value.
* When at the current index is an array, preceding value (at i) is array length.
*/
for (gint i = gimp_value_array_length (values) - 2; i >= 0; --i)
/* Counting down, i.e. traversing in reverse. */
for (gint i = gimp_value_array_length (values) - 1; i > 0; --i)
{
GValue *value = gimp_value_array_index (values, i + 1);
GValue *value = gimp_value_array_index (values, i);
pointer scheme_value;
pointer single_error = NULL;
gint32 array_length = 0;
g_debug ("Return value %d is type %s", i+1, G_VALUE_TYPE_NAME (value));
g_debug ("Return value %d is type %s", i, G_VALUE_TYPE_NAME (value));
/* In some cases previous value is array_length. */
if ( GIMP_VALUE_HOLDS_INT32_ARRAY (value)
|| GIMP_VALUE_HOLDS_FLOAT_ARRAY (value))
{
array_length = GIMP_VALUES_GET_INT (values, i);
}
scheme_value = marshal_returned_PDB_value (sc, value, array_length, &single_error);
scheme_value = marshal_returned_PDB_value (sc, value, &single_error);
if (single_error == NULL)
{
@ -337,10 +325,6 @@ marshal_returned_PDB_values (scheme *sc,
*
* Returns a scheme "pointer" type referencing the scheme value.
*
* When the value has C type an array type,
* array_length must be its length,
* otherwise array_length is not used.
*
* Either returns a non-null scheme value and sets error to null,
* or sets error and returns a null scheme value.
* IOW, error is an OUT argument.
@ -358,7 +342,6 @@ marshal_returned_PDB_values (scheme *sc,
static pointer
marshal_returned_PDB_value (scheme *sc,
GValue *value,
guint array_length,
pointer *error)
{
pointer result = sc->NIL;
@ -469,6 +452,7 @@ marshal_returned_PDB_value (scheme *sc,
}
else if (GIMP_VALUE_HOLDS_INT32_ARRAY (value))
{
guint array_length;
const gint32 *v = gimp_value_get_int32_array (value, (gsize *) &array_length);
pointer vector = sc->vptr->mk_vector (sc, array_length);
@ -497,7 +481,8 @@ marshal_returned_PDB_value (scheme *sc,
}
else if (GIMP_VALUE_HOLDS_FLOAT_ARRAY (value))
{
const gdouble *v = gimp_value_get_float_array (value);
guint array_length;
const gdouble *v = gimp_value_get_float_array (value, (gsize *) &array_length);
pointer vector = sc->vptr->mk_vector (sc, array_length);
for (j = 0; j < array_length; j++)

View File

@ -1084,7 +1084,9 @@ script_fu_marshal_procedure_call (scheme *sc,
{
vector = sc->vptr->pair_car (a);
if (! sc->vptr->is_vector (vector))
{
return script_type_error (sc, "vector", i, proc_name);
}
else
{
/* !!! Comments applying to all array args.
@ -1108,16 +1110,7 @@ script_fu_marshal_procedure_call (scheme *sc,
*/
gint32 *array;
if (i == 0)
return script_error (sc, "The first argument cannot be an array", a);
else if (! g_type_is_a (arg_specs[i - 1]->value_type, G_TYPE_INT))
return script_error (sc, "Array arguments must be preceded by an int argument (number of items)", a);
g_object_get (config, arg_specs[i - 1]->name, &n_elements, NULL);
if (n_elements > sc->vptr->vector_length (vector))
return script_length_error_in_vector (sc, i, proc_name, n_elements, vector);
n_elements = sc->vptr->vector_length (vector);
array = g_new0 (gint32, n_elements);
for (j = 0; j < n_elements; j++)
@ -1179,16 +1172,7 @@ script_fu_marshal_procedure_call (scheme *sc,
{
gdouble *array;
if (i == 0)
return script_error (sc, "The first argument cannot be an array", a);
else if (! g_type_is_a (arg_specs[i - 1]->value_type, G_TYPE_INT))
return script_error (sc, "Array arguments must be preceded by an int argument (number of items)", a);
g_object_get (config, arg_specs[i - 1]->name, &n_elements, NULL);
if (n_elements > sc->vptr->vector_length (vector))
return script_length_error_in_vector (sc, i, proc_name, n_elements, vector);
n_elements = sc->vptr->vector_length (vector);
array = g_new0 (gdouble, n_elements);
for (j = 0; j < n_elements; j++)
@ -1201,7 +1185,7 @@ script_fu_marshal_procedure_call (scheme *sc,
return script_type_error_in_container (sc, "numeric", i, j, proc_name, vector);
}
array[j] = (gfloat) sc->vptr->rvalue (v_element);
array[j] = (gdouble) sc->vptr->rvalue (v_element);
}
gimp_value_take_float_array (&value, array, n_elements);