From 121f56ca32122d1098a8deab953b9cbd4afa34c2 Mon Sep 17 00:00:00 2001 From: johan Date: Fri, 29 Nov 2013 23:53:58 +0100 Subject: [PATCH] setImage implemented for the EffectEngine Former-commit-id: 81889cd77125979a06732a8e98e8b398891ec385 --- libsrc/effectengine/Effect.cpp | 64 +++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/libsrc/effectengine/Effect.cpp b/libsrc/effectengine/Effect.cpp index 51ec3249..7b52fabd 100644 --- a/libsrc/effectengine/Effect.cpp +++ b/libsrc/effectengine/Effect.cpp @@ -172,6 +172,7 @@ PyObject* Effect::wrapSetColor(PyObject *self, PyObject *args) PyObject* Effect::wrapSetImage(PyObject *self, PyObject *args) { + // get the effect Effect * effect = getEffect(self); // check if we have aborted already @@ -180,7 +181,68 @@ PyObject* Effect::wrapSetImage(PyObject *self, PyObject *args) return Py_BuildValue(""); } - return Py_BuildValue(""); + // determine the timeout + int timeout = effect->_timeout; + if (timeout > 0) + { + timeout = effect->_endTime - QDateTime::currentMSecsSinceEpoch(); + + // we are done if the time has passed + if (timeout <= 0) + { + return Py_BuildValue(""); + } + } + + // bytearray of values + int width, height; + PyObject * bytearray = nullptr; + if (PyArg_ParseTuple(args, "iiO", &width, &height, &bytearray)) + { + if (PyByteArray_Check(bytearray)) + { + int length = PyByteArray_Size(bytearray); + if (length == 3 * width * height) + { + Image image(width, height); + char * data = PyByteArray_AS_STRING(bytearray); + for (int y = 0; y < height; ++y) + { + for (int x = 0; x < width; ++x) + { + ColorRgb & color = image(x, y); + int index = x+width*y; + color.red = data [3*index]; + color.green = data [3*index+1]; + color.blue = data [3*index+2]; + } + } + + std::vector colors(effect->_imageProcessor->getLedCount()); + effect->_imageProcessor->process(image, colors); + effect->setColors(effect->_priority, colors, timeout); + return Py_BuildValue(""); + } + else + { + PyErr_SetString(PyExc_RuntimeError, "Length of bytearray argument should be 3*ledCount"); + return nullptr; + } + } + else + { + PyErr_SetString(PyExc_RuntimeError, "Argument 3 is not a bytearray"); + return nullptr; + } + } + else + { + return nullptr; + } + + // error + PyErr_SetString(PyExc_RuntimeError, "Unknown error"); + return nullptr; } PyObject* Effect::wrapAbort(PyObject *self, PyObject *)