app, libgimp*, plug-ins: int32 array arguments don't need a size argument anymore.

GimpArray (and therefore the int32 array typedef) contains its own size.
We don't need to store the array size in a preceding argument.

Also adding gimp_int32_array_get_values() and gimp_int32_array_set_values()
to edit an existing GimpArray.
This comes with the fact we should start making the GimpArray type more
explicit, because clearly by trying to hide this type so much, it was
too much looking like the int32 array param spec was expecting a C array
(as was visible in the file-ico plug-in where we were getting a C array,
which was a bug only made invisible by the fact we were not setting the
C array back in the config object in the end).

Last but not least, I finally implemented int32 array (de)serialization.

As a side fix, the "images" arg in file-pdf-export-multi procedure is
now a proper image array (not an int32 array), and of course the "count"
arg was removed.
This commit is contained in:
Jehan 2024-10-24 17:43:09 +02:00
parent 60eb27ab18
commit f2b9babfb4
13 changed files with 306 additions and 187 deletions

View file

@ -85,6 +85,8 @@ EXPORTS
gimp_installation_directory
gimp_installation_directory_file
gimp_int32_array_get_type
gimp_int32_array_get_values
gimp_int32_array_set_values
gimp_interpolation_type_get_type
gimp_is_canonical_identifier
gimp_join_style_get_type

View file

@ -452,6 +452,49 @@ gimp_value_take_array (GValue *value,
typedef GimpArray GimpInt32Array;
G_DEFINE_BOXED_TYPE (GimpInt32Array, gimp_int32_array, gimp_array_copy, gimp_array_free)
/**
* gimp_int32_array_get_values:
* @array: the #GimpArray representing #int32 values.
* @length: the number of #int32 values in the returned array.
*
* Returns: (array length=length) (transfer none): a C-array of #gint32.
*/
const gint32 *
gimp_int32_array_get_values (GimpArray *array,
gsize *length)
{
g_return_val_if_fail (array->length % sizeof (gint32) == 0, NULL);
if (length)
*length = array->length / sizeof (gint32);
return (const gint32 *) array->data;
}
/**
* gimp_int32_array_set_values:
* @array: the array to modify.
* @values: (array length=length): the C-array.
* @length: the number of #int32 values in @data.
* @static_data: whether @data is a static rather than allocated array.
*/
void
gimp_int32_array_set_values (GimpArray *array,
const gint32 *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 (gint32);
array->data = static_data ? (guint8 *) values : g_memdup2 (values, array->length);
array->static_data = static_data;
}
/*
* GIMP_TYPE_PARAM_INT32_ARRAY
*/

View file

@ -211,10 +211,17 @@ GParamSpec * gimp_param_spec_array (const gchar *name,
* GIMP_TYPE_INT32_ARRAY
*/
#define GIMP_TYPE_INT32_ARRAY (gimp_int32_array_get_type ())
#define GIMP_VALUE_HOLDS_INT32_ARRAY(value) (G_TYPE_CHECK_VALUE_TYPE ((value), GIMP_TYPE_INT32_ARRAY))
#define GIMP_TYPE_INT32_ARRAY (gimp_int32_array_get_type ())
#define GIMP_VALUE_HOLDS_INT32_ARRAY(value) (G_TYPE_CHECK_VALUE_TYPE ((value), GIMP_TYPE_INT32_ARRAY))
GType gimp_int32_array_get_type (void) G_GNUC_CONST;
GType gimp_int32_array_get_type (void) G_GNUC_CONST;
const gint32 * gimp_int32_array_get_values (GimpArray *array,
gsize *length);
void gimp_int32_array_set_values (GimpArray *array,
const gint32 *values,
gsize length,
gboolean static_data);
/*