Add new PDB data type PDB_COLORARRAY for using arrays of GimpRGB colors as

2008-07-14  Sven Neumann  <sven@gimp.org>

	Add new PDB data type PDB_COLORARRAY for using arrays of GimpRGB
	colors as argument or return value.

	* libgimpbase/gimpbaseenums.[ch] (enum GimpPDBArgType): replaced
	the unused GIMP_PDB_BOUNDARY with GIMP_PDB_COLORARRAY.

	* libgimpbase/gimpprotocol.h: increased GIMP_PROTOCOL_VERSION.
	(struct _GPParam): added d_colorarray entry to the union.

	* libgimpbase/gimpprotocol.c
	* libgimp/gimp.[ch]
	* app/pdb/gimp-pdb-compat.c
	* app/plug-in/plug-in-params.c
	* app/plug-in/gimpplugin-message.c
	* tools/pdbgen/pdb.pl: deal with the new data type.

	* tools/pdbgen/enums.pl: regenerated.

	* plug-ins/pygimp/pygimp-pdb.c
	* plug-ins/script-fu/scheme-wrapper.c: handle the new data type.


svn path=/trunk/; revision=26189
This commit is contained in:
Sven Neumann 2008-07-14 14:09:16 +00:00 committed by Sven Neumann
parent fbbf39e138
commit 81131c0bb4
14 changed files with 230 additions and 46 deletions

View File

@ -1,3 +1,26 @@
2008-07-14 Sven Neumann <sven@gimp.org>
Add new PDB data type PDB_COLORARRAY for using arrays of GimpRGB
colors as argument or return value.
* libgimpbase/gimpbaseenums.[ch] (enum GimpPDBArgType): replaced
the unused GIMP_PDB_BOUNDARY with GIMP_PDB_COLORARRAY.
* libgimpbase/gimpprotocol.h: increased GIMP_PROTOCOL_VERSION.
(struct _GPParam): added d_colorarray entry to the union.
* libgimpbase/gimpprotocol.c
* libgimp/gimp.[ch]
* app/pdb/gimp-pdb-compat.c
* app/plug-in/plug-in-params.c
* app/plug-in/gimpplugin-message.c
* tools/pdbgen/pdb.pl: deal with the new data type.
* tools/pdbgen/enums.pl: regenerated.
* plug-ins/pygimp/pygimp-pdb.c
* plug-ins/script-fu/scheme-wrapper.c: handle the new data type.
2008-07-14 Sven Neumann <sven@gimp.org>
* app/widgets/gimpcontrollerkeyboard.c: changed cursor key event

View File

@ -148,7 +148,9 @@ gimp_pdb_compat_param_spec (Gimp *gimp,
G_PARAM_READWRITE);
break;
case GIMP_PDB_BOUNDARY:
case GIMP_PDB_COLORARRAY:
pspec = gimp_param_spec_color_array (name, name, desc,
G_PARAM_READWRITE);
break;
case GIMP_PDB_VECTORS:
@ -220,7 +222,6 @@ gimp_pdb_compat_arg_type_to_gtype (GimpPDBArgType type)
return GIMP_TYPE_RGB;
case GIMP_PDB_REGION:
case GIMP_PDB_BOUNDARY:
break;
case GIMP_PDB_DISPLAY:
@ -241,6 +242,9 @@ gimp_pdb_compat_arg_type_to_gtype (GimpPDBArgType type)
case GIMP_PDB_SELECTION:
return GIMP_TYPE_SELECTION_ID;
case GIMP_PDB_COLORARRAY:
return GIMP_TYPE_COLOR_ARRAY;
case GIMP_PDB_VECTORS:
return GIMP_TYPE_VECTORS_ID;

View File

@ -618,7 +618,8 @@ gimp_plug_in_handle_proc_install (GimpPlugIn *plug_in,
if ((proc_install->params[i].type == GIMP_PDB_INT32ARRAY ||
proc_install->params[i].type == GIMP_PDB_INT8ARRAY ||
proc_install->params[i].type == GIMP_PDB_FLOATARRAY ||
proc_install->params[i].type == GIMP_PDB_STRINGARRAY)
proc_install->params[i].type == GIMP_PDB_STRINGARRAY ||
proc_install->params[i].type == GIMP_PDB_COLORARRAY)
&&
proc_install->params[i - 1].type != GIMP_PDB_INT32)
{

View File

@ -221,8 +221,16 @@ plug_in_params_to_args (GParamSpec **pspecs,
g_value_set_int (&value, params[i].data.d_selection);
break;
case GIMP_PDB_BOUNDARY:
g_message ("the \"boundary\" arg type is not currently supported");
case GIMP_PDB_COLORARRAY:
count = g_value_get_int (&args->values[i - 1]);
if (full_copy)
gimp_value_set_colorarray (&value,
params[i].data.d_colorarray,
count);
else
gimp_value_set_static_colorarray (&value,
params[i].data.d_colorarray,
count);
break;
case GIMP_PDB_VECTORS:
@ -374,8 +382,11 @@ plug_in_args_to_params (GValueArray *args,
params[i].data.d_selection = g_value_get_int (value);
break;
case GIMP_PDB_BOUNDARY:
g_message ("the \"boundary\" arg type is not currently supported");
case GIMP_PDB_COLORARRAY:
if (full_copy)
params[i].data.d_colorarray = gimp_value_dup_colorarray (value);
else
params[i].data.d_colorarray = (GimpRGB *) gimp_value_get_colorarray (value);
break;
case GIMP_PDB_VECTORS:

View File

@ -736,7 +736,6 @@ gimp_run_procedure (const gchar *name,
case GIMP_PDB_CHANNEL:
case GIMP_PDB_DRAWABLE:
case GIMP_PDB_SELECTION:
case GIMP_PDB_BOUNDARY:
case GIMP_PDB_VECTORS:
case GIMP_PDB_STATUS:
(void) va_arg (args, gint);
@ -769,6 +768,7 @@ gimp_run_procedure (const gchar *name,
(void) va_arg (args, gchar **);
break;
case GIMP_PDB_COLOR:
case GIMP_PDB_COLORARRAY:
(void) va_arg (args, GimpRGB *);
break;
case GIMP_PDB_PARASITE:
@ -850,8 +850,8 @@ gimp_run_procedure (const gchar *name,
case GIMP_PDB_SELECTION:
params[i].data.d_selection = va_arg (args, gint32);
break;
case GIMP_PDB_BOUNDARY:
params[i].data.d_boundary = va_arg (args, gint32);
case GIMP_PDB_COLORARRAY:
params[i].data.d_colorarray = va_arg (args, GimpRGB *);
break;
case GIMP_PDB_VECTORS:
params[i].data.d_vectors = va_arg (args, gint32);

View File

@ -128,6 +128,7 @@ union _GimpParamData
guint8 *d_int8array;
gdouble *d_floatarray;
gchar **d_stringarray;
GimpRGB *d_colorarray;
GimpRGB d_color;
GimpParamRegion d_region;
gint32 d_display;

View File

@ -815,12 +815,11 @@ gimp_pdb_arg_type_get_type (void)
{ GIMP_PDB_CHANNEL, "GIMP_PDB_CHANNEL", "channel" },
{ GIMP_PDB_DRAWABLE, "GIMP_PDB_DRAWABLE", "drawable" },
{ GIMP_PDB_SELECTION, "GIMP_PDB_SELECTION", "selection" },
{ GIMP_PDB_BOUNDARY, "GIMP_PDB_BOUNDARY", "boundary" },
{ GIMP_PDB_COLORARRAY, "GIMP_PDB_COLORARRAY", "colorarray" },
{ GIMP_PDB_VECTORS, "GIMP_PDB_VECTORS", "vectors" },
{ GIMP_PDB_PARASITE, "GIMP_PDB_PARASITE", "parasite" },
{ GIMP_PDB_STATUS, "GIMP_PDB_STATUS", "status" },
{ GIMP_PDB_END, "GIMP_PDB_END", "end" },
{ GIMP_PDB_PATH, "GIMP_PDB_PATH", "path" },
{ 0, NULL, NULL }
};
@ -844,12 +843,11 @@ gimp_pdb_arg_type_get_type (void)
{ GIMP_PDB_CHANNEL, "GIMP_PDB_CHANNEL", NULL },
{ GIMP_PDB_DRAWABLE, "GIMP_PDB_DRAWABLE", NULL },
{ GIMP_PDB_SELECTION, "GIMP_PDB_SELECTION", NULL },
{ GIMP_PDB_BOUNDARY, "GIMP_PDB_BOUNDARY", NULL },
{ GIMP_PDB_COLORARRAY, "GIMP_PDB_COLORARRAY", NULL },
{ GIMP_PDB_VECTORS, "GIMP_PDB_VECTORS", NULL },
{ GIMP_PDB_PARASITE, "GIMP_PDB_PARASITE", NULL },
{ GIMP_PDB_STATUS, "GIMP_PDB_STATUS", NULL },
{ GIMP_PDB_END, "GIMP_PDB_END", NULL },
{ GIMP_PDB_PATH, "GIMP_PDB_PATH", NULL },
{ 0, NULL, NULL }
};

View File

@ -373,13 +373,15 @@ typedef enum
GIMP_PDB_CHANNEL,
GIMP_PDB_DRAWABLE,
GIMP_PDB_SELECTION,
GIMP_PDB_BOUNDARY,
GIMP_PDB_COLORARRAY,
GIMP_PDB_VECTORS,
GIMP_PDB_PARASITE,
GIMP_PDB_STATUS,
GIMP_PDB_END,
GIMP_PDB_PATH = GIMP_PDB_VECTORS /* deprecated */
/* the following aliases are deprecated */
GIMP_PDB_PATH = GIMP_PDB_VECTORS, /*< skip >*/
GIMP_PDB_BOUNDARY = GIMP_PDB_COLORARRAY /*< skip >*/
} GimpPDBArgType;

View File

@ -1481,11 +1481,17 @@ _gp_params_read (GIOChannel *channel,
goto cleanup;
break;
case GIMP_PDB_BOUNDARY:
if (! _gimp_wire_read_int32 (channel,
(guint32 *) &(*params)[i].data.d_boundary, 1,
user_data))
goto cleanup;
case GIMP_PDB_COLORARRAY:
(*params)[i].data.d_colorarray = g_new (GimpRGB,
(*params)[i-1].data.d_int32);
if (! _gimp_wire_read_color (channel,
(*params)[i].data.d_colorarray,
(*params)[i-1].data.d_int32,
user_data))
{
g_free ((*params)[i].data.d_colorarray);
goto cleanup;
}
break;
case GIMP_PDB_VECTORS:
@ -1698,9 +1704,10 @@ _gp_params_write (GIOChannel *channel,
return;
break;
case GIMP_PDB_BOUNDARY:
if (! _gimp_wire_write_int32 (channel,
(const guint32 *) &params[i].data.d_boundary, 1,
case GIMP_PDB_COLORARRAY:
if (! _gimp_wire_write_color (channel,
params[i].data.d_colorarray,
params[i-1].data.d_int32,
user_data))
return;
break;
@ -1773,7 +1780,6 @@ gp_params_destroy (GPParam *params,
case GIMP_PDB_CHANNEL:
case GIMP_PDB_DRAWABLE:
case GIMP_PDB_SELECTION:
case GIMP_PDB_BOUNDARY:
case GIMP_PDB_VECTORS:
case GIMP_PDB_STATUS:
break;
@ -1811,6 +1817,10 @@ gp_params_destroy (GPParam *params,
}
break;
case GIMP_PDB_COLORARRAY:
g_free (params[i].data.d_colorarray);
break;
case GIMP_PDB_PARASITE:
if (params[i].data.d_parasite.name)
g_free (params[i].data.d_parasite.name);

View File

@ -27,7 +27,7 @@ G_BEGIN_DECLS
/* Increment every time the protocol changes
*/
#define GIMP_PROTOCOL_VERSION 0x0012
#define GIMP_PROTOCOL_VERSION 0x0013
enum
@ -120,6 +120,7 @@ struct _GPParam
guint8 *d_int8array;
gdouble *d_floatarray;
gchar **d_stringarray;
GimpRGB *d_colorarray;
GimpRGB d_color;
struct
{

View File

@ -287,8 +287,26 @@ pygimp_param_to_tuple(int nparams, const GimpParam *params)
case GIMP_PDB_SELECTION:
value = pygimp_layer_new(params[i].data.d_selection);
break;
case GIMP_PDB_BOUNDARY:
value = PyInt_FromLong(params[i].data.d_boundary);
case GIMP_PDB_COLORARRAY:
if (params[i].data.d_colorarray == NULL) {
value = PyTuple_New(0);
break;
}
if ((tmp=PyTuple_GetItem(args, i-1)) == NULL) {
Py_DECREF(args);
return NULL;
}
if (!PyInt_Check(tmp)) {
PyErr_SetString(PyExc_TypeError,
"count type must be integer");
Py_DECREF(args);
return NULL;
}
n = PyInt_AsLong(tmp);
value = PyTuple_New(n);
for (j = 0; j < n; j++)
PyTuple_SetItem(value, j,
pygimp_rgb_new(&params[i].data.d_colorarray[j]));
break;
case GIMP_PDB_VECTORS:
value = pygimp_vectors_new(params[i].data.d_vectors);
@ -524,9 +542,23 @@ pygimp_param_from_tuple(PyObject *args, const GimpParamDef *ptype, int nparams)
check(!pygimp_layer_check(item));
ret[i].data.d_selection = ((PyGimpLayer *)item)->ID;
break;
case GIMP_PDB_BOUNDARY:
check(!PyInt_Check(item));
ret[i].data.d_boundary = PyInt_AsLong(item);
case GIMP_PDB_COLORARRAY:
{
GimpRGB *rgb;
check(!PySequence_Check(item));
len = PySequence_Length(item);
rgb = g_new(GimpRGB, len);
for (j = 0; j < len; j++) {
if (!pygimp_rgb_from_pyobject(item, &rgb[j])) {
Py_DECREF(tuple);
g_free(rgb);
gimp_destroy_params(ret, nparams);
return NULL;
}
}
ret[i].data.d_colorarray = rgb;
}
break;
case GIMP_PDB_VECTORS:
check(!pygimp_vectors_check(item));

View File

@ -615,18 +615,18 @@ script_fu_marshal_procedure_call (scheme *sc, pointer a)
#define typeflag(p) ((p)->_flag)
#define type(p) (typeflag(p)&T_MASKTYPE)
char *ret_types[] = {
static const char *ret_types[] = {
"GIMP_PDB_INT32", "GIMP_PDB_INT16", "GIMP_PDB_INT8",
"GIMP_PDB_FLOAT", "GIMP_PDB_STRING", "GIMP_PDB_INT32ARRAY",
"GIMP_PDB_INT16ARRAY", "GIMP_PDB_INT8ARRAY", "GIMP_PDB_FLOATARRAY",
"GIMP_PDB_STRINGARRAY", "GIMP_PDB_COLOR", "GIMP_PDB_REGION",
"GIMP_PDB_DISPLAY", "GIMP_PDB_IMAGE", "GIMP_PDB_LAYER",
"GIMP_PDB_CHANNEL", "GIMP_PDB_DRAWABLE", "GIMP_PDB_SELECTION",
"GIMP_PDB_BOUNDARY", "GIMP_PDB_VECTORS", "GIMP_PDB_PARASITE",
"GIMP_PDB_COLORARRY", "GIMP_PDB_VECTORS", "GIMP_PDB_PARASITE",
"GIMP_PDB_STATUS", "GIMP_PDB_END"
};
char *ts_types[] = {
static const char *ts_types[] = {
"T_NONE",
"T_STRING", "T_NUMBER", "T_SYMBOL", "T_PROC",
"T_PAIR", "T_CLOSURE", "T_CONTINUATION", "T_FOREIGN",
@ -634,7 +634,7 @@ char *ts_types[] = {
"T_PROMISE", "T_ENVIRONMENT","T_ARRAY"
};
char *status_types[] = {
static const char *status_types[] = {
"GIMP_PDB_EXECUTION_ERROR", "GIMP_PDB_CALLING_ERROR",
"GIMP_PDB_PASS_THROUGH", "GIMP_PDB_SUCCESS",
"GIMP_PDB_CANCEL"
@ -739,7 +739,6 @@ g_printerr (" passed arg is type %s (%d)\n",
case GIMP_PDB_CHANNEL:
case GIMP_PDB_DRAWABLE:
case GIMP_PDB_SELECTION:
case GIMP_PDB_BOUNDARY:
case GIMP_PDB_VECTORS:
if (!sc->vptr->is_number (sc->vptr->pair_car (a)))
success = FALSE;
@ -846,7 +845,7 @@ if (count > 0)
g_printerr (" ");
for (j = 0; j < count; ++j)
g_printerr (" %ld",
sc->vptr->ivalue ( sc->vptr->vector_elem (vector, j) ));
sc->vptr->ivalue ( sc->vptr->vector_elem (vector, j) ));
g_printerr ("\n");
}
}
@ -897,7 +896,7 @@ if (count > 0)
g_printerr (" ");
for (j = 0; j < count; ++j)
g_printerr (" %ld",
sc->vptr->ivalue ( sc->vptr->vector_elem (vector, j) ));
sc->vptr->ivalue ( sc->vptr->vector_elem (vector, j) ));
g_printerr ("\n");
}
}
@ -950,7 +949,7 @@ if (count > 0)
g_printerr (" ");
for (j = 0; j < count; ++j)
g_printerr (" %ld",
sc->vptr->ivalue ( sc->vptr->vector_elem (vector, j) ));
sc->vptr->ivalue ( sc->vptr->vector_elem (vector, j) ));
g_printerr ("\n");
}
}
@ -1003,7 +1002,7 @@ if (count > 0)
g_printerr (" ");
for (j = 0; j < count; ++j)
g_printerr (" %f",
sc->vptr->rvalue ( sc->vptr->vector_elem (vector, j) ));
sc->vptr->rvalue ( sc->vptr->vector_elem (vector, j) ));
g_printerr ("\n");
}
}
@ -1104,6 +1103,66 @@ g_printerr (" (%d %d %d)\n", r, g, b);
}
break;
case GIMP_PDB_COLORARRAY:
vector = sc->vptr->pair_car (a);
if (!sc->vptr->is_vector (vector))
success = FALSE;
if (success)
{
n_elements = args[i-1].data.d_int32;
if (n_elements < 0 ||
n_elements > sc->vptr->vector_length (vector))
{
g_snprintf (error_str, sizeof (error_str),
"COLOR vector (argument %d) for function %s has "
"size of %ld but expected size of %d",
i+1, proc_name,
sc->vptr->vector_length (vector), n_elements);
return foreign_error (sc, error_str, 0);
}
args[i].data.d_colorarray = g_new (GimpRGB, n_elements);
for (j = 0; j < n_elements; j++)
{
pointer v_element = sc->vptr->vector_elem (vector, j);
pointer color_list;
guchar r, g, b;
if (! (sc->vptr->is_list (sc,
sc->vptr->pair_car (v_element)) &&
sc->vptr->list_length (sc,
sc->vptr->pair_car (v_element)) == 3))
{
g_snprintf (error_str, sizeof (error_str),
"Item %d in vector is not a color "
"(argument %d for function %s)",
j+1, i+1, proc_name);
return foreign_error (sc, error_str, vector);
}
color_list = sc->vptr->pair_car (v_element);
r = CLAMP (sc->vptr->ivalue (sc->vptr->pair_car (color_list)),
0, 255);
color_list = sc->vptr->pair_cdr (color_list);
g = CLAMP (sc->vptr->ivalue (sc->vptr->pair_car (color_list)),
0, 255);
color_list = sc->vptr->pair_cdr (color_list);
b = CLAMP (sc->vptr->ivalue (sc->vptr->pair_car (color_list)),
0, 255);
gimp_rgba_set_uchar (&args[i].data.d_colorarray[j],
r, g, b, 255);
}
#if DEBUG_MARSHALL
{
glong count = sc->vptr->vector_length (vector);
g_printerr (" color vector has %ld elements\n", count);
}
#endif
}
break;
case GIMP_PDB_REGION:
if (! (sc->vptr->is_list (sc, sc->vptr->pair_car (a)) &&
sc->vptr->list_length (sc, sc->vptr->pair_car (a)) == 4))
@ -1282,7 +1341,6 @@ g_printerr (" value %d is type %s (%d)\n",
case GIMP_PDB_CHANNEL:
case GIMP_PDB_DRAWABLE:
case GIMP_PDB_SELECTION:
case GIMP_PDB_BOUNDARY:
case GIMP_PDB_VECTORS:
return_val = sc->vptr->cons (sc,
sc->vptr->mk_integer (sc,
@ -1457,6 +1515,38 @@ g_printerr (" value %d is type %s (%d)\n",
break;
}
case GIMP_PDB_COLORARRAY:
/* color arrays are always implemented such that the previous
* return value contains the number of strings in the array
*/
{
gint32 num_colors = values[i].data.d_int32;
GimpRGB *array = (GimpRGB *) values[i + 1].data.d_colorarray;
pointer vector = sc->vptr->mk_vector (sc, num_colors);
return_val = sc->vptr->cons (sc, vector, return_val);
set_safe_foreign (sc, return_val);
for (j = 0; j < num_colors; j++)
{
guchar r, g, b;
gimp_rgb_get_uchar (&array[j], &r, &g, &b);
intermediate_val = sc->vptr->cons (sc,
sc->vptr->mk_integer (sc, r),
sc->vptr->cons (sc,
sc->vptr->mk_integer (sc, g),
sc->vptr->cons (sc,
sc->vptr->mk_integer (sc, b),
sc->NIL)));
return_val = sc->vptr->cons (sc,
intermediate_val,
return_val);
set_safe_foreign (sc, return_val);
}
}
break;
case GIMP_PDB_REGION:
{
gint32 x, y, w, h;
@ -1612,6 +1702,10 @@ script_fu_marshal_destroy_args (GimpParam *params,
g_free (params[i].data.d_stringarray);
break;
case GIMP_PDB_COLORARRAY:
g_free (params[i].data.d_colorarray);
break;
case GIMP_PDB_COLOR:
case GIMP_PDB_REGION:
case GIMP_PDB_DISPLAY:
@ -1620,7 +1714,6 @@ script_fu_marshal_destroy_args (GimpParam *params,
case GIMP_PDB_CHANNEL:
case GIMP_PDB_DRAWABLE:
case GIMP_PDB_SELECTION:
case GIMP_PDB_BOUNDARY:
case GIMP_PDB_VECTORS:
case GIMP_PDB_PARASITE:
case GIMP_PDB_STATUS:

View File

@ -265,9 +265,9 @@ package Gimp::CodeGen::enums;
GIMP_PDB_COLOR GIMP_PDB_REGION GIMP_PDB_DISPLAY
GIMP_PDB_IMAGE GIMP_PDB_LAYER GIMP_PDB_CHANNEL
GIMP_PDB_DRAWABLE GIMP_PDB_SELECTION
GIMP_PDB_BOUNDARY GIMP_PDB_VECTORS
GIMP_PDB_COLORARRAY GIMP_PDB_VECTORS
GIMP_PDB_PARASITE GIMP_PDB_STATUS GIMP_PDB_END
GIMP_PDB_PATH) ],
GIMP_PDB_PATH GIMP_PDB_BOUNDARY) ],
mapping => { GIMP_PDB_INT32 => '0',
GIMP_PDB_INT16 => '1',
GIMP_PDB_INT8 => '2',
@ -286,12 +286,13 @@ package Gimp::CodeGen::enums;
GIMP_PDB_CHANNEL => '15',
GIMP_PDB_DRAWABLE => '16',
GIMP_PDB_SELECTION => '17',
GIMP_PDB_BOUNDARY => '18',
GIMP_PDB_COLORARRAY => '18',
GIMP_PDB_VECTORS => '19',
GIMP_PDB_PARASITE => '20',
GIMP_PDB_STATUS => '21',
GIMP_PDB_END => '22',
GIMP_PDB_PATH => 'GIMP_PDB_VECTORS' }
GIMP_PDB_PATH => 'GIMP_PDB_VECTORS',
GIMP_PDB_BOUNDARY => 'GIMP_PDB_COLORARRAY' }
},
GimpPDBProcType =>
{ contig => 1,

View File

@ -85,6 +85,13 @@ package Gimp::CodeGen::pdb;
init_value => 'NULL',
get_value_func => '$var = gimp_value_get_stringarray ($value)',
set_value_func => 'gimp_value_take_stringarray ($value, $var, $var_len)' },
colorarray => { name => 'COLORARRAY',
type => 'GimpRGB *',
const_type => 'const GimpRGB *',
array => 1,
init_value => 'NULL',
get_value_func => '$var = gimp_value_get_colorarray ($value)',
set_value_func => 'gimp_value_take_colorarray ($value, $var, $var_len)' },
color => { name => 'COLOR' ,
type => 'GimpRGB ',