diff --git a/ChangeLog b/ChangeLog index c8b51b48ab..745e98dacd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,28 @@ +1999-09-02 Tor Lillqvist + + * libgimp/parasiteio.[ch]: New files. Types and functions related + to "standard" parasite types. Used for the + gimp-brush-pipe-parameters parasite that the gpb and psp plug-ins + handle, and the value of which is stored in gih files, from + which gimpbrushpipe.c parses it. + + * libgimp/{Makefile.am,makefile.{cygwin,msc}}: Add new files. + + * libgimp/gimp.def: Add its entry points. + + * libgimp/gimp.h: Fix cosmetic argument name error. + + * app/gimpbrushpipe.c: Remove code that previously was copied + here, use functions from parasiteio.c. + + * plug-ins/common/gpb.c: Ditto. Add brush cell width and height + fields to the gih save dialog. Add cleverness to update rows and + columns as cell size is changes. (Still too easy for the user to + get confused, though.) Display corresponding guide grid on the + image. Unfortunately updating the guidelines doesn't seem to work. + + * plug-ins/common/psp.c: Use functions from parasiteio.c. + Wed Sep 1 23:18:21 BST 1999 Andy Thomas * app/gdisplay.c diff --git a/app/core/gimpbrushpipe-load.c b/app/core/gimpbrushpipe-load.c index ccda27459c..cc9f79621a 100644 --- a/app/core/gimpbrushpipe-load.c +++ b/app/core/gimpbrushpipe-load.c @@ -37,26 +37,7 @@ #include "libgimp/gimpintl.h" #include "libgimp/gimpmath.h" - -/* Code duplicated from plug-ins/common/gpb.c... - * The struct, and code to parse/build it probably should be in libgimp. - */ - -/* Parameters related to one single gih file, collected in a struct - * just for clarity. - */ -#define MAXDIM 4 -static struct { - gint step; - gint ncells; - gint dim; - gint cols; - gint rows; - gchar *placement; - gint rank[MAXDIM]; - gchar *selection[MAXDIM]; -} gihparms; - +#include "libgimp/parasiteio.h" static GimpBrushClass* gimp_brush_class; static GtkObjectClass* gimp_object_class; @@ -279,103 +260,19 @@ gimp_brush_pipe_get_type (void) return type; } -static void -init_pipe_parameters () -{ - int i; - - gihparms.step = 100; - gihparms.ncells = 1; - gihparms.dim = 1; - gihparms.cols = 1; - gihparms.rows = 1; - gihparms.placement = "constant"; - for (i = 0; i < MAXDIM; i++) - gihparms.selection[i] = "random"; - gihparms.rank[0] = 1; - for (i = 1; i < MAXDIM; i++) - gihparms.rank[i] = 0; -} - -static void -parse_brush_pipe_parameters (gchar *parameters) -{ - guchar *p, *q, *r, *s; /* Don't you love single-char identifiers? */ - gint i; - - q = parameters; - while ((p = strtok (q, " \r\n")) != NULL) - { - q = NULL; - r = strchr (p, ':'); - if (r) - *r = 0; - - if (strcmp (p, "ncells") == 0) - { - if (r) - gihparms.ncells = atoi (r + 1); - } - else if (strcmp (p, "step") == 0) - { - if (r) - gihparms.step = atoi (r + 1); - } - else if (strcmp (p, "dim") == 0) - { - if (r) - gihparms.dim = atoi (r + 1); - } - else if (strcmp (p, "cols") == 0) - { - if (r) - gihparms.cols = atoi (r + 1); - } - else if (strcmp (p, "rows") == 0) - { - if (r) - gihparms.rows = atoi (r + 1); - } - else if (strcmp (p, "placement") == 0) - { - if (r) - gihparms.placement = g_strdup (r + 1); - } - else if (strncmp (p, "rank", strlen ("rank")) == 0) - { - if (r) - { - i = atoi (p + strlen ("rank")); - if (i >= 0 && i < gihparms.dim) - gihparms.rank[i] = atoi (r + 1); - } - } - else if (strncmp (p, "sel", strlen ("sel")) == 0) - { - if (r) - { - i = atoi (p + strlen ("sel")); - if (i >= 0 && i < gihparms.dim) - gihparms.selection[i] = g_strdup (r + 1); - } - } - if (r) - *r = ':'; - } -} - GimpBrushPipe * gimp_brush_pipe_load (char *filename) { GimpBrushPipe *pipe; GPatternP pattern; + PixPipeParams params; FILE *fp; guchar buf[1024]; guchar *name; int i; int num_of_brushes; int totalcells; - gchar *params; + gchar *paramstring; if ((fp = fopen (filename, "rb")) == NULL) return NULL; @@ -400,7 +297,7 @@ gimp_brush_pipe_load (char *filename) gimp_object_destroy (pipe); return NULL; } - num_of_brushes = strtol(buf, ¶ms, 10); + num_of_brushes = strtol(buf, ¶mstring, 10); if (num_of_brushes < 1) { g_message (_("pixmap brush pipe should have at least one brush")); @@ -409,33 +306,33 @@ gimp_brush_pipe_load (char *filename) return NULL; } - while (*params && isspace(*params)) - params++; + while (*paramstring && isspace(*paramstring)) + paramstring++; - if (*params) + if (*paramstring) { - init_pipe_parameters (); - parse_brush_pipe_parameters (params); - pipe->dimension = gihparms.dim; + pixpipeparams_init (¶ms); + pixpipeparams_parse (paramstring, ¶ms); + pipe->dimension = params.dim; pipe->rank = g_new (int, pipe->dimension); pipe->select = g_new (PipeSelectModes, pipe->dimension); pipe->index = g_new (int, pipe->dimension); for (i = 0; i < pipe->dimension; i++) { - pipe->rank[i] = gihparms.rank[i]; - if (strcmp (gihparms.selection[i], "incremental") == 0) + pipe->rank[i] = params.rank[i]; + if (strcmp (params.selection[i], "incremental") == 0) pipe->select[i] = PIPE_SELECT_INCREMENTAL; - else if (strcmp (gihparms.selection[i], "angular") == 0) + else if (strcmp (params.selection[i], "angular") == 0) pipe->select[i] = PIPE_SELECT_ANGULAR; - else if (strcmp (gihparms.selection[i], "velocity") == 0) + else if (strcmp (params.selection[i], "velocity") == 0) pipe->select[i] = PIPE_SELECT_VELOCITY; - else if (strcmp (gihparms.selection[i], "random") == 0) + else if (strcmp (params.selection[i], "random") == 0) pipe->select[i] = PIPE_SELECT_RANDOM; - else if (strcmp (gihparms.selection[i], "pressure") == 0) + else if (strcmp (params.selection[i], "pressure") == 0) pipe->select[i] = PIPE_SELECT_PRESSURE; - else if (strcmp (gihparms.selection[i], "xtilt") == 0) + else if (strcmp (params.selection[i], "xtilt") == 0) pipe->select[i] = PIPE_SELECT_TILT_X; - else if (strcmp (gihparms.selection[i], "ytilt") == 0) + else if (strcmp (params.selection[i], "ytilt") == 0) pipe->select[i] = PIPE_SELECT_TILT_Y; else pipe->select[i] = PIPE_SELECT_CONSTANT; diff --git a/app/core/gimpbrushpipe.c b/app/core/gimpbrushpipe.c index ccda27459c..cc9f79621a 100644 --- a/app/core/gimpbrushpipe.c +++ b/app/core/gimpbrushpipe.c @@ -37,26 +37,7 @@ #include "libgimp/gimpintl.h" #include "libgimp/gimpmath.h" - -/* Code duplicated from plug-ins/common/gpb.c... - * The struct, and code to parse/build it probably should be in libgimp. - */ - -/* Parameters related to one single gih file, collected in a struct - * just for clarity. - */ -#define MAXDIM 4 -static struct { - gint step; - gint ncells; - gint dim; - gint cols; - gint rows; - gchar *placement; - gint rank[MAXDIM]; - gchar *selection[MAXDIM]; -} gihparms; - +#include "libgimp/parasiteio.h" static GimpBrushClass* gimp_brush_class; static GtkObjectClass* gimp_object_class; @@ -279,103 +260,19 @@ gimp_brush_pipe_get_type (void) return type; } -static void -init_pipe_parameters () -{ - int i; - - gihparms.step = 100; - gihparms.ncells = 1; - gihparms.dim = 1; - gihparms.cols = 1; - gihparms.rows = 1; - gihparms.placement = "constant"; - for (i = 0; i < MAXDIM; i++) - gihparms.selection[i] = "random"; - gihparms.rank[0] = 1; - for (i = 1; i < MAXDIM; i++) - gihparms.rank[i] = 0; -} - -static void -parse_brush_pipe_parameters (gchar *parameters) -{ - guchar *p, *q, *r, *s; /* Don't you love single-char identifiers? */ - gint i; - - q = parameters; - while ((p = strtok (q, " \r\n")) != NULL) - { - q = NULL; - r = strchr (p, ':'); - if (r) - *r = 0; - - if (strcmp (p, "ncells") == 0) - { - if (r) - gihparms.ncells = atoi (r + 1); - } - else if (strcmp (p, "step") == 0) - { - if (r) - gihparms.step = atoi (r + 1); - } - else if (strcmp (p, "dim") == 0) - { - if (r) - gihparms.dim = atoi (r + 1); - } - else if (strcmp (p, "cols") == 0) - { - if (r) - gihparms.cols = atoi (r + 1); - } - else if (strcmp (p, "rows") == 0) - { - if (r) - gihparms.rows = atoi (r + 1); - } - else if (strcmp (p, "placement") == 0) - { - if (r) - gihparms.placement = g_strdup (r + 1); - } - else if (strncmp (p, "rank", strlen ("rank")) == 0) - { - if (r) - { - i = atoi (p + strlen ("rank")); - if (i >= 0 && i < gihparms.dim) - gihparms.rank[i] = atoi (r + 1); - } - } - else if (strncmp (p, "sel", strlen ("sel")) == 0) - { - if (r) - { - i = atoi (p + strlen ("sel")); - if (i >= 0 && i < gihparms.dim) - gihparms.selection[i] = g_strdup (r + 1); - } - } - if (r) - *r = ':'; - } -} - GimpBrushPipe * gimp_brush_pipe_load (char *filename) { GimpBrushPipe *pipe; GPatternP pattern; + PixPipeParams params; FILE *fp; guchar buf[1024]; guchar *name; int i; int num_of_brushes; int totalcells; - gchar *params; + gchar *paramstring; if ((fp = fopen (filename, "rb")) == NULL) return NULL; @@ -400,7 +297,7 @@ gimp_brush_pipe_load (char *filename) gimp_object_destroy (pipe); return NULL; } - num_of_brushes = strtol(buf, ¶ms, 10); + num_of_brushes = strtol(buf, ¶mstring, 10); if (num_of_brushes < 1) { g_message (_("pixmap brush pipe should have at least one brush")); @@ -409,33 +306,33 @@ gimp_brush_pipe_load (char *filename) return NULL; } - while (*params && isspace(*params)) - params++; + while (*paramstring && isspace(*paramstring)) + paramstring++; - if (*params) + if (*paramstring) { - init_pipe_parameters (); - parse_brush_pipe_parameters (params); - pipe->dimension = gihparms.dim; + pixpipeparams_init (¶ms); + pixpipeparams_parse (paramstring, ¶ms); + pipe->dimension = params.dim; pipe->rank = g_new (int, pipe->dimension); pipe->select = g_new (PipeSelectModes, pipe->dimension); pipe->index = g_new (int, pipe->dimension); for (i = 0; i < pipe->dimension; i++) { - pipe->rank[i] = gihparms.rank[i]; - if (strcmp (gihparms.selection[i], "incremental") == 0) + pipe->rank[i] = params.rank[i]; + if (strcmp (params.selection[i], "incremental") == 0) pipe->select[i] = PIPE_SELECT_INCREMENTAL; - else if (strcmp (gihparms.selection[i], "angular") == 0) + else if (strcmp (params.selection[i], "angular") == 0) pipe->select[i] = PIPE_SELECT_ANGULAR; - else if (strcmp (gihparms.selection[i], "velocity") == 0) + else if (strcmp (params.selection[i], "velocity") == 0) pipe->select[i] = PIPE_SELECT_VELOCITY; - else if (strcmp (gihparms.selection[i], "random") == 0) + else if (strcmp (params.selection[i], "random") == 0) pipe->select[i] = PIPE_SELECT_RANDOM; - else if (strcmp (gihparms.selection[i], "pressure") == 0) + else if (strcmp (params.selection[i], "pressure") == 0) pipe->select[i] = PIPE_SELECT_PRESSURE; - else if (strcmp (gihparms.selection[i], "xtilt") == 0) + else if (strcmp (params.selection[i], "xtilt") == 0) pipe->select[i] = PIPE_SELECT_TILT_X; - else if (strcmp (gihparms.selection[i], "ytilt") == 0) + else if (strcmp (params.selection[i], "ytilt") == 0) pipe->select[i] = PIPE_SELECT_TILT_Y; else pipe->select[i] = PIPE_SELECT_CONSTANT; diff --git a/app/gimpbrushpipe.c b/app/gimpbrushpipe.c index ccda27459c..cc9f79621a 100644 --- a/app/gimpbrushpipe.c +++ b/app/gimpbrushpipe.c @@ -37,26 +37,7 @@ #include "libgimp/gimpintl.h" #include "libgimp/gimpmath.h" - -/* Code duplicated from plug-ins/common/gpb.c... - * The struct, and code to parse/build it probably should be in libgimp. - */ - -/* Parameters related to one single gih file, collected in a struct - * just for clarity. - */ -#define MAXDIM 4 -static struct { - gint step; - gint ncells; - gint dim; - gint cols; - gint rows; - gchar *placement; - gint rank[MAXDIM]; - gchar *selection[MAXDIM]; -} gihparms; - +#include "libgimp/parasiteio.h" static GimpBrushClass* gimp_brush_class; static GtkObjectClass* gimp_object_class; @@ -279,103 +260,19 @@ gimp_brush_pipe_get_type (void) return type; } -static void -init_pipe_parameters () -{ - int i; - - gihparms.step = 100; - gihparms.ncells = 1; - gihparms.dim = 1; - gihparms.cols = 1; - gihparms.rows = 1; - gihparms.placement = "constant"; - for (i = 0; i < MAXDIM; i++) - gihparms.selection[i] = "random"; - gihparms.rank[0] = 1; - for (i = 1; i < MAXDIM; i++) - gihparms.rank[i] = 0; -} - -static void -parse_brush_pipe_parameters (gchar *parameters) -{ - guchar *p, *q, *r, *s; /* Don't you love single-char identifiers? */ - gint i; - - q = parameters; - while ((p = strtok (q, " \r\n")) != NULL) - { - q = NULL; - r = strchr (p, ':'); - if (r) - *r = 0; - - if (strcmp (p, "ncells") == 0) - { - if (r) - gihparms.ncells = atoi (r + 1); - } - else if (strcmp (p, "step") == 0) - { - if (r) - gihparms.step = atoi (r + 1); - } - else if (strcmp (p, "dim") == 0) - { - if (r) - gihparms.dim = atoi (r + 1); - } - else if (strcmp (p, "cols") == 0) - { - if (r) - gihparms.cols = atoi (r + 1); - } - else if (strcmp (p, "rows") == 0) - { - if (r) - gihparms.rows = atoi (r + 1); - } - else if (strcmp (p, "placement") == 0) - { - if (r) - gihparms.placement = g_strdup (r + 1); - } - else if (strncmp (p, "rank", strlen ("rank")) == 0) - { - if (r) - { - i = atoi (p + strlen ("rank")); - if (i >= 0 && i < gihparms.dim) - gihparms.rank[i] = atoi (r + 1); - } - } - else if (strncmp (p, "sel", strlen ("sel")) == 0) - { - if (r) - { - i = atoi (p + strlen ("sel")); - if (i >= 0 && i < gihparms.dim) - gihparms.selection[i] = g_strdup (r + 1); - } - } - if (r) - *r = ':'; - } -} - GimpBrushPipe * gimp_brush_pipe_load (char *filename) { GimpBrushPipe *pipe; GPatternP pattern; + PixPipeParams params; FILE *fp; guchar buf[1024]; guchar *name; int i; int num_of_brushes; int totalcells; - gchar *params; + gchar *paramstring; if ((fp = fopen (filename, "rb")) == NULL) return NULL; @@ -400,7 +297,7 @@ gimp_brush_pipe_load (char *filename) gimp_object_destroy (pipe); return NULL; } - num_of_brushes = strtol(buf, ¶ms, 10); + num_of_brushes = strtol(buf, ¶mstring, 10); if (num_of_brushes < 1) { g_message (_("pixmap brush pipe should have at least one brush")); @@ -409,33 +306,33 @@ gimp_brush_pipe_load (char *filename) return NULL; } - while (*params && isspace(*params)) - params++; + while (*paramstring && isspace(*paramstring)) + paramstring++; - if (*params) + if (*paramstring) { - init_pipe_parameters (); - parse_brush_pipe_parameters (params); - pipe->dimension = gihparms.dim; + pixpipeparams_init (¶ms); + pixpipeparams_parse (paramstring, ¶ms); + pipe->dimension = params.dim; pipe->rank = g_new (int, pipe->dimension); pipe->select = g_new (PipeSelectModes, pipe->dimension); pipe->index = g_new (int, pipe->dimension); for (i = 0; i < pipe->dimension; i++) { - pipe->rank[i] = gihparms.rank[i]; - if (strcmp (gihparms.selection[i], "incremental") == 0) + pipe->rank[i] = params.rank[i]; + if (strcmp (params.selection[i], "incremental") == 0) pipe->select[i] = PIPE_SELECT_INCREMENTAL; - else if (strcmp (gihparms.selection[i], "angular") == 0) + else if (strcmp (params.selection[i], "angular") == 0) pipe->select[i] = PIPE_SELECT_ANGULAR; - else if (strcmp (gihparms.selection[i], "velocity") == 0) + else if (strcmp (params.selection[i], "velocity") == 0) pipe->select[i] = PIPE_SELECT_VELOCITY; - else if (strcmp (gihparms.selection[i], "random") == 0) + else if (strcmp (params.selection[i], "random") == 0) pipe->select[i] = PIPE_SELECT_RANDOM; - else if (strcmp (gihparms.selection[i], "pressure") == 0) + else if (strcmp (params.selection[i], "pressure") == 0) pipe->select[i] = PIPE_SELECT_PRESSURE; - else if (strcmp (gihparms.selection[i], "xtilt") == 0) + else if (strcmp (params.selection[i], "xtilt") == 0) pipe->select[i] = PIPE_SELECT_TILT_X; - else if (strcmp (gihparms.selection[i], "ytilt") == 0) + else if (strcmp (params.selection[i], "ytilt") == 0) pipe->select[i] = PIPE_SELECT_TILT_Y; else pipe->select[i] = PIPE_SELECT_CONSTANT; diff --git a/libgimp/Makefile.am b/libgimp/Makefile.am index 852bb4b55b..7ef1f8e81a 100644 --- a/libgimp/Makefile.am +++ b/libgimp/Makefile.am @@ -48,7 +48,9 @@ libgimpi_a_SOURCES = \ parasite.c \ parasite.h \ parasiteF.h \ - parasiteP.h + parasiteP.h \ + parasiteio.c \ + parasiteio.h if STATICLIBS ## Evil hack to insure all deps are satisfied on first-run make @@ -86,7 +88,9 @@ libgimp_la_SOURCES = \ parasite.c \ parasite.h \ parasiteF.h \ - parasiteP.h + parasiteP.h \ + parasiteio.c \ + parasiteio.h libgimpui_la_SOURCES = \ gimpmenu.c \ diff --git a/libgimp/gimp.def b/libgimp/gimp.def index acb671c9c4..30fbb36bf8 100644 --- a/libgimp/gimp.def +++ b/libgimp/gimp.def @@ -269,6 +269,9 @@ EXPORTS parasite_is_undoable parasite_name parasite_new + pixpipeparams_build + pixpipeparams_init + pixpipeparams_parse set_gimp_PLUG_IN_INFO_PTR wire_clear_error wire_destroy diff --git a/libgimp/gimp.h b/libgimp/gimp.h index 61fb5b627a..9df81d7032 100644 --- a/libgimp/gimp.h +++ b/libgimp/gimp.h @@ -535,7 +535,7 @@ guchar * gimp_image_get_thumbnail_data (gint32 image_ID, gint32 gimp_image_add_hguide (gint32 image_ID, gint32 yposition); gint32 gimp_image_add_vguide (gint32 image_ID, - gint32 yposition); + gint32 xposition); void gimp_image_delete_guide (gint32 image_ID, gint32 guide_ID); gint32 gimp_image_find_next_guide (gint32 image_ID, diff --git a/libgimp/gimpparasiteio.c b/libgimp/gimpparasiteio.c new file mode 100644 index 0000000000..17694bb56e --- /dev/null +++ b/libgimp/gimpparasiteio.c @@ -0,0 +1,154 @@ +/* Functions for bulding and parsing string representations of + * various standard parasite types. + * + * Copyright (C) 1999 Tor Lillqvist + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library 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. + */ + +#include "config.h" + +#include +#include +#include + +#include "libgimp/parasiteio.h" + +void +pixpipeparams_init (PixPipeParams *params) +{ + int 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"; + for (i = 0; i < PIXPIPE_MAXDIM; i++) + params->selection[i] = "random"; + params->rank[0] = 1; + for (i = 1; i < PIXPIPE_MAXDIM; i++) + params->rank[i] = 0; +} + +void +pixpipeparams_parse (gchar *string, + PixPipeParams *params) +{ + guchar *p, *q, *r; /* Don't you love single-char identifiers? */ + gint i; + + 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); + } + 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); + } + } + if (r) + *r = ':'; + } +} + +gchar * +pixpipeparams_build (PixPipeParams *params) +{ + GString *s = g_string_new (NULL); + gchar *str; + + int i; + + g_string_sprintf (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_sprintfa (s, " rank%d:%d", i, params->rank[i]); + g_string_sprintfa (s, " sel%d:%s", i, params->selection[i]); + } + + str = s->str; + g_string_free (s, FALSE); + + return str; +} + diff --git a/libgimp/gimpparasiteio.h b/libgimp/gimpparasiteio.h new file mode 100644 index 0000000000..d3bc67ff67 --- /dev/null +++ b/libgimp/gimpparasiteio.h @@ -0,0 +1,62 @@ +/* parasite.h + * Copyright (C) 1999 Tor Lillqvist + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library 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. + */ + +#ifndef _PARASITEIO_H_ +#define _PARASITEIO_H_ + +/* Data structures for various standard parasites used by plug-ins and + * the GIMP core, and functions to build and parse their string + * representations. + */ + +/* + * Pixmap brush pipes. + */ + +#define PIXPIPE_MAXDIM 4 + +typedef struct { + gint step; + gint ncells; + gint dim; + gint cols; + gint rows; + gint cellwidth; + gint cellheight; + gchar *placement; + gint rank[PIXPIPE_MAXDIM]; + gchar *selection[PIXPIPE_MAXDIM]; +} PixPipeParams; + +/* Initalize with dummy values */ +void pixpipeparams_init (PixPipeParams *params); + +/* Parse a string into a PixPipeParams */ +void pixpipeparams_parse (gchar *parameters, + PixPipeParams *params); + +/* Build a string representation of PixPipeParams */ +gchar *pixpipeparams_build (PixPipeParams *params); + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* _PARASITEIO_H_ */ diff --git a/libgimp/makefile.cygwin b/libgimp/makefile.cygwin index 1c57858d16..8283716c03 100644 --- a/libgimp/makefile.cygwin +++ b/libgimp/makefile.cygwin @@ -59,7 +59,8 @@ gimpi_OBJECTS = \ gimpunitmenu.o \ gimpwire.o \ gserialize.o \ - parasite.o + parasite.o \ + parasiteio.o libgimpi.a : $(gimpi_OBJECTS) ar cr libgimpi.a $(gimpi_OBJECTS) @@ -82,7 +83,8 @@ gimp_OBJECTS = \ gimpunit.o \ gimpwire.o \ gserialize.o \ - parasite.o + parasite.o \ + parasiteio.o gimp-$(GIMP_VER).dll : $(gimp_OBJECTS) gimp.def $(GLIB)/build-dll gimp $(GIMP_VER) gimp.def -s $(gimp_OBJECTS) -L $(INTL) -lgnu-intl -L $(GLIB) -lglib-$(GLIB_VER) -luser32 diff --git a/libgimp/makefile.msc b/libgimp/makefile.msc index 5f1a0d9186..8d4a6b0c45 100644 --- a/libgimp/makefile.msc +++ b/libgimp/makefile.msc @@ -65,7 +65,8 @@ gimpi_OBJECTS = \ gimpunitmenu.obj\ gimpwire.obj \ gserialize.obj \ - parasite.obj + parasite.obj \ + parasiteio.obj gimpi.lib : $(gimpi_OBJECTS) lib /out:gimpi.lib $(gimpi_OBJECTS) @@ -88,7 +89,8 @@ gimp_OBJECTS = \ gimpunit.obj \ gimpwire.obj \ gserialize.obj \ - parasite.obj + parasite.obj \ + parasiteio.obj gimp-$(GIMP_VER).dll : $(gimp_OBJECTS) gimp.def $(CC) $(CFLAGS) -LD -Fegimp-$(GIMP_VER).dll $(gimp_OBJECTS) $(INTL)\gnu-intl.lib $(GLIB)\glib-$(GLIB_VER).lib $(LDFLAGS) user32.lib /def:gimp.def diff --git a/libgimp/parasiteio.c b/libgimp/parasiteio.c new file mode 100644 index 0000000000..17694bb56e --- /dev/null +++ b/libgimp/parasiteio.c @@ -0,0 +1,154 @@ +/* Functions for bulding and parsing string representations of + * various standard parasite types. + * + * Copyright (C) 1999 Tor Lillqvist + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library 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. + */ + +#include "config.h" + +#include +#include +#include + +#include "libgimp/parasiteio.h" + +void +pixpipeparams_init (PixPipeParams *params) +{ + int 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"; + for (i = 0; i < PIXPIPE_MAXDIM; i++) + params->selection[i] = "random"; + params->rank[0] = 1; + for (i = 1; i < PIXPIPE_MAXDIM; i++) + params->rank[i] = 0; +} + +void +pixpipeparams_parse (gchar *string, + PixPipeParams *params) +{ + guchar *p, *q, *r; /* Don't you love single-char identifiers? */ + gint i; + + 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); + } + 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); + } + } + if (r) + *r = ':'; + } +} + +gchar * +pixpipeparams_build (PixPipeParams *params) +{ + GString *s = g_string_new (NULL); + gchar *str; + + int i; + + g_string_sprintf (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_sprintfa (s, " rank%d:%d", i, params->rank[i]); + g_string_sprintfa (s, " sel%d:%s", i, params->selection[i]); + } + + str = s->str; + g_string_free (s, FALSE); + + return str; +} + diff --git a/libgimp/parasiteio.h b/libgimp/parasiteio.h new file mode 100644 index 0000000000..d3bc67ff67 --- /dev/null +++ b/libgimp/parasiteio.h @@ -0,0 +1,62 @@ +/* parasite.h + * Copyright (C) 1999 Tor Lillqvist + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library 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. + */ + +#ifndef _PARASITEIO_H_ +#define _PARASITEIO_H_ + +/* Data structures for various standard parasites used by plug-ins and + * the GIMP core, and functions to build and parse their string + * representations. + */ + +/* + * Pixmap brush pipes. + */ + +#define PIXPIPE_MAXDIM 4 + +typedef struct { + gint step; + gint ncells; + gint dim; + gint cols; + gint rows; + gint cellwidth; + gint cellheight; + gchar *placement; + gint rank[PIXPIPE_MAXDIM]; + gchar *selection[PIXPIPE_MAXDIM]; +} PixPipeParams; + +/* Initalize with dummy values */ +void pixpipeparams_init (PixPipeParams *params); + +/* Parse a string into a PixPipeParams */ +void pixpipeparams_parse (gchar *parameters, + PixPipeParams *params); + +/* Build a string representation of PixPipeParams */ +gchar *pixpipeparams_build (PixPipeParams *params); + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* _PARASITEIO_H_ */ diff --git a/libgimpbase/gimpparasiteio.c b/libgimpbase/gimpparasiteio.c new file mode 100644 index 0000000000..17694bb56e --- /dev/null +++ b/libgimpbase/gimpparasiteio.c @@ -0,0 +1,154 @@ +/* Functions for bulding and parsing string representations of + * various standard parasite types. + * + * Copyright (C) 1999 Tor Lillqvist + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library 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. + */ + +#include "config.h" + +#include +#include +#include + +#include "libgimp/parasiteio.h" + +void +pixpipeparams_init (PixPipeParams *params) +{ + int 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"; + for (i = 0; i < PIXPIPE_MAXDIM; i++) + params->selection[i] = "random"; + params->rank[0] = 1; + for (i = 1; i < PIXPIPE_MAXDIM; i++) + params->rank[i] = 0; +} + +void +pixpipeparams_parse (gchar *string, + PixPipeParams *params) +{ + guchar *p, *q, *r; /* Don't you love single-char identifiers? */ + gint i; + + 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); + } + 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); + } + } + if (r) + *r = ':'; + } +} + +gchar * +pixpipeparams_build (PixPipeParams *params) +{ + GString *s = g_string_new (NULL); + gchar *str; + + int i; + + g_string_sprintf (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_sprintfa (s, " rank%d:%d", i, params->rank[i]); + g_string_sprintfa (s, " sel%d:%s", i, params->selection[i]); + } + + str = s->str; + g_string_free (s, FALSE); + + return str; +} + diff --git a/libgimpbase/gimpparasiteio.h b/libgimpbase/gimpparasiteio.h new file mode 100644 index 0000000000..d3bc67ff67 --- /dev/null +++ b/libgimpbase/gimpparasiteio.h @@ -0,0 +1,62 @@ +/* parasite.h + * Copyright (C) 1999 Tor Lillqvist + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library 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. + */ + +#ifndef _PARASITEIO_H_ +#define _PARASITEIO_H_ + +/* Data structures for various standard parasites used by plug-ins and + * the GIMP core, and functions to build and parse their string + * representations. + */ + +/* + * Pixmap brush pipes. + */ + +#define PIXPIPE_MAXDIM 4 + +typedef struct { + gint step; + gint ncells; + gint dim; + gint cols; + gint rows; + gint cellwidth; + gint cellheight; + gchar *placement; + gint rank[PIXPIPE_MAXDIM]; + gchar *selection[PIXPIPE_MAXDIM]; +} PixPipeParams; + +/* Initalize with dummy values */ +void pixpipeparams_init (PixPipeParams *params); + +/* Parse a string into a PixPipeParams */ +void pixpipeparams_parse (gchar *parameters, + PixPipeParams *params); + +/* Build a string representation of PixPipeParams */ +gchar *pixpipeparams_build (PixPipeParams *params); + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* _PARASITEIO_H_ */ diff --git a/plug-ins/common/gpb.c b/plug-ins/common/gpb.c index cb80e16f13..5dd62fb4a5 100644 --- a/plug-ins/common/gpb.c +++ b/plug-ins/common/gpb.c @@ -32,6 +32,7 @@ #include #include +#include #include "app/brush_header.h" #include "app/pattern_header.h" @@ -39,7 +40,6 @@ #define DUMMY_PATTERN_NAME "x" #define MAXDESCLEN 256 -#define MAXDIM 4 /* Parameters applicable each time we save a gpb or gih, saved * in the main gimp application between invocations of this plug-in. @@ -58,19 +58,26 @@ static struct { static gint run_flag = 0; static gint num_layers_with_alpha; -/* Parameters related to one single gih file, collected in a struct - * just for clarity. - */ -static struct { - gint step; - gint ncells; - gint dim; - gint cols; - gint rows; - gchar *placement; - gint rank[MAXDIM]; - gchar *selection[MAXDIM]; -} gihparms; +static PixPipeParams gihparms; + +typedef struct +{ + GOrientation orientation; + gint32 image; + gint32 toplayer; + gint nguides; + gint32 *guides; + gint *value; + GtkWidget *count_label; /* Corresponding count adjustment, */ + gint *count; /* cols or rows */ + gint *other_count; /* And the other one */ + GtkObject *ncells; + GtkObject *rank0; + GtkWidget *warning_label; +} SizeAdjustmentData; + +static gint32 *vguides, *hguides; +static gint nvguides = 0, nhguides = 0; /* Declare some local functions. */ @@ -163,6 +170,64 @@ adjustment_callback (GtkWidget *widget, *((gint *) data) = GTK_ADJUSTMENT (widget)->value; } +static void +size_adjustment_callback (GtkWidget *widget, + gpointer data) +{ + /* Unfortunately this doesn't work, sigh. The guides don't show up unless + * you manually force a redraw of the image. + */ + int i; + int size; + int newn; + SizeAdjustmentData *adj = (SizeAdjustmentData *) data; + char buf[10]; + + for (i = 0; i < adj->nguides; i++) + gimp_image_delete_guide (adj->image, adj->guides[i]); + g_free (adj->guides); + adj->guides = NULL; + gimp_displays_flush (); + + *(adj->value) = GTK_ADJUSTMENT (widget)->value; + + if (adj->orientation == ORIENTATION_VERTICAL) + { + size = gimp_image_width (adj->image); + newn = size / *(adj->value); + adj->nguides = newn - 1; + adj->guides = g_new (gint32, adj->nguides); + for (i = 0; i < adj->nguides; i++) + adj->guides[i] = gimp_image_add_vguide (adj->image, + *(adj->value) * (i+1)); + } + else + { + size = gimp_image_height (adj->image); + newn = size / *(adj->value); + adj->nguides = newn - 1; + adj->guides = g_new (gint32, adj->nguides); + for (i = 0; i < adj->nguides; i++) + adj->guides[i] = gimp_image_add_hguide (adj->image, + *(adj->value) * (i+1)); + } + gimp_displays_flush (); + sprintf (buf, "%2d", newn); + gtk_label_set_text (GTK_LABEL (adj->count_label), buf); + *(adj->count) = newn; + if (newn * *(adj->value) != size) + gtk_widget_show (GTK_WIDGET (adj->warning_label)); + else + gtk_widget_hide (GTK_WIDGET (adj->warning_label)); + if (adj->ncells != NULL) + gtk_adjustment_set_value (GTK_ADJUSTMENT (adj->ncells), + *(adj->other_count) * *(adj->count)); + if (adj->rank0 != NULL) + gtk_adjustment_set_value (GTK_ADJUSTMENT (adj->rank0), + *(adj->other_count) * *(adj->count)); + +} + static void entry_callback (GtkWidget *widget, gpointer data) @@ -322,7 +387,7 @@ gpb_save_dialog () } static gint -gih_save_dialog () +gih_save_dialog (gint32 image_ID) { GtkWidget *dlg; GtkWidget *table, *dimtable; @@ -337,12 +402,21 @@ gih_save_dialog () gchar **argv; gint argc; gchar buffer[100]; + SizeAdjustmentData cellw_adjust, cellh_adjust; + gint32 *layer_ID; + gint32 nlayers; /* Setup default values */ if (gihparms.rows >= 1 && gihparms.cols >= 1) gihparms.ncells = num_layers_with_alpha * gihparms.rows * gihparms.cols; else - gihparms.ncells = 1; + gihparms.ncells = num_layers_with_alpha; + + if (gihparms.cellwidth == 1 && gihparms.cellheight == 1) + { + gihparms.cellwidth = gimp_image_width (image_ID) / gihparms.cols; + gihparms.cellheight = gimp_image_height (image_ID) / gihparms.rows; + } argc = 1; argv = g_new (gchar *, 1); @@ -365,6 +439,77 @@ gih_save_dialog () common_save_dialog (dlg, table); + /* + * Cell size: __ x __ pixels + */ + + gtk_table_resize (GTK_TABLE (table), + GTK_TABLE (table)->nrows + 1, GTK_TABLE (table)->ncols); + + label = gtk_label_new ("Cell size:"); + gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); + gtk_table_attach (GTK_TABLE (table), label, 0, 1, + GTK_TABLE (table)->nrows - 1, GTK_TABLE (table)->nrows, + GTK_FILL, GTK_FILL, 0, 0); + gtk_widget_show (label); + + box = gtk_hbox_new (FALSE, 0); + + adjustment = gtk_adjustment_new (gihparms.cellwidth, + 2, gimp_image_width (image_ID), 1, 1, 1); + spinbutton = gtk_spin_button_new (GTK_ADJUSTMENT (adjustment), 1, 0); + gtk_spin_button_set_shadow_type (GTK_SPIN_BUTTON (spinbutton), + GTK_SHADOW_NONE); + gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton), TRUE); + gtk_widget_set_usize (spinbutton, 75, 0); + gtk_box_pack_start (GTK_BOX (box), spinbutton, FALSE, FALSE, 0); + + layer_ID = gimp_image_get_layers (image_ID, &nlayers); + cellw_adjust.orientation = ORIENTATION_VERTICAL; + cellw_adjust.image = image_ID; + cellw_adjust.toplayer = layer_ID[nlayers-1]; + cellw_adjust.nguides = 0; + cellw_adjust.guides = NULL; + cellw_adjust.value = &gihparms.cellwidth; + gtk_signal_connect (GTK_OBJECT (adjustment), "value_changed", + (GtkSignalFunc) size_adjustment_callback, + &cellw_adjust); + gtk_widget_show (spinbutton); + + label = gtk_label_new (" x "); + gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0); + gtk_widget_show (label); + + adjustment = gtk_adjustment_new (gihparms.cellheight, + 2, gimp_image_height (image_ID), 1, 1, 1); + spinbutton = gtk_spin_button_new (GTK_ADJUSTMENT (adjustment), 1, 0); + gtk_spin_button_set_shadow_type (GTK_SPIN_BUTTON (spinbutton), + GTK_SHADOW_NONE); + gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton), TRUE); + gtk_widget_set_usize (spinbutton, 75, 0); + gtk_box_pack_start (GTK_BOX (box), spinbutton, FALSE, FALSE, 0); + cellh_adjust.orientation = ORIENTATION_HORIZONTAL; + cellh_adjust.image = image_ID; + cellh_adjust.toplayer = layer_ID[nlayers-1]; + cellh_adjust.nguides = 0; + cellh_adjust.guides = NULL; + cellh_adjust.value = &gihparms.cellheight; + gtk_signal_connect (GTK_OBJECT (adjustment), "value_changed", + (GtkSignalFunc) size_adjustment_callback, + &cellh_adjust); + gtk_widget_show (spinbutton); + + label = gtk_label_new (" pixels"); + gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0); + gtk_widget_show (label); + + gtk_table_attach (GTK_TABLE (table), box, 1, 2, + GTK_TABLE (table)->nrows - 1, GTK_TABLE (table)->nrows, + GTK_FILL, GTK_FILL, 0, 0); + gtk_widget_show (box); + + g_free (layer_ID); + /* * Number of cells: ___ */ @@ -395,6 +540,11 @@ gih_save_dialog () gtk_widget_show (spinbutton); gtk_widget_show (box); + if (gihparms.dim == 1) + cellw_adjust.ncells = cellh_adjust.ncells = adjustment; + else + cellw_adjust.ncells = cellh_adjust.ncells = NULL; + /* * Display as: __ rows x __ cols */ @@ -410,36 +560,38 @@ gih_save_dialog () box = gtk_hbox_new (FALSE, 0); - adjustment = gtk_adjustment_new (gihparms.rows, 1, 10, 1, 1, 1); - spinbutton = gtk_spin_button_new (GTK_ADJUSTMENT (adjustment), 1, 0); - gtk_spin_button_set_shadow_type (GTK_SPIN_BUTTON (spinbutton), - GTK_SHADOW_NONE); - gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton), TRUE); - gtk_widget_set_usize (spinbutton, 75, 0); - gtk_box_pack_start (GTK_BOX (box), spinbutton, FALSE, FALSE, 0); - gtk_signal_connect (GTK_OBJECT (adjustment), "value_changed", - (GtkSignalFunc) adjustment_callback, &gihparms.rows); - gtk_widget_show (spinbutton); + sprintf (buffer, "%2d", gihparms.rows); + label = gtk_label_new (buffer); + gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0); + cellh_adjust.count_label = label; + cellh_adjust.count = &gihparms.rows; + cellh_adjust.other_count = &gihparms.cols; + gtk_widget_show (label); label = gtk_label_new (" rows of "); gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0); gtk_widget_show (label); - adjustment = gtk_adjustment_new (gihparms.cols, 1, 10, 1, 1, 1); - spinbutton = gtk_spin_button_new (GTK_ADJUSTMENT (adjustment), 1, 0); - gtk_spin_button_set_shadow_type (GTK_SPIN_BUTTON (spinbutton), - GTK_SHADOW_NONE); - gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton), TRUE); - gtk_widget_set_usize (spinbutton, 75, 0); - gtk_box_pack_start (GTK_BOX (box), spinbutton, FALSE, FALSE, 0); - gtk_signal_connect (GTK_OBJECT (adjustment), "value_changed", - (GtkSignalFunc) adjustment_callback, &gihparms.cols); - gtk_widget_show (spinbutton); + sprintf (buffer, "%2d", gihparms.cols); + label = gtk_label_new (buffer); + gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0); + cellw_adjust.count_label = label; + cellw_adjust.count = &gihparms.cols; + cellw_adjust.other_count = &gihparms.rows; + gtk_widget_show (label); - label = gtk_label_new (" columns"); + label = gtk_label_new (" columns on each layer"); gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0); gtk_widget_show (label); + label = gtk_label_new (" (width mismatch!) "); + gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0); + cellw_adjust.warning_label = label; + + label = gtk_label_new (" (height mismatch!) "); + gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0); + cellh_adjust.warning_label = label; + gtk_table_attach (GTK_TABLE (table), box, 1, 2, GTK_TABLE (table)->nrows - 1, GTK_TABLE (table)->nrows, GTK_FILL, GTK_FILL, 0, 0); @@ -489,8 +641,8 @@ gih_save_dialog () GTK_FILL, GTK_FILL, 0, 0); gtk_widget_show (label); - dimtable = gtk_table_new (MAXDIM, 1, FALSE); - for (i = 0; i < MAXDIM; i++) + dimtable = gtk_table_new (PIXPIPE_MAXDIM, 1, FALSE); + for (i = 0; i < PIXPIPE_MAXDIM; i++) { adjustment = gtk_adjustment_new (gihparms.rank[i], 0, 100, 1, 1, 1); spinbutton = gtk_spin_button_new (GTK_ADJUSTMENT (adjustment), 1, 0); @@ -506,6 +658,11 @@ gih_save_dialog () (GtkSignalFunc) adjustment_callback, &gihparms.rank[i]); gtk_widget_show (spinbutton); gtk_widget_show (box); + if (i == 0) + if (gihparms.dim == 1) + cellw_adjust.rank0 = cellh_adjust.rank0 = adjustment; + else + cellw_adjust.rank0 = cellh_adjust.rank0 = NULL; } gtk_table_attach (GTK_TABLE (table), dimtable, 1, 2, GTK_TABLE (table)->nrows - 1, GTK_TABLE (table)->nrows, @@ -535,7 +692,7 @@ gih_save_dialog () cbitems = g_list_append (cbitems, "ytilt"); box = gtk_hbox_new (FALSE, 0); - for (i = 0; i < MAXDIM; i++) + for (i = 0; i < PIXPIPE_MAXDIM; i++) { cb = gtk_combo_new (); gtk_combo_set_popdown_strings (GTK_COMBO (cb), cbitems); @@ -561,6 +718,11 @@ gih_save_dialog () gtk_main (); gdk_flush (); + for (i = 0; i < cellw_adjust.nguides; i++) + gimp_image_delete_guide (image_ID, cellw_adjust.guides[i]); + for (i = 0; i < cellh_adjust.nguides; i++) + gimp_image_delete_guide (image_ID, cellh_adjust.guides[i]); + if (run_flag) { /* Fix up bogus values */ @@ -761,133 +923,6 @@ gpb_save_image (char *filename, return TRUE; } -static void -init_pipe_parameters () -{ - int i; - - gihparms.step = 100; - gihparms.ncells = 1; - gihparms.dim = 1; - gihparms.cols = 1; - gihparms.rows = 1; - gihparms.placement = "constant"; - for (i = 0; i < MAXDIM; i++) - gihparms.selection[i] = "random"; - gihparms.rank[0] = 1; - for (i = 1; i < MAXDIM; i++) - gihparms.rank[i] = 0; -} - -static void -parse_brush_pipe_parameters (gchar *parameters) -{ - guchar *p, *q, *r, *s; /* Don't you love single-char identifiers? */ - gint i; - - IFDBG(2) g_message ("parsing parasite: %s", parameters); - - q = parameters; - while ((p = strtok (q, " ")) != NULL) - { - q = NULL; - r = strchr (p, ':'); - if (r) - *r = 0; - - if (strcmp (p, "ncells") == 0) - { - if (r) - gihparms.ncells = atoi (r + 1); - } - else if (strcmp (p, "step") == 0) - { - if (r) - gihparms.step = atoi (r + 1); - } - else if (strcmp (p, "dim") == 0) - { - if (r) - gihparms.dim = atoi (r + 1); - } - else if (strcmp (p, "cols") == 0) - { - if (r) - gihparms.cols = atoi (r + 1); - } - else if (strcmp (p, "rows") == 0) - { - if (r) - gihparms.rows = atoi (r + 1); - } - else if (strcmp (p, "placement") == 0) - { - if (r) - gihparms.placement = g_strdup (r + 1); - } - else if (strncmp (p, "rank", strlen ("rank")) == 0 && r) - { - if (r) - { - i = atoi (p + strlen ("rank")); - if (i >= 0 && i < gihparms.dim) - gihparms.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 < gihparms.dim) - gihparms.selection[i] = g_strdup (r + 1); - } - } - if (r) - *r = ':'; - } - - IFDBG(2) g_message ("parsed parasite: " - "ncells:%d step:%d dim:%d cols:%d rows:%d " - "placement:%s " - "rank0:%d rank1:%d rank2:%d rank3:%d" - "sel%d:%s sel%d:%s sel%d:%s ", - gihparms.ncells, gihparms.step, - gihparms.dim, gihparms.cols, gihparms.rows, - gihparms.placement, - gihparms.rank[0], gihparms.rank[1], - gihparms.rank[2], gihparms.rank[3], - gihparms.selection[0], gihparms.selection[1], - gihparms.selection[2], gihparms.selection[3]); -} - -static gchar * -build_brush_pipe_parameters () -{ - GString *s = g_string_new (NULL); - gchar *str; - - int i; - - g_string_sprintf (s, "ncells:%d step:%d dim:%d cols:%d rows:%d placement:%s", - gihparms.ncells, gihparms.step, - gihparms.dim, - gihparms.cols, gihparms.rows, - gihparms.placement); - - for (i = 0; i < gihparms.dim; i++) - { - g_string_sprintfa (s, " rank%d:%d", i, gihparms.rank[i]); - g_string_sprintfa (s, " sel%d:%s", i, gihparms.selection[i]); - } - - str = s->str; - g_string_free (s, FALSE); - - IFDBG(2) g_message ("built parasite string: %s", str); - return str; -} - static gboolean gih_save_image (char *filename, gint32 image_ID, @@ -897,7 +932,7 @@ gih_save_image (char *filename, GPixelRgn pixel_rgn; FILE *file; Parasite *pipe_parasite; - gchar *msg, *pars, *ncells; + gchar *msg, *parstring, *ncells; gint32 *layer_ID; gint nlayers, layer, row, col; gint imagew, imageh, offsetx, offsety; @@ -919,26 +954,27 @@ gih_save_image (char *filename, return FALSE; } - pars = build_brush_pipe_parameters (); + parstring = pixpipeparams_build (&gihparms); + IFDBG(2) g_message ("parameter string: %s", parstring); ncells = g_strdup_printf ("%d ", gihparms.ncells); if (!(try_fwrite (info.description, strlen (info.description), 1, file) && try_fwrite ("\n", 1, 1, file) && try_fwrite (ncells, strlen (ncells), 1, file) - && try_fwrite (pars, strlen (pars), 1, file) + && try_fwrite (parstring, strlen (parstring), 1, file) && try_fwrite ("\n", 1, 1, file))) { - g_free (pars); + g_free (parstring); g_free (ncells); return FALSE; } pipe_parasite = parasite_new ("gimp-brush-pipe-parameters", PARASITE_PERSISTENT, - strlen (pars) + 1, pars); + strlen (parstring) + 1, parstring); gimp_image_attach_parasite (image_ID, pipe_parasite); parasite_free (pipe_parasite); - g_free (pars); + g_free (parstring); g_free (ncells); layer_ID = gimp_image_get_layers (image_ID, &nlayers); @@ -1070,13 +1106,11 @@ run (char *name, /* Possibly retrieve data */ gimp_get_data ("file_gih_save", &info); pipe_parasite = gimp_image_find_parasite (image_ID, "gimp-brush-pipe-parameters"); - init_pipe_parameters (); + pixpipeparams_init (&gihparms); if (pipe_parasite) - { - parse_brush_pipe_parameters (pipe_parasite->data); - } + pixpipeparams_parse (pipe_parasite->data, &gihparms); - if (!gih_save_dialog ()) + if (!gih_save_dialog (image_ID)) return; break; diff --git a/plug-ins/common/psp.c b/plug-ins/common/psp.c index 13ff5d3547..9fb9b3a234 100644 --- a/plug-ins/common/psp.c +++ b/plug-ins/common/psp.c @@ -50,6 +50,7 @@ #include #include +#include #include /* Note that the upcoming PSP version 6 writes PSP file format version @@ -1462,9 +1463,12 @@ read_tube_block (FILE *f, guint32 step_size, column_count, row_count, cell_count; guint32 placement_mode, selection_mode; gint i; + PixPipeParams params; Parasite *pipe_parasite; gchar *parasite_text; + pixpipeparams_init (¶ms); + if (fread (&version, 2, 1, f) < 1 || fread (name, 513, 1, f) < 1 || fread (&step_size, 4, 1, f) < 1 @@ -1481,10 +1485,10 @@ read_tube_block (FILE *f, } name[513] = 0; version = GUINT16_FROM_LE (version); - step_size = GUINT32_FROM_LE (step_size); - column_count = GUINT32_FROM_LE (column_count); - row_count = GUINT32_FROM_LE (row_count); - cell_count = GUINT32_FROM_LE (cell_count); + params.step = GUINT32_FROM_LE (step_size); + params.cols = GUINT32_FROM_LE (column_count); + params.rows = GUINT32_FROM_LE (row_count); + params.ncells = GUINT32_FROM_LE (cell_count); placement_mode = GUINT32_FROM_LE (placement_mode); selection_mode = GUINT32_FROM_LE (selection_mode); @@ -1497,21 +1501,23 @@ read_tube_block (FILE *f, * case we will have any use of those, for instance in the gpb * plug-in that saves a GIMP image pipe. */ - parasite_text = - g_strdup_printf ("ncells:%d step:%d dim:%d cols:%d rows:%d " - "rank0:%d " - "placement:%s sel0:%s", - cell_count, step_size, 1, column_count, row_count, - cell_count, - (placement_mode == tpmRandom ? "random" : + params.dim = 1; + params.cellwidth = ia->width / params.cols; + params.cellheight = ia->height / params.rows; + params.placement = (placement_mode == tpmRandom ? "random" : (placement_mode == tpmConstant ? "constant" : - "default")), - (selection_mode == tsmRandom ? "random" : - (selection_mode == tsmIncremental ? "incremental" : - (selection_mode == tsmAngular ? "angular" : - (selection_mode == tsmPressure ? "pressure" : - (selection_mode == tsmVelocity ? "velocity" : - "default")))))); + "default")); + params.rank[0] = params.ncells; + params.selection[0] = (selection_mode == tsmRandom ? "random" : + (selection_mode == tsmIncremental ? "incremental" : + (selection_mode == tsmAngular ? "angular" : + (selection_mode == tsmPressure ? "pressure" : + (selection_mode == tsmVelocity ? "velocity" : + "default"))))); + parasite_text = pixpipeparams_build (¶ms); + + IFDBG(2) g_message ("parasite: %s", parasite_text); + pipe_parasite = parasite_new ("gimp-brush-pipe-parameters", PARASITE_PERSISTENT, strlen (parasite_text) + 1, parasite_text);