[gimp] app: implement saving of GimpBrushPipes in the core
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: implement saving of GimpBrushPipes in the core
- Date: Sat, 23 Feb 2019 18:43:57 +0000 (UTC)
commit aee097fa9723a16fcd989ad99a34b8bc2d26b326
Author: Michael Natterer <mitch gimp org>
Date: Sat Feb 23 19:41:06 2019 +0100
app: implement saving of GimpBrushPipes in the core
Just the GimpData::save() and ::copy() part that is needed to
duplicate and rename them, the image-to-pipe logic from the export
plug-in remains to be ported.
app/core/Makefile.am | 2 +
app/core/gimp-data-factories.c | 2 +-
app/core/gimpbrushpipe-save.c | 59 ++++++++++++++++++++++
app/core/gimpbrushpipe-save.h | 28 +++++++++++
app/core/gimpbrushpipe.c | 108 +++++++++++++++++++++++++++++++++--------
5 files changed, 179 insertions(+), 20 deletions(-)
---
diff --git a/app/core/Makefile.am b/app/core/Makefile.am
index 43ce3bd2cf..a06b289b39 100644
--- a/app/core/Makefile.am
+++ b/app/core/Makefile.am
@@ -131,6 +131,8 @@ libappcore_a_sources = \
gimpbrushpipe.h \
gimpbrushpipe-load.c \
gimpbrushpipe-load.h \
+ gimpbrushpipe-save.c \
+ gimpbrushpipe-save.h \
gimpbuffer.c \
gimpbuffer.h \
gimpcancelable.c \
diff --git a/app/core/gimp-data-factories.c b/app/core/gimp-data-factories.c
index 3a6f628f6a..ad358f31e4 100644
--- a/app/core/gimp-data-factories.c
+++ b/app/core/gimp-data-factories.c
@@ -103,7 +103,7 @@ gimp_data_factories_init (Gimp *gimp)
"GIMP Brush Pipe",
gimp_brush_pipe_load,
GIMP_BRUSH_PIPE_FILE_EXTENSION,
- FALSE);
+ TRUE);
gimp->dynamics_factory =
gimp_data_loader_factory_new (gimp,
diff --git a/app/core/gimpbrushpipe-save.c b/app/core/gimpbrushpipe-save.c
new file mode 100644
index 0000000000..1b8e7fb165
--- /dev/null
+++ b/app/core/gimpbrushpipe-save.c
@@ -0,0 +1,59 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 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 3 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, see <https://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <gdk-pixbuf/gdk-pixbuf.h>
+
+#include "core-types.h"
+
+#include "gimpbrushpipe.h"
+#include "gimpbrushpipe-save.h"
+
+
+gboolean
+gimp_brush_pipe_save (GimpData *data,
+ GOutputStream *output,
+ GError **error)
+{
+ GimpBrushPipe *pipe = GIMP_BRUSH_PIPE (data);
+ const gchar *name;
+ gint i;
+
+ name = gimp_object_get_name (pipe);
+
+ if (! g_output_stream_printf (output, NULL, NULL, error,
+ "%s\n%d %s\n",
+ name, pipe->n_brushes, pipe->params))
+ {
+ return FALSE;
+ }
+
+ for (i = 0; i < pipe->n_brushes; i++)
+ {
+ GimpBrush *brush = pipe->brushes[i];
+
+ if (brush &&
+ ! GIMP_DATA_GET_CLASS (brush)->save (GIMP_DATA (brush),
+ output, error))
+ {
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+}
diff --git a/app/core/gimpbrushpipe-save.h b/app/core/gimpbrushpipe-save.h
new file mode 100644
index 0000000000..df768555aa
--- /dev/null
+++ b/app/core/gimpbrushpipe-save.h
@@ -0,0 +1,28 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 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 3 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, see <https://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GIMP_BRUSH_PIPE_SAVE_H__
+#define __GIMP_BRUSH_PIPE_SAVE_H__
+
+
+/* don't call this function directly, use gimp_data_save() instead */
+gboolean gimp_brush_pipe_save (GimpData *data,
+ GOutputStream *output,
+ GError **error);
+
+
+#endif /* __GIMP_BRUSH_PIPE_SAVE_H__ */
diff --git a/app/core/gimpbrushpipe.c b/app/core/gimpbrushpipe.c
index 75e54cf0c9..db02feee51 100644
--- a/app/core/gimpbrushpipe.c
+++ b/app/core/gimpbrushpipe.c
@@ -28,28 +28,34 @@
#include "gimpbrush-private.h"
#include "gimpbrushpipe.h"
#include "gimpbrushpipe-load.h"
+#include "gimpbrushpipe-save.h"
+#include "gimptempbuf.h"
-static void gimp_brush_pipe_finalize (GObject *object);
+static void gimp_brush_pipe_finalize (GObject *object);
-static gint64 gimp_brush_pipe_get_memsize (GimpObject *object,
- gint64 *gui_size);
+static gint64 gimp_brush_pipe_get_memsize (GimpObject *object,
+ gint64 *gui_size);
-static gboolean gimp_brush_pipe_get_popup_size (GimpViewable *viewable,
- gint width,
- gint height,
- gboolean dot_for_dot,
- gint *popup_width,
- gint *popup_height);
+static gboolean gimp_brush_pipe_get_popup_size (GimpViewable *viewable,
+ gint width,
+ gint height,
+ gboolean dot_for_dot,
+ gint *popup_width,
+ gint *popup_height);
-static void gimp_brush_pipe_begin_use (GimpBrush *brush);
-static void gimp_brush_pipe_end_use (GimpBrush *brush);
-static GimpBrush * gimp_brush_pipe_select_brush (GimpBrush *brush,
- const GimpCoords *last_coords,
- const GimpCoords *current_coords);
-static gboolean gimp_brush_pipe_want_null_motion (GimpBrush *brush,
- const GimpCoords *last_coords,
- const GimpCoords *current_coords);
+static const gchar * gimp_brush_pipe_get_extension (GimpData *data);
+static void gimp_brush_pipe_copy (GimpData *data,
+ GimpData *src_data);
+
+static void gimp_brush_pipe_begin_use (GimpBrush *brush);
+static void gimp_brush_pipe_end_use (GimpBrush *brush);
+static GimpBrush * gimp_brush_pipe_select_brush (GimpBrush *brush,
+ const GimpCoords *last_coords,
+ const GimpCoords *current_coords);
+static gboolean gimp_brush_pipe_want_null_motion (GimpBrush *brush,
+ const GimpCoords *last_coords,
+ const GimpCoords *current_coords);
G_DEFINE_TYPE (GimpBrushPipe, gimp_brush_pipe, GIMP_TYPE_BRUSH);
@@ -72,8 +78,9 @@ gimp_brush_pipe_class_init (GimpBrushPipeClass *klass)
viewable_class->get_popup_size = gimp_brush_pipe_get_popup_size;
- data_class->save = NULL; /* don't inherit */
- data_class->copy = NULL; /* don't inherit */
+ data_class->save = gimp_brush_pipe_save;
+ data_class->get_extension = gimp_brush_pipe_get_extension;
+ data_class->copy = gimp_brush_pipe_copy;
brush_class->begin_use = gimp_brush_pipe_begin_use;
brush_class->end_use = gimp_brush_pipe_end_use;
@@ -154,6 +161,69 @@ gimp_brush_pipe_get_popup_size (GimpViewable *viewable,
return gimp_viewable_get_size (viewable, popup_width, popup_height);
}
+static const gchar *
+gimp_brush_pipe_get_extension (GimpData *data)
+{
+ return GIMP_BRUSH_PIPE_FILE_EXTENSION;
+}
+
+static void
+gimp_brush_pipe_copy (GimpData *data,
+ GimpData *src_data)
+{
+ GimpBrushPipe *pipe = GIMP_BRUSH_PIPE (data);
+ GimpBrushPipe *src_pipe = GIMP_BRUSH_PIPE (src_data);
+ gint i;
+
+ pipe->dimension = src_pipe->dimension;
+
+ g_clear_pointer (&pipe->rank, g_free);
+ pipe->rank = g_memdup (src_pipe->rank,
+ pipe->dimension * sizeof (gint));
+
+ g_clear_pointer (&pipe->stride, g_free);
+ pipe->stride = g_memdup (src_pipe->stride,
+ pipe->dimension * sizeof (gint));
+
+ g_clear_pointer (&pipe->select, g_free);
+ pipe->select = g_memdup (src_pipe->select,
+ pipe->dimension * sizeof (PipeSelectModes));
+
+ g_clear_pointer (&pipe->index, g_free);
+ pipe->index = g_memdup (src_pipe->index,
+ pipe->dimension * sizeof (gint));
+
+ for (i = 0; i < pipe->n_brushes; i++)
+ if (pipe->brushes[i])
+ g_object_unref (pipe->brushes[i]);
+ g_clear_pointer (&pipe->brushes, g_free);
+
+ pipe->n_brushes = src_pipe->n_brushes;
+
+ pipe->brushes = g_new0 (GimpBrush *, pipe->n_brushes);
+ for (i = 0; i < pipe->n_brushes; i++)
+ if (src_pipe->brushes[i])
+ {
+ pipe->brushes[i] =
+ GIMP_BRUSH (gimp_data_duplicate (GIMP_DATA (src_pipe->brushes[i])));
+ gimp_object_set_name (GIMP_OBJECT (pipe->brushes[i]),
+ gimp_object_get_name (src_pipe->brushes[i]));
+ }
+
+ g_clear_pointer (&pipe->params, g_free);
+ pipe->params = g_strdup (src_pipe->params);
+
+ pipe->current = pipe->brushes[0];
+
+ GIMP_BRUSH (pipe)->priv->spacing = pipe->current->priv->spacing;
+ GIMP_BRUSH (pipe)->priv->x_axis = pipe->current->priv->x_axis;
+ GIMP_BRUSH (pipe)->priv->y_axis = pipe->current->priv->y_axis;
+ GIMP_BRUSH (pipe)->priv->mask = pipe->current->priv->mask;
+ GIMP_BRUSH (pipe)->priv->pixmap = pipe->current->priv->pixmap;
+
+ gimp_data_dirty (data);
+}
+
static void
gimp_brush_pipe_begin_use (GimpBrush *brush)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]