mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Use GIF files for effects (#477)
* Add new Effects * add schema file for gif based effects * add background color to snake effect * add background color to snake effect * Update schema file for snake effect * Add function getImage * add function getImage * optimize lights.gif * Add format to GIF schema
This commit is contained in:
committed by
brindosch
parent
838008568a
commit
9cc6c75633
@@ -14,6 +14,8 @@
|
||||
#include <QConicalGradient>
|
||||
#include <QRadialGradient>
|
||||
#include <QRect>
|
||||
#include <QImageReader>
|
||||
#include <QResource>
|
||||
|
||||
// effect engin eincludes
|
||||
#include "Effect.h"
|
||||
@@ -24,6 +26,7 @@
|
||||
PyMethodDef Effect::effectMethods[] = {
|
||||
{"setColor" , Effect::wrapSetColor , METH_VARARGS, "Set a new color for the leds."},
|
||||
{"setImage" , Effect::wrapSetImage , METH_VARARGS, "Set a new image to process and determine new led colors."},
|
||||
{"getImage" , Effect::wrapGetImage , METH_VARARGS, "get image data from file."},
|
||||
{"abort" , Effect::wrapAbort , METH_NOARGS, "Check if the effect should abort execution."},
|
||||
{"imageShow" , Effect::wrapImageShow , METH_VARARGS, "set current effect image to hyperion core."},
|
||||
{"imageLinearGradient" , Effect::wrapImageLinearGradient , METH_VARARGS, ""},
|
||||
@@ -465,6 +468,85 @@ PyObject* Effect::wrapSetImage(PyObject *self, PyObject *args)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PyObject* Effect::wrapGetImage(PyObject *self, PyObject *args)
|
||||
{
|
||||
Q_INIT_RESOURCE(EffectEngine);
|
||||
|
||||
char *source;
|
||||
if(!PyArg_ParseTuple(args, "s", &source))
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "String required");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
QString file = QString::fromUtf8(source);
|
||||
|
||||
if (file.mid(0, 1) == ":")
|
||||
file = ":/effects/"+file.mid(1);
|
||||
|
||||
QImageReader reader(file);
|
||||
|
||||
PyObject* prop;
|
||||
static PyObject* imageClass = NULL;
|
||||
|
||||
if (imageClass == NULL)
|
||||
imageClass = PyClass_New(NULL, PyDict_New(), PyString_FromString("ImageClass"));
|
||||
|
||||
if (reader.canRead())
|
||||
{
|
||||
PyObject* result = PyList_New(reader.imageCount());
|
||||
|
||||
for (int i = 0; i < reader.imageCount(); ++i)
|
||||
{
|
||||
reader.jumpToImage(i);
|
||||
if (reader.canRead())
|
||||
{
|
||||
QImage qimage = reader.read();
|
||||
PyObject* imageDict = PyDict_New();
|
||||
|
||||
int width = qimage.width();
|
||||
int height = qimage.height();
|
||||
|
||||
prop = Py_BuildValue("i", width);
|
||||
PyDict_SetItemString(imageDict, "imageWidth", prop);
|
||||
Py_XDECREF(prop);
|
||||
prop = Py_BuildValue("i", height);
|
||||
PyDict_SetItemString(imageDict, "imageHeight", prop);
|
||||
Py_XDECREF(prop);
|
||||
|
||||
QByteArray binaryImage;
|
||||
for (int i = 0; i<height; ++i)
|
||||
{
|
||||
const QRgb * scanline = reinterpret_cast<const QRgb *>(qimage.scanLine(i));
|
||||
for (int j = 0; j< width; ++j)
|
||||
{
|
||||
binaryImage.append((char) qRed(scanline[j]));
|
||||
binaryImage.append((char) qGreen(scanline[j]));
|
||||
binaryImage.append((char) qBlue(scanline[j]));
|
||||
}
|
||||
}
|
||||
|
||||
prop = Py_BuildValue("O", PyByteArray_FromStringAndSize(binaryImage.constData(),binaryImage.size()));
|
||||
PyDict_SetItemString(imageDict, "imageData", prop);
|
||||
Py_XDECREF(prop);
|
||||
|
||||
PyList_SET_ITEM(result, i, Py_BuildValue("O", PyInstance_NewRaw(imageClass, imageDict)));
|
||||
}
|
||||
else
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, reader.errorString().toUtf8().constData());
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, reader.errorString().toUtf8().constData());
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
PyObject* Effect::wrapAbort(PyObject *self, PyObject *)
|
||||
{
|
||||
Effect * effect = getEffect();
|
||||
|
@@ -46,6 +46,7 @@ private:
|
||||
static PyMethodDef effectMethods[];
|
||||
static PyObject* wrapSetColor (PyObject *self, PyObject *args);
|
||||
static PyObject* wrapSetImage (PyObject *self, PyObject *args);
|
||||
static PyObject* wrapGetImage (PyObject *self, PyObject *args);
|
||||
static PyObject* wrapAbort (PyObject *self, PyObject *args);
|
||||
static PyObject* wrapImageShow (PyObject *self, PyObject *args);
|
||||
static PyObject* wrapImageLinearGradient (PyObject *self, PyObject *args);
|
||||
|
Reference in New Issue
Block a user