~ubuntu-branches/ubuntu/karmic/gimp/karmic-security

« back to all changes in this revision

Viewing changes to plug-ins/sel2path/curve.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2008-10-06 13:30:41 UTC
  • mfrom: (1.1.15 upstream)
  • Revision ID: james.westby@ubuntu.com-20081006133041-axco233xt49jobn7
Tags: 2.6.0-1ubuntu1
* Sync on debian and new version (lp: #276839)
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch:
  - updated some strings for ubuntu
* debian/rules:
  - updated translation templates

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* curve.c: operations on the lists of pixels and lists of curves.
2
 
 *
3
 
 * Copyright (C) 1992 Free Software Foundation, Inc.
4
 
 *
5
 
 * This program is free software; you can redistribute it and/or modify
6
 
 * it under the terms of the GNU General Public License as published by
7
 
 * the Free Software Foundation; either version 2, or (at your option)
8
 
 * any later version.
9
 
 *
10
 
 * This program is distributed in the hope that it will be useful,
11
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 * GNU General Public License for more details.
14
 
 *
15
 
 * You should have received a copy of the GNU General Public License
16
 
 * along with this program; if not, write to the Free Software
17
 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
 
 */
19
 
 
20
 
#include "config.h"
21
 
 
22
 
#include <glib.h>
23
 
 
24
 
#include "global.h"
25
 
#include "curve.h"
26
 
 
27
 
 
28
 
/* Return an entirely empty curve.  */
29
 
 
30
 
curve_type
31
 
new_curve (void)
32
 
{
33
 
  curve_type curve = g_new (struct curve, 1);
34
 
 
35
 
  curve->point_list = NULL;
36
 
  CURVE_LENGTH (curve) = 0;
37
 
  CURVE_CYCLIC (curve) = false;
38
 
  CURVE_START_TANGENT (curve) = CURVE_END_TANGENT (curve) = NULL;
39
 
  PREVIOUS_CURVE (curve) = NEXT_CURVE (curve) = NULL;
40
 
 
41
 
  return curve;
42
 
}
43
 
 
44
 
 
45
 
/* Start the returned curve off with COORD as the first point.  */
46
 
 
47
 
curve_type
48
 
init_curve (coordinate_type coord)
49
 
{
50
 
  curve_type curve = new_curve ();
51
 
 
52
 
  curve->point_list = g_new (point_type, 1);
53
 
  CURVE_LENGTH (curve) = 1;
54
 
 
55
 
  CURVE_POINT (curve, 0) = int_to_real_coord (coord);
56
 
 
57
 
  return curve;
58
 
}
59
 
 
60
 
 
61
 
/* Don't copy the points or tangents, but copy everything else.  */
62
 
 
63
 
curve_type
64
 
copy_most_of_curve (curve_type old_curve)
65
 
{
66
 
  curve_type curve = new_curve ();
67
 
 
68
 
  CURVE_CYCLIC (curve) = CURVE_CYCLIC (old_curve);
69
 
  PREVIOUS_CURVE (curve) = PREVIOUS_CURVE (old_curve);
70
 
  NEXT_CURVE (curve) = NEXT_CURVE (old_curve);
71
 
 
72
 
  return curve;
73
 
}
74
 
 
75
 
 
76
 
/* The length of CURVE will be zero if we ended up not being able to fit
77
 
   it (which in turn implies a problem elsewhere in the program, but at
78
 
   any rate, we shouldn't try here to free the nonexistent curve).  */
79
 
 
80
 
void
81
 
free_curve (curve_type curve)
82
 
{
83
 
  if (CURVE_LENGTH (curve) > 0)
84
 
    safe_free ((address *) &(curve->point_list));
85
 
}
86
 
 
87
 
 
88
 
void
89
 
append_pixel (curve_type curve, coordinate_type coord)
90
 
{
91
 
  append_point (curve, int_to_real_coord (coord));
92
 
}
93
 
 
94
 
 
95
 
void
96
 
append_point (curve_type curve, real_coordinate_type coord)
97
 
{
98
 
  CURVE_LENGTH (curve)++;
99
 
  curve->point_list = g_realloc (curve->point_list,CURVE_LENGTH (curve) * sizeof(point_type));
100
 
  LAST_CURVE_POINT (curve) = coord;
101
 
  /* The t value does not need to be set.  */
102
 
}
103
 
 
104
 
/* Return an initialized but empty curve list.  */
105
 
 
106
 
curve_list_type
107
 
new_curve_list (void)
108
 
{
109
 
  curve_list_type curve_list;
110
 
 
111
 
  curve_list.length    = 0;
112
 
  curve_list.data      = NULL;
113
 
  curve_list.clockwise = FALSE;
114
 
 
115
 
  return curve_list;
116
 
}
117
 
 
118
 
 
119
 
/* Free a curve list and all the curves it contains.  */
120
 
 
121
 
void
122
 
free_curve_list (curve_list_type *curve_list)
123
 
{
124
 
  unsigned this_curve;
125
 
 
126
 
  for (this_curve = 0; this_curve < curve_list->length; this_curve++)
127
 
    free_curve (curve_list->data[this_curve]);
128
 
 
129
 
  /* If the character was empty, it won't have any curves.  */
130
 
  if (curve_list->data != NULL)
131
 
    safe_free ((address *) &(curve_list->data));
132
 
}
133
 
 
134
 
 
135
 
/* Add an element to a curve list.  */
136
 
 
137
 
void
138
 
append_curve (curve_list_type *curve_list, curve_type curve)
139
 
{
140
 
  curve_list->length++;
141
 
  curve_list->data = g_realloc (curve_list->data,curve_list->length*sizeof(curve_type));
142
 
  curve_list->data[curve_list->length - 1] = curve;
143
 
}
144
 
 
145
 
 
146
 
/* Return an initialized but empty curve list array.  */
147
 
 
148
 
curve_list_array_type
149
 
new_curve_list_array (void)
150
 
{
151
 
  curve_list_array_type curve_list_array;
152
 
 
153
 
  CURVE_LIST_ARRAY_LENGTH (curve_list_array) = 0;
154
 
  curve_list_array.data = NULL;
155
 
 
156
 
  return curve_list_array;
157
 
}
158
 
 
159
 
 
160
 
/* Free a curve list array and all the curve lists it contains.  */
161
 
 
162
 
void
163
 
free_curve_list_array (curve_list_array_type *curve_list_array)
164
 
{
165
 
  unsigned this_list;
166
 
 
167
 
  for (this_list = 0; this_list < CURVE_LIST_ARRAY_LENGTH (*curve_list_array);
168
 
       this_list++)
169
 
    free_curve_list (&CURVE_LIST_ARRAY_ELT (*curve_list_array, this_list));
170
 
 
171
 
  /* If the character was empty, it won't have any curves.  */
172
 
  if (curve_list_array->data != NULL)
173
 
    safe_free ((address *) &(curve_list_array->data));
174
 
}
175
 
 
176
 
 
177
 
/* Add an element to a curve list array.  */
178
 
 
179
 
void
180
 
append_curve_list (curve_list_array_type *l, curve_list_type curve_list)
181
 
{
182
 
  CURVE_LIST_ARRAY_LENGTH (*l)++;
183
 
  l->data = g_realloc (l->data,( CURVE_LIST_ARRAY_LENGTH (*l))*sizeof(curve_list_type));
184
 
  LAST_CURVE_LIST_ARRAY_ELT (*l) = curve_list;
185
 
}