2009-01-26 02:01:47 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* gimpparamspecs-duplicate.c
|
2014-05-17 06:19:20 +08:00
|
|
|
* Copyright (C) 2008-2014 Michael Natterer <mitch@gimp.org>
|
2009-01-26 02:01:47 +08:00
|
|
|
*
|
|
|
|
* 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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2011-04-28 21:50:39 +08:00
|
|
|
#include <cairo.h>
|
2009-01-26 02:01:47 +08:00
|
|
|
#include <gegl.h>
|
|
|
|
#include <gegl-paramspecs.h>
|
2012-05-03 09:36:22 +08:00
|
|
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
2009-01-26 02:01:47 +08:00
|
|
|
|
|
|
|
#include "libgimpcolor/gimpcolor.h"
|
|
|
|
#include "libgimpconfig/gimpconfig.h"
|
|
|
|
|
|
|
|
#include "core-types.h"
|
|
|
|
|
2014-05-17 06:19:20 +08:00
|
|
|
#include "gegl/gimp-gegl-utils.h"
|
|
|
|
|
2009-01-26 02:01:47 +08:00
|
|
|
#include "gimpparamspecs.h"
|
|
|
|
#include "gimpparamspecs-duplicate.h"
|
|
|
|
|
|
|
|
|
2009-07-20 17:53:02 +08:00
|
|
|
/* FIXME: this code is not yet general as it should be (gegl tool only atm) */
|
2009-01-26 02:01:47 +08:00
|
|
|
|
|
|
|
GParamSpec *
|
|
|
|
gimp_param_spec_duplicate (GParamSpec *pspec)
|
|
|
|
{
|
2014-05-15 04:50:59 +08:00
|
|
|
GParamSpec *copy = NULL;
|
|
|
|
GParamFlags flags;
|
|
|
|
|
2009-01-26 02:01:47 +08:00
|
|
|
g_return_val_if_fail (pspec != NULL, NULL);
|
|
|
|
|
2014-05-17 06:19:20 +08:00
|
|
|
flags = pspec->flags;
|
|
|
|
|
|
|
|
if (! gimp_gegl_param_spec_has_key (pspec, "role", "output-extent"))
|
|
|
|
flags |= GIMP_CONFIG_PARAM_SERIALIZE;
|
2014-05-15 04:50:59 +08:00
|
|
|
|
2009-01-26 02:01:47 +08:00
|
|
|
if (G_IS_PARAM_SPEC_STRING (pspec))
|
|
|
|
{
|
|
|
|
GParamSpecString *spec = G_PARAM_SPEC_STRING (pspec);
|
|
|
|
|
|
|
|
if (GEGL_IS_PARAM_SPEC_FILE_PATH (pspec))
|
|
|
|
{
|
2014-05-15 04:50:59 +08:00
|
|
|
copy = gimp_param_spec_config_path (pspec->name,
|
2009-01-26 02:01:47 +08:00
|
|
|
g_param_spec_get_nick (pspec),
|
|
|
|
g_param_spec_get_blurb (pspec),
|
|
|
|
GIMP_CONFIG_PATH_FILE,
|
|
|
|
spec->default_value,
|
2014-05-15 04:50:59 +08:00
|
|
|
flags);
|
2009-01-26 02:01:47 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
|
2014-05-15 04:50:59 +08:00
|
|
|
copy = g_param_spec_string (pspec->name,
|
|
|
|
g_param_spec_get_nick (pspec),
|
|
|
|
g_param_spec_get_blurb (pspec),
|
|
|
|
spec->default_value,
|
|
|
|
flags);
|
2009-01-26 02:01:47 +08:00
|
|
|
|
|
|
|
if (GEGL_IS_PARAM_SPEC_MULTILINE (pspec))
|
|
|
|
{
|
2014-05-21 02:47:31 +08:00
|
|
|
static GQuark multiline_quark = 0;
|
|
|
|
|
|
|
|
if (! multiline_quark)
|
|
|
|
multiline_quark = g_quark_from_static_string ("multiline");
|
|
|
|
|
2014-05-15 04:50:59 +08:00
|
|
|
g_param_spec_set_qdata (copy, multiline_quark,
|
2009-01-26 02:01:47 +08:00
|
|
|
GINT_TO_POINTER (TRUE));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (G_IS_PARAM_SPEC_BOOLEAN (pspec))
|
|
|
|
{
|
|
|
|
GParamSpecBoolean *spec = G_PARAM_SPEC_BOOLEAN (pspec);
|
|
|
|
|
2014-05-15 04:50:59 +08:00
|
|
|
copy = g_param_spec_boolean (pspec->name,
|
2009-01-26 02:01:47 +08:00
|
|
|
g_param_spec_get_nick (pspec),
|
|
|
|
g_param_spec_get_blurb (pspec),
|
|
|
|
spec->default_value,
|
2014-05-15 04:50:59 +08:00
|
|
|
flags);
|
2009-01-26 02:01:47 +08:00
|
|
|
}
|
|
|
|
else if (G_IS_PARAM_SPEC_ENUM (pspec))
|
|
|
|
{
|
|
|
|
GParamSpecEnum *spec = G_PARAM_SPEC_ENUM (pspec);
|
|
|
|
|
2014-05-15 04:50:59 +08:00
|
|
|
copy = g_param_spec_enum (pspec->name,
|
2009-01-26 02:01:47 +08:00
|
|
|
g_param_spec_get_nick (pspec),
|
|
|
|
g_param_spec_get_blurb (pspec),
|
|
|
|
G_TYPE_FROM_CLASS (spec->enum_class),
|
|
|
|
spec->default_value,
|
2014-05-15 04:50:59 +08:00
|
|
|
flags);
|
2009-01-26 02:01:47 +08:00
|
|
|
}
|
2012-03-31 03:22:00 +08:00
|
|
|
else if (GEGL_IS_PARAM_SPEC_DOUBLE (pspec))
|
|
|
|
{
|
|
|
|
GeglParamSpecDouble *gspec = GEGL_PARAM_SPEC_DOUBLE (pspec);
|
2014-05-21 02:47:31 +08:00
|
|
|
GParamSpecDouble *spec = G_PARAM_SPEC_DOUBLE (pspec);
|
2012-03-31 03:22:00 +08:00
|
|
|
|
2014-05-15 04:50:59 +08:00
|
|
|
copy = gegl_param_spec_double (pspec->name,
|
2012-03-31 03:22:00 +08:00
|
|
|
g_param_spec_get_nick (pspec),
|
|
|
|
g_param_spec_get_blurb (pspec),
|
|
|
|
spec->minimum,
|
|
|
|
spec->maximum,
|
|
|
|
spec->default_value,
|
|
|
|
gspec->ui_minimum,
|
|
|
|
gspec->ui_maximum,
|
|
|
|
gspec->ui_gamma,
|
2014-05-15 04:50:59 +08:00
|
|
|
flags);
|
2014-05-20 22:16:18 +08:00
|
|
|
gegl_param_spec_double_set_steps (GEGL_PARAM_SPEC_DOUBLE (copy),
|
|
|
|
gspec->ui_step_small,
|
|
|
|
gspec->ui_step_big);
|
|
|
|
gegl_param_spec_double_set_digits (GEGL_PARAM_SPEC_DOUBLE (copy),
|
|
|
|
gspec->ui_digits);
|
2012-03-31 03:22:00 +08:00
|
|
|
}
|
2009-01-26 02:01:47 +08:00
|
|
|
else if (G_IS_PARAM_SPEC_DOUBLE (pspec))
|
|
|
|
{
|
|
|
|
GParamSpecDouble *spec = G_PARAM_SPEC_DOUBLE (pspec);
|
|
|
|
|
2014-05-15 04:50:59 +08:00
|
|
|
copy = g_param_spec_double (pspec->name,
|
2009-01-26 02:01:47 +08:00
|
|
|
g_param_spec_get_nick (pspec),
|
|
|
|
g_param_spec_get_blurb (pspec),
|
|
|
|
spec->minimum,
|
|
|
|
spec->maximum,
|
|
|
|
spec->default_value,
|
2014-05-15 04:50:59 +08:00
|
|
|
flags);
|
2009-01-26 02:01:47 +08:00
|
|
|
}
|
|
|
|
else if (G_IS_PARAM_SPEC_FLOAT (pspec))
|
|
|
|
{
|
|
|
|
GParamSpecFloat *spec = G_PARAM_SPEC_FLOAT (pspec);
|
|
|
|
|
2014-05-15 04:50:59 +08:00
|
|
|
copy = g_param_spec_float (pspec->name,
|
2009-01-26 02:01:47 +08:00
|
|
|
g_param_spec_get_nick (pspec),
|
|
|
|
g_param_spec_get_blurb (pspec),
|
|
|
|
spec->minimum,
|
|
|
|
spec->maximum,
|
|
|
|
spec->default_value,
|
2014-05-15 04:50:59 +08:00
|
|
|
flags);
|
2009-01-26 02:01:47 +08:00
|
|
|
}
|
2012-03-31 03:22:00 +08:00
|
|
|
else if (GEGL_IS_PARAM_SPEC_INT (pspec))
|
|
|
|
{
|
|
|
|
GeglParamSpecInt *gspec = GEGL_PARAM_SPEC_INT (pspec);
|
2014-05-15 04:50:59 +08:00
|
|
|
GParamSpecInt *spec = G_PARAM_SPEC_INT (pspec);
|
2012-03-31 03:22:00 +08:00
|
|
|
|
2014-05-15 04:50:59 +08:00
|
|
|
copy = gegl_param_spec_int (pspec->name,
|
2012-03-31 03:22:00 +08:00
|
|
|
g_param_spec_get_nick (pspec),
|
|
|
|
g_param_spec_get_blurb (pspec),
|
|
|
|
spec->minimum,
|
|
|
|
spec->maximum,
|
|
|
|
spec->default_value,
|
|
|
|
gspec->ui_minimum,
|
|
|
|
gspec->ui_maximum,
|
2012-03-31 04:38:47 +08:00
|
|
|
gspec->ui_gamma,
|
2014-05-15 04:50:59 +08:00
|
|
|
flags);
|
2014-05-20 22:16:18 +08:00
|
|
|
gegl_param_spec_int_set_steps (GEGL_PARAM_SPEC_INT (copy),
|
|
|
|
gspec->ui_step_small,
|
|
|
|
gspec->ui_step_big);
|
2012-03-31 03:22:00 +08:00
|
|
|
}
|
2012-11-30 09:58:48 +08:00
|
|
|
else if (GEGL_IS_PARAM_SPEC_SEED (pspec))
|
|
|
|
{
|
2014-05-15 04:50:59 +08:00
|
|
|
copy = gegl_param_spec_seed (pspec->name,
|
2012-11-30 09:58:48 +08:00
|
|
|
g_param_spec_get_nick (pspec),
|
|
|
|
g_param_spec_get_blurb (pspec),
|
|
|
|
pspec->flags |
|
|
|
|
GIMP_CONFIG_PARAM_SERIALIZE);
|
|
|
|
}
|
2009-01-26 02:01:47 +08:00
|
|
|
else if (G_IS_PARAM_SPEC_INT (pspec))
|
|
|
|
{
|
|
|
|
GParamSpecInt *spec = G_PARAM_SPEC_INT (pspec);
|
|
|
|
|
2014-05-15 04:50:59 +08:00
|
|
|
copy = g_param_spec_int (pspec->name,
|
2009-01-26 02:01:47 +08:00
|
|
|
g_param_spec_get_nick (pspec),
|
|
|
|
g_param_spec_get_blurb (pspec),
|
|
|
|
spec->minimum,
|
|
|
|
spec->maximum,
|
|
|
|
spec->default_value,
|
2014-05-15 04:50:59 +08:00
|
|
|
flags);
|
2009-01-26 02:01:47 +08:00
|
|
|
}
|
|
|
|
else if (G_IS_PARAM_SPEC_UINT (pspec))
|
|
|
|
{
|
|
|
|
GParamSpecUInt *spec = G_PARAM_SPEC_UINT (pspec);
|
|
|
|
|
2014-05-15 04:50:59 +08:00
|
|
|
copy = g_param_spec_uint (pspec->name,
|
2009-01-26 02:01:47 +08:00
|
|
|
g_param_spec_get_nick (pspec),
|
|
|
|
g_param_spec_get_blurb (pspec),
|
|
|
|
spec->minimum,
|
|
|
|
spec->maximum,
|
|
|
|
spec->default_value,
|
2014-05-15 04:50:59 +08:00
|
|
|
flags);
|
2009-01-26 02:01:47 +08:00
|
|
|
}
|
2012-05-05 05:50:02 +08:00
|
|
|
else if (GIMP_IS_PARAM_SPEC_RGB (pspec))
|
|
|
|
{
|
|
|
|
GValue value = G_VALUE_INIT;
|
|
|
|
GimpRGB color;
|
|
|
|
|
|
|
|
g_value_init (&value, GIMP_TYPE_RGB);
|
|
|
|
g_param_value_set_default (pspec, &value);
|
|
|
|
gimp_value_get_rgb (&value, &color);
|
|
|
|
g_value_unset (&value);
|
|
|
|
|
2014-05-15 04:50:59 +08:00
|
|
|
copy = gimp_param_spec_rgb (pspec->name,
|
2012-05-05 05:50:02 +08:00
|
|
|
g_param_spec_get_nick (pspec),
|
|
|
|
g_param_spec_get_blurb (pspec),
|
|
|
|
gimp_param_spec_rgb_has_alpha (pspec),
|
|
|
|
&color,
|
2014-05-15 04:50:59 +08:00
|
|
|
flags);
|
2012-05-05 05:50:02 +08:00
|
|
|
}
|
2009-01-26 02:01:47 +08:00
|
|
|
else if (GEGL_IS_PARAM_SPEC_COLOR (pspec))
|
|
|
|
{
|
|
|
|
GeglColor *gegl_color;
|
|
|
|
GimpRGB gimp_color;
|
|
|
|
gdouble r = 0.0;
|
|
|
|
gdouble g = 0.0;
|
|
|
|
gdouble b = 0.0;
|
|
|
|
gdouble a = 1.0;
|
|
|
|
GValue value = { 0, };
|
|
|
|
|
|
|
|
g_value_init (&value, GEGL_TYPE_COLOR);
|
|
|
|
g_param_value_set_default (pspec, &value);
|
|
|
|
|
|
|
|
gegl_color = g_value_get_object (&value);
|
|
|
|
if (gegl_color)
|
|
|
|
gegl_color_get_rgba (gegl_color, &r, &g, &b, &a);
|
|
|
|
|
|
|
|
gimp_rgba_set (&gimp_color, r, g, b, a);
|
|
|
|
|
|
|
|
g_value_unset (&value);
|
|
|
|
|
2014-05-15 04:50:59 +08:00
|
|
|
copy = gimp_param_spec_rgb (pspec->name,
|
2009-01-26 02:01:47 +08:00
|
|
|
g_param_spec_get_nick (pspec),
|
|
|
|
g_param_spec_get_blurb (pspec),
|
|
|
|
TRUE,
|
|
|
|
&gimp_color,
|
2014-05-15 04:50:59 +08:00
|
|
|
flags);
|
2009-01-26 02:01:47 +08:00
|
|
|
}
|
|
|
|
else if (G_IS_PARAM_SPEC_OBJECT (pspec) ||
|
|
|
|
G_IS_PARAM_SPEC_POINTER (pspec))
|
|
|
|
{
|
2014-05-15 04:50:59 +08:00
|
|
|
/* silently ignore object properties */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_warning ("%s: not supported: %s (%s)\n", G_STRFUNC,
|
|
|
|
g_type_name (G_TYPE_FROM_INSTANCE (pspec)), pspec->name);
|
2009-01-26 02:01:47 +08:00
|
|
|
}
|
|
|
|
|
2014-05-16 08:30:41 +08:00
|
|
|
if (copy)
|
|
|
|
{
|
|
|
|
GQuark quark = g_quark_from_static_string ("gegl-property-keys");
|
|
|
|
GHashTable *keys = g_param_spec_get_qdata (pspec, quark);
|
|
|
|
|
|
|
|
if (keys)
|
2014-06-20 15:00:46 +08:00
|
|
|
g_param_spec_set_qdata_full (copy, quark, g_hash_table_ref (keys),
|
|
|
|
(GDestroyNotify) g_hash_table_unref);
|
2014-05-16 08:30:41 +08:00
|
|
|
}
|
|
|
|
|
2014-05-15 04:50:59 +08:00
|
|
|
return copy;
|
2009-01-26 02:01:47 +08:00
|
|
|
}
|