mirror of https://github.com/GNOME/gimp.git
app, libgimp*: add protocol support for GValues holding a GParamSpec
so we can have PDB introspection procedures for the new plug-in API.
This commit is contained in:
parent
e77382ee75
commit
aa505b43dc
|
@ -21,7 +21,6 @@ libappplug_in_a_SOURCES = \
|
|||
gimpenvirontable.c \
|
||||
gimpenvirontable.h \
|
||||
gimpgpparams.c \
|
||||
gimpgpparams.h \
|
||||
gimpinterpreterdb.c \
|
||||
gimpinterpreterdb.h \
|
||||
gimpplugindebug.c \
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
#include "core/gimp.h"
|
||||
#include "core/gimpparamspecs.h"
|
||||
|
||||
#include "gimpgpparams.h"
|
||||
#include "libgimp/gimpgpparams.h"
|
||||
|
||||
|
||||
/* public functions */
|
||||
|
@ -49,7 +49,7 @@
|
|||
#include "../../libgimp/gimpgpparams-body.c"
|
||||
|
||||
GParamSpec *
|
||||
_gimp_gp_param_def_to_param_spec (Gimp *gimp,
|
||||
_gimp_gp_param_def_to_param_spec (gpointer gimp,
|
||||
GPParamDef *param_def)
|
||||
{
|
||||
const gchar *name = param_def->name;
|
||||
|
|
|
@ -1,45 +0,0 @@
|
|||
/* GIMP - The GNU Image Manipulation Program
|
||||
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
||||
*
|
||||
* gimpgpparams.h
|
||||
* Copyright (C) 2019 Michael Natterer <mitch@gimp.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __GIMP_GP_PARAMS_H__
|
||||
#define __GIMP_GP_PARAMS_H__
|
||||
|
||||
|
||||
/* function names start with an underscore because we incude code
|
||||
* from libgimp/ which is private there
|
||||
*/
|
||||
|
||||
void _gimp_param_spec_to_gp_param_def (GParamSpec *pspec,
|
||||
GPParamDef *param_def);
|
||||
|
||||
GParamSpec * _gimp_gp_param_def_to_param_spec (Gimp *gimp,
|
||||
GPParamDef *param_def);
|
||||
|
||||
GimpValueArray * _gimp_gp_params_to_value_array (GParamSpec **pspecs,
|
||||
gint n_pspecs,
|
||||
GPParam *params,
|
||||
gint n_params,
|
||||
gboolean return_values,
|
||||
gboolean full_copy);
|
||||
GPParam * _gimp_value_array_to_gp_params (GimpValueArray *args,
|
||||
gboolean full_copy);
|
||||
|
||||
|
||||
#endif /* __GIMP_GP_PARAMS_H__ */
|
|
@ -28,6 +28,8 @@
|
|||
#include "libgimpbase/gimpprotocol.h"
|
||||
#include "libgimpbase/gimpwire.h"
|
||||
|
||||
#include "libgimp/gimpgpparams.h"
|
||||
|
||||
#include "plug-in-types.h"
|
||||
|
||||
#include "gegl/gimp-babl.h"
|
||||
|
@ -41,7 +43,6 @@
|
|||
#include "pdb/gimppdb.h"
|
||||
#include "pdb/gimppdberror.h"
|
||||
|
||||
#include "gimpgpparams.h"
|
||||
#include "gimpplugin.h"
|
||||
#include "gimpplugin-cleanup.h"
|
||||
#include "gimpplugin-message.h"
|
||||
|
@ -566,7 +567,8 @@ gimp_plug_in_handle_proc_run (GimpPlugIn *plug_in,
|
|||
if (! proc_name)
|
||||
proc_name = canonical;
|
||||
|
||||
args = _gimp_gp_params_to_value_array (procedure ? procedure->args : NULL,
|
||||
args = _gimp_gp_params_to_value_array (plug_in->manager->gimp,
|
||||
procedure ? procedure->args : NULL,
|
||||
procedure ? procedure->num_args : 0,
|
||||
proc_run->params,
|
||||
proc_run->nparams,
|
||||
|
@ -635,7 +637,8 @@ gimp_plug_in_handle_proc_return (GimpPlugIn *plug_in,
|
|||
g_return_if_fail (proc_return != NULL);
|
||||
|
||||
proc_frame->return_vals =
|
||||
_gimp_gp_params_to_value_array (proc_frame->procedure->values,
|
||||
_gimp_gp_params_to_value_array (plug_in->manager->gimp,
|
||||
proc_frame->procedure->values,
|
||||
proc_frame->procedure->num_values,
|
||||
proc_return->params,
|
||||
proc_return->nparams,
|
||||
|
@ -670,7 +673,8 @@ gimp_plug_in_handle_temp_proc_return (GimpPlugIn *plug_in,
|
|||
GimpPlugInProcFrame *proc_frame = plug_in->temp_proc_frames->data;
|
||||
|
||||
proc_frame->return_vals =
|
||||
_gimp_gp_params_to_value_array (proc_frame->procedure->values,
|
||||
_gimp_gp_params_to_value_array (plug_in->manager->gimp,
|
||||
proc_frame->procedure->values,
|
||||
proc_frame->procedure->num_values,
|
||||
proc_return->params,
|
||||
proc_return->nparams,
|
||||
|
|
|
@ -30,6 +30,8 @@
|
|||
#include "libgimpbase/gimpprotocol.h"
|
||||
#include "libgimpbase/gimpwire.h"
|
||||
|
||||
#include "libgimp/gimpgpparams.h"
|
||||
|
||||
#include "plug-in-types.h"
|
||||
|
||||
#include "config/gimpguiconfig.h"
|
||||
|
@ -39,7 +41,6 @@
|
|||
|
||||
#include "pdb/gimppdbcontext.h"
|
||||
|
||||
#include "gimpgpparams.h"
|
||||
#include "gimpplugin.h"
|
||||
#include "gimpplugin-message.h"
|
||||
#include "gimpplugindef.h"
|
||||
|
|
|
@ -27,11 +27,12 @@
|
|||
#include "libgimpbase/gimpprotocol.h"
|
||||
#include "libgimpconfig/gimpconfig.h"
|
||||
|
||||
#include "libgimp/gimpgpparams.h"
|
||||
|
||||
#include "plug-in-types.h"
|
||||
|
||||
#include "core/gimp.h"
|
||||
|
||||
#include "gimpgpparams.h"
|
||||
#include "gimpplugindef.h"
|
||||
#include "gimppluginprocedure.h"
|
||||
#include "plug-in-rc.h"
|
||||
|
|
|
@ -748,7 +748,8 @@ gimp_run_procedure_with_array (const gchar *name,
|
|||
|
||||
proc_return = msg.data;
|
||||
|
||||
return_values = _gimp_gp_params_to_value_array (NULL, 0,
|
||||
return_values = _gimp_gp_params_to_value_array (NULL,
|
||||
NULL, 0,
|
||||
proc_return->params,
|
||||
proc_return->nparams,
|
||||
TRUE, FALSE);
|
||||
|
|
|
@ -158,8 +158,168 @@ _gimp_param_spec_to_gp_param_def (GParamSpec *pspec,
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
_gimp_gp_param_to_value (gpointer gimp,
|
||||
GPParam *param,
|
||||
GType type,
|
||||
GValue *value,
|
||||
gboolean full_copy)
|
||||
{
|
||||
g_return_if_fail (param != NULL);
|
||||
g_return_if_fail (value != NULL);
|
||||
|
||||
if (type == G_TYPE_NONE)
|
||||
type = g_type_from_name (param->type_name);
|
||||
|
||||
g_value_init (value, type);
|
||||
|
||||
if (type == G_TYPE_INT ||
|
||||
type == GIMP_TYPE_INT32 ||
|
||||
type == GIMP_TYPE_INT16 ||
|
||||
type == GIMP_TYPE_UNIT)
|
||||
{
|
||||
g_value_set_int (value, param->data.d_int);
|
||||
}
|
||||
else if (G_VALUE_HOLDS_UINT (value))
|
||||
{
|
||||
g_value_set_uint (value, param->data.d_int);
|
||||
}
|
||||
else if (G_VALUE_HOLDS_ENUM (value))
|
||||
{
|
||||
g_value_set_enum (value, param->data.d_int);
|
||||
}
|
||||
else if (G_VALUE_HOLDS_BOOLEAN (value))
|
||||
{
|
||||
g_value_set_boolean (value, param->data.d_int ? TRUE : FALSE);
|
||||
}
|
||||
else if (G_VALUE_HOLDS_DOUBLE (value))
|
||||
{
|
||||
g_value_set_double (value, param->data.d_float);
|
||||
}
|
||||
else if (G_VALUE_HOLDS_STRING (value))
|
||||
{
|
||||
if (full_copy)
|
||||
g_value_set_string (value, param->data.d_string);
|
||||
else
|
||||
g_value_set_static_string (value, param->data.d_string);
|
||||
}
|
||||
else if (GIMP_VALUE_HOLDS_RGB (value))
|
||||
{
|
||||
gimp_value_set_rgb (value, ¶m->data.d_color);
|
||||
}
|
||||
else if (GIMP_VALUE_HOLDS_PARASITE (value))
|
||||
{
|
||||
if (full_copy)
|
||||
g_value_set_boxed (value, ¶m->data.d_parasite);
|
||||
else
|
||||
g_value_set_static_boxed (value, ¶m->data.d_parasite);
|
||||
}
|
||||
else if (GIMP_VALUE_HOLDS_INT32_ARRAY (value))
|
||||
{
|
||||
if (full_copy)
|
||||
gimp_value_set_int32_array (value,
|
||||
(gint32 *) param->data.d_array.data,
|
||||
param->data.d_array.size /
|
||||
sizeof (gint32));
|
||||
else
|
||||
gimp_value_set_static_int32_array (value,
|
||||
(gint32 *) param->data.d_array.data,
|
||||
param->data.d_array.size /
|
||||
sizeof (gint32));
|
||||
}
|
||||
else if (GIMP_VALUE_HOLDS_INT16_ARRAY (value))
|
||||
{
|
||||
if (full_copy)
|
||||
gimp_value_set_int16_array (value,
|
||||
(gint16 *) param->data.d_array.data,
|
||||
param->data.d_array.size /
|
||||
sizeof (gint16));
|
||||
else
|
||||
gimp_value_set_static_int16_array (value,
|
||||
(gint16 *) param->data.d_array.data,
|
||||
param->data.d_array.size /
|
||||
sizeof (gint16));
|
||||
}
|
||||
else if (GIMP_VALUE_HOLDS_INT8_ARRAY (value))
|
||||
{
|
||||
if (full_copy)
|
||||
gimp_value_set_int8_array (value,
|
||||
param->data.d_array.data,
|
||||
param->data.d_array.size /
|
||||
sizeof (guint8));
|
||||
else
|
||||
gimp_value_set_static_int8_array (value,
|
||||
param->data.d_array.data,
|
||||
param->data.d_array.size /
|
||||
sizeof (guint8));
|
||||
}
|
||||
else if (GIMP_VALUE_HOLDS_FLOAT_ARRAY (value))
|
||||
{
|
||||
if (full_copy)
|
||||
gimp_value_set_float_array (value,
|
||||
(const gdouble *)
|
||||
param->data.d_array.data,
|
||||
param->data.d_array.size /
|
||||
sizeof (gdouble));
|
||||
else
|
||||
gimp_value_set_static_float_array (value,
|
||||
(const gdouble *)
|
||||
param->data.d_array.data,
|
||||
param->data.d_array.size /
|
||||
sizeof (gdouble));
|
||||
}
|
||||
else if (GIMP_VALUE_HOLDS_STRING_ARRAY (value))
|
||||
{
|
||||
if (full_copy)
|
||||
gimp_value_set_string_array (value,
|
||||
(const gchar **)
|
||||
param->data.d_string_array.data,
|
||||
param->data.d_string_array.size);
|
||||
else
|
||||
gimp_value_set_static_string_array (value,
|
||||
(const gchar **)
|
||||
param->data.d_string_array.data,
|
||||
param->data.d_string_array.size);
|
||||
}
|
||||
else if (GIMP_VALUE_HOLDS_RGB_ARRAY (value))
|
||||
{
|
||||
if (full_copy)
|
||||
gimp_value_set_rgb_array (value,
|
||||
(GimpRGB *)
|
||||
param->data.d_array.data,
|
||||
param->data.d_array.size /
|
||||
sizeof (GimpRGB));
|
||||
else
|
||||
gimp_value_set_static_rgb_array (value,
|
||||
(GimpRGB *)
|
||||
param->data.d_array.data,
|
||||
param->data.d_array.size /
|
||||
sizeof (GimpRGB));
|
||||
}
|
||||
else if (GIMP_VALUE_HOLDS_DISPLAY_ID (value) ||
|
||||
GIMP_VALUE_HOLDS_IMAGE_ID (value) ||
|
||||
GIMP_VALUE_HOLDS_ITEM_ID (value) ||
|
||||
GIMP_VALUE_HOLDS_DRAWABLE_ID (value) ||
|
||||
GIMP_VALUE_HOLDS_LAYER_ID (value) ||
|
||||
GIMP_VALUE_HOLDS_CHANNEL_ID (value) ||
|
||||
GIMP_VALUE_HOLDS_LAYER_MASK_ID (value) ||
|
||||
GIMP_VALUE_HOLDS_SELECTION_ID (value) ||
|
||||
GIMP_VALUE_HOLDS_VECTORS_ID (value))
|
||||
{
|
||||
g_value_set_int (value, param->data.d_int);
|
||||
}
|
||||
else if (G_VALUE_HOLDS_PARAM (value))
|
||||
{
|
||||
GParamSpec *pspec =
|
||||
_gimp_gp_param_def_to_param_spec (gimp, ¶m->data.d_param_def);
|
||||
|
||||
g_value_take_param (value, pspec);
|
||||
}
|
||||
}
|
||||
|
||||
GimpValueArray *
|
||||
_gimp_gp_params_to_value_array (GParamSpec **pspecs,
|
||||
_gimp_gp_params_to_value_array (gpointer gimp,
|
||||
GParamSpec **pspecs,
|
||||
gint n_pspecs,
|
||||
GPParam *params,
|
||||
gint n_params,
|
||||
|
@ -230,143 +390,7 @@ _gimp_gp_params_to_value_array (GParamSpec **pspecs,
|
|||
}
|
||||
}
|
||||
|
||||
g_value_init (&value, type);
|
||||
|
||||
if (type == G_TYPE_INT ||
|
||||
type == GIMP_TYPE_INT32 ||
|
||||
type == GIMP_TYPE_INT16 ||
|
||||
type == GIMP_TYPE_UNIT)
|
||||
{
|
||||
g_value_set_int (&value, params[i].data.d_int);
|
||||
}
|
||||
else if (G_VALUE_HOLDS_UINT (&value))
|
||||
{
|
||||
g_value_set_uint (&value, params[i].data.d_int);
|
||||
}
|
||||
else if (G_VALUE_HOLDS_ENUM (&value))
|
||||
{
|
||||
g_value_set_enum (&value, params[i].data.d_int);
|
||||
}
|
||||
else if (G_VALUE_HOLDS_BOOLEAN (&value))
|
||||
{
|
||||
g_value_set_boolean (&value, params[i].data.d_int ? TRUE : FALSE);
|
||||
}
|
||||
else if (G_VALUE_HOLDS_DOUBLE (&value))
|
||||
{
|
||||
g_value_set_double (&value, params[i].data.d_float);
|
||||
}
|
||||
else if (G_VALUE_HOLDS_STRING (&value))
|
||||
{
|
||||
if (full_copy)
|
||||
g_value_set_string (&value, params[i].data.d_string);
|
||||
else
|
||||
g_value_set_static_string (&value, params[i].data.d_string);
|
||||
}
|
||||
else if (GIMP_VALUE_HOLDS_RGB (&value))
|
||||
{
|
||||
gimp_value_set_rgb (&value, ¶ms[i].data.d_color);
|
||||
}
|
||||
else if (GIMP_VALUE_HOLDS_PARASITE (&value))
|
||||
{
|
||||
if (full_copy)
|
||||
g_value_set_boxed (&value, ¶ms[i].data.d_parasite);
|
||||
else
|
||||
g_value_set_static_boxed (&value, ¶ms[i].data.d_parasite);
|
||||
}
|
||||
else if (GIMP_VALUE_HOLDS_INT32_ARRAY (&value))
|
||||
{
|
||||
if (full_copy)
|
||||
gimp_value_set_int32_array (&value,
|
||||
(gint32 *) params[i].data.d_array.data,
|
||||
params[i].data.d_array.size /
|
||||
sizeof (gint32));
|
||||
else
|
||||
gimp_value_set_static_int32_array (&value,
|
||||
(gint32 *) params[i].data.d_array.data,
|
||||
params[i].data.d_array.size /
|
||||
sizeof (gint32));
|
||||
}
|
||||
else if (GIMP_VALUE_HOLDS_INT16_ARRAY (&value))
|
||||
{
|
||||
if (full_copy)
|
||||
gimp_value_set_int16_array (&value,
|
||||
(gint16 *) params[i].data.d_array.data,
|
||||
params[i].data.d_array.size /
|
||||
sizeof (gint16));
|
||||
else
|
||||
gimp_value_set_static_int16_array (&value,
|
||||
(gint16 *) params[i].data.d_array.data,
|
||||
params[i].data.d_array.size /
|
||||
sizeof (gint16));
|
||||
}
|
||||
else if (GIMP_VALUE_HOLDS_INT8_ARRAY (&value))
|
||||
{
|
||||
if (full_copy)
|
||||
gimp_value_set_int8_array (&value,
|
||||
params[i].data.d_array.data,
|
||||
params[i].data.d_array.size /
|
||||
sizeof (guint8));
|
||||
else
|
||||
gimp_value_set_static_int8_array (&value,
|
||||
params[i].data.d_array.data,
|
||||
params[i].data.d_array.size /
|
||||
sizeof (guint8));
|
||||
}
|
||||
else if (GIMP_VALUE_HOLDS_FLOAT_ARRAY (&value))
|
||||
{
|
||||
if (full_copy)
|
||||
gimp_value_set_float_array (&value,
|
||||
(const gdouble *)
|
||||
params[i].data.d_array.data,
|
||||
params[i].data.d_array.size /
|
||||
sizeof (gdouble));
|
||||
else
|
||||
gimp_value_set_static_float_array (&value,
|
||||
(const gdouble *)
|
||||
params[i].data.d_array.data,
|
||||
params[i].data.d_array.size /
|
||||
sizeof (gdouble));
|
||||
}
|
||||
else if (GIMP_VALUE_HOLDS_STRING_ARRAY (&value))
|
||||
{
|
||||
if (full_copy)
|
||||
gimp_value_set_string_array (&value,
|
||||
(const gchar **)
|
||||
params[i].data.d_string_array.data,
|
||||
params[i].data.d_string_array.size);
|
||||
else
|
||||
gimp_value_set_static_string_array (&value,
|
||||
(const gchar **)
|
||||
params[i].data.d_string_array.data,
|
||||
params[i].data.d_string_array.size);
|
||||
}
|
||||
else if (GIMP_VALUE_HOLDS_RGB_ARRAY (&value))
|
||||
{
|
||||
if (full_copy)
|
||||
gimp_value_set_rgb_array (&value,
|
||||
(GimpRGB *)
|
||||
params[i].data.d_array.data,
|
||||
params[i].data.d_array.size /
|
||||
sizeof (GimpRGB));
|
||||
else
|
||||
gimp_value_set_static_rgb_array (&value,
|
||||
(GimpRGB *)
|
||||
params[i].data.d_array.data,
|
||||
params[i].data.d_array.size /
|
||||
sizeof (GimpRGB));
|
||||
}
|
||||
else if (GIMP_VALUE_HOLDS_DISPLAY_ID (&value) ||
|
||||
GIMP_VALUE_HOLDS_IMAGE_ID (&value) ||
|
||||
GIMP_VALUE_HOLDS_ITEM_ID (&value) ||
|
||||
GIMP_VALUE_HOLDS_DRAWABLE_ID (&value) ||
|
||||
GIMP_VALUE_HOLDS_LAYER_ID (&value) ||
|
||||
GIMP_VALUE_HOLDS_CHANNEL_ID (&value) ||
|
||||
GIMP_VALUE_HOLDS_LAYER_MASK_ID (&value) ||
|
||||
GIMP_VALUE_HOLDS_SELECTION_ID (&value) ||
|
||||
GIMP_VALUE_HOLDS_VECTORS_ID (&value))
|
||||
{
|
||||
g_value_set_int (&value, params[i].data.d_int);
|
||||
}
|
||||
_gimp_gp_param_to_value (gimp, ¶ms[i], type, &value, full_copy);
|
||||
|
||||
gimp_value_array_append (args, &value);
|
||||
g_value_unset (&value);
|
||||
|
@ -375,6 +399,167 @@ _gimp_gp_params_to_value_array (GParamSpec **pspecs,
|
|||
return args;
|
||||
}
|
||||
|
||||
void
|
||||
_gimp_value_to_gp_param (const GValue *value,
|
||||
GPParam *param,
|
||||
gboolean full_copy)
|
||||
{
|
||||
GType type;
|
||||
|
||||
g_return_if_fail (value != NULL);
|
||||
g_return_if_fail (param != NULL);
|
||||
|
||||
type = G_VALUE_TYPE (value);
|
||||
|
||||
param->param_type = -1;
|
||||
|
||||
if (full_copy)
|
||||
param->type_name = g_strdup (g_type_name (type));
|
||||
else
|
||||
param->type_name = (gchar *) g_type_name (type);
|
||||
|
||||
if (type == G_TYPE_INT ||
|
||||
type == GIMP_TYPE_INT32 ||
|
||||
type == GIMP_TYPE_INT16 ||
|
||||
type == GIMP_TYPE_UNIT)
|
||||
{
|
||||
param->param_type = GP_PARAM_TYPE_INT;
|
||||
|
||||
param->data.d_int = g_value_get_int (value);
|
||||
}
|
||||
else if (type == G_TYPE_UINT ||
|
||||
type == GIMP_TYPE_INT8)
|
||||
{
|
||||
param->param_type = GP_PARAM_TYPE_INT;
|
||||
|
||||
param->data.d_int = g_value_get_uint (value);
|
||||
}
|
||||
else if (G_VALUE_HOLDS_ENUM (value))
|
||||
{
|
||||
param->param_type = GP_PARAM_TYPE_INT;
|
||||
|
||||
param->data.d_int = g_value_get_enum (value);
|
||||
}
|
||||
else if (G_VALUE_HOLDS_BOOLEAN (value))
|
||||
{
|
||||
param->param_type = GP_PARAM_TYPE_INT;
|
||||
|
||||
param->data.d_int = g_value_get_boolean (value);
|
||||
}
|
||||
else if (G_VALUE_HOLDS_DOUBLE (value))
|
||||
{
|
||||
param->param_type = GP_PARAM_TYPE_FLOAT;
|
||||
|
||||
param->data.d_float = g_value_get_double (value);
|
||||
}
|
||||
else if (G_VALUE_HOLDS_STRING (value))
|
||||
{
|
||||
param->param_type = GP_PARAM_TYPE_STRING;
|
||||
|
||||
if (full_copy)
|
||||
param->data.d_string = g_value_dup_string (value);
|
||||
else
|
||||
param->data.d_string = (gchar *) g_value_get_string (value);
|
||||
}
|
||||
else if (GIMP_VALUE_HOLDS_RGB (value))
|
||||
{
|
||||
param->param_type = GP_PARAM_TYPE_COLOR;
|
||||
|
||||
gimp_value_get_rgb (value, ¶m->data.d_color);
|
||||
}
|
||||
else if (GIMP_VALUE_HOLDS_PARASITE (value))
|
||||
{
|
||||
GimpParasite *parasite = (full_copy ?
|
||||
g_value_dup_boxed (value) :
|
||||
g_value_get_boxed (value));
|
||||
|
||||
param->param_type = GP_PARAM_TYPE_PARASITE;
|
||||
|
||||
if (parasite)
|
||||
{
|
||||
param->data.d_parasite.name = parasite->name;
|
||||
param->data.d_parasite.flags = parasite->flags;
|
||||
param->data.d_parasite.size = parasite->size;
|
||||
param->data.d_parasite.data = parasite->data;
|
||||
|
||||
if (full_copy)
|
||||
{
|
||||
parasite->name = NULL;
|
||||
parasite->flags = 0;
|
||||
parasite->size = 0;
|
||||
parasite->data = NULL;
|
||||
|
||||
gimp_parasite_free (parasite);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
param->data.d_parasite.name = NULL;
|
||||
param->data.d_parasite.flags = 0;
|
||||
param->data.d_parasite.size = 0;
|
||||
param->data.d_parasite.data = NULL;
|
||||
}
|
||||
}
|
||||
else if (GIMP_VALUE_HOLDS_INT32_ARRAY (value) ||
|
||||
GIMP_VALUE_HOLDS_INT16_ARRAY (value) ||
|
||||
GIMP_VALUE_HOLDS_INT8_ARRAY (value) ||
|
||||
GIMP_VALUE_HOLDS_FLOAT_ARRAY (value) ||
|
||||
GIMP_VALUE_HOLDS_RGB_ARRAY (value))
|
||||
{
|
||||
GimpArray *array = g_value_get_boxed (value);
|
||||
|
||||
param->param_type = GP_PARAM_TYPE_ARRAY;
|
||||
|
||||
param->data.d_array.size = array->length;
|
||||
|
||||
if (full_copy)
|
||||
param->data.d_array.data = g_memdup (array->data,
|
||||
array->length);
|
||||
else
|
||||
param->data.d_array.data = array->data;
|
||||
}
|
||||
else if (GIMP_VALUE_HOLDS_STRING_ARRAY (value))
|
||||
{
|
||||
GimpArray *array = g_value_get_boxed (value);
|
||||
|
||||
param->param_type = GP_PARAM_TYPE_STRING_ARRAY;
|
||||
|
||||
param->data.d_string_array.size = array->length;
|
||||
|
||||
if (full_copy)
|
||||
param->data.d_string_array.data =
|
||||
gimp_value_dup_string_array (value);
|
||||
else
|
||||
param->data.d_string_array.data =
|
||||
(gchar **) gimp_value_get_string_array (value);
|
||||
}
|
||||
else if (GIMP_VALUE_HOLDS_DISPLAY_ID (value) ||
|
||||
GIMP_VALUE_HOLDS_IMAGE_ID (value) ||
|
||||
GIMP_VALUE_HOLDS_ITEM_ID (value) ||
|
||||
GIMP_VALUE_HOLDS_DRAWABLE_ID (value) ||
|
||||
GIMP_VALUE_HOLDS_LAYER_ID (value) ||
|
||||
GIMP_VALUE_HOLDS_CHANNEL_ID (value) ||
|
||||
GIMP_VALUE_HOLDS_LAYER_MASK_ID (value) ||
|
||||
GIMP_VALUE_HOLDS_SELECTION_ID (value) ||
|
||||
GIMP_VALUE_HOLDS_VECTORS_ID (value))
|
||||
{
|
||||
param->param_type = GP_PARAM_TYPE_INT;
|
||||
|
||||
param->data.d_int = g_value_get_int (value);
|
||||
}
|
||||
else if (G_VALUE_HOLDS_PARAM (value))
|
||||
{
|
||||
param->param_type = GP_PARAM_TYPE_PARAM_DEF;
|
||||
|
||||
_gimp_param_spec_to_gp_param_def (g_value_get_param (value),
|
||||
¶m->data.d_param_def);
|
||||
}
|
||||
|
||||
if (param->param_type == -1)
|
||||
g_printerr ("%s: GValue contains unsupported type '%s'\n",
|
||||
G_STRFUNC, param->type_name);
|
||||
}
|
||||
|
||||
GPParam *
|
||||
_gimp_value_array_to_gp_params (GimpValueArray *args,
|
||||
gboolean full_copy)
|
||||
|
@ -385,155 +570,15 @@ _gimp_value_array_to_gp_params (GimpValueArray *args,
|
|||
|
||||
g_return_val_if_fail (args != NULL, NULL);
|
||||
|
||||
params = g_new0 (GPParam, gimp_value_array_length (args));
|
||||
|
||||
length = gimp_value_array_length (args);
|
||||
|
||||
params = g_new0 (GPParam, length);
|
||||
|
||||
for (i = 0; i < length; i++)
|
||||
{
|
||||
GValue *value = gimp_value_array_index (args, i);
|
||||
GType type = G_VALUE_TYPE (value);
|
||||
|
||||
params[i].param_type = -1;
|
||||
|
||||
if (full_copy)
|
||||
params[i].type_name = g_strdup (g_type_name (type));
|
||||
else
|
||||
params[i].type_name = (gchar *) g_type_name (type);
|
||||
|
||||
if (type == G_TYPE_INT ||
|
||||
type == GIMP_TYPE_INT32 ||
|
||||
type == GIMP_TYPE_INT16 ||
|
||||
type == GIMP_TYPE_UNIT)
|
||||
{
|
||||
params[i].param_type = GP_PARAM_TYPE_INT;
|
||||
|
||||
params[i].data.d_int = g_value_get_int (value);
|
||||
}
|
||||
else if (type == G_TYPE_UINT ||
|
||||
type == GIMP_TYPE_INT8)
|
||||
{
|
||||
params[i].param_type = GP_PARAM_TYPE_INT;
|
||||
|
||||
params[i].data.d_int = g_value_get_uint (value);
|
||||
}
|
||||
else if (G_VALUE_HOLDS_ENUM (value))
|
||||
{
|
||||
params[i].param_type = GP_PARAM_TYPE_INT;
|
||||
|
||||
params[i].data.d_int = g_value_get_enum (value);
|
||||
}
|
||||
else if (G_VALUE_HOLDS_BOOLEAN (value))
|
||||
{
|
||||
params[i].param_type = GP_PARAM_TYPE_INT;
|
||||
|
||||
params[i].data.d_int = g_value_get_boolean (value);
|
||||
}
|
||||
else if (G_VALUE_HOLDS_DOUBLE (value))
|
||||
{
|
||||
params[i].param_type = GP_PARAM_TYPE_FLOAT;
|
||||
|
||||
params[i].data.d_float = g_value_get_double (value);
|
||||
}
|
||||
else if (G_VALUE_HOLDS_STRING (value))
|
||||
{
|
||||
params[i].param_type = GP_PARAM_TYPE_STRING;
|
||||
|
||||
if (full_copy)
|
||||
params[i].data.d_string = g_value_dup_string (value);
|
||||
else
|
||||
params[i].data.d_string = (gchar *) g_value_get_string (value);
|
||||
}
|
||||
else if (GIMP_VALUE_HOLDS_RGB (value))
|
||||
{
|
||||
params[i].param_type = GP_PARAM_TYPE_COLOR;
|
||||
|
||||
gimp_value_get_rgb (value, ¶ms[i].data.d_color);
|
||||
}
|
||||
else if (GIMP_VALUE_HOLDS_PARASITE (value))
|
||||
{
|
||||
GimpParasite *parasite = (full_copy ?
|
||||
g_value_dup_boxed (value) :
|
||||
g_value_get_boxed (value));
|
||||
|
||||
params[i].param_type = GP_PARAM_TYPE_PARASITE;
|
||||
|
||||
if (parasite)
|
||||
{
|
||||
params[i].data.d_parasite.name = parasite->name;
|
||||
params[i].data.d_parasite.flags = parasite->flags;
|
||||
params[i].data.d_parasite.size = parasite->size;
|
||||
params[i].data.d_parasite.data = parasite->data;
|
||||
|
||||
if (full_copy)
|
||||
{
|
||||
parasite->name = NULL;
|
||||
parasite->flags = 0;
|
||||
parasite->size = 0;
|
||||
parasite->data = NULL;
|
||||
|
||||
gimp_parasite_free (parasite);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
params[i].data.d_parasite.name = NULL;
|
||||
params[i].data.d_parasite.flags = 0;
|
||||
params[i].data.d_parasite.size = 0;
|
||||
params[i].data.d_parasite.data = NULL;
|
||||
}
|
||||
}
|
||||
else if (GIMP_VALUE_HOLDS_INT32_ARRAY (value) ||
|
||||
GIMP_VALUE_HOLDS_INT16_ARRAY (value) ||
|
||||
GIMP_VALUE_HOLDS_INT8_ARRAY (value) ||
|
||||
GIMP_VALUE_HOLDS_FLOAT_ARRAY (value) ||
|
||||
GIMP_VALUE_HOLDS_RGB_ARRAY (value))
|
||||
{
|
||||
GimpArray *array = g_value_get_boxed (value);
|
||||
|
||||
params[i].param_type = GP_PARAM_TYPE_ARRAY;
|
||||
|
||||
params[i].data.d_array.size = array->length;
|
||||
|
||||
if (full_copy)
|
||||
params[i].data.d_array.data = g_memdup (array->data,
|
||||
array->length);
|
||||
else
|
||||
params[i].data.d_array.data = array->data;
|
||||
}
|
||||
else if (GIMP_VALUE_HOLDS_STRING_ARRAY (value))
|
||||
{
|
||||
GimpArray *array = g_value_get_boxed (value);
|
||||
|
||||
params[i].param_type = GP_PARAM_TYPE_STRING_ARRAY;
|
||||
|
||||
params[i].data.d_string_array.size = array->length;
|
||||
|
||||
if (full_copy)
|
||||
params[i].data.d_string_array.data =
|
||||
gimp_value_dup_string_array (value);
|
||||
else
|
||||
params[i].data.d_string_array.data =
|
||||
(gchar **) gimp_value_get_string_array (value);
|
||||
}
|
||||
else if (GIMP_VALUE_HOLDS_DISPLAY_ID (value) ||
|
||||
GIMP_VALUE_HOLDS_IMAGE_ID (value) ||
|
||||
GIMP_VALUE_HOLDS_ITEM_ID (value) ||
|
||||
GIMP_VALUE_HOLDS_DRAWABLE_ID (value) ||
|
||||
GIMP_VALUE_HOLDS_LAYER_ID (value) ||
|
||||
GIMP_VALUE_HOLDS_CHANNEL_ID (value) ||
|
||||
GIMP_VALUE_HOLDS_LAYER_MASK_ID (value) ||
|
||||
GIMP_VALUE_HOLDS_SELECTION_ID (value) ||
|
||||
GIMP_VALUE_HOLDS_VECTORS_ID (value))
|
||||
{
|
||||
params[i].param_type = GP_PARAM_TYPE_INT;
|
||||
|
||||
params[i].data.d_int = g_value_get_int (value);
|
||||
}
|
||||
|
||||
if (params[i].param_type == -1)
|
||||
g_printerr ("%s: GValue contains unsupported type '%s'\n",
|
||||
G_STRFUNC, params[i].type_name);
|
||||
_gimp_value_to_gp_param (value, ¶ms[i], full_copy);
|
||||
}
|
||||
|
||||
return params;
|
||||
|
|
|
@ -38,3 +38,172 @@
|
|||
* libgimp/ but need different headers.
|
||||
*/
|
||||
#include "gimpgpparams-body.c"
|
||||
|
||||
GParamSpec *
|
||||
_gimp_gp_param_def_to_param_spec (gpointer gimp,
|
||||
GPParamDef *param_def)
|
||||
{
|
||||
const gchar *name = param_def->name;
|
||||
const gchar *nick = param_def->nick;
|
||||
const gchar *blurb = param_def->blurb;
|
||||
GParamFlags flags = G_PARAM_READWRITE;
|
||||
|
||||
switch (param_def->param_def_type)
|
||||
{
|
||||
case GP_PARAM_DEF_TYPE_DEFAULT:
|
||||
if (! strcmp (param_def->type_name, "GimpParamInt32Array"))
|
||||
return gimp_param_spec_int32_array (name, nick, blurb, flags);
|
||||
|
||||
if (! strcmp (param_def->type_name, "GimpParamInt16Array"))
|
||||
return gimp_param_spec_int16_array (name, nick, blurb, flags);
|
||||
|
||||
if (! strcmp (param_def->type_name, "GimpParamInt8Array"))
|
||||
return gimp_param_spec_int8_array (name, nick, blurb, flags);
|
||||
|
||||
if (! strcmp (param_def->type_name, "GimpParamFloatArray"))
|
||||
return gimp_param_spec_float_array (name, nick, blurb, flags);
|
||||
|
||||
if (! strcmp (param_def->type_name, "GimpParamStringArray"))
|
||||
return gimp_param_spec_string_array (name, nick, blurb, flags);
|
||||
|
||||
if (! strcmp (param_def->type_name, "GimpParamRGBArray"))
|
||||
return gimp_param_spec_rgb_array (name, nick, blurb, flags);
|
||||
|
||||
if (! strcmp (param_def->type_name, "GimpParamParasite"))
|
||||
return gimp_param_spec_parasite (name, nick, blurb, flags);
|
||||
break;
|
||||
|
||||
case GP_PARAM_DEF_TYPE_INT:
|
||||
if (! strcmp (param_def->type_name, "GParamInt"))
|
||||
return g_param_spec_int (name, nick, blurb,
|
||||
param_def->meta.m_int.min_val,
|
||||
param_def->meta.m_int.max_val,
|
||||
param_def->meta.m_int.default_val,
|
||||
flags);
|
||||
|
||||
if (! strcmp (param_def->type_name, "GimpParamInt32"))
|
||||
return gimp_param_spec_int32 (name, nick, blurb,
|
||||
param_def->meta.m_int.min_val,
|
||||
param_def->meta.m_int.max_val,
|
||||
param_def->meta.m_int.default_val,
|
||||
flags);
|
||||
|
||||
if (! strcmp (param_def->type_name, "GimpParamInt16"))
|
||||
return gimp_param_spec_int16 (name, nick, blurb,
|
||||
param_def->meta.m_int.min_val,
|
||||
param_def->meta.m_int.max_val,
|
||||
param_def->meta.m_int.default_val,
|
||||
flags);
|
||||
|
||||
if (! strcmp (param_def->type_name, "GimpParamInt8"))
|
||||
return gimp_param_spec_int8 (name, nick, blurb,
|
||||
param_def->meta.m_int.min_val,
|
||||
param_def->meta.m_int.max_val,
|
||||
param_def->meta.m_int.default_val,
|
||||
flags);
|
||||
break;
|
||||
|
||||
case GP_PARAM_DEF_TYPE_UNIT:
|
||||
if (! strcmp (param_def->type_name, "GimpParamUnit"))
|
||||
return gimp_param_spec_unit (name, nick, blurb,
|
||||
param_def->meta.m_unit.allow_pixels,
|
||||
param_def->meta.m_unit.allow_percent,
|
||||
param_def->meta.m_unit.default_val,
|
||||
flags);
|
||||
break;
|
||||
|
||||
case GP_PARAM_DEF_TYPE_ENUM:
|
||||
if (! strcmp (param_def->type_name, "GParamEnum"))
|
||||
return g_param_spec_enum (name, nick, blurb,
|
||||
g_type_from_name (param_def->meta.m_enum.type_name),
|
||||
param_def->meta.m_enum.default_val,
|
||||
flags);
|
||||
break;
|
||||
|
||||
case GP_PARAM_DEF_TYPE_BOOLEAN:
|
||||
if (! strcmp (param_def->type_name, "GParamBoolean"))
|
||||
return g_param_spec_boolean (name, nick, blurb,
|
||||
param_def->meta.m_boolean.default_val,
|
||||
flags);
|
||||
break;
|
||||
|
||||
case GP_PARAM_DEF_TYPE_FLOAT:
|
||||
if (! strcmp (param_def->type_name, "GParamDouble"))
|
||||
return g_param_spec_double (name, nick, blurb,
|
||||
param_def->meta.m_float.min_val,
|
||||
param_def->meta.m_float.max_val,
|
||||
param_def->meta.m_float.default_val,
|
||||
flags);
|
||||
break;
|
||||
|
||||
case GP_PARAM_DEF_TYPE_STRING:
|
||||
if (! strcmp (param_def->type_name, "GimpParamString") ||
|
||||
! strcmp (param_def->type_name, "GParamString"))
|
||||
return gimp_param_spec_string (name, nick, blurb,
|
||||
param_def->meta.m_string.allow_non_utf8,
|
||||
param_def->meta.m_string.null_ok,
|
||||
param_def->meta.m_string.non_empty,
|
||||
param_def->meta.m_string.default_val,
|
||||
flags);
|
||||
break;
|
||||
|
||||
case GP_PARAM_DEF_TYPE_COLOR:
|
||||
if (! strcmp (param_def->type_name, "GimpParamRGB"))
|
||||
return gimp_param_spec_rgb (name, nick, blurb,
|
||||
param_def->meta.m_color.has_alpha,
|
||||
¶m_def->meta.m_color.default_val,
|
||||
flags);
|
||||
|
||||
case GP_PARAM_DEF_TYPE_ID:
|
||||
if (! strcmp (param_def->type_name, "GimpParamDisplayID"))
|
||||
return gimp_param_spec_display_id (name, nick, blurb,
|
||||
param_def->meta.m_id.none_ok,
|
||||
flags);
|
||||
|
||||
if (! strcmp (param_def->type_name, "GimpParamImageID"))
|
||||
return gimp_param_spec_image_id (name, nick, blurb,
|
||||
param_def->meta.m_id.none_ok,
|
||||
flags);
|
||||
|
||||
if (! strcmp (param_def->type_name, "GimpParamItemID"))
|
||||
return gimp_param_spec_item_id (name, nick, blurb,
|
||||
param_def->meta.m_id.none_ok,
|
||||
flags);
|
||||
|
||||
if (! strcmp (param_def->type_name, "GimpParamDrawableID"))
|
||||
return gimp_param_spec_drawable_id (name, nick, blurb,
|
||||
param_def->meta.m_id.none_ok,
|
||||
flags);
|
||||
|
||||
if (! strcmp (param_def->type_name, "GimpParamLayerID"))
|
||||
return gimp_param_spec_layer_id (name, nick, blurb,
|
||||
param_def->meta.m_id.none_ok,
|
||||
flags);
|
||||
|
||||
if (! strcmp (param_def->type_name, "GimpParamChannelID"))
|
||||
return gimp_param_spec_channel_id (name, nick, blurb,
|
||||
param_def->meta.m_id.none_ok,
|
||||
flags);
|
||||
|
||||
if (! strcmp (param_def->type_name, "GimpParamLayerMaskID"))
|
||||
return gimp_param_spec_layer_mask_id (name, nick, blurb,
|
||||
param_def->meta.m_id.none_ok,
|
||||
flags);
|
||||
|
||||
if (! strcmp (param_def->type_name, "GimpParamSelectionID"))
|
||||
return gimp_param_spec_selection_id (name, nick, blurb,
|
||||
param_def->meta.m_id.none_ok,
|
||||
flags);
|
||||
|
||||
if (! strcmp (param_def->type_name, "GimpParamVectorsID"))
|
||||
return gimp_param_spec_vectors_id (name, nick, blurb,
|
||||
param_def->meta.m_id.none_ok,
|
||||
flags);
|
||||
break;
|
||||
}
|
||||
|
||||
g_printerr ("%s: GParamSpec type '%s' is not handled\n",
|
||||
G_STRFUNC, param_def->type_name);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -25,15 +25,28 @@
|
|||
G_BEGIN_DECLS
|
||||
|
||||
|
||||
GParamSpec * _gimp_gp_param_def_to_param_spec (gpointer gimp,
|
||||
GPParamDef *param_def);
|
||||
|
||||
void _gimp_param_spec_to_gp_param_def (GParamSpec *pspec,
|
||||
GPParamDef *param_def);
|
||||
|
||||
GimpValueArray * _gimp_gp_params_to_value_array (GParamSpec **pspecs,
|
||||
void _gimp_gp_param_to_value (gpointer gimp,
|
||||
GPParam *param,
|
||||
GType type,
|
||||
GValue *value,
|
||||
gboolean full_copy);
|
||||
GimpValueArray * _gimp_gp_params_to_value_array (gpointer gimp,
|
||||
GParamSpec **pspecs,
|
||||
gint n_pspecs,
|
||||
GPParam *params,
|
||||
gint n_params,
|
||||
gboolean return_values,
|
||||
gboolean full_copy);
|
||||
|
||||
void _gimp_value_to_gp_param (const GValue *value,
|
||||
GPParam *param,
|
||||
gboolean full_copy);
|
||||
GPParam * _gimp_value_array_to_gp_params (GimpValueArray *args,
|
||||
gboolean full_copy);
|
||||
|
||||
|
|
|
@ -1165,7 +1165,8 @@ gimp_proc_run_internal (GPProcRun *proc_run,
|
|||
gint n_params;
|
||||
gint n_return_vals;
|
||||
|
||||
arguments = _gimp_gp_params_to_value_array (NULL, 0,
|
||||
arguments = _gimp_gp_params_to_value_array (NULL,
|
||||
NULL, 0,
|
||||
proc_run->params,
|
||||
proc_run->nparams,
|
||||
FALSE, FALSE);
|
||||
|
|
|
@ -347,7 +347,8 @@ gimp_plug_in_proc_run_internal (GPProcRun *proc_run,
|
|||
GimpValueArray *arguments;
|
||||
GimpValueArray *return_values = NULL;
|
||||
|
||||
arguments = _gimp_gp_params_to_value_array (NULL, 0,
|
||||
arguments = _gimp_gp_params_to_value_array (NULL,
|
||||
NULL, 0,
|
||||
proc_run->params,
|
||||
proc_run->nparams,
|
||||
FALSE, FALSE);
|
||||
|
|
|
@ -1721,6 +1721,13 @@ _gp_params_read (GIOChannel *channel,
|
|||
else
|
||||
(*params)[i].data.d_parasite.data = NULL;
|
||||
break;
|
||||
|
||||
case GP_PARAM_TYPE_PARAM_DEF:
|
||||
if (! _gp_param_def_read (channel,
|
||||
&(*params)[i].data.d_param_def,
|
||||
user_data))
|
||||
goto cleanup;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1833,6 +1840,13 @@ _gp_params_write (GIOChannel *channel,
|
|||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case GP_PARAM_TYPE_PARAM_DEF:
|
||||
if (! _gp_param_def_write (channel,
|
||||
¶ms[i].data.d_param_def,
|
||||
user_data))
|
||||
return;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1883,6 +1897,10 @@ _gp_params_destroy (GPParam *params,
|
|||
if (params[i].data.d_parasite.data)
|
||||
g_free (params[i].data.d_parasite.data);
|
||||
break;
|
||||
|
||||
case GP_PARAM_TYPE_PARAM_DEF:
|
||||
_gp_param_def_destroy (¶ms[i].data.d_param_def);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -67,7 +67,8 @@ typedef enum
|
|||
GP_PARAM_TYPE_COLOR,
|
||||
GP_PARAM_TYPE_PARASITE,
|
||||
GP_PARAM_TYPE_ARRAY,
|
||||
GP_PARAM_TYPE_STRING_ARRAY
|
||||
GP_PARAM_TYPE_STRING_ARRAY,
|
||||
GP_PARAM_TYPE_PARAM_DEF
|
||||
} GPParamType;
|
||||
|
||||
|
||||
|
@ -236,6 +237,7 @@ struct _GPParam
|
|||
GimpParasite d_parasite;
|
||||
GPParamArray d_array;
|
||||
GPParamStringArray d_string_array;
|
||||
GPParamDef d_param_def;
|
||||
} data;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue