mirror of https://github.com/GNOME/gimp.git
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.
This commit is contained in:
parent
e986310e3e
commit
a16fc33c43
|
@ -20,6 +20,8 @@ libappvectors_a_SOURCES = \
|
|||
vectors-types.h \
|
||||
gimpanchor.c \
|
||||
gimpanchor.h \
|
||||
gimpbezierdesc.h \
|
||||
gimpbezierdesc.c \
|
||||
gimpbezierstroke.h \
|
||||
gimpbezierstroke.c \
|
||||
gimpstroke.h \
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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__ */
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue