aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/matplotlib/py2/src/_backend_gdk.c
diff options
context:
space:
mode:
authormaxim-yurchuk <maxim-yurchuk@yandex-team.com>2024-10-09 12:29:46 +0300
committermaxim-yurchuk <maxim-yurchuk@yandex-team.com>2024-10-09 13:14:22 +0300
commit9731d8a4bb7ee2cc8554eaf133bb85498a4c7d80 (patch)
treea8fb3181d5947c0d78cf402aa56e686130179049 /contrib/python/matplotlib/py2/src/_backend_gdk.c
parenta44b779cd359f06c3ebbef4ec98c6b38609d9d85 (diff)
downloadydb-9731d8a4bb7ee2cc8554eaf133bb85498a4c7d80.tar.gz
publishFullContrib: true for ydb
<HIDDEN_URL> commit_hash:c82a80ac4594723cebf2c7387dec9c60217f603e
Diffstat (limited to 'contrib/python/matplotlib/py2/src/_backend_gdk.c')
-rw-r--r--contrib/python/matplotlib/py2/src/_backend_gdk.c72
1 files changed, 72 insertions, 0 deletions
diff --git a/contrib/python/matplotlib/py2/src/_backend_gdk.c b/contrib/python/matplotlib/py2/src/_backend_gdk.c
new file mode 100644
index 0000000000..8314219cca
--- /dev/null
+++ b/contrib/python/matplotlib/py2/src/_backend_gdk.c
@@ -0,0 +1,72 @@
+/* -*- mode: C; c-basic-offset: 4 -*-
+ * C extensions for backend_gdk
+ */
+
+#include "Python.h"
+#include "numpy/arrayobject.h"
+
+#include <pygtk/pygtk.h>
+
+static PyTypeObject *_PyGdkPixbuf_Type;
+#define PyGdkPixbuf_Type (*_PyGdkPixbuf_Type)
+
+static PyObject *pixbuf_get_pixels_array(PyObject *self, PyObject *args)
+{
+ /* 1) read in Python pixbuf, get the underlying gdk_pixbuf */
+ PyGObject *py_pixbuf;
+ GdkPixbuf *gdk_pixbuf;
+ PyArrayObject *array;
+ npy_intp dims[3] = { 0, 0, 3 };
+ npy_intp strides[3];
+
+ if (!PyArg_ParseTuple(args, "O!:pixbuf_get_pixels_array", &PyGdkPixbuf_Type, &py_pixbuf))
+ return NULL;
+
+ gdk_pixbuf = GDK_PIXBUF(py_pixbuf->obj);
+
+ /* 2) same as pygtk/gtk/gdk.c _wrap_gdk_pixbuf_get_pixels_array()
+ * with 'self' changed to py_pixbuf
+ */
+
+ dims[0] = gdk_pixbuf_get_height(gdk_pixbuf);
+ dims[1] = gdk_pixbuf_get_width(gdk_pixbuf);
+ if (gdk_pixbuf_get_has_alpha(gdk_pixbuf))
+ dims[2] = 4;
+
+ strides[0] = gdk_pixbuf_get_rowstride(gdk_pixbuf);
+ strides[1] = dims[2];
+ strides[2] = 1;
+
+ array = (PyArrayObject*)
+ PyArray_New(&PyArray_Type, 3, dims, NPY_UBYTE, strides,
+ (void*)gdk_pixbuf_get_pixels(gdk_pixbuf), 1,
+ NPY_ARRAY_WRITEABLE, NULL);
+
+ if (array == NULL)
+ return NULL;
+
+ /* the array holds a ref to the pixbuf pixels through this wrapper*/
+ Py_INCREF(py_pixbuf);
+ if (PyArray_SetBaseObject(array, (PyObject *)py_pixbuf) == -1) {
+ Py_DECREF(py_pixbuf);
+ Py_DECREF(array);
+ return NULL;
+ }
+ return PyArray_Return(array);
+}
+
+static PyMethodDef _backend_gdk_functions[] = {
+ { "pixbuf_get_pixels_array", (PyCFunction)pixbuf_get_pixels_array, METH_VARARGS },
+ { NULL, NULL, 0 }
+};
+
+PyMODINIT_FUNC init_backend_gdk(void)
+{
+ PyObject *mod;
+ mod = Py_InitModule("matplotlib.backends._backend_gdk", _backend_gdk_functions);
+ import_array();
+ init_pygtk();
+
+ mod = PyImport_ImportModule("gtk.gdk");
+ _PyGdkPixbuf_Type = (PyTypeObject *)PyObject_GetAttrString(mod, "Pixbuf");
+}