2010-07-31 06:52:47 +04:00
|
|
|
/*
|
|
|
|
* 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"
|
|
|
|
|
2020-09-16 08:10:28 +03:00
|
|
|
#include "libImaging/Imaging.h"
|
2010-07-31 06:52:47 +04:00
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
2020-05-01 15:08:57 +03:00
|
|
|
/* Class */
|
2010-07-31 06:52:47 +04:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
PyObject_HEAD ImagingOutline outline;
|
|
|
|
} OutlineObject;
|
|
|
|
|
2012-10-13 20:53:07 +04:00
|
|
|
static PyTypeObject OutlineType;
|
2010-07-31 06:52:47 +04:00
|
|
|
|
2012-10-13 20:53:07 +04:00
|
|
|
#define PyOutline_Check(op) (Py_TYPE(op) == &OutlineType)
|
2010-07-31 06:52:47 +04:00
|
|
|
|
|
|
|
static OutlineObject *
|
|
|
|
_outline_new(void) {
|
|
|
|
OutlineObject *self;
|
|
|
|
|
2020-05-10 12:56:36 +03:00
|
|
|
if (PyType_Ready(&OutlineType) < 0) {
|
2012-10-13 20:53:07 +04:00
|
|
|
return NULL;
|
2020-05-10 12:56:36 +03:00
|
|
|
}
|
2012-10-13 20:53:07 +04:00
|
|
|
|
2010-07-31 06:52:47 +04:00
|
|
|
self = PyObject_New(OutlineObject, &OutlineType);
|
2020-05-10 12:56:36 +03:00
|
|
|
if (self == NULL) {
|
2020-05-01 15:08:57 +03:00
|
|
|
return NULL;
|
2020-05-10 12:56:36 +03:00
|
|
|
}
|
2010-07-31 06:52:47 +04:00
|
|
|
|
|
|
|
self->outline = ImagingOutlineNew();
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_outline_dealloc(OutlineObject *self) {
|
|
|
|
ImagingOutlineDelete(self->outline);
|
|
|
|
PyObject_Del(self);
|
|
|
|
}
|
|
|
|
|
|
|
|
ImagingOutline
|
|
|
|
PyOutline_AsOutline(PyObject *outline) {
|
2020-05-10 12:56:36 +03:00
|
|
|
if (PyOutline_Check(outline)) {
|
2010-07-31 06:52:47 +04:00
|
|
|
return ((OutlineObject *)outline)->outline;
|
2020-05-10 12:56:36 +03:00
|
|
|
}
|
2010-07-31 06:52:47 +04:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
2020-05-01 15:08:57 +03:00
|
|
|
/* Factories */
|
2010-07-31 06:52:47 +04:00
|
|
|
|
|
|
|
PyObject *
|
|
|
|
PyOutline_Create(PyObject *self, PyObject *args) {
|
2020-05-10 12:56:36 +03:00
|
|
|
if (!PyArg_ParseTuple(args, ":outline")) {
|
2010-07-31 06:52:47 +04:00
|
|
|
return NULL;
|
2020-05-10 12:56:36 +03:00
|
|
|
}
|
2010-07-31 06:52:47 +04:00
|
|
|
|
|
|
|
return (PyObject *)_outline_new();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
2020-05-01 15:08:57 +03:00
|
|
|
/* Methods */
|
2010-07-31 06:52:47 +04:00
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_outline_move(OutlineObject *self, PyObject *args) {
|
|
|
|
float x0, y0;
|
2020-05-10 12:56:36 +03:00
|
|
|
if (!PyArg_ParseTuple(args, "ff", &x0, &y0)) {
|
2020-05-01 15:08:57 +03:00
|
|
|
return NULL;
|
2020-05-10 12:56:36 +03:00
|
|
|
}
|
2010-07-31 06:52:47 +04:00
|
|
|
|
|
|
|
ImagingOutlineMove(self->outline, x0, y0);
|
|
|
|
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_outline_line(OutlineObject *self, PyObject *args) {
|
|
|
|
float x1, y1;
|
2020-05-10 12:56:36 +03:00
|
|
|
if (!PyArg_ParseTuple(args, "ff", &x1, &y1)) {
|
2020-05-01 15:08:57 +03:00
|
|
|
return NULL;
|
2020-05-10 12:56:36 +03:00
|
|
|
}
|
2010-07-31 06:52:47 +04:00
|
|
|
|
|
|
|
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;
|
2020-05-10 12:56:36 +03:00
|
|
|
if (!PyArg_ParseTuple(args, "ffffff", &x1, &y1, &x2, &y2, &x3, &y3)) {
|
2020-05-01 15:08:57 +03:00
|
|
|
return NULL;
|
2020-05-10 12:56:36 +03:00
|
|
|
}
|
2010-07-31 06:52:47 +04:00
|
|
|
|
|
|
|
ImagingOutlineCurve(self->outline, x1, y1, x2, y2, x3, y3);
|
|
|
|
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_outline_close(OutlineObject *self, PyObject *args) {
|
2020-05-10 12:56:36 +03:00
|
|
|
if (!PyArg_ParseTuple(args, ":close")) {
|
2010-07-31 06:52:47 +04:00
|
|
|
return NULL;
|
2020-05-10 12:56:36 +03:00
|
|
|
}
|
2010-07-31 06:52:47 +04:00
|
|
|
|
|
|
|
ImagingOutlineClose(self->outline);
|
|
|
|
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_outline_transform(OutlineObject *self, PyObject *args) {
|
|
|
|
double a[6];
|
2020-05-10 12:56:36 +03:00
|
|
|
if (!PyArg_ParseTuple(args, "(dddddd)", a + 0, a + 1, a + 2, a + 3, a + 4, a + 5)) {
|
2010-07-31 06:52:47 +04:00
|
|
|
return NULL;
|
2020-05-10 12:56:36 +03:00
|
|
|
}
|
2010-07-31 06:52:47 +04:00
|
|
|
|
|
|
|
ImagingOutlineTransform(self->outline, a);
|
|
|
|
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct PyMethodDef _outline_methods[] = {
|
2021-05-11 13:16:44 +03:00
|
|
|
{"line", (PyCFunction)_outline_line, METH_VARARGS},
|
|
|
|
{"curve", (PyCFunction)_outline_curve, METH_VARARGS},
|
|
|
|
{"move", (PyCFunction)_outline_move, METH_VARARGS},
|
|
|
|
{"close", (PyCFunction)_outline_close, METH_VARARGS},
|
|
|
|
{"transform", (PyCFunction)_outline_transform, METH_VARARGS},
|
2010-07-31 06:52:47 +04:00
|
|
|
{NULL, NULL} /* sentinel */
|
|
|
|
};
|
|
|
|
|
2012-10-13 20:53:07 +04:00
|
|
|
static PyTypeObject OutlineType = {
|
2020-05-01 15:08:57 +03:00
|
|
|
PyVarObject_HEAD_INIT(NULL, 0) "Outline", /*tp_name*/
|
2023-07-02 08:52:08 +03:00
|
|
|
sizeof(OutlineObject), /*tp_basicsize*/
|
2020-05-01 15:08:57 +03:00
|
|
|
0, /*tp_itemsize*/
|
|
|
|
/* methods */
|
|
|
|
(destructor)_outline_dealloc, /*tp_dealloc*/
|
2023-07-02 08:52:08 +03:00
|
|
|
0, /*tp_vectorcall_offset*/
|
2020-05-01 15:08:57 +03:00
|
|
|
0, /*tp_getattr*/
|
|
|
|
0, /*tp_setattr*/
|
2023-07-02 08:52:08 +03:00
|
|
|
0, /*tp_as_async*/
|
2020-05-01 15:08:57 +03:00
|
|
|
0, /*tp_repr*/
|
2023-07-02 08:52:08 +03:00
|
|
|
0, /*tp_as_number*/
|
|
|
|
0, /*tp_as_sequence*/
|
|
|
|
0, /*tp_as_mapping*/
|
2020-05-01 15:08:57 +03:00
|
|
|
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*/
|
2010-07-31 06:52:47 +04:00
|
|
|
};
|