outline.c 5.1 KB

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