-
Notifications
You must be signed in to change notification settings - Fork 0
/
outline.c
190 lines (149 loc) · 4.94 KB
/
outline.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*
* THIS IS WORK IN PROGRESS.
*
* The Python Imaging Library.
*
* "arrow" outline stuff. the contents of this module
* will be merged with the path module and the rest of
* the arrow graphics package, but not before PIL 1.1.
* use at your own risk.
*
* history:
* 99-01-10 fl Added to PIL (experimental)
*
* Copyright (c) Secret Labs AB 1999.
* Copyright (c) Fredrik Lundh 1999.
*
* See the README file for information on usage and redistribution.
*/
#include "Python.h"
#include "Imaging.h"
/* -------------------------------------------------------------------- */
/* Class */
typedef struct {
PyObject_HEAD
ImagingOutline outline;
} OutlineObject;
static PyTypeObject OutlineType;
#define PyOutline_Check(op) (Py_TYPE(op) == &OutlineType)
static OutlineObject*
_outline_new(void)
{
OutlineObject *self;
self = PyObject_New(OutlineObject, &OutlineType);
if (self == NULL)
return NULL;
self->outline = ImagingOutlineNew();
return self;
}
static void
_outline_dealloc(OutlineObject* self)
{
ImagingOutlineDelete(self->outline);
PyObject_Del(self);
}
ImagingOutline
PyOutline_AsOutline(PyObject* outline)
{
if (PyOutline_Check(outline))
return ((OutlineObject*)outline)->outline;
return NULL;
}
/* -------------------------------------------------------------------- */
/* Factories */
PyObject*
PyOutline_Create(PyObject* self, PyObject* args)
{
if (!PyArg_ParseTuple(args, ":outline"))
return NULL;
return (PyObject*)_outline_new();
}
/* -------------------------------------------------------------------- */
/* Methods */
static PyObject*
_outline_move(OutlineObject* self, PyObject* args)
{
float x0, y0;
if (!PyArg_ParseTuple(args, "ff", &x0, &y0))
return NULL;
ImagingOutlineMove(self->outline, x0, y0);
Py_RETURN_NONE;
}
static PyObject*
_outline_line(OutlineObject* self, PyObject* args)
{
float x1, y1;
if (!PyArg_ParseTuple(args, "ff", &x1, &y1))
return NULL;
ImagingOutlineLine(self->outline, x1, y1);
Py_RETURN_NONE;
}
static PyObject*
_outline_curve(OutlineObject* self, PyObject* args)
{
float x1, y1, x2, y2, x3, y3;
if (!PyArg_ParseTuple(args, "ffffff", &x1, &y1, &x2, &y2, &x3, &y3))
return NULL;
ImagingOutlineCurve(self->outline, x1, y1, x2, y2, x3, y3);
Py_RETURN_NONE;
}
static PyObject*
_outline_close(OutlineObject* self, PyObject* args)
{
if (!PyArg_ParseTuple(args, ":close"))
return NULL;
ImagingOutlineClose(self->outline);
Py_RETURN_NONE;
}
static PyObject*
_outline_transform(OutlineObject* self, PyObject* args)
{
double a[6];
if (!PyArg_ParseTuple(args, "(dddddd)", a+0, a+1, a+2, a+3, a+4, a+5))
return NULL;
ImagingOutlineTransform(self->outline, a);
Py_RETURN_NONE;
}
static struct PyMethodDef _outline_methods[] = {
{"line", (PyCFunction)_outline_line, METH_VARARGS,
"FIXME: _outline_line doc string"},
{"curve", (PyCFunction)_outline_curve, METH_VARARGS,
"FIXME: curve doc string"},
{"move", (PyCFunction)_outline_move, METH_VARARGS,
"FIXME: move doc string"},
{"close", (PyCFunction)_outline_close, METH_VARARGS,
"FIXME: close doc string"},
{"transform", (PyCFunction)_outline_transform, METH_VARARGS,
"FIXME: transform doc string"},
{NULL, NULL, 0, NULL} /* sentinel */
};
static PyTypeObject OutlineType = {
PyVarObject_HEAD_INIT(NULL, 0)
"Outline", /* tp_name */
sizeof(OutlineObject), /* tp_basicsize */
0, /* tp_itemsize */
(destructor)_outline_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_reserved */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
PyObject_GenericGetAttr, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
0, /* tp_flags */
0, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
_outline_methods /* tp_methods */
};