app, libgimp, pdb: imagearray PDB type as GimpCoreObjectArray.

This commit is contained in:
Jehan 2024-10-22 13:10:06 +02:00
parent 64f9c71ad5
commit 08fd3a3f0d
9 changed files with 41 additions and 71 deletions

View file

@ -113,27 +113,20 @@ get_images_invoker (GimpProcedure *procedure,
GError **error) GError **error)
{ {
GimpValueArray *return_vals; GimpValueArray *return_vals;
gint num_images = 0;
GimpImage **images = NULL; GimpImage **images = NULL;
GList *list = gimp_get_image_iter (gimp); GList *list = gimp_get_image_iter (gimp);
gsize num_images;
gint i;
num_images = g_list_length (list); num_images = g_list_length (list);
images = g_new0 (GimpImage *, num_images + 1);
if (num_images) for (i = 0; i < num_images; i++, list = g_list_next (list))
{ images[i] = list->data;
gint i;
images = g_new (GimpImage *, num_images);
for (i = 0; i < num_images; i++, list = g_list_next (list))
images[i] = g_object_ref (list->data);
}
return_vals = gimp_procedure_get_return_values (procedure, TRUE, NULL); return_vals = gimp_procedure_get_return_values (procedure, TRUE, NULL);
g_value_take_boxed (gimp_value_array_index (return_vals, 1), images);
g_value_set_int (gimp_value_array_index (return_vals, 1), num_images);
gimp_value_take_object_array (gimp_value_array_index (return_vals, 2), GIMP_TYPE_IMAGE, (GObject **) images, num_images);
return return_vals; return return_vals;
} }
@ -3077,17 +3070,11 @@ register_image_procs (GimpPDB *pdb)
"Spencer Kimball & Peter Mattis", "Spencer Kimball & Peter Mattis",
"1995-1996"); "1995-1996");
gimp_procedure_add_return_value (procedure, gimp_procedure_add_return_value (procedure,
g_param_spec_int ("num-images", gimp_param_spec_core_object_array ("images",
"num images", "images",
"The number of images currently open", "The list of images currently open.",
0, G_MAXINT32, 0, GIMP_TYPE_IMAGE,
GIMP_PARAM_READWRITE)); GIMP_PARAM_READWRITE));
gimp_procedure_add_return_value (procedure,
gimp_param_spec_object_array ("images",
"images",
"The list of images currently open.",
GIMP_TYPE_IMAGE,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure); gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure); g_object_unref (procedure);

View file

@ -201,13 +201,12 @@ GList *
gimp_list_images (void) gimp_list_images (void)
{ {
GimpImage **images; GimpImage **images;
gint num_images;
GList *list = NULL; GList *list = NULL;
gint i; gint i;
images = gimp_get_images (&num_images); images = gimp_get_images ();
for (i = 0; i < num_images; i++) for (i = 0; images[i] != NULL; i++)
list = g_list_prepend (list, images[i]); list = g_list_prepend (list, images[i]);
g_free (images); g_free (images);

View file

@ -76,18 +76,16 @@ gimp_image_id_is_valid (gint image_id)
/** /**
* gimp_get_images: * gimp_get_images:
* @num_images: (out): The number of images currently open.
* *
* Returns the list of images currently open. * Returns the list of images currently open.
* *
* This procedure returns the list of images currently open in GIMP. * This procedure returns the list of images currently open in GIMP.
* *
* Returns: (array length=num_images) (element-type GimpImage) (transfer container): * Returns: (element-type GimpImage) (array zero-terminated=1) (transfer container):
* The list of images currently open. * The list of images currently open.
* The returned value must be freed with g_free().
**/ **/
GimpImage ** GimpImage **
gimp_get_images (gint *num_images) gimp_get_images (void)
{ {
GimpValueArray *args; GimpValueArray *args;
GimpValueArray *return_vals; GimpValueArray *return_vals;
@ -101,13 +99,8 @@ gimp_get_images (gint *num_images)
args); args);
gimp_value_array_unref (args); gimp_value_array_unref (args);
*num_images = 0;
if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS) if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS)
{ images = g_value_dup_boxed (gimp_value_array_index (return_vals, 1));
*num_images = GIMP_VALUES_GET_INT (return_vals, 1);
{ GimpObjectArray *a = g_value_get_boxed (gimp_value_array_index (return_vals, 2)); if (a) images = g_memdup2 (a->data, a->length * sizeof (gpointer)); };
}
gimp_value_array_unref (return_vals); gimp_value_array_unref (return_vals);

View file

@ -33,7 +33,7 @@ G_BEGIN_DECLS
gboolean gimp_image_id_is_valid (gint image_id); gboolean gimp_image_id_is_valid (gint image_id);
GimpImage** gimp_get_images (gint *num_images); GimpImage** gimp_get_images (void);
GimpImage* gimp_image_new (gint width, GimpImage* gimp_image_new (gint width,
gint height, gint height,
GimpImageBaseType type); GimpImageBaseType type);

View file

@ -26,7 +26,6 @@ gimp_c_test_run (GimpProcedure *procedure,
GimpLayer *export_layer; GimpLayer *export_layer;
GimpExportOptions *options; GimpExportOptions *options;
GimpExportReturn delete; GimpExportReturn delete;
gint n_images;
gboolean identical_buffers; gboolean identical_buffers;
new_image = gimp_image_new (NEW_IMAGE_WIDTH, NEW_IMAGE_HEIGHT, GIMP_RGB); new_image = gimp_image_new (NEW_IMAGE_WIDTH, NEW_IMAGE_HEIGHT, GIMP_RGB);
@ -42,8 +41,8 @@ gimp_c_test_run (GimpProcedure *procedure,
NULL); NULL);
GIMP_TEST_START("Verify start state (1)"); GIMP_TEST_START("Verify start state (1)");
images = gimp_get_images (&n_images); images = gimp_get_images ();
GIMP_TEST_END(n_images == 1 && images[0] == new_image); GIMP_TEST_END(gimp_core_object_array_get_length ((GObject **) images) == 1 && images[0] == new_image);
g_free (images); g_free (images);
GIMP_TEST_START("Verify start state (2)"); GIMP_TEST_START("Verify start state (2)");
@ -55,8 +54,8 @@ gimp_c_test_run (GimpProcedure *procedure,
GIMP_TEST_START("gimp_export_options_get_image() created a new image"); GIMP_TEST_START("gimp_export_options_get_image() created a new image");
delete = gimp_export_options_get_image (options, &new_image); delete = gimp_export_options_get_image (options, &new_image);
images = gimp_get_images (&n_images); images = gimp_get_images ();
GIMP_TEST_END(delete == GIMP_EXPORT_EXPORT && n_images == 2 && new_image != original_image); GIMP_TEST_END(delete == GIMP_EXPORT_EXPORT && gimp_core_object_array_get_length ((GObject **) images) == 2 && new_image != original_image);
g_free (images); g_free (images);
GIMP_TEST_START("The new image has a single layer"); GIMP_TEST_START("The new image has a single layer");

View file

@ -16,15 +16,14 @@ gimp_c_test_run (GimpProcedure *procedure,
GimpImage **images; GimpImage **images;
GimpImage *new_image; GimpImage *new_image;
GimpTextLayer *text_layer; GimpTextLayer *text_layer;
gint n_images;
GIMP_TEST_START("gimp_image_new()"); GIMP_TEST_START("gimp_image_new()");
new_image = gimp_image_new (NEW_IMAGE_WIDTH, NEW_IMAGE_HEIGHT, GIMP_RGB); new_image = gimp_image_new (NEW_IMAGE_WIDTH, NEW_IMAGE_HEIGHT, GIMP_RGB);
GIMP_TEST_END(GIMP_IS_IMAGE (new_image)); GIMP_TEST_END(GIMP_IS_IMAGE (new_image));
GIMP_TEST_START("gimp_get_images()"); GIMP_TEST_START("gimp_get_images()");
images = gimp_get_images (&n_images); images = gimp_get_images ();
GIMP_TEST_END(n_images == 1 && images[0] == new_image); GIMP_TEST_END(gimp_core_object_array_get_length ((GObject **) images) == 1 && images[0] == new_image);
g_free (images); g_free (images);
GIMP_TEST_START("gimp_text_layer_new() with point unit"); GIMP_TEST_START("gimp_text_layer_new() with point unit");

View file

@ -682,11 +682,11 @@ CODE
} }
elsif ($pdbtype eq 'imagearray') { elsif ($pdbtype eq 'imagearray') {
$pspec = <<CODE; $pspec = <<CODE;
gimp_param_spec_object_array ("$name", gimp_param_spec_core_object_array ("$name",
"$nick", "$nick",
"$blurb", "$blurb",
GIMP_TYPE_IMAGE, GIMP_TYPE_IMAGE,
$flags) $flags)
CODE CODE
} }
elsif ($pdbtype eq 'itemarray') { elsif ($pdbtype eq 'itemarray') {

View file

@ -56,27 +56,21 @@ HELP
@outargs = ( @outargs = (
{ name => 'images', type => 'imagearray', { name => 'images', type => 'imagearray',
desc => 'The list of images currently open.', desc => 'The list of images currently open.' }
array => { name => 'num_images',
desc => 'The number of images currently open' } }
); );
%invoke = ( %invoke = (
code => <<CODE code => <<CODE
{ {
GList *list = gimp_get_image_iter (gimp); GList *list = gimp_get_image_iter (gimp);
gsize num_images;
gint i;
num_images = g_list_length (list); num_images = g_list_length (list);
images = g_new0 (GimpImage *, num_images + 1);
if (num_images) for (i = 0; i < num_images; i++, list = g_list_next (list))
{ images[i] = list->data;
gint i;
images = g_new (GimpImage *, num_images);
for (i = 0; i < num_images; i++, list = g_list_next (list))
images[i] = g_object_ref (list->data);
}
} }
CODE CODE
); );

View file

@ -110,17 +110,16 @@ package Gimp::CodeGen::pdb;
take_value_func => 'g_value_take_boxed ($value, $var)' }, take_value_func => 'g_value_take_boxed ($value, $var)' },
imagearray => { name => 'IMAGEARRAY', imagearray => { name => 'IMAGEARRAY',
gtype => 'GIMP_TYPE_OBJECT_ARRAY', gtype => 'GIMP_TYPE_CORE_OBJECT_ARRAY',
type => 'GimpImage **', type => 'GimpImage **',
const_type => 'const GimpImage **', const_type => 'const GimpImage **',
array => 1,
init_value => 'NULL', init_value => 'NULL',
in_annotate => '(element-type GimpImage)', in_annotate => '(element-type GimpImage) (array zero-terminated=1)',
out_annotate => '(element-type GimpImage) (transfer container)', out_annotate => '(element-type GimpImage) (array zero-terminated=1) (transfer container)',
get_value_func => '$var = (const GimpImage **) gimp_value_get_object_array ($value)', get_value_func => '$var = g_value_get_boxed ($value)',
dup_value_func => '{ GimpObjectArray *a = g_value_get_boxed (gimp_value_array_index ($value)); if (a) $var = g_memdup2 (a->data, a->length * sizeof (gpointer)); }', dup_value_func => '$var = g_value_dup_boxed (gimp_value_array_index ($value))',
set_value_func => 'gimp_value_set_object_array ($value, GIMP_TYPE_IMAGE, (GObject **) $var, $var_len)', set_value_func => 'g_value_set_boxed ($value, $var)',
take_value_func => 'gimp_value_take_object_array ($value, GIMP_TYPE_IMAGE, (GObject **) $var, $var_len)' }, take_value_func => 'g_value_take_boxed ($value, $var)' },
itemarray => { name => 'ITEMARRAY', itemarray => { name => 'ITEMARRAY',
gtype => 'GIMP_TYPE_CORE_OBJECT_ARRAY', gtype => 'GIMP_TYPE_CORE_OBJECT_ARRAY',