diff --git a/effects/rainbow-mood.py b/effects/rainbow-mood.py index 622dfd8c..4f6c0255 100644 --- a/effects/rainbow-mood.py +++ b/effects/rainbow-mood.py @@ -3,7 +3,7 @@ import time import colorsys # Get the parameters -rotationTime = hyperion.args.get('rotation-time', 3.0) +rotationTime = hyperion.args.get('rotation-time', 30.0) brightness = hyperion.args.get('brightness', 1.0) saturation = hyperion.args.get('saturation', 1.0) reverse = hyperion.args.get('reverse', False) diff --git a/libsrc/effectengine/Effect.cpp b/libsrc/effectengine/Effect.cpp index 730287eb..497ca700 100644 --- a/libsrc/effectengine/Effect.cpp +++ b/libsrc/effectengine/Effect.cpp @@ -29,8 +29,11 @@ Effect::Effect(int priority, int timeout, const std::string & script, const Json _endTime(-1), _interpreterThreadState(nullptr), _abortRequested(false), - _imageProcessor(ImageProcessorFactory::getInstance().newImageProcessor()) + _imageProcessor(ImageProcessorFactory::getInstance().newImageProcessor()), + _colors() { + _colors.resize(_imageProcessor->getLedCount(), ColorRgb::BLACK); + // connect the finished signal connect(this, SIGNAL(finished()), this, SLOT(effectFinished())); } @@ -170,7 +173,8 @@ PyObject* Effect::wrapSetColor(PyObject *self, PyObject *args) ColorRgb color; if (PyArg_ParseTuple(args, "bbb", &color.red, &color.green, &color.blue)) { - effect->setColors(effect->_priority, std::vector(effect->_imageProcessor->getLedCount(), color), timeout); + std::fill(effect->_colors.begin(), effect->_colors.end(), color); + effect->setColors(effect->_priority, effect->_colors, timeout); return Py_BuildValue(""); } else @@ -189,16 +193,9 @@ PyObject* Effect::wrapSetColor(PyObject *self, PyObject *args) size_t length = PyByteArray_Size(bytearray); if (length == 3 * effect->_imageProcessor->getLedCount()) { - std::vector colors(effect->_imageProcessor->getLedCount()); char * data = PyByteArray_AS_STRING(bytearray); - for (size_t i = 0; i < colors.size(); ++i) - { - ColorRgb & color = colors[i]; - color.red = data [3*i]; - color.green = data [3*i+1]; - color.blue = data [3*i+2]; - } - effect->setColors(effect->_priority, colors, timeout); + memcpy(effect->_colors.data(), data, length); + effect->setColors(effect->_priority, effect->_colors, timeout); return Py_BuildValue(""); } else @@ -265,21 +262,10 @@ PyObject* Effect::wrapSetImage(PyObject *self, PyObject *args) { 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]; - } - } + memcpy(image.memptr(), data, length); - std::vector colors(effect->_imageProcessor->getLedCount()); - effect->_imageProcessor->process(image, colors); - effect->setColors(effect->_priority, colors, timeout); + effect->_imageProcessor->process(image, effect->_colors); + effect->setColors(effect->_priority, effect->_colors, timeout); return Py_BuildValue(""); } else @@ -307,13 +293,6 @@ PyObject* Effect::wrapSetImage(PyObject *self, PyObject *args) PyObject* Effect::wrapAbort(PyObject *self, PyObject *) { Effect * effect = getEffect(self); - return Py_BuildValue("i", effect->_abortRequested ? 1 : 0); -} - -Effect * Effect::getEffect(PyObject *self) -{ - // Get the effect from the capsule in the self pointer - Effect * effect = reinterpret_cast(PyCapsule_GetPointer(self, nullptr)); // Test if the effect has reached it end time if (effect->_timeout > 0 && QDateTime::currentMSecsSinceEpoch() > effect->_endTime) @@ -321,6 +300,11 @@ Effect * Effect::getEffect(PyObject *self) effect->_abortRequested = true; } - // return the effect - return effect; + return Py_BuildValue("i", effect->_abortRequested ? 1 : 0); +} + +Effect * Effect::getEffect(PyObject *self) +{ + // Get the effect from the capsule in the self pointer + return reinterpret_cast(PyCapsule_GetPointer(self, nullptr)); } diff --git a/libsrc/effectengine/Effect.h b/libsrc/effectengine/Effect.h index 765872b2..4f681a6e 100644 --- a/libsrc/effectengine/Effect.h +++ b/libsrc/effectengine/Effect.h @@ -61,4 +61,7 @@ private: /// The processor for translating images to led-values ImageProcessor * _imageProcessor; + + /// Buffer for colorData + std::vector _colors; };