[gimp] app: add new() copy() and free() API around GimpBezierDesc
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: add new() copy() and free() API around GimpBezierDesc
- Date: Wed, 6 Oct 2010 20:39:40 +0000 (UTC)
commit a16fc33c43526ee1bec6f424ae1201820c54b7ae
Author: Michael Natterer <mitch gimp org>
Date: Wed Oct 6 22:37:07 2010 +0200
app: add new() copy() and free() API around GimpBezierDesc
and use it instead of manually (de)allocating. Will also be used in a
new canvas path item.
app/vectors/Makefile.am | 2 +
app/vectors/gimpbezierdesc.c | 79 ++++++++++++++++++++++++++++++++++++++++
app/vectors/gimpbezierdesc.h | 33 +++++++++++++++++
app/vectors/gimpbezierstroke.c | 8 ++---
app/vectors/gimpvectors.c | 16 +++-----
5 files changed, 123 insertions(+), 15 deletions(-)
---
diff --git a/app/vectors/Makefile.am b/app/vectors/Makefile.am
index eb2274b..51549ed 100644
--- a/app/vectors/Makefile.am
+++ b/app/vectors/Makefile.am
@@ -20,6 +20,8 @@ libappvectors_a_SOURCES = \
vectors-types.h \
gimpanchor.c \
gimpanchor.h \
+ gimpbezierdesc.h \
+ gimpbezierdesc.c \
gimpbezierstroke.h \
gimpbezierstroke.c \
gimpstroke.h \
diff --git a/app/vectors/gimpbezierdesc.c b/app/vectors/gimpbezierdesc.c
new file mode 100644
index 0000000..8d52f63
--- /dev/null
+++ b/app/vectors/gimpbezierdesc.c
@@ -0,0 +1,79 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * gimpbezierdesc.c
+ * Copyright (C) 2010 Michael Natterer <mitch gimp org>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <gegl.h>
+#include <cairo.h>
+
+#include "vectors-types.h"
+
+#include "gimpbezierdesc.h"
+
+
+GimpBezierDesc *
+gimp_bezier_desc_new (cairo_path_data_t *data,
+ gint n_data)
+{
+ GimpBezierDesc *desc;
+
+ g_return_val_if_fail (n_data == 0 || data != NULL, NULL);
+
+ desc = g_slice_new (GimpBezierDesc);
+
+ desc->status = CAIRO_STATUS_SUCCESS;
+ desc->num_data = n_data;
+ desc->data = data;
+
+ return desc;
+}
+
+GimpBezierDesc *
+gimp_bezier_desc_copy (const GimpBezierDesc *desc)
+{
+ g_return_val_if_fail (desc != NULL, NULL);
+
+ return gimp_bezier_desc_new (g_memdup (desc->data,
+ desc->num_data * sizeof (cairo_path_data_t)),
+ desc->num_data);
+}
+
+cairo_path_data_t *
+gimp_bezier_desc_free (GimpBezierDesc *desc,
+ gboolean free_data)
+{
+ cairo_path_data_t *data;
+
+ g_return_val_if_fail (desc != NULL, NULL);
+
+ if (free_data)
+ {
+ g_free (desc->data);
+ data = NULL;
+ }
+ else
+ {
+ data = desc->data;
+ }
+
+ g_slice_free (GimpBezierDesc, desc);
+
+ return data;
+}
diff --git a/app/vectors/gimpbezierdesc.h b/app/vectors/gimpbezierdesc.h
new file mode 100644
index 0000000..fbcacb9
--- /dev/null
+++ b/app/vectors/gimpbezierdesc.h
@@ -0,0 +1,33 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * gimpbezierdesc.h
+ * Copyright (C) 2010 Michael Natterer <mitch gimp org>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GIMP_BEZIER_DESC_H__
+#define __GIMP_BEZIER_DESC_H__
+
+
+/* takes ownership of "data" */
+GimpBezierDesc * gimp_bezier_desc_new (cairo_path_data_t *data,
+ gint n_data);
+GimpBezierDesc * gimp_bezier_desc_copy (const GimpBezierDesc *desc);
+cairo_path_data_t * gimp_bezier_desc_free (GimpBezierDesc *desc,
+ gboolean free_data);
+
+
+#endif /* __GIMP_BEZIER_DESC_H__ */
diff --git a/app/vectors/gimpbezierstroke.c b/app/vectors/gimpbezierstroke.c
index 5ba0e63..3efdfbe 100644
--- a/app/vectors/gimpbezierstroke.c
+++ b/app/vectors/gimpbezierstroke.c
@@ -31,6 +31,7 @@
#include "core/gimpcoords-interpolate.h"
#include "gimpanchor.h"
+#include "gimpbezierdesc.h"
#include "gimpbezierstroke.h"
@@ -1535,11 +1536,8 @@ gimp_bezier_stroke_make_bezier (const GimpStroke *stroke)
g_printerr ("miscalculated path cmd length! (%d vs. %d)\n",
cmd_array->len, num_cmds);
- bezdesc = g_slice_new (GimpBezierDesc);
- bezdesc->status = CAIRO_STATUS_SUCCESS;
- bezdesc->data = (cairo_path_data_t *) cmd_array->data;
- bezdesc->num_data = cmd_array->len;
-
+ bezdesc = gimp_bezier_desc_new ((cairo_path_data_t *) cmd_array->data,
+ cmd_array->len);
g_array_free (points, TRUE);
g_array_free (cmd_array, FALSE);
diff --git a/app/vectors/gimpvectors.c b/app/vectors/gimpvectors.c
index 8620ead..d578ed6 100644
--- a/app/vectors/gimpvectors.c
+++ b/app/vectors/gimpvectors.c
@@ -44,6 +44,7 @@
#include "paint/gimppaintoptions.h"
#include "gimpanchor.h"
+#include "gimpbezierdesc.c"
#include "gimpstroke.h"
#include "gimpvectors.h"
#include "gimpvectors-preview.h"
@@ -260,8 +261,7 @@ gimp_vectors_finalize (GObject *object)
if (vectors->bezier_desc)
{
- g_free (vectors->bezier_desc->data);
- g_slice_free (GimpBezierDesc, vectors->bezier_desc);
+ gimp_bezier_desc_free (vectors->bezier_desc, TRUE);
vectors->bezier_desc = NULL;
}
@@ -613,8 +613,7 @@ gimp_vectors_real_freeze (GimpVectors *vectors)
/* release cached bezier representation */
if (vectors->bezier_desc)
{
- g_free (vectors->bezier_desc->data);
- g_slice_free (GimpBezierDesc, vectors->bezier_desc);
+ gimp_bezier_desc_free (vectors->bezier_desc, TRUE);
vectors->bezier_desc = NULL;
}
@@ -1159,17 +1158,14 @@ gimp_vectors_real_make_bezier (const GimpVectors *vectors)
{
cmd_array = g_array_append_vals (cmd_array, bezdesc->data,
bezdesc->num_data);
- g_free (bezdesc->data);
- g_slice_free (GimpBezierDesc, bezdesc);
+ gimp_bezier_desc_free (bezdesc, TRUE);
}
}
if (cmd_array->len > 0)
{
- ret_bezdesc = g_slice_new (GimpBezierDesc);
- ret_bezdesc->status = CAIRO_STATUS_SUCCESS;
- ret_bezdesc->num_data = cmd_array->len;
- ret_bezdesc->data = (cairo_path_data_t *) cmd_array->data;
+ ret_bezdesc = gimp_bezier_desc_new ((cairo_path_data_t *) cmd_array->data,
+ cmd_array->len);
g_array_free (cmd_array, FALSE);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]