diff --git a/app/core/gimpbrushpipe-load.c b/app/core/gimpbrushpipe-load.c index 1c6612d8be..18ad8989d0 100644 --- a/app/core/gimpbrushpipe-load.c +++ b/app/core/gimpbrushpipe-load.c @@ -21,10 +21,8 @@ #include #include -#include #include "libgimpbase/gimpbase.h" -#include "libgimpbase/gimpparasiteio.h" #include "core-types.h" @@ -42,14 +40,12 @@ gimp_brush_pipe_load (GimpContext *context, GInputStream *input, GError **error) { - GimpBrushPipe *pipe = NULL; - gint i; - gint num_of_brushes = 0; - gint totalcells; - gchar *paramstring; - GString *buffer; - gchar c; - gsize bytes_read; + GimpBrushPipe *pipe = NULL; + gint n_brushes = 0; + GString *buffer; + gchar *paramstring; + gchar c; + gsize bytes_read; g_return_val_if_fail (G_IS_FILE (file), NULL); g_return_val_if_fail (G_IS_INPUT_STREAM (input), NULL); @@ -105,10 +101,10 @@ gimp_brush_pipe_load (GimpContext *context, if (buffer->len > 0 && buffer->len < 1024) { - num_of_brushes = strtol (buffer->str, ¶mstring, 10); + n_brushes = strtol (buffer->str, ¶mstring, 10); } - if (num_of_brushes < 1) + if (n_brushes < 1) { g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, _("Fatal parse error in brush file '%s': " @@ -122,74 +118,9 @@ gimp_brush_pipe_load (GimpContext *context, while (*paramstring && g_ascii_isspace (*paramstring)) paramstring++; - if (*paramstring) - { - GimpPixPipeParams params; + pipe->brushes = g_new0 (GimpBrush *, n_brushes); - gimp_pixpipe_params_init (¶ms); - gimp_pixpipe_params_parse (paramstring, ¶ms); - - pipe->dimension = params.dim; - pipe->rank = g_new0 (gint, pipe->dimension); - pipe->select = g_new0 (PipeSelectModes, pipe->dimension); - pipe->index = g_new0 (gint, pipe->dimension); - /* placement is not used at all ?? */ - - for (i = 0; i < pipe->dimension; i++) - { - pipe->rank[i] = MAX (1, params.rank[i]); - if (strcmp (params.selection[i], "incremental") == 0) - pipe->select[i] = PIPE_SELECT_INCREMENTAL; - else if (strcmp (params.selection[i], "angular") == 0) - pipe->select[i] = PIPE_SELECT_ANGULAR; - else if (strcmp (params.selection[i], "velocity") == 0) - pipe->select[i] = PIPE_SELECT_VELOCITY; - else if (strcmp (params.selection[i], "random") == 0) - pipe->select[i] = PIPE_SELECT_RANDOM; - else if (strcmp (params.selection[i], "pressure") == 0) - pipe->select[i] = PIPE_SELECT_PRESSURE; - else if (strcmp (params.selection[i], "xtilt") == 0) - pipe->select[i] = PIPE_SELECT_TILT_X; - else if (strcmp (params.selection[i], "ytilt") == 0) - pipe->select[i] = PIPE_SELECT_TILT_Y; - else - pipe->select[i] = PIPE_SELECT_CONSTANT; - pipe->index[i] = 0; - } - - gimp_pixpipe_params_free (¶ms); - - pipe->params = g_strdup (paramstring); - } - else - { - pipe->dimension = 1; - pipe->rank = g_new (gint, 1); - pipe->rank[0] = num_of_brushes; - pipe->select = g_new (PipeSelectModes, 1); - pipe->select[0] = PIPE_SELECT_INCREMENTAL; - pipe->index = g_new (gint, 1); - pipe->index[0] = 0; - } - - g_string_free (buffer, TRUE); - - totalcells = 1; /* Not all necessarily present, maybe */ - for (i = 0; i < pipe->dimension; i++) - totalcells *= pipe->rank[i]; - pipe->stride = g_new0 (gint, pipe->dimension); - for (i = 0; i < pipe->dimension; i++) - { - if (i == 0) - pipe->stride[i] = totalcells / pipe->rank[i]; - else - pipe->stride[i] = pipe->stride[i-1] / pipe->rank[i]; - } - g_return_val_if_fail (pipe->stride[pipe->dimension-1] == 1, NULL); - - pipe->brushes = g_new0 (GimpBrush *, num_of_brushes); - - while (pipe->n_brushes < num_of_brushes) + while (pipe->n_brushes < n_brushes) { pipe->brushes[pipe->n_brushes] = gimp_brush_load_brush (context, file, input, @@ -198,12 +129,26 @@ gimp_brush_pipe_load (GimpContext *context, if (! pipe->brushes[pipe->n_brushes]) { g_object_unref (pipe); + g_string_free (buffer, TRUE); return NULL; } pipe->n_brushes++; } + if (! gimp_brush_pipe_set_params (pipe, paramstring)) + { + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, + _("Fatal parse error in brush file '%s': " + "Inconsistent parameters."), + gimp_file_get_utf8_name (file)); + g_object_unref (pipe); + g_string_free (buffer, TRUE); + return NULL; + } + + g_string_free (buffer, TRUE); + /* Current brush is the first one. */ pipe->current = pipe->brushes[0]; diff --git a/app/core/gimpbrushpipe.c b/app/core/gimpbrushpipe.c index db02feee51..6d1aa02ed5 100644 --- a/app/core/gimpbrushpipe.c +++ b/app/core/gimpbrushpipe.c @@ -21,6 +21,7 @@ #include #include +#include "libgimpbase/gimpparasiteio.h" #include "libgimpmath/gimpmath.h" #include "core-types.h" @@ -333,3 +334,88 @@ gimp_brush_pipe_want_null_motion (GimpBrush *brush, return TRUE; } + + +/* public functions */ + +gboolean +gimp_brush_pipe_set_params (GimpBrushPipe *pipe, + const gchar *paramstring) +{ + gint totalcells; + gint i; + + g_return_val_if_fail (GIMP_IS_BRUSH_PIPE (pipe), FALSE); + g_return_val_if_fail (pipe->dimension == 0, FALSE); /* only on a new pipe! */ + + if (paramstring && *paramstring) + { + GimpPixPipeParams params; + + gimp_pixpipe_params_init (¶ms); + gimp_pixpipe_params_parse (paramstring, ¶ms); + + pipe->dimension = params.dim; + pipe->rank = g_new0 (gint, pipe->dimension); + pipe->select = g_new0 (PipeSelectModes, pipe->dimension); + pipe->index = g_new0 (gint, pipe->dimension); + /* placement is not used at all ?? */ + + for (i = 0; i < pipe->dimension; i++) + { + pipe->rank[i] = MAX (1, params.rank[i]); + + if (strcmp (params.selection[i], "incremental") == 0) + pipe->select[i] = PIPE_SELECT_INCREMENTAL; + else if (strcmp (params.selection[i], "angular") == 0) + pipe->select[i] = PIPE_SELECT_ANGULAR; + else if (strcmp (params.selection[i], "velocity") == 0) + pipe->select[i] = PIPE_SELECT_VELOCITY; + else if (strcmp (params.selection[i], "random") == 0) + pipe->select[i] = PIPE_SELECT_RANDOM; + else if (strcmp (params.selection[i], "pressure") == 0) + pipe->select[i] = PIPE_SELECT_PRESSURE; + else if (strcmp (params.selection[i], "xtilt") == 0) + pipe->select[i] = PIPE_SELECT_TILT_X; + else if (strcmp (params.selection[i], "ytilt") == 0) + pipe->select[i] = PIPE_SELECT_TILT_Y; + else + pipe->select[i] = PIPE_SELECT_CONSTANT; + + pipe->index[i] = 0; + } + + gimp_pixpipe_params_free (¶ms); + + pipe->params = g_strdup (paramstring); + } + else + { + pipe->dimension = 1; + pipe->rank = g_new (gint, 1); + pipe->rank[0] = pipe->n_brushes; + pipe->select = g_new (PipeSelectModes, 1); + pipe->select[0] = PIPE_SELECT_INCREMENTAL; + pipe->index = g_new (gint, 1); + pipe->index[0] = 0; + } + + totalcells = 1; /* Not all necessarily present, maybe */ + for (i = 0; i < pipe->dimension; i++) + totalcells *= pipe->rank[i]; + + pipe->stride = g_new0 (gint, pipe->dimension); + + for (i = 0; i < pipe->dimension; i++) + { + if (i == 0) + pipe->stride[i] = totalcells / pipe->rank[i]; + else + pipe->stride[i] = pipe->stride[i-1] / pipe->rank[i]; + } + + if (pipe->stride[pipe->dimension - 1] != 1) + return FALSE; + + return TRUE; +} diff --git a/app/core/gimpbrushpipe.h b/app/core/gimpbrushpipe.h index 0f27fa70f5..9615210392 100644 --- a/app/core/gimpbrushpipe.h +++ b/app/core/gimpbrushpipe.h @@ -71,7 +71,10 @@ struct _GimpBrushPipeClass }; -GType gimp_brush_pipe_get_type (void) G_GNUC_CONST; +GType gimp_brush_pipe_get_type (void) G_GNUC_CONST; + +gboolean gimp_brush_pipe_set_params (GimpBrushPipe *pipe, + const gchar *paramstring); #endif /* __GIMP_BRUSH_PIPE_H__ */