gimp/app/pdb/gradients_cmds.c

402 lines
9.8 KiB
C
Raw Normal View History

/* The GIMP -- an image manipulation program
* Copyright (C) 1995-2000 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. */
app/Makefile.am app/channel_pvt.h app/drawable_pvt.h app/gdisplayF.h 2000-12-29 Michael Natterer <mitch@gimp.org> * app/Makefile.am * app/channel_pvt.h * app/drawable_pvt.h * app/gdisplayF.h * app/gimpdrawableP.h * app/gimpimageP.h * app/layer_pvt.h * app/toolsF.h: removed these files. * app/apptypes.h * tools/pdbgen/enums.pl: added tons of opaque typedefs and enums. * tools/pdbgen/pdb/brush_select.pdb * tools/pdbgen/pdb/brushes.pdb * tools/pdbgen/pdb/channel.pdb * tools/pdbgen/pdb/color.pdb * tools/pdbgen/pdb/convert.pdb * tools/pdbgen/pdb/display.pdb * tools/pdbgen/pdb/drawable.pdb * tools/pdbgen/pdb/fileops.pdb * tools/pdbgen/pdb/gradient_select.pdb * tools/pdbgen/pdb/gradients.pdb * tools/pdbgen/pdb/help.pdb * tools/pdbgen/pdb/image.pdb * tools/pdbgen/pdb/layer.pdb * tools/pdbgen/pdb/pattern_select.pdb * tools/pdbgen/pdb/patterns.pdb * tools/pdbgen/pdb/selection.pdb * tools/pdbgen/pdb/tools.pdb * app/*: chainsaw #include cleanup: - Never (never!!) include stuff in header files except where we need access to structures' contents (like derived objects). - Added prototypes and proper formating in many files. - The #include order in *all* *.c files is as follows: #include "config.h" #include <system stuff> #include <gtk/gtk.h> #include "apptypes.h" #include "gimp stuff" #include "libgimp stuff" #include "libgimp/gimpintl.h" By following this scheme we can easily see a file's dependencies from it's #include's and can grep for the inclusion to find out where a file is used. * tools/pdbgen/app.pl: changed to follow the include scheme above. * libgimp/Makefile.am * libgimp/gimpuitypes.h: new file, included from libgimp/gimpui.h and from app/apptypes.h. * libgimp/gimpcolorbutton.[ch] * libgimp/gimpdialog.[ch] * libgimp/gimphelpui.[ch] * libgimp/gimpparasite.[ch] * libgimp/gimppatheditor.[ch] * libgimp/gimpprotocol.c * libgimp/gimpquerybox.[ch] * libgimp/gimpsizeentry.[ch] * libgimp/gimptypes.h * libgimp/gimpui.h * libgimp/gimpunit.h * libgimp/gimpunitmenu.[ch] * libgimp/gimpwidgets.[ch]: changed accordingly. * plug-ins/FractalExplorer/Dialogs.c * plug-ins/gdyntext/message_window.c * plug-ins/imagemap/imap_default_dialog.c * plug-ins/imagemap/imap_file.c: these files used to include "libgimp/gimpui.h" without including "libgimp/gimp.h". This is no longer possible because the libgimpui headers don't inlcude "libgimp/gimpunit.h" any more.
2000-12-29 23:22:01 +08:00
#include "config.h"
#include <gtk/gtk.h>
#include "core/core-types.h"
#include "procedural_db.h"
took gimpcontextpreview.[ch] out of the build but still left the sources 2001-02-12 Michael Natterer <mitch@gimp.org> * app/Makefile.am: took gimpcontextpreview.[ch] out of the build but still left the sources there as reference. * app/app_procs.c: initialize the render stuff before creating the toolbox (needed for the previews). * app/devices.c * app/indicator_area.c: use GimpPreviews instead of GimpContextPreviews. * app/context_manager.[ch]: create the global data lists here because they now must exist before any context is created. * app/brushes.[ch] * app/gradients.[ch] * app/palettes.[ch] * app/patterns.[ch]: removed them here. * app/gimpcontainer.[ch]: added a "freeze_count" and emit the "freeze" and "thaw" signals accordingly. * app/gimpcontext.[ch]: greatly simplified the way how the contexts connect to the data lists (simply keep them connected all the time). Also removed all those ugly explicit update functions because "thaw" callbacks do this job now. * app/gimpdata.c: a GimpData object now becomes dirty on "name_changed"; "dirty" now triggers "invalidate_preview" because the context does not dispatch these signals any more soon. * app/brush_select.c * app/convert.c * app/gimpdnd.c * app/gradient_editor.c * app/gradient_select.c * app/pattern_select.c * app/gradient_editor.c * app/gradient_select.c * app/gradients.[ch] * app/pdb/brush_select_cmds.c * app/pdb/brushes_cmds.c * app/pdb/convert_cmds.c * app/pdb/gradient_select_cmds.c * app/pdb/gradients_cmds.c * app/pdb/pattern_select_cmds.c * app/pdb/patterns_cmds.c * tools/pdbgen/pdb/brush_select.pdb * tools/pdbgen/pdb/brushes.pdb * tools/pdbgen/pdb/convert.pdb * tools/pdbgen/pdb/gradient_select.pdb * tools/pdbgen/pdb/gradients.pdb * tools/pdbgen/pdb/pattern_select.pdb * tools/pdbgen/pdb/patterns.pdb: changed accordingly.
2001-02-12 11:27:28 +08:00
#include "context_manager.h"
#include "core/gimpcontainer.h"
#include "core/gimpcontext.h"
#include "core/gimpdatafactory.h"
#include "core/gimpgradient.h"
#include "core/gimplist.h"
static ProcRecord gradients_get_list_proc;
static ProcRecord gradients_get_active_proc;
static ProcRecord gradients_set_active_proc;
static ProcRecord gradients_sample_uniform_proc;
static ProcRecord gradients_sample_custom_proc;
void
register_gradients_procs (void)
{
procedural_db_register (&gradients_get_list_proc);
procedural_db_register (&gradients_get_active_proc);
procedural_db_register (&gradients_set_active_proc);
procedural_db_register (&gradients_sample_uniform_proc);
procedural_db_register (&gradients_sample_custom_proc);
}
static Argument *
gradients_get_list_invoker (Argument *args)
{
gboolean success;
Argument *return_args;
gint32 num_gradients;
gchar **gradients;
GimpGradient *grad;
GList *list = NULL;
int i = 0;
gimprc.in user_install user_install.bat app/gimprc.[ch] removed the 2001-02-13 Michael Natterer <mitch@gimp.org> * gimprc.in * user_install * user_install.bat * app/gimprc.[ch] * app/preferences_dialog.c: removed the "brush_vbr_path" variable, because all data types will be editable and saveable soon. * app/Makefile.am * app/apptypes.h * app/gimpdatafactory.[ch]: new object which holds a data list and knows how to create, edit, duplicate etc. the items in it. Will completely replace the brushes.[ch], patterns.[ch], ... files soon. * po/POTFILES.in * app/gimpdatacontainerview.[ch]: removed. * app/gimpdatafactoryview.[ch]: added. A view on the GimpDataFactory with a GUI for creating, editing, deleting etc. items (mostly unimplemented). * app/context_manager.[ch]: replaced the global data lists by global data factories. * app/brush_select.c * app/brushes.[ch] * app/commands.c * app/convert.c * app/devices.c * app/gimpbrush.[ch] * app/gimpbrushgenerated.c * app/gimpcontext.c * app/gimpdata.[ch] * app/gimpdatalist.[ch] * app/gimpdnd.c * app/gimpgradient.[ch] * app/gimppalette.[ch] * app/gimppattern.[ch] * app/gradient_editor.c * app/gradient_select.c * app/gradients.[ch] * app/indicator_area.c * app/palette.c * app/palette_import.c * app/palette_select.c * app/palettes.[ch] * app/pattern_select.c * app/patterns.[ch] * app/pdb/brush_select_cmds.c * app/pdb/brushes_cmds.c * app/pdb/convert_cmds.c * app/pdb/gradient_select_cmds.c * app/pdb/gradients_cmds.c * app/pdb/pattern_select_cmds.c * app/pdb/patterns_cmds.c * tools/pdbgen/pdb/brush_select.pdb * tools/pdbgen/pdb/brushes.pdb * tools/pdbgen/pdb/convert.pdb * tools/pdbgen/pdb/gradient_select.pdb * tools/pdbgen/pdb/gradients.pdb * tools/pdbgen/pdb/pattern_select.pdb * tools/pdbgen/pdb/patterns.pdb: changed accordingly.
2001-02-14 03:53:07 +08:00
num_gradients =
gimp_container_num_children (global_gradient_factory->container);
gradients = g_new (gchar *, num_gradients);
if (num_gradients)
{
gimprc.in user_install user_install.bat app/gimprc.[ch] removed the 2001-02-13 Michael Natterer <mitch@gimp.org> * gimprc.in * user_install * user_install.bat * app/gimprc.[ch] * app/preferences_dialog.c: removed the "brush_vbr_path" variable, because all data types will be editable and saveable soon. * app/Makefile.am * app/apptypes.h * app/gimpdatafactory.[ch]: new object which holds a data list and knows how to create, edit, duplicate etc. the items in it. Will completely replace the brushes.[ch], patterns.[ch], ... files soon. * po/POTFILES.in * app/gimpdatacontainerview.[ch]: removed. * app/gimpdatafactoryview.[ch]: added. A view on the GimpDataFactory with a GUI for creating, editing, deleting etc. items (mostly unimplemented). * app/context_manager.[ch]: replaced the global data lists by global data factories. * app/brush_select.c * app/brushes.[ch] * app/commands.c * app/convert.c * app/devices.c * app/gimpbrush.[ch] * app/gimpbrushgenerated.c * app/gimpcontext.c * app/gimpdata.[ch] * app/gimpdatalist.[ch] * app/gimpdnd.c * app/gimpgradient.[ch] * app/gimppalette.[ch] * app/gimppattern.[ch] * app/gradient_editor.c * app/gradient_select.c * app/gradients.[ch] * app/indicator_area.c * app/palette.c * app/palette_import.c * app/palette_select.c * app/palettes.[ch] * app/pattern_select.c * app/patterns.[ch] * app/pdb/brush_select_cmds.c * app/pdb/brushes_cmds.c * app/pdb/convert_cmds.c * app/pdb/gradient_select_cmds.c * app/pdb/gradients_cmds.c * app/pdb/pattern_select_cmds.c * app/pdb/patterns_cmds.c * tools/pdbgen/pdb/brush_select.pdb * tools/pdbgen/pdb/brushes.pdb * tools/pdbgen/pdb/convert.pdb * tools/pdbgen/pdb/gradient_select.pdb * tools/pdbgen/pdb/gradients.pdb * tools/pdbgen/pdb/pattern_select.pdb * tools/pdbgen/pdb/patterns.pdb: changed accordingly.
2001-02-14 03:53:07 +08:00
list = GIMP_LIST (global_gradient_factory->container)->list;
}
success = (list != NULL);
while (list)
{
grad = list->data;
gradients[i++] = g_strdup (GIMP_OBJECT (grad)->name);
list = list->next;
}
return_args = procedural_db_return_args (&gradients_get_list_proc, success);
if (success)
{
return_args[1].value.pdb_int = num_gradients;
return_args[2].value.pdb_pointer = gradients;
}
return return_args;
}
static ProcArg gradients_get_list_outargs[] =
{
{
PDB_INT32,
"num_gradients",
"The number of loaded gradients"
},
{
PDB_STRINGARRAY,
"gradient_names",
"The list of gradient names"
}
};
static ProcRecord gradients_get_list_proc =
{
"gimp_gradients_get_list",
"Retrieve the list of loaded gradients.",
"This procedure returns a list of the gradients that are currently loaded in the gradient editor. You can later use the gimp_gradients_set_active function to set the active gradient.",
"Federico Mena Quintero",
"Federico Mena Quintero",
"1997",
PDB_INTERNAL,
0,
NULL,
2,
gradients_get_list_outargs,
{ { gradients_get_list_invoker } }
};
static Argument *
gradients_get_active_invoker (Argument *args)
{
gboolean success = TRUE;
Argument *return_args;
success = gimp_context_get_gradient (NULL) != NULL;
return_args = procedural_db_return_args (&gradients_get_active_proc, success);
if (success)
return_args[1].value.pdb_pointer = g_strdup (GIMP_OBJECT (gimp_context_get_gradient (NULL))->name);
return return_args;
}
static ProcArg gradients_get_active_outargs[] =
{
{
PDB_STRING,
"name",
"The name of the active gradient"
}
};
static ProcRecord gradients_get_active_proc =
{
"gimp_gradients_get_active",
"Retrieve the name of the active gradient.",
"This procedure returns the name of the active gradient in the gradient editor.",
"Federico Mena Quintero",
"Federico Mena Quintero",
"1997",
PDB_INTERNAL,
0,
NULL,
1,
gradients_get_active_outargs,
{ { gradients_get_active_invoker } }
};
static Argument *
gradients_set_active_invoker (Argument *args)
{
gboolean success = TRUE;
gchar *name;
GimpGradient *gradient;
name = (gchar *) args[0].value.pdb_pointer;
if (name == NULL)
success = FALSE;
if (success)
{
gradient = (GimpGradient *)
gimprc.in user_install user_install.bat app/gimprc.[ch] removed the 2001-02-13 Michael Natterer <mitch@gimp.org> * gimprc.in * user_install * user_install.bat * app/gimprc.[ch] * app/preferences_dialog.c: removed the "brush_vbr_path" variable, because all data types will be editable and saveable soon. * app/Makefile.am * app/apptypes.h * app/gimpdatafactory.[ch]: new object which holds a data list and knows how to create, edit, duplicate etc. the items in it. Will completely replace the brushes.[ch], patterns.[ch], ... files soon. * po/POTFILES.in * app/gimpdatacontainerview.[ch]: removed. * app/gimpdatafactoryview.[ch]: added. A view on the GimpDataFactory with a GUI for creating, editing, deleting etc. items (mostly unimplemented). * app/context_manager.[ch]: replaced the global data lists by global data factories. * app/brush_select.c * app/brushes.[ch] * app/commands.c * app/convert.c * app/devices.c * app/gimpbrush.[ch] * app/gimpbrushgenerated.c * app/gimpcontext.c * app/gimpdata.[ch] * app/gimpdatalist.[ch] * app/gimpdnd.c * app/gimpgradient.[ch] * app/gimppalette.[ch] * app/gimppattern.[ch] * app/gradient_editor.c * app/gradient_select.c * app/gradients.[ch] * app/indicator_area.c * app/palette.c * app/palette_import.c * app/palette_select.c * app/palettes.[ch] * app/pattern_select.c * app/patterns.[ch] * app/pdb/brush_select_cmds.c * app/pdb/brushes_cmds.c * app/pdb/convert_cmds.c * app/pdb/gradient_select_cmds.c * app/pdb/gradients_cmds.c * app/pdb/pattern_select_cmds.c * app/pdb/patterns_cmds.c * tools/pdbgen/pdb/brush_select.pdb * tools/pdbgen/pdb/brushes.pdb * tools/pdbgen/pdb/convert.pdb * tools/pdbgen/pdb/gradient_select.pdb * tools/pdbgen/pdb/gradients.pdb * tools/pdbgen/pdb/pattern_select.pdb * tools/pdbgen/pdb/patterns.pdb: changed accordingly.
2001-02-14 03:53:07 +08:00
gimp_container_get_child_by_name (global_gradient_factory->container, name);
success = FALSE;
if (gradient)
{
gimp_context_set_gradient (NULL, gradient);
success = TRUE;
}
}
return procedural_db_return_args (&gradients_set_active_proc, success);
}
static ProcArg gradients_set_active_inargs[] =
{
{
PDB_STRING,
"name",
"The name of the gradient to set"
}
};
static ProcRecord gradients_set_active_proc =
{
"gimp_gradients_set_active",
"Sets the specified gradient as the active gradient.",
"This procedure lets you set the specified gradient as the active or \"current\" one. The name is simply a string which corresponds to one of the loaded gradients in the gradient editor. If no matching gradient is found, this procedure will return an error. Otherwise, the specified gradient will become active and will be used for subsequent custom gradient operations.",
"Federico Mena Quintero",
"Federico Mena Quintero",
"1997",
PDB_INTERNAL,
1,
gradients_set_active_inargs,
0,
NULL,
{ { gradients_set_active_invoker } }
};
static Argument *
gradients_sample_uniform_invoker (Argument *args)
{
gboolean success = TRUE;
Argument *return_args;
gint32 i;
gint32 array_length = 0;
gdouble *color_samples = NULL;
GimpGradient *gradient;
gdouble pos, delta;
GimpRGB color;
gdouble *pv;
i = args[0].value.pdb_int;
if (i < 2)
success = FALSE;
if (success)
{
pos = 0.0;
delta = 1.0 / (i - 1);
array_length = i * 4;
pv = color_samples = g_new (gdouble, array_length);
gradient = gimp_context_get_gradient (NULL);
while (i--)
{
gimp_gradient_get_color_at (gradient, pos, &color);
*pv++ = color.r;
*pv++ = color.g;
*pv++ = color.b;
*pv++ = color.a;
pos += delta;
}
}
return_args = procedural_db_return_args (&gradients_sample_uniform_proc, success);
if (success)
{
return_args[1].value.pdb_int = array_length;
return_args[2].value.pdb_pointer = color_samples;
}
return return_args;
}
static ProcArg gradients_sample_uniform_inargs[] =
{
{
PDB_INT32,
"num_samples",
"The number of samples to take"
}
};
static ProcArg gradients_sample_uniform_outargs[] =
{
{
PDB_INT32,
"array_length",
"Length of the color_samples array (4 * num_samples)"
},
{
PDB_FLOATARRAY,
"color_samples",
"Color samples: { R1, G1, B1, A1, ..., Rn, Gn, Bn, An }"
}
};
static ProcRecord gradients_sample_uniform_proc =
{
"gimp_gradients_sample_uniform",
"Sample the active gradient in uniform parts.",
"This procedure samples the active gradient from the gradient editor in the specified number of uniform parts. It returns a list of floating-point values which correspond to the RGBA values for each sample. The minimum number of samples to take is 2, in which case the returned colors will correspond to the { 0.0, 1.0 } positions in the gradient. For example, if the number of samples is 3, the procedure will return the colors at positions { 0.0, 0.5, 1.0 }.",
"Federico Mena Quintero",
"Federico Mena Quintero",
"1997",
PDB_INTERNAL,
1,
gradients_sample_uniform_inargs,
2,
gradients_sample_uniform_outargs,
{ { gradients_sample_uniform_invoker } }
};
static Argument *
gradients_sample_custom_invoker (Argument *args)
{
gboolean success = TRUE;
Argument *return_args;
gint32 i;
gdouble *pos;
gint32 array_length = 0;
gdouble *color_samples = NULL;
GimpGradient *gradient;
GimpRGB color;
gdouble *pv;
i = args[0].value.pdb_int;
if (i <= 0)
success = FALSE;
pos = (gdouble *) args[1].value.pdb_pointer;
if (success)
{
array_length = i * 4;
pv = color_samples = g_new (gdouble, array_length);
gradient = gimp_context_get_gradient (NULL);
while (i--)
{
gimp_gradient_get_color_at (gradient, *pos, &color);
*pv++ = color.r;
*pv++ = color.g;
*pv++ = color.b;
*pv++ = color.a;
pos++;
}
}
return_args = procedural_db_return_args (&gradients_sample_custom_proc, success);
if (success)
{
return_args[1].value.pdb_int = array_length;
return_args[2].value.pdb_pointer = color_samples;
}
return return_args;
}
static ProcArg gradients_sample_custom_inargs[] =
{
{
PDB_INT32,
"num_samples",
"The number of samples to take"
},
{
PDB_FLOATARRAY,
"positions",
"The list of positions to sample along the gradient"
}
};
static ProcArg gradients_sample_custom_outargs[] =
{
{
PDB_INT32,
"array_length",
"Length of the color_samples array (4 * num_samples)"
},
{
PDB_FLOATARRAY,
"color_samples",
"Color samples: { R1, G1, B1, A1, ..., Rn, Gn, Bn, An }"
}
};
static ProcRecord gradients_sample_custom_proc =
{
"gimp_gradients_sample_custom",
"Sample the active gradient in custom positions.",
"This procedure samples the active gradient from the gradient editor in the specified number of points. The procedure will sample the gradient in the specified positions from the list. The left endpoint of the gradient corresponds to position 0.0, and the right endpoint corresponds to 1.0. The procedure returns a list of floating-point values which correspond to the RGBA values for each sample.",
"Federico Mena Quintero",
"Federico Mena Quintero",
"1997",
PDB_INTERNAL,
2,
gradients_sample_custom_inargs,
2,
gradients_sample_custom_outargs,
{ { gradients_sample_custom_invoker } }
};