2003-12-05 23:55:15 +08:00
|
|
|
/* LIBGIMP - The GIMP Library
|
2000-02-26 11:41:06 +08:00
|
|
|
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
|
1999-09-02 08:01:41 +08:00
|
|
|
*
|
2000-05-27 06:28:40 +08:00
|
|
|
* gimpparasiteio.c
|
1999-09-02 08:01:41 +08:00
|
|
|
* Copyright (C) 1999 Tor Lillqvist <tml@iki.fi>
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* 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
|
1999-09-02 08:01:41 +08:00
|
|
|
* License as published by the Free Software Foundation; either
|
2009-01-18 06:28:01 +08:00
|
|
|
* version 3 of the License, or (at your option) any later version.
|
1999-09-02 08:01:41 +08:00
|
|
|
*
|
|
|
|
* 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
|
2000-05-27 06:28:40 +08:00
|
|
|
* Lesser General Public License for more details.
|
1999-09-02 08:01:41 +08:00
|
|
|
*
|
1999-11-18 05:13:50 +08:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2009-01-18 06:28:01 +08:00
|
|
|
* License along with this library. If not, see
|
2018-07-12 05:27:07 +08:00
|
|
|
* <https://www.gnu.org/licenses/>.
|
1999-09-02 08:01:41 +08:00
|
|
|
*/
|
|
|
|
|
2000-02-26 11:41:06 +08:00
|
|
|
/*
|
2016-06-26 04:54:10 +08:00
|
|
|
* Functions for building and parsing string representations of
|
2000-02-26 11:41:06 +08:00
|
|
|
* various standard parasite types.
|
|
|
|
*/
|
|
|
|
|
1999-09-02 08:01:41 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
1999-09-12 03:33:33 +08:00
|
|
|
#include <stdlib.h>
|
1999-09-02 08:01:41 +08:00
|
|
|
#include <string.h>
|
2000-05-27 06:28:40 +08:00
|
|
|
|
1999-09-02 08:01:41 +08:00
|
|
|
#include <glib.h>
|
|
|
|
|
2000-05-27 09:30:21 +08:00
|
|
|
#include "gimpparasiteio.h"
|
2000-05-27 06:28:40 +08:00
|
|
|
|
1999-09-02 08:01:41 +08:00
|
|
|
|
2010-06-30 01:13:40 +08:00
|
|
|
/**
|
|
|
|
* SECTION: gimpparasiteio
|
|
|
|
* @title: gimpparasiteio
|
|
|
|
* @short_description: Utility functions to (de)serialize certain C
|
|
|
|
* structures to/from #GimpParasite's.
|
|
|
|
* @see_also: #GimpParasite
|
|
|
|
*
|
|
|
|
* Utility functions to (de)serialize certain C structures to/from*
|
|
|
|
* #GimpParasite's.
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
1999-09-02 08:01:41 +08:00
|
|
|
void
|
2000-05-27 06:28:40 +08:00
|
|
|
gimp_pixpipe_params_init (GimpPixPipeParams *params)
|
1999-09-02 08:01:41 +08:00
|
|
|
{
|
2000-05-27 06:28:40 +08:00
|
|
|
gint i;
|
1999-09-02 08:01:41 +08:00
|
|
|
|
2004-11-23 22:28:43 +08:00
|
|
|
g_return_if_fail (params != NULL);
|
|
|
|
|
2000-05-27 06:28:40 +08:00
|
|
|
params->step = 100;
|
|
|
|
params->ncells = 1;
|
|
|
|
params->cellwidth = 1;
|
1999-09-02 08:01:41 +08:00
|
|
|
params->cellheight = 1;
|
2000-05-27 06:28:40 +08:00
|
|
|
params->dim = 1;
|
|
|
|
params->cols = 1;
|
|
|
|
params->rows = 1;
|
2019-07-24 08:09:49 +08:00
|
|
|
params->placement = g_strdup ("constant");
|
|
|
|
|
2000-05-27 06:28:40 +08:00
|
|
|
for (i = 0; i < GIMP_PIXPIPE_MAXDIM; i++)
|
2018-06-28 00:03:37 +08:00
|
|
|
params->selection[i] = g_strdup ("random");
|
2019-07-24 08:09:49 +08:00
|
|
|
|
1999-09-02 08:01:41 +08:00
|
|
|
params->rank[0] = 1;
|
2000-05-27 06:28:40 +08:00
|
|
|
for (i = 1; i < GIMP_PIXPIPE_MAXDIM; i++)
|
1999-09-02 08:01:41 +08:00
|
|
|
params->rank[i] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-11-23 22:28:43 +08:00
|
|
|
gimp_pixpipe_params_parse (const gchar *string,
|
2006-04-12 18:53:28 +08:00
|
|
|
GimpPixPipeParams *params)
|
1999-09-02 08:01:41 +08:00
|
|
|
{
|
2004-11-23 22:28:43 +08:00
|
|
|
gchar *copy;
|
2004-03-22 20:33:52 +08:00
|
|
|
gchar *p, *q, *r;
|
|
|
|
gint i;
|
1999-09-02 08:01:41 +08:00
|
|
|
|
2004-11-23 22:28:43 +08:00
|
|
|
g_return_if_fail (string != NULL);
|
|
|
|
g_return_if_fail (params != NULL);
|
|
|
|
|
|
|
|
copy = g_strdup (string);
|
|
|
|
|
|
|
|
q = copy;
|
1999-09-02 08:01:41 +08:00
|
|
|
while ((p = strtok (q, " \r\n")) != NULL)
|
|
|
|
{
|
|
|
|
q = NULL;
|
|
|
|
r = strchr (p, ':');
|
|
|
|
if (r)
|
2006-04-12 18:53:28 +08:00
|
|
|
*r = 0;
|
1999-09-02 08:01:41 +08:00
|
|
|
|
|
|
|
if (strcmp (p, "ncells") == 0)
|
2006-04-12 18:53:28 +08:00
|
|
|
{
|
|
|
|
if (r)
|
|
|
|
params->ncells = atoi (r + 1);
|
|
|
|
}
|
1999-09-02 08:01:41 +08:00
|
|
|
else if (strcmp (p, "step") == 0)
|
2006-04-12 18:53:28 +08:00
|
|
|
{
|
|
|
|
if (r)
|
|
|
|
params->step = atoi (r + 1);
|
|
|
|
}
|
1999-09-02 08:01:41 +08:00
|
|
|
else if (strcmp (p, "dim") == 0)
|
2006-04-12 18:53:28 +08:00
|
|
|
{
|
|
|
|
if (r)
|
2004-03-22 20:33:52 +08:00
|
|
|
{
|
|
|
|
params->dim = atoi (r + 1);
|
|
|
|
params->dim = CLAMP (params->dim, 1, GIMP_PIXPIPE_MAXDIM);
|
|
|
|
}
|
|
|
|
}
|
1999-09-02 08:01:41 +08:00
|
|
|
else if (strcmp (p, "cols") == 0)
|
2006-04-12 18:53:28 +08:00
|
|
|
{
|
|
|
|
if (r)
|
|
|
|
params->cols = atoi (r + 1);
|
|
|
|
}
|
1999-09-02 08:01:41 +08:00
|
|
|
else if (strcmp (p, "rows") == 0)
|
2006-04-12 18:53:28 +08:00
|
|
|
{
|
|
|
|
if (r)
|
|
|
|
params->rows = atoi (r + 1);
|
|
|
|
}
|
1999-09-02 08:01:41 +08:00
|
|
|
else if (strcmp (p, "cellwidth") == 0)
|
2006-04-12 18:53:28 +08:00
|
|
|
{
|
|
|
|
if (r)
|
|
|
|
params->cellwidth = atoi (r + 1);
|
|
|
|
}
|
1999-09-02 08:01:41 +08:00
|
|
|
else if (strcmp (p, "cellheight") == 0)
|
2006-04-12 18:53:28 +08:00
|
|
|
{
|
|
|
|
if (r)
|
|
|
|
params->cellheight = atoi (r + 1);
|
|
|
|
}
|
1999-09-02 08:01:41 +08:00
|
|
|
else if (strcmp (p, "placement") == 0)
|
2006-04-12 18:53:28 +08:00
|
|
|
{
|
|
|
|
if (r)
|
|
|
|
{
|
2019-07-24 08:09:49 +08:00
|
|
|
g_free (params->placement);
|
2006-04-12 18:53:28 +08:00
|
|
|
params->placement = g_strdup (r + 1);
|
|
|
|
}
|
|
|
|
}
|
1999-09-02 08:01:41 +08:00
|
|
|
else if (strncmp (p, "rank", strlen ("rank")) == 0 && r)
|
2006-04-12 18:53:28 +08:00
|
|
|
{
|
|
|
|
if (r)
|
|
|
|
{
|
|
|
|
i = atoi (p + strlen ("rank"));
|
|
|
|
if (i >= 0 && i < params->dim)
|
|
|
|
params->rank[i] = atoi (r + 1);
|
|
|
|
}
|
|
|
|
}
|
1999-09-02 08:01:41 +08:00
|
|
|
else if (strncmp (p, "sel", strlen ("sel")) == 0 && r)
|
2006-04-12 18:53:28 +08:00
|
|
|
{
|
|
|
|
if (r)
|
|
|
|
{
|
|
|
|
i = atoi (p + strlen ("sel"));
|
|
|
|
if (i >= 0 && i < params->dim)
|
|
|
|
{
|
2018-06-28 00:03:37 +08:00
|
|
|
g_free (params->selection[i]);
|
2006-04-12 18:53:28 +08:00
|
|
|
params->selection[i] = g_strdup (r + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-09-02 08:01:41 +08:00
|
|
|
if (r)
|
2006-04-12 18:53:28 +08:00
|
|
|
*r = ':';
|
1999-09-02 08:01:41 +08:00
|
|
|
}
|
2004-11-23 22:28:43 +08:00
|
|
|
|
|
|
|
g_free (copy);
|
1999-09-02 08:01:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
gchar *
|
2000-05-27 06:28:40 +08:00
|
|
|
gimp_pixpipe_params_build (GimpPixPipeParams *params)
|
1999-09-02 08:01:41 +08:00
|
|
|
{
|
2006-07-05 21:55:11 +08:00
|
|
|
GString *str;
|
2004-11-23 22:28:43 +08:00
|
|
|
gint i;
|
2000-05-27 06:28:40 +08:00
|
|
|
|
2004-11-23 22:28:43 +08:00
|
|
|
g_return_val_if_fail (params != NULL, NULL);
|
|
|
|
|
2006-07-05 21:55:11 +08:00
|
|
|
str = g_string_new (NULL);
|
1999-09-02 08:01:41 +08:00
|
|
|
|
2006-07-05 21:55:11 +08:00
|
|
|
g_string_printf (str, "ncells:%d cellwidth:%d cellheight:%d "
|
2001-08-01 08:35:59 +08:00
|
|
|
"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);
|
1999-09-02 08:01:41 +08:00
|
|
|
|
|
|
|
for (i = 0; i < params->dim; i++)
|
|
|
|
{
|
2006-07-05 21:55:11 +08:00
|
|
|
g_string_append_printf (str, " rank%d:%d", i, params->rank[i]);
|
|
|
|
g_string_append_printf (str, " sel%d:%s", i, params->selection[i]);
|
1999-09-02 08:01:41 +08:00
|
|
|
}
|
|
|
|
|
2006-07-05 21:55:11 +08:00
|
|
|
return g_string_free (str, FALSE);
|
1999-09-02 08:01:41 +08:00
|
|
|
}
|
2018-06-28 00:31:38 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
gimp_pixpipe_params_free (GimpPixPipeParams *params)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
2019-07-24 08:09:49 +08:00
|
|
|
g_free (params->placement);
|
|
|
|
|
2018-06-28 00:31:38 +08:00
|
|
|
for (i = 0; i < GIMP_PIXPIPE_MAXDIM; i++)
|
|
|
|
g_free (params->selection[i]);
|
|
|
|
}
|