From 5daf079d0905d445e5de64a19b552e288bef0222 Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Sun, 28 Apr 2019 14:09:18 +0300 Subject: [PATCH] trying to get a qpixmap from libkcardgame. --- kcardgame/Makefile | 7 +++ kcardgame/kcardgame.cpp | 89 +++++++++++++++++++++++++++++++++++++++ kcardgame/kcardgame.hpp | 10 +++++ pysollib/ui/tktile/svg.py | 2 +- 4 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 kcardgame/Makefile create mode 100644 kcardgame/kcardgame.cpp create mode 100644 kcardgame/kcardgame.hpp diff --git a/kcardgame/Makefile b/kcardgame/Makefile new file mode 100644 index 00000000..b36124ad --- /dev/null +++ b/kcardgame/Makefile @@ -0,0 +1,7 @@ +# ---- Link --------------------------- +kcardgame.so: kcardgame.o Makefile + gcc -shared -o kcardgame.so kcardgame.o `pkg-config --libs python3` + +# ---- gcc C compile ------------------ +kcardgame.o: kcardgame.cpp kcardgame.hpp Makefile + gcc `pkg-config --cflags Qt5Gui` -I build-kpat/libkcardgame/ -I kpat/libkcardgame/include -I kpat/libkcardgame/ -g -fPIC -c kcardgame.cpp -I /usr/include/python3.7m/ -I /usr/lib64/python3.7/site-packages/numpy/core/include/numpy diff --git a/kcardgame/kcardgame.cpp b/kcardgame/kcardgame.cpp new file mode 100644 index 00000000..3cd45448 --- /dev/null +++ b/kcardgame/kcardgame.cpp @@ -0,0 +1,89 @@ +/* A file to test imorting C modules for handling arrays to Python */ + +#include "Python.h" +#include "arrayobject.h" +#include "kcardgame.hpp" +#include + +/* #### Globals #################################### */ + +/* ==== Set up the methods table ====================== */ +static struct PyMethodDef _kcardgameMethods[] = { + {"np_kcardgame", np_kcardgame, METH_VARARGS, "kcardgame"}, + {NULL, NULL, 0, NULL} /* Sentinel - marks the end of this structure */ +}; + +static struct PyModuleDef _kcardgame_mod = { + PyModuleDef_HEAD_INIT, + "_kcardgame", + NULL, + -1, + _kcardgameMethods + }; + + +/* ==== Initialize the C_test functions ====================== */ +// Module name must be _kcardgame in compile and linked +PyMODINIT_FUNC +PyInit_kcardgame() { + PyObject* ret = PyModule_Create(&_kcardgame_mod); + import_array(); // Must be present for NumPy. Called first after above line. + return ret; +} + +/* ==== Create 1D Carray from PyArray ====================== + Assumes PyArray is contiguous in memory. */ +static inline uint64_t *pyvector_to_Carrayptrs(PyArrayObject *arrayin) { + return (uint64_t *) arrayin->data; /* pointer to arrayin data as double */ +} + +int my_kcardgame( + const uint64_t *const cin, + const size_t n) +{ + unsigned __int128 sum = 0; + /* Operate on the vectors */ + for ( size_t i=0; idescr->type_num != NPY_UINT64 || vec->nd != 1) { + PyErr_SetString(PyExc_ValueError, + "In not_doublevector: array must be of type uint644 and 1 dimensional (n)."); + return 1; } + return 0; +} + +/* #### Matrix Extensions ############################## */ + diff --git a/kcardgame/kcardgame.hpp b/kcardgame/kcardgame.hpp new file mode 100644 index 00000000..ab69ea83 --- /dev/null +++ b/kcardgame/kcardgame.hpp @@ -0,0 +1,10 @@ +/* Header to test of C modules for arrays for Python: C_test.c */ + +/* ==== Prototypes =================================== */ + +// .... Python callable Vector functions .................. +static PyObject *np_kcardgame(PyObject *self, PyObject *args); + +/* .... C vector utility functions ..................*/ +PyArrayObject *pyvector(PyObject *objin); +int not_doublevector(PyArrayObject *vec); diff --git a/pysollib/ui/tktile/svg.py b/pysollib/ui/tktile/svg.py index 50c4bed5..6bbec4aa 100644 --- a/pysollib/ui/tktile/svg.py +++ b/pysollib/ui/tktile/svg.py @@ -25,6 +25,7 @@ class SVGManager: # Taken from https://stackoverflow.com/questions/44471795 # Under MIT License - thanks. + @pysnooper.snoop() def pixbuf2image(self, pxb): """ Convert GdkPixbuf.Pixbuf to PIL image """ data = pxb.get_pixels() @@ -37,7 +38,6 @@ class SVGManager: img = Image.frombytes(mode, (w, h), data, "raw", mode, stride) return img - @pysnooper.snoop() def render_fragment(self, id_, width, height): id__ = '#' + id_ """docstring for render_"""