gimp/app/pdb/gradients_cmds.c
Michael Natterer 169faefb18 renamed procedural_db_return_args() to procedural_db_return_values() and
2006-03-27  Michael Natterer  <mitch@gimp.org>

	* app/pdb/procedural_db.[ch]: renamed procedural_db_return_args()
	to procedural_db_return_values() and added
	procedural_db_arguments(), which returns a newly allocated,
	initialized array of the procedure's arguments.

	* app/actions/plug-in-commands.c
	* app/actions/vectors-commands.c
	* app/plug-in/plug-in-run.c
	* app/widgets/gimphelp.c
	* app/xcf/xcf.c
	* tools/pdbgen/app.pl
	* tools/pdbgen/pdb/fileops.pdb: changed accordingly, some cleanup.

	* app/pdb/*_cmds.c: regenerated.
2006-03-27 21:09:32 +00:00

517 lines
13 KiB
C

/* The GIMP -- an 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 2 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* NOTE: This file is autogenerated by pdbgen.pl. */
#include "config.h"
#include <string.h>
#include <glib-object.h>
#include "pdb-types.h"
#include "procedural_db.h"
#include "core/gimp.h"
#include "core/gimpcontainer-filter.h"
#include "core/gimpcontext.h"
#include "core/gimpdatafactory.h"
#include "core/gimpgradient.h"
#include "core/gimplist.h"
static ProcRecord gradients_refresh_proc;
static ProcRecord gradients_get_list_proc;
static ProcRecord gradients_sample_uniform_proc;
static ProcRecord gradients_sample_custom_proc;
static ProcRecord gradients_get_gradient_data_proc;
void
register_gradients_procs (Gimp *gimp)
{
procedural_db_register (gimp, &gradients_refresh_proc);
procedural_db_register (gimp, &gradients_get_list_proc);
procedural_db_register (gimp, &gradients_sample_uniform_proc);
procedural_db_register (gimp, &gradients_sample_custom_proc);
procedural_db_register (gimp, &gradients_get_gradient_data_proc);
}
static Argument *
gradients_refresh_invoker (ProcRecord *proc_record,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
Argument *args)
{
gimp_data_factory_data_refresh (gimp->gradient_factory);
return procedural_db_return_values (proc_record, TRUE);
}
static ProcRecord gradients_refresh_proc =
{
"gimp-gradients-refresh",
"gimp-gradients-refresh",
"Refresh current gradients. This function always succeeds.",
"This procedure retrieves all gradients currently in the user's gradient path and updates the gradient dialogs accordingly.",
"Michael Natterer <mitch@gimp.org>",
"Michael Natterer",
"2002",
NULL,
GIMP_INTERNAL,
0,
NULL,
0,
NULL,
{ { gradients_refresh_invoker } }
};
static Argument *
gradients_get_list_invoker (ProcRecord *proc_record,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
Argument *args)
{
gboolean success = TRUE;
Argument *return_vals;
gchar *filter;
gint32 num_gradients = 0;
gchar **gradient_list = NULL;
filter = (gchar *) args[0].value.pdb_pointer;
if (filter && !g_utf8_validate (filter, -1, NULL))
success = FALSE;
if (success)
{
gradient_list = gimp_container_get_filtered_name_array (gimp->gradient_factory->container,
filter, &num_gradients);
}
return_vals = procedural_db_return_values (proc_record, success);
if (success)
{
return_vals[1].value.pdb_int = num_gradients;
return_vals[2].value.pdb_pointer = gradient_list;
}
return return_vals;
}
static ProcArg gradients_get_list_inargs[] =
{
{
GIMP_PDB_STRING,
"filter",
"An optional regular expression used to filter the list"
}
};
static ProcArg gradients_get_list_outargs[] =
{
{
GIMP_PDB_INT32,
"num-gradients",
"The number of loaded gradients"
},
{
GIMP_PDB_STRINGARRAY,
"gradient-list",
"The list of gradient names"
}
};
static ProcRecord gradients_get_list_proc =
{
"gimp-gradients-get-list",
"gimp-gradients-get-list",
"Retrieve the list of loaded gradients.",
"This procedure returns a list of the gradients that are currently loaded. You can later use the 'gimp-context-set-gradient' function to set the active gradient.",
"Federico Mena Quintero",
"Federico Mena Quintero",
"1997",
NULL,
GIMP_INTERNAL,
1,
gradients_get_list_inargs,
2,
gradients_get_list_outargs,
{ { gradients_get_list_invoker } }
};
static Argument *
gradients_sample_uniform_invoker (ProcRecord *proc_record,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
Argument *args)
{
gboolean success = TRUE;
Argument *return_vals;
gint32 num_samples;
gboolean reverse;
gint32 array_length = 0;
gdouble *color_samples = NULL;
num_samples = args[0].value.pdb_int;
if (num_samples < 2)
success = FALSE;
reverse = args[1].value.pdb_int ? TRUE : FALSE;
if (success)
{
GimpGradient *gradient;
GimpGradientSegment *seg = NULL;
gdouble pos, delta;
GimpRGB color;
gdouble *pv;
pos = 0.0;
delta = 1.0 / (num_samples - 1);
array_length = num_samples * 4;
pv = color_samples = g_new (gdouble, array_length);
gradient = gimp_context_get_gradient (context);
while (num_samples--)
{
seg = gimp_gradient_get_color_at (gradient, seg, pos, reverse, &color);
*pv++ = color.r;
*pv++ = color.g;
*pv++ = color.b;
*pv++ = color.a;
pos += delta;
}
}
return_vals = procedural_db_return_values (proc_record, success);
if (success)
{
return_vals[1].value.pdb_int = array_length;
return_vals[2].value.pdb_pointer = color_samples;
}
return return_vals;
}
static ProcArg gradients_sample_uniform_inargs[] =
{
{
GIMP_PDB_INT32,
"num-samples",
"The number of samples to take"
},
{
GIMP_PDB_INT32,
"reverse",
"Use the reverse gradient (TRUE or FALSE)"
}
};
static ProcArg gradients_sample_uniform_outargs[] =
{
{
GIMP_PDB_INT32,
"array-length",
"Length of the color_samples array (4 * num_samples)"
},
{
GIMP_PDB_FLOATARRAY,
"color-samples",
"Color samples: { R1, G1, B1, A1, ..., Rn, Gn, Bn, An }"
}
};
static ProcRecord gradients_sample_uniform_proc =
{
"gimp-gradients-sample-uniform",
"gimp-gradients-sample-uniform",
"This procedure is deprecated! Use 'gimp-gradient-get-uniform-samples' instead.",
"This procedure is deprecated! Use 'gimp-gradient-get-uniform-samples' instead.",
"",
"",
"",
"gimp-gradient-get-uniform-samples",
GIMP_INTERNAL,
2,
gradients_sample_uniform_inargs,
2,
gradients_sample_uniform_outargs,
{ { gradients_sample_uniform_invoker } }
};
static Argument *
gradients_sample_custom_invoker (ProcRecord *proc_record,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
Argument *args)
{
gboolean success = TRUE;
Argument *return_vals;
gint32 num_samples;
gdouble *positions;
gboolean reverse;
gint32 array_length = 0;
gdouble *color_samples = NULL;
num_samples = args[0].value.pdb_int;
if (num_samples <= 0)
success = FALSE;
positions = (gdouble *) args[1].value.pdb_pointer;
reverse = args[2].value.pdb_int ? TRUE : FALSE;
if (success)
{
GimpGradient *gradient;
GimpGradientSegment *seg = NULL;
GimpRGB color;
gdouble *pv;
array_length = num_samples * 4;
pv = color_samples = g_new (gdouble, array_length);
gradient = gimp_context_get_gradient (context);
while (num_samples--)
{
seg = gimp_gradient_get_color_at (gradient, seg, *positions,
reverse, &color);
*pv++ = color.r;
*pv++ = color.g;
*pv++ = color.b;
*pv++ = color.a;
positions++;
}
}
return_vals = procedural_db_return_values (proc_record, success);
if (success)
{
return_vals[1].value.pdb_int = array_length;
return_vals[2].value.pdb_pointer = color_samples;
}
return return_vals;
}
static ProcArg gradients_sample_custom_inargs[] =
{
{
GIMP_PDB_INT32,
"num-samples",
"The number of samples to take"
},
{
GIMP_PDB_FLOATARRAY,
"positions",
"The list of positions to sample along the gradient"
},
{
GIMP_PDB_INT32,
"reverse",
"Use the reverse gradient (TRUE or FALSE)"
}
};
static ProcArg gradients_sample_custom_outargs[] =
{
{
GIMP_PDB_INT32,
"array-length",
"Length of the color_samples array (4 * num_samples)"
},
{
GIMP_PDB_FLOATARRAY,
"color-samples",
"Color samples: { R1, G1, B1, A1, ..., Rn, Gn, Bn, An }"
}
};
static ProcRecord gradients_sample_custom_proc =
{
"gimp-gradients-sample-custom",
"gimp-gradients-sample-custom",
"This procedure is deprecated! Use 'gimp-gradient-get-custom-samples' instead.",
"This procedure is deprecated! Use 'gimp-gradient-get-custom-samples' instead.",
"",
"",
"",
"gimp-gradient-get-custom-samples",
GIMP_INTERNAL,
3,
gradients_sample_custom_inargs,
2,
gradients_sample_custom_outargs,
{ { gradients_sample_custom_invoker } }
};
static Argument *
gradients_get_gradient_data_invoker (ProcRecord *proc_record,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
Argument *args)
{
gboolean success = TRUE;
Argument *return_vals;
gchar *name;
gint32 sample_size;
gboolean reverse;
gchar *actual_name = NULL;
gint32 width = 0;
gdouble *grad_data = NULL;
name = (gchar *) args[0].value.pdb_pointer;
if (name && !g_utf8_validate (name, -1, NULL))
success = FALSE;
sample_size = args[1].value.pdb_int;
reverse = args[2].value.pdb_int ? TRUE : FALSE;
if (success)
{
GimpGradient *gradient;
if (sample_size < 1 || sample_size > 10000)
sample_size = GIMP_GRADIENT_DEFAULT_SAMPLE_SIZE;
if (name && strlen (name))
{
gradient = (GimpGradient *)
gimp_container_get_child_by_name (gimp->gradient_factory->container,
name);
}
else
{
gradient = gimp_context_get_gradient (context);
}
if (gradient)
{
GimpGradientSegment *seg = NULL;
gdouble *pv;
gdouble pos, delta;
GimpRGB color;
pos = 0.0;
delta = 1.0 / (sample_size - 1);
actual_name = g_strdup (gimp_object_get_name (GIMP_OBJECT (gradient)));
grad_data = g_new (gdouble, sample_size * 4);
width = sample_size * 4;
pv = grad_data;
while (sample_size)
{
seg = gimp_gradient_get_color_at (gradient, seg, pos, reverse, &color);
*pv++ = color.r;
*pv++ = color.g;
*pv++ = color.b;
*pv++ = color.a;
pos += delta;
}
}
else
success = FALSE;
}
return_vals = procedural_db_return_values (proc_record, success);
if (success)
{
return_vals[1].value.pdb_pointer = actual_name;
return_vals[2].value.pdb_int = width;
return_vals[3].value.pdb_pointer = grad_data;
}
return return_vals;
}
static ProcArg gradients_get_gradient_data_inargs[] =
{
{
GIMP_PDB_STRING,
"name",
"The gradient name (\"\" means current active gradient)"
},
{
GIMP_PDB_INT32,
"sample-size",
"Size of the sample to return when the gradient is changed: (1 <= sample_size <= 10000)"
},
{
GIMP_PDB_INT32,
"reverse",
"Use the reverse gradient (TRUE or FALSE)"
}
};
static ProcArg gradients_get_gradient_data_outargs[] =
{
{
GIMP_PDB_STRING,
"actual-name",
"The gradient name"
},
{
GIMP_PDB_INT32,
"width",
"The gradient sample width (r,g,b,a)"
},
{
GIMP_PDB_FLOATARRAY,
"grad-data",
"The gradient sample data"
}
};
static ProcRecord gradients_get_gradient_data_proc =
{
"gimp-gradients-get-gradient-data",
"gimp-gradients-get-gradient-data",
"This procedure is deprecated! Use 'gimp-gradient-get-uniform-samples' instead.",
"This procedure is deprecated! Use 'gimp-gradient-get-uniform-samples' instead.",
"",
"",
"",
"gimp-gradient-get-uniform-samples",
GIMP_INTERNAL,
3,
gradients_get_gradient_data_inargs,
3,
gradients_get_gradient_data_outargs,
{ { gradients_get_gradient_data_invoker } }
};