mirror of https://github.com/GNOME/gimp.git
added new PDB function gimp-palette-get-colors that retrieves all colors
2008-07-14 Sven Neumann <sven@gimp.org> * 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. svn path=/trunk/; revision=26192
This commit is contained in:
parent
bad4568f58
commit
f92a070fa8
12
ChangeLog
12
ChangeLog
|
@ -1,3 +1,15 @@
|
|||
2008-07-14 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* 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 <sven@gimp.org>
|
||||
|
||||
* tools/pdbgen/app.pl: added support for color arrays.
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
#include "internal-procs.h"
|
||||
|
||||
|
||||
/* 586 procedures registered total */
|
||||
/* 587 procedures registered total */
|
||||
|
||||
void
|
||||
internal_procs_init (GimpPDB *pdb)
|
||||
|
|
|
@ -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@gimp.org>",
|
||||
"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
|
||||
*/
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#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.
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue