diff --git a/ChangeLog b/ChangeLog index 9044033b69..08f0836894 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2008-07-14 Sven Neumann + + * tools/pdbgen/pdb/palette.pdb: added new PDB function + gimp-palette-get-colors that retrieves all colors from a palette + in a single call. Based on patches from bug #332206. + + * app/pdb/palette-cmds.c + * app/pdb/internal-procs.c + * libgimp/gimppalette_pdb.[ch]: regenerated. + + * libgimp/gimp.def: updated. + 2008-07-14 Sven Neumann * tools/pdbgen/app.pl: added support for color arrays. diff --git a/app/pdb/internal-procs.c b/app/pdb/internal-procs.c index 45967330b8..c1f53b22cc 100644 --- a/app/pdb/internal-procs.c +++ b/app/pdb/internal-procs.c @@ -29,7 +29,7 @@ #include "internal-procs.h" -/* 586 procedures registered total */ +/* 587 procedures registered total */ void internal_procs_init (GimpPDB *pdb) diff --git a/app/pdb/palette-cmds.c b/app/pdb/palette-cmds.c index a1b9ad1a73..02ca042b62 100644 --- a/app/pdb/palette-cmds.c +++ b/app/pdb/palette-cmds.c @@ -247,6 +247,54 @@ palette_get_info_invoker (GimpProcedure *procedure, return return_vals; } +static GValueArray * +palette_get_colors_invoker (GimpProcedure *procedure, + Gimp *gimp, + GimpContext *context, + GimpProgress *progress, + const GValueArray *args, + GError **error) +{ + gboolean success = TRUE; + GValueArray *return_vals; + const gchar *name; + gint32 num_colors = 0; + GimpRGB *colors = NULL; + + name = g_value_get_string (&args->values[0]); + + if (success) + { + GimpPalette *palette = gimp_pdb_get_palette (gimp, name, FALSE, error); + + if (palette) + { + GList *list = palette->colors; + gint i; + + num_colors = palette->n_colors; + colors = g_new (GimpRGB, num_colors); + + for (i = 0; i < num_colors; i++, list = g_list_next (list)) + colors[i] = ((GimpPaletteEntry *)(list->data))->color; + } + else + { + success = FALSE; + } + } + + return_vals = gimp_procedure_get_return_values (procedure, success); + + if (success) + { + g_value_set_int (&return_vals->values[1], num_colors); + gimp_value_take_colorarray (&return_vals->values[2], colors, num_colors); + } + + return return_vals; +} + static GValueArray * palette_get_columns_invoker (GimpProcedure *procedure, Gimp *gimp, @@ -747,6 +795,41 @@ register_palette_procs (GimpPDB *pdb) gimp_pdb_register_procedure (pdb, procedure); g_object_unref (procedure); + /* + * gimp-palette-get-colors + */ + procedure = gimp_procedure_new (palette_get_colors_invoker); + gimp_object_set_static_name (GIMP_OBJECT (procedure), + "gimp-palette-get-colors"); + gimp_procedure_set_static_strings (procedure, + "gimp-palette-get-colors", + "Gets all colors from the specified palette.", + "This procedure retrieves all color entries of the specified palette.", + "Sven Neumann ", + "Sven Neumann", + "2006", + NULL); + gimp_procedure_add_argument (procedure, + gimp_param_spec_string ("name", + "name", + "The palette name", + FALSE, FALSE, TRUE, + NULL, + GIMP_PARAM_READWRITE)); + gimp_procedure_add_return_value (procedure, + gimp_param_spec_int32 ("num-colors", + "num colors", + "Length of the colors array", + 0, G_MAXINT32, 0, + GIMP_PARAM_READWRITE)); + gimp_procedure_add_return_value (procedure, + gimp_param_spec_color_array ("colors", + "colors", + "The colors in the palette", + GIMP_PARAM_READWRITE)); + gimp_pdb_register_procedure (pdb, procedure); + g_object_unref (procedure); + /* * gimp-palette-get-columns */ diff --git a/libgimp/gimp.def b/libgimp/gimp.def index b13ae8627d..fc393516e8 100644 --- a/libgimp/gimp.def +++ b/libgimp/gimp.def @@ -460,6 +460,7 @@ EXPORTS gimp_palette_entry_set_color gimp_palette_entry_set_name gimp_palette_get_background + gimp_palette_get_colors gimp_palette_get_columns gimp_palette_get_foreground gimp_palette_get_info diff --git a/libgimp/gimppalette_pdb.c b/libgimp/gimppalette_pdb.c index d173be86fe..f255aee3f6 100644 --- a/libgimp/gimppalette_pdb.c +++ b/libgimp/gimppalette_pdb.c @@ -23,6 +23,8 @@ #include "config.h" +#include + #include "gimp.h" /** @@ -226,6 +228,48 @@ gimp_palette_get_info (const gchar *name, return success; } +/** + * gimp_palette_get_colors: + * @name: The palette name. + * @num_colors: Length of the colors array. + * + * Gets all colors from the specified palette. + * + * This procedure retrieves all color entries of the specified palette. + * + * Returns: The colors in the palette. + * + * Since: GIMP 2.6 + */ +GimpRGB * +gimp_palette_get_colors (const gchar *name, + gint *num_colors) +{ + GimpParam *return_vals; + gint nreturn_vals; + GimpRGB *colors = NULL; + + return_vals = gimp_run_procedure ("gimp-palette-get-colors", + &nreturn_vals, + GIMP_PDB_STRING, name, + GIMP_PDB_END); + + *num_colors = 0; + + if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS) + { + *num_colors = return_vals[1].data.d_int32; + colors = g_new (GimpRGB, *num_colors); + memcpy (colors, + return_vals[2].data.d_colorarray, + *num_colors * sizeof (GimpRGB)); + } + + gimp_destroy_params (return_vals, nreturn_vals); + + return colors; +} + /** * gimp_palette_get_columns: * @name: The palette name. diff --git a/libgimp/gimppalette_pdb.h b/libgimp/gimppalette_pdb.h index cec7fc297f..82c2c5cdee 100644 --- a/libgimp/gimppalette_pdb.h +++ b/libgimp/gimppalette_pdb.h @@ -37,6 +37,8 @@ gboolean gimp_palette_delete (const gchar *name); gboolean gimp_palette_is_editable (const gchar *name); gboolean gimp_palette_get_info (const gchar *name, gint *num_colors); +GimpRGB* gimp_palette_get_colors (const gchar *name, + gint *num_colors); gint gimp_palette_get_columns (const gchar *name); gboolean gimp_palette_set_columns (const gchar *name, gint columns); diff --git a/tools/pdbgen/pdb/palette.pdb b/tools/pdbgen/pdb/palette.pdb index 991e4df5ed..fb9ba67095 100644 --- a/tools/pdbgen/pdb/palette.pdb +++ b/tools/pdbgen/pdb/palette.pdb @@ -212,6 +212,53 @@ CODE ); } +sub palette_get_colors { + $blurb = 'Gets all colors from the specified palette.'; + + $help = <<'HELP'; +This procedure retrieves all color entries of the specified palette. +HELP + + &neo_pdb_misc('2006', '2.6'); + + @inargs = ( + { name => 'name', type => 'string', non_empty => 1, + desc => 'The palette name' } + ); + + @outargs = ( + { name => 'colors', type => 'colorarray', + desc => 'The colors in the palette', + array => { name => 'num_colors', + desc => 'Length of the colors array' } } + ); + + %invoke = ( + vars => [ 'GimpPalette *palette = NULL' ], + code => <<'CODE' +{ + GimpPalette *palette = gimp_pdb_get_palette (gimp, name, FALSE, error); + + if (palette) + { + GList *list = palette->colors; + gint i; + + num_colors = palette->n_colors; + colors = g_new (GimpRGB, num_colors); + + for (i = 0; i < num_colors; i++, list = g_list_next (list)) + colors[i] = ((GimpPaletteEntry *)(list->data))->color; + } + else + { + success = FALSE; + } +} +CODE + ); +} + sub palette_get_columns { $blurb = "Retrieves the number of columns to use to display this palette"; $help = <<'HELP'; @@ -551,7 +598,7 @@ CODE palette_rename palette_delete palette_is_editable - palette_get_info + palette_get_info palette_get_colors palette_get_columns palette_set_columns palette_add_entry palette_delete_entry palette_entry_get_color palette_entry_set_color