gimp/libgimpbase/gimpparasiteio.c

173 lines
4.0 KiB
C
Raw Normal View History

/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpparasiteio.c
* Copyright (C) 1999 Tor Lillqvist <tml@iki.fi>
*
* This library is free software; you can redistribute it and/or
1999-11-18 05:13:50 +08:00
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
1999-11-18 05:13:50 +08:00
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/*
* Functions for bulding and parsing string representations of
* various standard parasite types.
*/
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
Libgimp cleanup part II (with a little help from Yosh who moved the CVS 2000-05-27 Michael Natterer <mitch@gimp.org> Libgimp cleanup part II (with a little help from Yosh who moved the CVS files). * libgimp/Makefile.am * libgimp/gimpchannel_pdb.c * libgimp/gimpdisplay_pdb.c * libgimp/gimpdrawable_pdb.c * libgimp/gimpgradient_pdb.c * libgimp/gimphelp_pdb.c * libgimp/gimpimage_pdb.c * libgimp/gimplayer_pdb.c * libgimp/gimppalette_pdb.c * libgimp/gimpparasite_pdb.c * libgimp/gimpselection_pdb.c * libgimp/gimpunit_pdb.c: new names of all files which contain PDB wrappers. * modules/Makefile.am * libgimp/gimpcolordisplay.h * libgimp/gimpcolorselector.h * modules/gimpmodregister.[ch]: renamed. * libgimp/gimpparasiteF.h * libgimp/gimpparasiteP.h: removed because gimp.h had to include the private header anyway. * app/color_notebook.c * app/color_select.c * app/gdisplay_color.[ch] * app/gdisplay_color_ui.c * app/gimpbrushpipe.c * app/gimpdrawable.[ch] * app/gimpimage.c * app/gimpimage.h * app/gimpparasite.[ch] * app/gimprc.c * app/image_new.c * app/layer.c * app/parasite_cmds.c * app/parasitelist.[ch] * app/plug_in.c * app/procedural_db.c * app/undo.c * app/xcf.c * libgimp/gimp.[ch] * libgimp/gimpcolordisplay.h * libgimp/gimpparasite.[ch] * modules/cdisplay_gamma.c * modules/cdisplay_highcontrast.c * modules/colorsel_gtk.c * modules/colorsel_triangle.c * modules/colorsel_water.c * plug-ins/FractalExplorer/Dialogs.c * plug-ins/FractalExplorer/Events.c * plug-ins/Lighting/lighting_apply.c * plug-ins/Lighting/lighting_shade.c * plug-ins/MapObject/mapobject_image.c * plug-ins/common/gpb.c * plug-ins/common/psp.c * plug-ins/sel2path/sel2path.c * po-libgimp/POTFILES.in * tools/pdbgen/pdb.pl * tools/pdbgen/pdb/parasite.pdb: changed includes accordingly.
2000-05-27 09:30:21 +08:00
#include "gimpparasiteio.h"
void
gimp_pixpipe_params_init (GimpPixPipeParams *params)
{
gint i;
params->step = 100;
params->ncells = 1;
params->cellwidth = 1;
params->cellheight = 1;
params->dim = 1;
params->cols = 1;
params->rows = 1;
params->placement = "constant";
params->free_placement_string = FALSE;
for (i = 0; i < GIMP_PIXPIPE_MAXDIM; i++)
{
params->selection[i] = "random";
params->free_selection_string = FALSE;
}
params->rank[0] = 1;
for (i = 1; i < GIMP_PIXPIPE_MAXDIM; i++)
params->rank[i] = 0;
}
void
gimp_pixpipe_params_parse (gchar *string,
GimpPixPipeParams *params)
{
1999-12-07 06:44:40 +08:00
gchar *p, *q, *r; /* Don't you love single-char identifiers? */
gint i; /* No, we don't!! <Sven> */
q = string;
while ((p = strtok (q, " \r\n")) != NULL)
{
q = NULL;
r = strchr (p, ':');
if (r)
*r = 0;
if (strcmp (p, "ncells") == 0)
{
if (r)
params->ncells = atoi (r + 1);
}
else if (strcmp (p, "step") == 0)
{
if (r)
params->step = atoi (r + 1);
}
else if (strcmp (p, "dim") == 0)
{
if (r)
params->dim = atoi (r + 1);
}
else if (strcmp (p, "cols") == 0)
{
if (r)
params->cols = atoi (r + 1);
}
else if (strcmp (p, "rows") == 0)
{
if (r)
params->rows = atoi (r + 1);
}
else if (strcmp (p, "cellwidth") == 0)
{
if (r)
params->cellwidth = atoi (r + 1);
}
else if (strcmp (p, "cellheight") == 0)
{
if (r)
params->cellheight = atoi (r + 1);
}
else if (strcmp (p, "placement") == 0)
{
if (r)
{
params->placement = g_strdup (r + 1);
params->free_placement_string = TRUE;
}
}
else if (strncmp (p, "rank", strlen ("rank")) == 0 && r)
{
if (r)
{
i = atoi (p + strlen ("rank"));
if (i >= 0 && i < params->dim)
params->rank[i] = atoi (r + 1);
}
}
else if (strncmp (p, "sel", strlen ("sel")) == 0 && r)
{
if (r)
{
i = atoi (p + strlen ("sel"));
if (i >= 0 && i < params->dim)
{
params->selection[i] = g_strdup (r + 1);
params->free_selection_string = TRUE;
}
}
}
if (r)
*r = ':';
}
}
gchar *
gimp_pixpipe_params_build (GimpPixPipeParams *params)
{
GString *s = g_string_new (NULL);
gchar *str;
gint i;
g_string_printf (s, "ncells:%d cellwidth:%d cellheight:%d "
"step:%d dim:%d cols:%d rows:%d placement:%s",
params->ncells, params->cellwidth, params->cellheight,
params->step, params->dim,
params->cols, params->rows,
params->placement);
for (i = 0; i < params->dim; i++)
{
g_string_append_printf (s, " rank%d:%d", i, params->rank[i]);
g_string_append_printf (s, " sel%d:%s", i, params->selection[i]);
}
str = s->str;
g_string_free (s, FALSE);
return str;
}