aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/Pillow/py2/outline.c
blob: 25e63aeaf56d8927a7bb1509239c37f0b0f197ac (plain) (blame)
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
191
192
/*
 * 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;

    if (PyType_Ready(&OutlineType) < 0)
        return NULL;

    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_INCREF(Py_None);
    return Py_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_INCREF(Py_None);
    return Py_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_INCREF(Py_None);
    return Py_None;
}

static PyObject*
_outline_close(OutlineObject* self, PyObject* args)
{
    if (!PyArg_ParseTuple(args, ":close"))
        return NULL;

    ImagingOutlineClose(self->outline);

    Py_INCREF(Py_None);
    return Py_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_INCREF(Py_None);
    return Py_None;
}

static struct PyMethodDef _outline_methods[] = {
    {"line", (PyCFunction)_outline_line, 1},
    {"curve", (PyCFunction)_outline_curve, 1},
    {"move", (PyCFunction)_outline_move, 1},
    {"close", (PyCFunction)_outline_close, 1},
    {"transform", (PyCFunction)_outline_transform, 1},
    {NULL, NULL} /* sentinel */
};

static PyTypeObject OutlineType = {
	PyVarObject_HEAD_INIT(NULL, 0)
	"Outline",			/*tp_name*/
	sizeof(OutlineObject),		/*tp_size*/
	0,				/*tp_itemsize*/
	/* methods */
	(destructor)_outline_dealloc,	/*tp_dealloc*/
	0,				/*tp_print*/
    0,                          /*tp_getattr*/
    0,                          /*tp_setattr*/
    0,                          /*tp_compare*/
    0,                          /*tp_repr*/
    0,                          /*tp_as_number */
    0,                          /*tp_as_sequence */
    0,                          /*tp_as_mapping */
    0,                          /*tp_hash*/
    0,                          /*tp_call*/
    0,                          /*tp_str*/
    0,                          /*tp_getattro*/
    0,                          /*tp_setattro*/
    0,                          /*tp_as_buffer*/
    Py_TPFLAGS_DEFAULT,         /*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*/
    0,                          /*tp_members*/
    0,                          /*tp_getset*/
};