gimp/app/pdb/drawable-filter-cmds.c
Jehan 2cf6b637e7 app, libgimp, pdb: new GimpDrawableFilterConfig class.
This is mostly an empty shell whose goal is to serve as base class for
specific dynamically generated per-operation subclasses, which will have
properties mimicking the arguments of the GEGL operation.

Most of the fundamental type args will just use the base GLib param spec
types instead of GEGL ones.

As a special case, the GeglParamEnum arguments are transformed into
GimpChoice param specs on libgimp side. The reason is that most of the
time, enum types are created within the scope of an operation code only
and cannot be properly reconstructed over the wire. I could just
transform these into an int type (which is mostly what is done in GEGL
right now when running an op with such arg), but GimpChoice allow much
nicer string-type args, which make much more semantic code. This class
was initially created for plug-ins, but it would work very well to run
GEGL ops on drawables. So let's do it.

Finally add a gimp_drawable_filter_get_config() to request the current
config of a filter.

Note that right now, we can't do much with this config object other than
observing an operation args and default values. Being able to update a
filter's settings will come up in further commits.
2024-12-17 16:24:54 +00:00

558 lines
24 KiB
C

/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995-2003 Spencer Kimball and Peter Mattis
*
* 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/>.
*/
/* NOTE: This file is auto-generated by pdbgen.pl. */
#include "config.h"
#include "stamp-pdbgen.h"
#include <gegl.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include "libgimpbase/gimpbase.h"
#include "pdb-types.h"
#include "core/gimpcontainer.h"
#include "core/gimpdrawable-filters.h"
#include "core/gimpdrawablefilter.h"
#include "core/gimpimage-undo-push.h"
#include "core/gimpitem.h"
#include "core/gimpparamspecs.h"
#include "gimppdb.h"
#include "gimpprocedure.h"
#include "internal-procs.h"
#include "gimp-intl.h"
static GimpValueArray *
drawable_filter_id_is_valid_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GimpValueArray *args,
GError **error)
{
gboolean success = TRUE;
GimpValueArray *return_vals;
gint filter_id;
gboolean valid = FALSE;
filter_id = g_value_get_int (gimp_value_array_index (args, 0));
if (success)
{
valid = (gimp_drawable_filter_get_by_id (gimp, filter_id) != NULL);
}
return_vals = gimp_procedure_get_return_values (procedure, success,
error ? *error : NULL);
if (success)
g_value_set_boolean (gimp_value_array_index (return_vals, 1), valid);
return return_vals;
}
static GimpValueArray *
drawable_filter_get_name_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GimpValueArray *args,
GError **error)
{
gboolean success = TRUE;
GimpValueArray *return_vals;
GimpDrawableFilter *filter;
gchar *name = NULL;
filter = g_value_get_object (gimp_value_array_index (args, 0));
if (success)
{
name = g_strdup (gimp_object_get_name (GIMP_OBJECT (filter)));
}
return_vals = gimp_procedure_get_return_values (procedure, success,
error ? *error : NULL);
if (success)
g_value_take_string (gimp_value_array_index (return_vals, 1), name);
return return_vals;
}
static GimpValueArray *
drawable_filter_get_operation_name_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GimpValueArray *args,
GError **error)
{
gboolean success = TRUE;
GimpValueArray *return_vals;
GimpDrawableFilter *filter;
gchar *name = NULL;
filter = g_value_get_object (gimp_value_array_index (args, 0));
if (success)
{
GeglNode *node;
node = gimp_drawable_filter_get_operation (filter);
name = g_strdup (gegl_node_get_operation (node));
}
return_vals = gimp_procedure_get_return_values (procedure, success,
error ? *error : NULL);
if (success)
g_value_take_string (gimp_value_array_index (return_vals, 1), name);
return return_vals;
}
static GimpValueArray *
drawable_filter_get_visible_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GimpValueArray *args,
GError **error)
{
gboolean success = TRUE;
GimpValueArray *return_vals;
GimpDrawableFilter *filter;
gboolean visible = FALSE;
filter = g_value_get_object (gimp_value_array_index (args, 0));
if (success)
{
visible = gimp_filter_get_active (GIMP_FILTER (filter));
}
return_vals = gimp_procedure_get_return_values (procedure, success,
error ? *error : NULL);
if (success)
g_value_set_boolean (gimp_value_array_index (return_vals, 1), visible);
return return_vals;
}
static GimpValueArray *
drawable_filter_set_visible_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GimpValueArray *args,
GError **error)
{
gboolean success = TRUE;
GimpDrawableFilter *filter;
gboolean visible;
filter = g_value_get_object (gimp_value_array_index (args, 0));
visible = g_value_get_boolean (gimp_value_array_index (args, 1));
if (success)
{
gimp_filter_set_active (GIMP_FILTER (filter), visible);
}
return gimp_procedure_get_return_values (procedure, success,
error ? *error : NULL);
}
static GimpValueArray *
drawable_filter_get_number_arguments_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GimpValueArray *args,
GError **error)
{
gboolean success = TRUE;
GimpValueArray *return_vals;
const gchar *operation_name;
gint num_args = 0;
operation_name = g_value_get_string (gimp_value_array_index (args, 0));
if (success)
{
if (gegl_has_operation (operation_name))
{
guint n_properties;
g_free (gegl_operation_list_properties (operation_name, &n_properties));
num_args = (gint) n_properties;
}
else
{
success = FALSE;
}
}
return_vals = gimp_procedure_get_return_values (procedure, success,
error ? *error : NULL);
if (success)
g_value_set_int (gimp_value_array_index (return_vals, 1), num_args);
return return_vals;
}
static GimpValueArray *
drawable_filter_get_argument_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GimpValueArray *args,
GError **error)
{
gboolean success = TRUE;
GimpValueArray *return_vals;
const gchar *operation_name;
gint arg_num;
GParamSpec *param_spec = NULL;
operation_name = g_value_get_string (gimp_value_array_index (args, 0));
arg_num = g_value_get_int (gimp_value_array_index (args, 1));
if (success)
{
if (gegl_has_operation (operation_name))
{
GParamSpec **specs;
guint n_properties;
specs = gegl_operation_list_properties (operation_name, &n_properties);
if (arg_num >= 0 && arg_num < n_properties)
{
param_spec = g_param_spec_ref (specs[arg_num]);
}
else
{
success = FALSE;
}
g_free (specs);
}
else
{
success = FALSE;
}
}
return_vals = gimp_procedure_get_return_values (procedure, success,
error ? *error : NULL);
if (success)
g_value_take_param (gimp_value_array_index (return_vals, 1), param_spec);
return return_vals;
}
static GimpValueArray *
drawable_filter_delete_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GimpValueArray *args,
GError **error)
{
gboolean success = TRUE;
GimpDrawableFilter *filter;
filter = g_value_get_object (gimp_value_array_index (args, 0));
if (success)
{
GimpDrawable *drawable = gimp_drawable_filter_get_drawable (filter);
if (drawable && gimp_drawable_has_filter (drawable, GIMP_FILTER (filter)))
{
gimp_image_undo_push_filter_remove (gimp_item_get_image (GIMP_ITEM (drawable)),
_("Remove filter"), drawable, filter);
gimp_drawable_filter_abort (filter);
}
else
{
g_clear_object (&filter);
}
}
return gimp_procedure_get_return_values (procedure, success,
error ? *error : NULL);
}
void
register_drawable_filter_procs (GimpPDB *pdb)
{
GimpProcedure *procedure;
/*
* gimp-drawable-filter-id-is-valid
*/
procedure = gimp_procedure_new (drawable_filter_id_is_valid_invoker);
gimp_object_set_static_name (GIMP_OBJECT (procedure),
"gimp-drawable-filter-id-is-valid");
gimp_procedure_set_static_help (procedure,
"Returns %TRUE if the drawable filter ID is valid.",
"This procedure checks if the given drawable filter ID is valid and refers to an existing filter.",
NULL);
gimp_procedure_set_static_attribution (procedure,
"Jehan",
"Jehan",
"2024");
gimp_procedure_add_argument (procedure,
g_param_spec_int ("filter-id",
"filter id",
"The filter ID to check",
G_MININT32, G_MAXINT32, 0,
GIMP_PARAM_READWRITE));
gimp_procedure_add_return_value (procedure,
g_param_spec_boolean ("valid",
"valid",
"Whether the filter ID is valid",
FALSE,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-drawable-filter-get-name
*/
procedure = gimp_procedure_new (drawable_filter_get_name_invoker);
gimp_object_set_static_name (GIMP_OBJECT (procedure),
"gimp-drawable-filter-get-name");
gimp_procedure_set_static_help (procedure,
"Get a drawable filter's name.",
"This procedure returns the specified filter's name.\n"
"Since it is not possible to set a drawable filter's name yet, this will be the operation's name. Eventually this filter's name will be a free form field so do not rely on this information for any processing.",
NULL);
gimp_procedure_set_static_attribution (procedure,
"Jehan",
"Jehan",
"2024");
gimp_procedure_add_argument (procedure,
gimp_param_spec_drawable_filter ("filter",
"filter",
"The filter whose name you want",
FALSE,
GIMP_PARAM_READWRITE));
gimp_procedure_add_return_value (procedure,
gimp_param_spec_string ("name",
"name",
"The filter's name",
FALSE, FALSE, FALSE,
NULL,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-drawable-filter-get-operation-name
*/
procedure = gimp_procedure_new (drawable_filter_get_operation_name_invoker);
gimp_object_set_static_name (GIMP_OBJECT (procedure),
"gimp-drawable-filter-get-operation-name");
gimp_procedure_set_static_help (procedure,
"Get a drawable filter's operation name.",
"This procedure returns the specified filter's operation name.",
NULL);
gimp_procedure_set_static_attribution (procedure,
"Jehan",
"Jehan",
"2024");
gimp_procedure_add_argument (procedure,
gimp_param_spec_drawable_filter ("filter",
"filter",
"The filter whose operation name you want",
FALSE,
GIMP_PARAM_READWRITE));
gimp_procedure_add_return_value (procedure,
gimp_param_spec_string ("name",
"name",
"The filter's operation name",
FALSE, FALSE, FALSE,
NULL,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-drawable-filter-get-visible
*/
procedure = gimp_procedure_new (drawable_filter_get_visible_invoker);
gimp_object_set_static_name (GIMP_OBJECT (procedure),
"gimp-drawable-filter-get-visible");
gimp_procedure_set_static_help (procedure,
"Get the visibility of the specified filter.",
"This procedure returns the specified filter's visibility.",
NULL);
gimp_procedure_set_static_attribution (procedure,
"Jehan",
"Jehan",
"2024");
gimp_procedure_add_argument (procedure,
gimp_param_spec_drawable_filter ("filter",
"filter",
"The filter",
FALSE,
GIMP_PARAM_READWRITE));
gimp_procedure_add_return_value (procedure,
g_param_spec_boolean ("visible",
"visible",
"The filter visibility",
FALSE,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-drawable-filter-set-visible
*/
procedure = gimp_procedure_new (drawable_filter_set_visible_invoker);
gimp_object_set_static_name (GIMP_OBJECT (procedure),
"gimp-drawable-filter-set-visible");
gimp_procedure_set_static_help (procedure,
"Set the visibility of the specified filter.",
"This procedure sets the specified filter's visibility.\n"
"The drawable won't be immediately rendered. Use [method@Gimp.Drawable.update] to trigger an update.",
NULL);
gimp_procedure_set_static_attribution (procedure,
"Jehan",
"Jehan",
"2024");
gimp_procedure_add_argument (procedure,
gimp_param_spec_drawable_filter ("filter",
"filter",
"The filter",
FALSE,
GIMP_PARAM_READWRITE));
gimp_procedure_add_argument (procedure,
g_param_spec_boolean ("visible",
"visible",
"The new filter visibility",
FALSE,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-drawable-filter-get-number-arguments
*/
procedure = gimp_procedure_new (drawable_filter_get_number_arguments_invoker);
gimp_object_set_static_name (GIMP_OBJECT (procedure),
"gimp-drawable-filter-get-number-arguments");
gimp_procedure_set_static_help (procedure,
"Queries for the number of arguments on the specified filter.",
"This procedure returns the number of arguments on the specified filter.\n"
"For specific information on each input argument, use 'gimp-drawable-filter-get-argument'.",
NULL);
gimp_procedure_set_static_attribution (procedure,
"Jehan",
"Jehan",
"2024");
gimp_procedure_add_argument (procedure,
gimp_param_spec_string ("operation-name",
"operation name",
"The procedure name",
FALSE, FALSE, TRUE,
NULL,
GIMP_PARAM_READWRITE));
gimp_procedure_add_return_value (procedure,
g_param_spec_int ("num-args",
"num args",
"The number of input arguments",
G_MININT32, G_MAXINT32, 0,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-drawable-filter-get-argument
*/
procedure = gimp_procedure_new (drawable_filter_get_argument_invoker);
gimp_object_set_static_name (GIMP_OBJECT (procedure),
"gimp-drawable-filter-get-argument");
gimp_procedure_set_static_help (procedure,
"Queries for information on the specified filter's argument.",
"This procedure returns the #GParamSpec of filter's argument.",
NULL);
gimp_procedure_set_static_attribution (procedure,
"Jehan",
"Jehan",
"2024");
gimp_procedure_add_argument (procedure,
gimp_param_spec_string ("operation-name",
"operation name",
"The procedure name",
FALSE, FALSE, TRUE,
NULL,
GIMP_PARAM_READWRITE));
gimp_procedure_add_argument (procedure,
g_param_spec_int ("arg-num",
"arg num",
"The argument number",
G_MININT32, G_MAXINT32, 0,
GIMP_PARAM_READWRITE));
gimp_procedure_add_return_value (procedure,
g_param_spec_param ("param-spec",
"param spec",
"The GParamSpec of the argument",
G_TYPE_PARAM,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-drawable-filter-delete
*/
procedure = gimp_procedure_new (drawable_filter_delete_invoker);
gimp_object_set_static_name (GIMP_OBJECT (procedure),
"gimp-drawable-filter-delete");
gimp_procedure_set_static_help (procedure,
"Delete a drawable filter.",
"This procedure deletes the specified filter. This must not be done if the drawable whose this filter was applied to was already deleted or if the drawable was already removed from the image.\n"
"Do not use anymore the @filter object after having deleted it.",
NULL);
gimp_procedure_set_static_attribution (procedure,
"Jehan",
"Jehan",
"2024");
gimp_procedure_add_argument (procedure,
gimp_param_spec_drawable_filter ("filter",
"filter",
"The filter to delete",
FALSE,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
}