2013-11-26 21:38:24 +01:00
|
|
|
// stl includes
|
2013-11-27 20:15:29 +01:00
|
|
|
#include <iostream>
|
2013-11-26 21:38:24 +01:00
|
|
|
#include <sstream>
|
2016-10-14 20:59:03 +02:00
|
|
|
#include <cmath>
|
2013-11-26 21:38:24 +01:00
|
|
|
|
2013-11-28 14:29:31 +01:00
|
|
|
// Qt includes
|
|
|
|
#include <QDateTime>
|
2016-09-13 11:51:16 +02:00
|
|
|
#include <QFile>
|
2016-09-21 22:01:50 +02:00
|
|
|
#include <Qt>
|
|
|
|
#include <QLinearGradient>
|
|
|
|
#include <QConicalGradient>
|
|
|
|
#include <QRadialGradient>
|
|
|
|
#include <QRect>
|
2017-10-12 12:00:32 +02:00
|
|
|
#include <QImageReader>
|
|
|
|
#include <QResource>
|
2013-11-28 14:29:31 +01:00
|
|
|
|
2013-11-26 21:38:24 +01:00
|
|
|
// effect engin eincludes
|
2013-11-24 16:10:48 +01:00
|
|
|
#include "Effect.h"
|
2016-06-23 13:48:49 +02:00
|
|
|
#include <utils/Logger.h>
|
2016-09-21 22:01:50 +02:00
|
|
|
#include <hyperion/Hyperion.h>
|
2013-11-24 16:10:48 +01:00
|
|
|
|
2013-11-28 14:15:52 +01:00
|
|
|
// Python method table
|
|
|
|
PyMethodDef Effect::effectMethods[] = {
|
2017-02-16 07:33:58 +01:00
|
|
|
{"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."},
|
2017-10-12 12:00:32 +02:00
|
|
|
{"getImage" , Effect::wrapGetImage , METH_VARARGS, "get image data from file."},
|
2017-02-16 07:33:58 +01:00
|
|
|
{"abort" , Effect::wrapAbort , METH_NOARGS, "Check if the effect should abort execution."},
|
2017-04-14 07:58:34 +02:00
|
|
|
{"imageShow" , Effect::wrapImageShow , METH_VARARGS, "set current effect image to hyperion core."},
|
2017-07-30 14:36:23 +02:00
|
|
|
{"imageLinearGradient" , Effect::wrapImageLinearGradient , METH_VARARGS, ""},
|
|
|
|
{"imageConicalGradient" , Effect::wrapImageConicalGradient , METH_VARARGS, ""},
|
2017-02-16 07:33:58 +01:00
|
|
|
{"imageRadialGradient" , Effect::wrapImageRadialGradient , METH_VARARGS, ""},
|
|
|
|
{"imageSolidFill" , Effect::wrapImageSolidFill , METH_VARARGS, ""},
|
|
|
|
{"imageDrawLine" , Effect::wrapImageDrawLine , METH_VARARGS, ""},
|
2017-07-30 14:36:23 +02:00
|
|
|
{"imageDrawPoint" , Effect::wrapImageDrawPoint , METH_VARARGS, ""},
|
2017-02-16 07:33:58 +01:00
|
|
|
{"imageDrawRect" , Effect::wrapImageDrawRect , METH_VARARGS, ""},
|
2017-07-30 14:36:23 +02:00
|
|
|
{"imageDrawPolygon" , Effect::wrapImageDrawPolygon , METH_VARARGS, ""},
|
|
|
|
{"imageDrawPie" , Effect::wrapImageDrawPie , METH_VARARGS, ""},
|
2017-02-16 07:33:58 +01:00
|
|
|
{"imageSetPixel" , Effect::wrapImageSetPixel , METH_VARARGS, "set pixel color of image"},
|
|
|
|
{"imageGetPixel" , Effect::wrapImageGetPixel , METH_VARARGS, "get pixel color of image"},
|
2017-04-14 07:58:34 +02:00
|
|
|
{"imageSave" , Effect::wrapImageSave , METH_NOARGS, "adds a new background image"},
|
2017-07-30 14:36:23 +02:00
|
|
|
{"imageMinSize" , Effect::wrapImageMinSize , METH_VARARGS, "sets minimal dimension of background image"},
|
2017-04-14 07:58:34 +02:00
|
|
|
{"imageWidth" , Effect::wrapImageWidth , METH_NOARGS, "gets image width"},
|
|
|
|
{"imageHeight" , Effect::wrapImageHeight , METH_NOARGS, "gets image height"},
|
2017-07-30 14:36:23 +02:00
|
|
|
{"imageCRotate" , Effect::wrapImageCRotate , METH_VARARGS, "rotate the coordinate system by given angle"},
|
|
|
|
{"imageCOffset" , Effect::wrapImageCOffset , METH_VARARGS, "Add offset to the coordinate system"},
|
|
|
|
{"imageCShear" , Effect::wrapImageCShear , METH_VARARGS, "Shear of coordinate system by the given horizontal/vertical axis"},
|
|
|
|
{"imageResetT" , Effect::wrapImageResetT , METH_NOARGS, "Resets all coords modifications (rotate,offset,shear)"},
|
2013-11-26 21:38:24 +01:00
|
|
|
{NULL, NULL, 0, NULL}
|
|
|
|
};
|
|
|
|
|
2017-10-13 17:49:29 +02:00
|
|
|
|
2014-02-26 18:10:17 +01:00
|
|
|
// create the hyperion module
|
|
|
|
struct PyModuleDef Effect::moduleDef = {
|
2014-03-01 19:28:57 +01:00
|
|
|
PyModuleDef_HEAD_INIT,
|
|
|
|
"hyperion", /* m_name */
|
|
|
|
"Hyperion module", /* m_doc */
|
|
|
|
-1, /* m_size */
|
|
|
|
Effect::effectMethods, /* m_methods */
|
|
|
|
NULL, /* m_reload */
|
|
|
|
NULL, /* m_traverse */
|
|
|
|
NULL, /* m_clear */
|
|
|
|
NULL, /* m_free */
|
2014-02-26 18:10:17 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
PyObject* Effect::PyInit_hyperion()
|
|
|
|
{
|
2014-03-01 19:28:57 +01:00
|
|
|
return PyModule_Create(&moduleDef);
|
2014-02-26 18:10:17 +01:00
|
|
|
}
|
2013-11-26 21:38:24 +01:00
|
|
|
|
2014-02-26 18:10:17 +01:00
|
|
|
void Effect::registerHyperionExtensionModule()
|
|
|
|
{
|
2014-03-01 19:28:57 +01:00
|
|
|
PyImport_AppendInittab("hyperion", &PyInit_hyperion);
|
2014-02-26 18:10:17 +01:00
|
|
|
}
|
|
|
|
|
2017-10-13 17:49:29 +02:00
|
|
|
Effect::Effect(PyThreadState* mainThreadState, int priority, int timeout, const QString & script, const QString & name, const QJsonObject & args, const QString & origin, unsigned smoothCfg)
|
2016-08-08 00:17:00 +02:00
|
|
|
: QThread()
|
2017-10-13 17:49:29 +02:00
|
|
|
, _mainThreadState(mainThreadState)
|
2016-08-08 00:17:00 +02:00
|
|
|
, _priority(priority)
|
|
|
|
, _timeout(timeout)
|
|
|
|
, _script(script)
|
2016-09-13 11:51:16 +02:00
|
|
|
, _name(name)
|
2017-08-04 12:01:45 +02:00
|
|
|
, _smoothCfg(smoothCfg)
|
2016-08-08 00:17:00 +02:00
|
|
|
, _args(args)
|
|
|
|
, _endTime(-1)
|
|
|
|
, _imageProcessor(ImageProcessorFactory::getInstance().newImageProcessor())
|
|
|
|
, _colors()
|
2017-03-01 15:23:53 +01:00
|
|
|
, _origin(origin)
|
2017-04-14 07:58:34 +02:00
|
|
|
, _imageSize(Hyperion::getInstance()->getLedGridSize())
|
2017-08-04 12:01:45 +02:00
|
|
|
, _image(_imageSize,QImage::Format_ARGB32_Premultiplied)
|
2013-11-24 16:10:48 +01:00
|
|
|
{
|
2017-04-14 07:58:34 +02:00
|
|
|
_colors.resize(_imageProcessor->getLedCount());
|
|
|
|
_colors.fill(ColorRgb::BLACK);
|
2013-12-08 12:46:33 +01:00
|
|
|
|
2017-10-12 11:55:03 +02:00
|
|
|
_log = Logger::getInstance("EFFECTENGINE");
|
|
|
|
|
2014-04-30 22:53:05 +02:00
|
|
|
// disable the black border detector for effects
|
2016-07-15 10:28:12 +02:00
|
|
|
_imageProcessor->enableBlackBorderDetector(false);
|
2017-10-12 11:55:03 +02:00
|
|
|
|
2016-09-21 22:01:50 +02:00
|
|
|
// init effect image for image based effects, size is based on led layout
|
2017-04-14 07:58:34 +02:00
|
|
|
_image.fill(Qt::black);
|
|
|
|
_painter = new QPainter(&_image);
|
2014-04-30 22:53:05 +02:00
|
|
|
|
2016-09-13 11:51:16 +02:00
|
|
|
Q_INIT_RESOURCE(EffectEngine);
|
2013-11-24 16:10:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Effect::~Effect()
|
|
|
|
{
|
2016-09-21 22:01:50 +02:00
|
|
|
delete _painter;
|
2017-04-14 07:58:34 +02:00
|
|
|
_imageStack.clear();
|
2013-11-24 16:10:48 +01:00
|
|
|
}
|
|
|
|
|
2013-11-26 21:38:24 +01:00
|
|
|
void Effect::run()
|
|
|
|
{
|
2017-10-13 17:49:29 +02:00
|
|
|
// get global lock
|
|
|
|
PyEval_RestoreThread(_mainThreadState);
|
2014-02-26 18:10:17 +01:00
|
|
|
|
2013-11-26 21:38:24 +01:00
|
|
|
// Initialize a new thread state
|
2017-10-13 17:49:29 +02:00
|
|
|
PyThreadState* tstate = Py_NewInterpreter();
|
|
|
|
if(tstate == nullptr)
|
|
|
|
{
|
|
|
|
PyEval_ReleaseLock();
|
|
|
|
Error(_log, "Failed to get thread state for %s",QSTRING_CSTR(_name));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
PyThreadState_Swap(tstate);
|
2013-11-27 20:15:29 +01:00
|
|
|
|
2014-03-01 19:28:57 +01:00
|
|
|
// import the buildtin Hyperion module
|
|
|
|
PyObject * module = PyImport_ImportModule("hyperion");
|
2014-02-26 18:10:17 +01:00
|
|
|
|
2014-03-01 19:28:57 +01:00
|
|
|
// add a capsule containing 'this' to the module to be able to retrieve the effect from the callback function
|
|
|
|
PyObject_SetAttrString(module, "__effectObj", PyCapsule_New(this, nullptr, nullptr));
|
2013-11-29 23:22:49 +01:00
|
|
|
|
2013-11-28 16:26:32 +01:00
|
|
|
// add ledCount variable to the interpreter
|
|
|
|
PyObject_SetAttrString(module, "ledCount", Py_BuildValue("i", _imageProcessor->getLedCount()));
|
2013-11-26 21:38:24 +01:00
|
|
|
|
2017-04-09 22:28:32 +02:00
|
|
|
// add minimumWriteTime variable to the interpreter
|
|
|
|
PyObject_SetAttrString(module, "latchTime", Py_BuildValue("i", Hyperion::getInstance()->getLatchTime()));
|
|
|
|
|
2013-11-30 00:28:04 +01:00
|
|
|
// add a args variable to the interpreter
|
2013-11-30 17:41:38 +01:00
|
|
|
PyObject_SetAttrString(module, "args", json2python(_args));
|
2013-11-26 21:38:24 +01:00
|
|
|
|
2014-03-01 19:28:57 +01:00
|
|
|
// decref the module
|
|
|
|
Py_XDECREF(module);
|
2013-11-30 00:28:04 +01:00
|
|
|
|
2013-11-28 14:29:31 +01:00
|
|
|
// Set the end time if applicable
|
|
|
|
if (_timeout > 0)
|
|
|
|
{
|
|
|
|
_endTime = QDateTime::currentMSecsSinceEpoch() + _timeout;
|
|
|
|
}
|
|
|
|
|
2013-11-26 21:38:24 +01:00
|
|
|
// Run the effect script
|
2016-09-13 11:51:16 +02:00
|
|
|
QFile file (_script);
|
|
|
|
QByteArray python_code;
|
|
|
|
if (file.open(QIODevice::ReadOnly))
|
2013-11-30 00:28:04 +01:00
|
|
|
{
|
2016-09-13 11:51:16 +02:00
|
|
|
python_code = file.readAll();
|
2013-11-30 00:28:04 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-10-12 11:55:03 +02:00
|
|
|
Error(_log, "Unable to open script file %s.", QSTRING_CSTR(_script));
|
2016-09-13 11:51:16 +02:00
|
|
|
}
|
|
|
|
file.close();
|
|
|
|
|
|
|
|
if (!python_code.isEmpty())
|
|
|
|
{
|
2017-10-12 11:55:03 +02:00
|
|
|
PyObject *main_module = PyImport_ImportModule("__main__"); // New Reference
|
|
|
|
PyObject *main_dict = PyModule_GetDict(main_module); // Borrowed reference
|
|
|
|
Py_INCREF(main_dict); // Incref "main_dict" to use it in PyRun_String(), because PyModule_GetDict() has decref "main_dict"
|
|
|
|
Py_DECREF(main_module); // // release "main_module" when done
|
|
|
|
PyObject *result = PyRun_String(python_code.constData(), Py_file_input, main_dict, main_dict); // New Reference
|
|
|
|
|
|
|
|
if (!result)
|
|
|
|
{
|
|
|
|
if (PyErr_Occurred()) // Nothing needs to be done for a borrowed reference
|
|
|
|
{
|
|
|
|
Error(_log,"###### PYTHON EXCEPTION ######");
|
|
|
|
Error(_log,"## In effect '%s'", QSTRING_CSTR(_name));
|
|
|
|
/* Objects all initialized to NULL for Py_XDECREF */
|
|
|
|
PyObject *errorType = NULL, *errorValue = NULL, *errorTraceback = NULL;
|
|
|
|
|
|
|
|
PyErr_Fetch(&errorType, &errorValue, &errorTraceback); // New Reference or NULL
|
|
|
|
PyErr_NormalizeException(&errorType, &errorValue, &errorTraceback);
|
|
|
|
|
|
|
|
// Extract exception message from "errorValue"
|
|
|
|
if(errorValue)
|
|
|
|
{
|
|
|
|
QString message;
|
|
|
|
if(PyObject_HasAttrString(errorValue, "__class__"))
|
|
|
|
{
|
|
|
|
PyObject *classPtr = PyObject_GetAttrString(errorValue, "__class__"); // New Reference
|
|
|
|
PyObject *class_name = NULL; /* Object "class_name" initialized to NULL for Py_XDECREF */
|
|
|
|
class_name = PyObject_GetAttrString(classPtr, "__name__"); // New Reference or NULL
|
|
|
|
|
2017-10-13 17:49:29 +02:00
|
|
|
if(class_name && PyUnicode_Check(class_name))
|
|
|
|
message.append(PyUnicode_AsUTF8(class_name));
|
2017-10-12 11:55:03 +02:00
|
|
|
|
|
|
|
Py_DECREF(classPtr); // release "classPtr" when done
|
|
|
|
Py_XDECREF(class_name); // Use Py_XDECREF() to ignore NULL references
|
|
|
|
}
|
|
|
|
|
|
|
|
// Object "class_name" initialized to NULL for Py_XDECREF
|
|
|
|
PyObject *valueString = NULL;
|
|
|
|
valueString = PyObject_Str(errorValue); // New Reference or NULL
|
|
|
|
|
2017-10-13 17:49:29 +02:00
|
|
|
if(valueString && PyUnicode_Check(valueString))
|
2017-10-12 11:55:03 +02:00
|
|
|
{
|
|
|
|
if(!message.isEmpty())
|
|
|
|
message.append(": ");
|
|
|
|
|
2017-10-13 17:49:29 +02:00
|
|
|
message.append(PyUnicode_AsUTF8(valueString));
|
2017-10-12 11:55:03 +02:00
|
|
|
}
|
|
|
|
Py_XDECREF(valueString); // Use Py_XDECREF() to ignore NULL references
|
|
|
|
|
|
|
|
Error(_log, "## %s", QSTRING_CSTR(message));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Extract exception message from "errorTraceback"
|
|
|
|
if(errorTraceback)
|
|
|
|
{
|
|
|
|
// Object "tracebackList" initialized to NULL for Py_XDECREF
|
|
|
|
PyObject *tracebackModule = NULL, *methodName = NULL, *tracebackList = NULL;
|
|
|
|
QString tracebackMsg;
|
|
|
|
|
|
|
|
tracebackModule = PyImport_ImportModule("traceback"); // New Reference or NULL
|
2017-10-13 17:49:29 +02:00
|
|
|
methodName = PyUnicode_FromString("format_exception"); // New Reference or NULL
|
2017-10-12 11:55:03 +02:00
|
|
|
tracebackList = PyObject_CallMethodObjArgs(tracebackModule, methodName, errorType, errorValue, errorTraceback, NULL); // New Reference or NULL
|
|
|
|
|
|
|
|
if(tracebackList)
|
|
|
|
{
|
|
|
|
PyObject* iterator = PyObject_GetIter(tracebackList); // New Reference
|
|
|
|
|
|
|
|
PyObject* item;
|
|
|
|
while( (item = PyIter_Next(iterator)) ) // New Reference
|
|
|
|
{
|
2017-10-13 17:49:29 +02:00
|
|
|
Error(_log, "## %s",QSTRING_CSTR(QString(PyUnicode_AsUTF8(item)).trimmed()));
|
2017-10-12 11:55:03 +02:00
|
|
|
Py_DECREF(item); // release "item" when done
|
|
|
|
}
|
|
|
|
Py_DECREF(iterator); // release "iterator" when done
|
|
|
|
}
|
|
|
|
|
|
|
|
// Use Py_XDECREF() to ignore NULL references
|
|
|
|
Py_XDECREF(tracebackModule);
|
|
|
|
Py_XDECREF(methodName);
|
|
|
|
Py_XDECREF(tracebackList);
|
|
|
|
|
|
|
|
// Give the exception back to python and print it to stderr in case anyone else wants it.
|
|
|
|
Py_XINCREF(errorType);
|
|
|
|
Py_XINCREF(errorValue);
|
|
|
|
Py_XINCREF(errorTraceback);
|
|
|
|
|
|
|
|
PyErr_Restore(errorType, errorValue, errorTraceback);
|
|
|
|
//PyErr_PrintEx(0); // Remove this line to switch off stderr output
|
|
|
|
}
|
|
|
|
Error(_log,"###### EXCEPTION END ######");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Py_DECREF(result); // release "result" when done
|
|
|
|
}
|
|
|
|
|
|
|
|
Py_DECREF(main_dict); // release "main_dict" when done
|
2013-11-30 00:28:04 +01:00
|
|
|
}
|
2017-10-13 17:49:29 +02:00
|
|
|
// stop sub threads if needed
|
|
|
|
for (PyThreadState* s = tstate->interp->tstate_head, *old = nullptr; s;)
|
|
|
|
{
|
|
|
|
if (s == tstate)
|
|
|
|
{
|
|
|
|
s = s->next;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (old != s)
|
|
|
|
{
|
|
|
|
Debug(_log,"ID %s: Waiting on thread %u", QSTRING_CSTR(_name), s->thread_id);
|
|
|
|
old = s;
|
|
|
|
}
|
|
|
|
|
|
|
|
Py_BEGIN_ALLOW_THREADS;
|
|
|
|
msleep(100);
|
|
|
|
Py_END_ALLOW_THREADS;
|
|
|
|
|
|
|
|
s = tstate->interp->tstate_head;
|
|
|
|
}
|
2013-11-26 21:38:24 +01:00
|
|
|
|
|
|
|
// Clean up the thread state
|
2017-10-13 17:49:29 +02:00
|
|
|
Py_EndInterpreter(tstate);
|
2013-11-26 21:38:24 +01:00
|
|
|
PyEval_ReleaseLock();
|
|
|
|
}
|
|
|
|
|
2016-10-09 22:22:17 +02:00
|
|
|
PyObject *Effect::json2python(const QJsonValue &jsonData) const
|
2017-10-12 11:55:03 +02:00
|
|
|
{
|
2016-10-09 22:22:17 +02:00
|
|
|
switch (jsonData.type())
|
2013-11-30 17:41:38 +01:00
|
|
|
{
|
2016-10-09 22:22:17 +02:00
|
|
|
case QJsonValue::Null:
|
|
|
|
return Py_BuildValue("");
|
|
|
|
case QJsonValue::Undefined:
|
|
|
|
return Py_BuildValue("");
|
|
|
|
case QJsonValue::Double:
|
2013-11-30 17:41:38 +01:00
|
|
|
{
|
2016-10-14 20:59:03 +02:00
|
|
|
if (std::rint(jsonData.toDouble()) != jsonData.toDouble())
|
|
|
|
{
|
|
|
|
return Py_BuildValue("d", jsonData.toDouble());
|
|
|
|
}
|
|
|
|
return Py_BuildValue("i", jsonData.toInt());
|
2013-11-30 17:41:38 +01:00
|
|
|
}
|
2016-10-09 22:22:17 +02:00
|
|
|
case QJsonValue::Bool:
|
|
|
|
return Py_BuildValue("i", jsonData.toBool() ? 1 : 0);
|
|
|
|
case QJsonValue::String:
|
|
|
|
return Py_BuildValue("s", jsonData.toString().toUtf8().constData());
|
|
|
|
case QJsonValue::Object:
|
2013-11-30 17:41:38 +01:00
|
|
|
{
|
2016-10-09 22:22:17 +02:00
|
|
|
PyObject * dict= PyDict_New();
|
|
|
|
QJsonObject objectData = jsonData.toObject();
|
|
|
|
for (QJsonObject::iterator i = objectData.begin(); i != objectData.end(); ++i)
|
|
|
|
{
|
|
|
|
PyObject * obj = json2python(*i);
|
|
|
|
PyDict_SetItemString(dict, i.key().toStdString().c_str(), obj);
|
|
|
|
Py_XDECREF(obj);
|
|
|
|
}
|
|
|
|
return dict;
|
|
|
|
}
|
|
|
|
case QJsonValue::Array:
|
|
|
|
{
|
|
|
|
QJsonArray arrayData = jsonData.toArray();
|
|
|
|
PyObject * list = PyList_New(arrayData.size());
|
|
|
|
int index = 0;
|
|
|
|
for (QJsonArray::iterator i = arrayData.begin(); i != arrayData.end(); ++i, ++index)
|
|
|
|
{
|
|
|
|
PyObject * obj = json2python(*i);
|
2017-07-30 14:36:23 +02:00
|
|
|
Py_INCREF(obj);
|
2016-10-09 22:22:17 +02:00
|
|
|
PyList_SetItem(list, index, obj);
|
|
|
|
Py_XDECREF(obj);
|
|
|
|
}
|
|
|
|
return list;
|
2013-11-30 17:41:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(false);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2013-11-28 14:15:52 +01:00
|
|
|
PyObject* Effect::wrapSetColor(PyObject *self, PyObject *args)
|
|
|
|
{
|
2013-11-29 23:22:49 +01:00
|
|
|
// get the effect
|
2014-03-01 19:28:57 +01:00
|
|
|
Effect * effect = getEffect();
|
2013-11-29 23:22:49 +01:00
|
|
|
|
|
|
|
// check if we have aborted already
|
2017-10-12 11:55:03 +02:00
|
|
|
if (effect->isInterruptionRequested())
|
2013-11-29 23:22:49 +01:00
|
|
|
{
|
|
|
|
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("");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// check the number of arguments
|
|
|
|
int argCount = PyTuple_Size(args);
|
|
|
|
if (argCount == 3)
|
|
|
|
{
|
|
|
|
// three seperate arguments for red, green, and blue
|
|
|
|
ColorRgb color;
|
|
|
|
if (PyArg_ParseTuple(args, "bbb", &color.red, &color.green, &color.blue))
|
|
|
|
{
|
2017-04-14 07:58:34 +02:00
|
|
|
effect->_colors.fill(color);
|
2017-08-04 12:01:45 +02:00
|
|
|
effect->setColors(effect->_priority, effect->_colors.toStdVector(), timeout, false, hyperion::COMP_EFFECT, effect->_origin, effect->_smoothCfg);
|
2013-11-29 23:22:49 +01:00
|
|
|
return Py_BuildValue("");
|
|
|
|
}
|
2017-04-14 07:58:34 +02:00
|
|
|
return nullptr;
|
2013-11-29 23:22:49 +01:00
|
|
|
}
|
|
|
|
else if (argCount == 1)
|
|
|
|
{
|
|
|
|
// bytearray of values
|
|
|
|
PyObject * bytearray = nullptr;
|
|
|
|
if (PyArg_ParseTuple(args, "O", &bytearray))
|
|
|
|
{
|
|
|
|
if (PyByteArray_Check(bytearray))
|
|
|
|
{
|
|
|
|
size_t length = PyByteArray_Size(bytearray);
|
|
|
|
if (length == 3 * effect->_imageProcessor->getLedCount())
|
|
|
|
{
|
|
|
|
char * data = PyByteArray_AS_STRING(bytearray);
|
2013-12-08 12:46:33 +01:00
|
|
|
memcpy(effect->_colors.data(), data, length);
|
2017-08-04 12:01:45 +02:00
|
|
|
effect->setColors(effect->_priority, effect->_colors.toStdVector(), timeout, false, hyperion::COMP_EFFECT, effect->_origin, effect->_smoothCfg);
|
2013-11-29 23:22:49 +01:00
|
|
|
return Py_BuildValue("");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PyErr_SetString(PyExc_RuntimeError, "Length of bytearray argument should be 3*ledCount");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PyErr_SetString(PyExc_RuntimeError, "Argument is not a bytearray");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PyErr_SetString(PyExc_RuntimeError, "Function expect 1 or 3 arguments");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// error
|
|
|
|
PyErr_SetString(PyExc_RuntimeError, "Unknown error");
|
|
|
|
return nullptr;
|
2013-11-28 14:15:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
PyObject* Effect::wrapSetImage(PyObject *self, PyObject *args)
|
|
|
|
{
|
2013-11-29 23:53:58 +01:00
|
|
|
// get the effect
|
2014-03-01 19:28:57 +01:00
|
|
|
Effect * effect = getEffect();
|
2013-11-29 23:22:49 +01:00
|
|
|
|
|
|
|
// check if we have aborted already
|
2017-10-12 11:55:03 +02:00
|
|
|
if (effect->isInterruptionRequested())
|
2013-11-29 23:22:49 +01:00
|
|
|
{
|
|
|
|
return Py_BuildValue("");
|
|
|
|
}
|
|
|
|
|
2013-11-29 23:53:58 +01:00
|
|
|
// 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<ColorRgb> image(width, height);
|
|
|
|
char * data = PyByteArray_AS_STRING(bytearray);
|
2013-12-08 12:46:33 +01:00
|
|
|
memcpy(image.memptr(), data, length);
|
2017-04-14 07:58:34 +02:00
|
|
|
std::vector<ColorRgb> v = effect->_colors.toStdVector();
|
|
|
|
effect->_imageProcessor->process(image, v);
|
2017-08-04 12:01:45 +02:00
|
|
|
effect->setColors(effect->_priority, v, timeout, false, hyperion::COMP_EFFECT, effect->_origin, effect->_smoothCfg);
|
2013-11-29 23:53:58 +01:00
|
|
|
return Py_BuildValue("");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-19 10:54:15 +02:00
|
|
|
PyErr_SetString(PyExc_RuntimeError, "Length of bytearray argument should be 3*width*height");
|
2013-11-29 23:53:58 +01:00
|
|
|
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;
|
2013-11-28 14:15:52 +01:00
|
|
|
}
|
|
|
|
|
2017-10-12 12:00:32 +02:00
|
|
|
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);
|
|
|
|
|
|
|
|
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();
|
2017-10-13 17:49:29 +02:00
|
|
|
|
2017-10-12 12:00:32 +02:00
|
|
|
int width = qimage.width();
|
|
|
|
int height = qimage.height();
|
|
|
|
|
|
|
|
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]));
|
|
|
|
}
|
|
|
|
}
|
2017-10-13 17:49:29 +02:00
|
|
|
PyList_SET_ITEM(result, i, Py_BuildValue("{s:i,s:i,s:O}", "imageWidth", width, "imageHeight", height, "imageData", PyByteArray_FromStringAndSize(binaryImage.constData(),binaryImage.size())));
|
2017-10-12 12:00:32 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PyErr_SetString(PyExc_TypeError, reader.errorString().toUtf8().constData());
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PyErr_SetString(PyExc_TypeError, reader.errorString().toUtf8().constData());
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-28 14:15:52 +01:00
|
|
|
PyObject* Effect::wrapAbort(PyObject *self, PyObject *)
|
|
|
|
{
|
2014-03-01 19:28:57 +01:00
|
|
|
Effect * effect = getEffect();
|
2013-11-29 23:22:49 +01:00
|
|
|
|
2013-11-28 14:29:31 +01:00
|
|
|
// Test if the effect has reached it end time
|
|
|
|
if (effect->_timeout > 0 && QDateTime::currentMSecsSinceEpoch() > effect->_endTime)
|
|
|
|
{
|
2017-10-12 11:55:03 +02:00
|
|
|
effect->requestInterruption();
|
2013-11-28 14:29:31 +01:00
|
|
|
}
|
2013-11-29 23:22:49 +01:00
|
|
|
|
2017-10-12 11:55:03 +02:00
|
|
|
return Py_BuildValue("i", effect->isInterruptionRequested() ? 1 : 0);
|
2013-12-08 12:46:33 +01:00
|
|
|
}
|
|
|
|
|
2016-09-21 22:01:50 +02:00
|
|
|
|
|
|
|
PyObject* Effect::wrapImageShow(PyObject *self, PyObject *args)
|
|
|
|
{
|
|
|
|
Effect * effect = getEffect();
|
|
|
|
|
|
|
|
// 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("");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-14 07:58:34 +02:00
|
|
|
int argCount = PyTuple_Size(args);
|
|
|
|
int imgId = -1;
|
|
|
|
bool argsOk = (argCount == 0);
|
|
|
|
if (argCount == 1 && PyArg_ParseTuple(args, "i", &imgId))
|
|
|
|
{
|
|
|
|
argsOk = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! argsOk || (imgId>-1 && imgId >= effect->_imageStack.size()))
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QImage * qimage = (imgId<0) ? &(effect->_image) : &(effect->_imageStack[imgId]);
|
|
|
|
int width = qimage->width();
|
|
|
|
int height = qimage->height();
|
|
|
|
|
2016-09-21 22:01:50 +02:00
|
|
|
Image<ColorRgb> image(width, height);
|
|
|
|
QByteArray binaryImage;
|
|
|
|
|
2017-04-14 07:58:34 +02:00
|
|
|
for (int i = 0; i<height; ++i)
|
2016-09-21 22:01:50 +02:00
|
|
|
{
|
|
|
|
const QRgb * scanline = reinterpret_cast<const QRgb *>(qimage->scanLine(i));
|
2017-04-14 07:58:34 +02:00
|
|
|
for (int j = 0; j< width; ++j)
|
2016-09-21 22:01:50 +02:00
|
|
|
{
|
|
|
|
binaryImage.append((char) qRed(scanline[j]));
|
|
|
|
binaryImage.append((char) qGreen(scanline[j]));
|
|
|
|
binaryImage.append((char) qBlue(scanline[j]));
|
|
|
|
}
|
|
|
|
}
|
2017-10-12 11:55:03 +02:00
|
|
|
|
2016-09-21 22:01:50 +02:00
|
|
|
memcpy(image.memptr(), binaryImage.data(), binaryImage.size());
|
2017-04-14 07:58:34 +02:00
|
|
|
std::vector<ColorRgb> v = effect->_colors.toStdVector();
|
|
|
|
effect->_imageProcessor->process(image, v);
|
2017-08-04 12:01:45 +02:00
|
|
|
effect->setColors(effect->_priority, v, timeout, false, hyperion::COMP_EFFECT, effect->_origin, effect->_smoothCfg);
|
2016-09-21 22:01:50 +02:00
|
|
|
|
|
|
|
return Py_BuildValue("");
|
|
|
|
}
|
|
|
|
|
2017-07-30 14:36:23 +02:00
|
|
|
PyObject* Effect::wrapImageLinearGradient(PyObject *self, PyObject *args)
|
|
|
|
{
|
|
|
|
Effect * effect = getEffect();
|
|
|
|
|
|
|
|
int argCount = PyTuple_Size(args);
|
|
|
|
PyObject * bytearray = nullptr;
|
|
|
|
int startRX = 0;
|
|
|
|
int startRY = 0;
|
|
|
|
int startX = 0;
|
|
|
|
int startY = 0;
|
|
|
|
int endX, width = effect->_imageSize.width();
|
|
|
|
int endY, height = effect->_imageSize.height();
|
|
|
|
int spread = 0;
|
|
|
|
|
|
|
|
bool argsOK = false;
|
|
|
|
|
|
|
|
if ( argCount == 10 && PyArg_ParseTuple(args, "iiiiiiiiOi", &startRX, &startRY, &width, &height, &startX, &startY, &endX, &endY, &bytearray, &spread) )
|
|
|
|
{
|
|
|
|
argsOK = true;
|
|
|
|
}
|
|
|
|
if ( argCount == 6 && PyArg_ParseTuple(args, "iiiiOi", &startX, &startY, &endX, &endY, &bytearray, &spread) )
|
|
|
|
{
|
|
|
|
argsOK = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argsOK)
|
|
|
|
{
|
|
|
|
if (PyByteArray_Check(bytearray))
|
|
|
|
{
|
|
|
|
const int length = PyByteArray_Size(bytearray);
|
|
|
|
const unsigned arrayItemLength = 5;
|
|
|
|
if (length % arrayItemLength == 0)
|
|
|
|
{
|
|
|
|
QRect myQRect(startRX,startRY,width,height);
|
|
|
|
QLinearGradient gradient(QPoint(startX,startY), QPoint(endX,endY));
|
|
|
|
char * data = PyByteArray_AS_STRING(bytearray);
|
|
|
|
|
|
|
|
for (int idx=0; idx<length; idx+=arrayItemLength)
|
|
|
|
{
|
|
|
|
gradient.setColorAt(
|
|
|
|
((uint8_t)data[idx])/255.0,
|
|
|
|
QColor(
|
|
|
|
(uint8_t)(data[idx+1]),
|
|
|
|
(uint8_t)(data[idx+2]),
|
|
|
|
(uint8_t)(data[idx+3]),
|
|
|
|
(uint8_t)(data[idx+4])
|
|
|
|
));
|
|
|
|
}
|
2016-09-21 22:01:50 +02:00
|
|
|
|
2017-07-30 14:36:23 +02:00
|
|
|
gradient.setSpread(static_cast<QGradient::Spread>(spread));
|
|
|
|
effect->_painter->fillRect(myQRect, gradient);
|
2017-10-12 11:55:03 +02:00
|
|
|
|
2017-07-30 14:36:23 +02:00
|
|
|
return Py_BuildValue("");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PyErr_SetString(PyExc_RuntimeError, "Length of bytearray argument should multiple of 5");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PyErr_SetString(PyExc_RuntimeError, "No bytearray properly defined");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
PyObject* Effect::wrapImageConicalGradient(PyObject *self, PyObject *args)
|
2016-09-21 22:01:50 +02:00
|
|
|
{
|
|
|
|
Effect * effect = getEffect();
|
|
|
|
|
|
|
|
int argCount = PyTuple_Size(args);
|
|
|
|
PyObject * bytearray = nullptr;
|
|
|
|
int centerX, centerY, angle;
|
|
|
|
int startX = 0;
|
|
|
|
int startY = 0;
|
|
|
|
int width = effect->_imageSize.width();
|
|
|
|
int height = effect->_imageSize.height();
|
|
|
|
|
|
|
|
bool argsOK = false;
|
|
|
|
|
|
|
|
if ( argCount == 8 && PyArg_ParseTuple(args, "iiiiiiiO", &startX, &startY, &width, &height, ¢erX, ¢erY, &angle, &bytearray) )
|
|
|
|
{
|
2017-02-16 07:33:58 +01:00
|
|
|
argsOK = true;
|
2016-09-21 22:01:50 +02:00
|
|
|
}
|
|
|
|
if ( argCount == 4 && PyArg_ParseTuple(args, "iiiO", ¢erX, ¢erY, &angle, &bytearray) )
|
|
|
|
{
|
2017-02-16 07:33:58 +01:00
|
|
|
argsOK = true;
|
2016-09-21 22:01:50 +02:00
|
|
|
}
|
2017-08-04 12:01:45 +02:00
|
|
|
angle = qMax(qMin(angle,360),0);
|
2016-09-21 22:01:50 +02:00
|
|
|
|
|
|
|
if (argsOK)
|
|
|
|
{
|
|
|
|
if (PyByteArray_Check(bytearray))
|
|
|
|
{
|
2016-10-01 21:34:30 +02:00
|
|
|
const int length = PyByteArray_Size(bytearray);
|
|
|
|
const unsigned arrayItemLength = 5;
|
|
|
|
if (length % arrayItemLength == 0)
|
2016-09-21 22:01:50 +02:00
|
|
|
{
|
|
|
|
QRect myQRect(startX,startY,width,height);
|
|
|
|
QConicalGradient gradient(QPoint(centerX,centerY), angle );
|
|
|
|
char * data = PyByteArray_AS_STRING(bytearray);
|
|
|
|
|
2016-10-01 21:34:30 +02:00
|
|
|
for (int idx=0; idx<length; idx+=arrayItemLength)
|
2016-09-21 22:01:50 +02:00
|
|
|
{
|
|
|
|
gradient.setColorAt(
|
|
|
|
((uint8_t)data[idx])/255.0,
|
|
|
|
QColor(
|
|
|
|
(uint8_t)(data[idx+1]),
|
|
|
|
(uint8_t)(data[idx+2]),
|
2016-10-01 21:34:30 +02:00
|
|
|
(uint8_t)(data[idx+3]),
|
|
|
|
(uint8_t)(data[idx+4])
|
2016-09-21 22:01:50 +02:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2017-04-14 07:58:34 +02:00
|
|
|
effect->_painter->fillRect(myQRect, gradient);
|
2017-10-12 11:55:03 +02:00
|
|
|
|
2016-09-21 22:01:50 +02:00
|
|
|
return Py_BuildValue("");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-10-01 21:34:30 +02:00
|
|
|
PyErr_SetString(PyExc_RuntimeError, "Length of bytearray argument should multiple of 5");
|
2016-09-21 22:01:50 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PyErr_SetString(PyExc_RuntimeError, "Argument 8 is not a bytearray");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
2017-04-14 07:58:34 +02:00
|
|
|
return nullptr;
|
2016-09-21 22:01:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PyObject* Effect::wrapImageRadialGradient(PyObject *self, PyObject *args)
|
|
|
|
{
|
|
|
|
Effect * effect = getEffect();
|
|
|
|
|
|
|
|
int argCount = PyTuple_Size(args);
|
|
|
|
PyObject * bytearray = nullptr;
|
2017-07-30 14:36:23 +02:00
|
|
|
int centerX, centerY, radius, focalX, focalY, focalRadius, spread;
|
2016-09-21 22:01:50 +02:00
|
|
|
int startX = 0;
|
|
|
|
int startY = 0;
|
|
|
|
int width = effect->_imageSize.width();
|
|
|
|
int height = effect->_imageSize.height();
|
|
|
|
|
|
|
|
bool argsOK = false;
|
2017-07-30 14:36:23 +02:00
|
|
|
|
|
|
|
if ( argCount == 12 && PyArg_ParseTuple(args, "iiiiiiiiiiOi", &startX, &startY, &width, &height, ¢erX, ¢erY, &radius, &focalX, &focalY, &focalRadius, &bytearray, &spread) )
|
2016-09-21 22:01:50 +02:00
|
|
|
{
|
|
|
|
argsOK = true;
|
2017-10-12 11:55:03 +02:00
|
|
|
}
|
2017-07-30 14:36:23 +02:00
|
|
|
if ( argCount == 9 && PyArg_ParseTuple(args, "iiiiiiiOi", &startX, &startY, &width, &height, ¢erX, ¢erY, &radius, &bytearray, &spread) )
|
2016-09-21 22:01:50 +02:00
|
|
|
{
|
|
|
|
argsOK = true;
|
|
|
|
focalX = centerX;
|
|
|
|
focalY = centerY;
|
|
|
|
focalRadius = radius;
|
|
|
|
}
|
2017-07-30 14:36:23 +02:00
|
|
|
if ( argCount == 8 && PyArg_ParseTuple(args, "iiiiiiOi", ¢erX, ¢erY, &radius, &focalX, &focalY, &focalRadius, &bytearray, &spread) )
|
2016-09-21 22:01:50 +02:00
|
|
|
{
|
2017-02-16 07:33:58 +01:00
|
|
|
argsOK = true;
|
2016-09-21 22:01:50 +02:00
|
|
|
}
|
2017-07-30 14:36:23 +02:00
|
|
|
if ( argCount == 5 && PyArg_ParseTuple(args, "iiiOi", ¢erX, ¢erY, &radius, &bytearray, &spread) )
|
2016-09-21 22:01:50 +02:00
|
|
|
{
|
|
|
|
argsOK = true;
|
|
|
|
focalX = centerX;
|
|
|
|
focalY = centerY;
|
|
|
|
focalRadius = radius;
|
|
|
|
}
|
2017-10-12 11:55:03 +02:00
|
|
|
|
2016-09-21 22:01:50 +02:00
|
|
|
if (argsOK)
|
|
|
|
{
|
|
|
|
if (PyByteArray_Check(bytearray))
|
|
|
|
{
|
|
|
|
int length = PyByteArray_Size(bytearray);
|
|
|
|
if (length % 4 == 0)
|
|
|
|
{
|
|
|
|
|
|
|
|
QRect myQRect(startX,startY,width,height);
|
2017-08-04 12:01:45 +02:00
|
|
|
QRadialGradient gradient(QPoint(centerX,centerY), qMax(radius,0) );
|
2016-09-21 22:01:50 +02:00
|
|
|
char * data = PyByteArray_AS_STRING(bytearray);
|
|
|
|
|
|
|
|
for (int idx=0; idx<length; idx+=4)
|
|
|
|
{
|
|
|
|
gradient.setColorAt(
|
|
|
|
((uint8_t)data[idx])/255.0,
|
|
|
|
QColor(
|
|
|
|
(uint8_t)(data[idx+1]),
|
|
|
|
(uint8_t)(data[idx+2]),
|
|
|
|
(uint8_t)(data[idx+3])
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2017-07-30 14:36:23 +02:00
|
|
|
gradient.setSpread(static_cast<QGradient::Spread>(spread));
|
2017-04-14 07:58:34 +02:00
|
|
|
effect->_painter->fillRect(myQRect, gradient);
|
2017-10-12 11:55:03 +02:00
|
|
|
|
2016-09-21 22:01:50 +02:00
|
|
|
return Py_BuildValue("");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PyErr_SetString(PyExc_RuntimeError, "Length of bytearray argument should multiple of 4");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PyErr_SetString(PyExc_RuntimeError, "Last argument is not a bytearray");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
2017-04-14 07:58:34 +02:00
|
|
|
return nullptr;
|
2016-09-21 22:01:50 +02:00
|
|
|
}
|
|
|
|
|
2017-07-30 14:36:23 +02:00
|
|
|
PyObject* Effect::wrapImageDrawPolygon(PyObject *self, PyObject *args)
|
|
|
|
{
|
|
|
|
Effect * effect = getEffect();
|
|
|
|
PyObject * bytearray = nullptr;
|
|
|
|
|
|
|
|
int argCount = PyTuple_Size(args);
|
|
|
|
int r, g, b;
|
|
|
|
int a = 255;
|
|
|
|
|
|
|
|
bool argsOK = false;
|
|
|
|
|
|
|
|
if ( argCount == 5 && PyArg_ParseTuple(args, "Oiiii", &bytearray, &r, &g, &b, &a) )
|
|
|
|
{
|
|
|
|
argsOK = true;
|
|
|
|
}
|
|
|
|
if ( argCount == 4 && PyArg_ParseTuple(args, "Oiii", &bytearray, &r, &g, &b) )
|
|
|
|
{
|
|
|
|
argsOK = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argsOK)
|
|
|
|
{
|
|
|
|
if (PyByteArray_Check(bytearray))
|
|
|
|
{
|
|
|
|
int length = PyByteArray_Size(bytearray);
|
|
|
|
if (length % 2 == 0)
|
|
|
|
{
|
|
|
|
QVector <QPoint> points;
|
|
|
|
char * data = PyByteArray_AS_STRING(bytearray);
|
|
|
|
|
|
|
|
for (int idx=0; idx<length; idx+=2)
|
|
|
|
{
|
|
|
|
points.append(QPoint((int)(data[idx]),(int)(data[idx+1])));
|
|
|
|
}
|
|
|
|
|
|
|
|
QPainter * painter = effect->_painter;
|
|
|
|
QPen oldPen = painter->pen();
|
|
|
|
QPen newPen(QColor(r,g,b,a));
|
|
|
|
painter->setPen(newPen);
|
|
|
|
painter->setBrush(QBrush(QColor(r,g,b,a), Qt::SolidPattern));
|
|
|
|
painter->drawPolygon(points);
|
|
|
|
painter->setPen(oldPen);
|
|
|
|
return Py_BuildValue("");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PyErr_SetString(PyExc_RuntimeError, "Length of bytearray argument should multiple of 2");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PyErr_SetString(PyExc_RuntimeError, "Argument 1 is not a bytearray");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
PyObject* Effect::wrapImageDrawPie(PyObject *self, PyObject *args)
|
|
|
|
{
|
|
|
|
Effect * effect = getEffect();
|
|
|
|
PyObject * bytearray = nullptr;
|
2017-10-12 11:55:03 +02:00
|
|
|
|
2017-07-30 14:36:23 +02:00
|
|
|
QString brush;
|
|
|
|
int argCount = PyTuple_Size(args);
|
|
|
|
int radius, centerX, centerY;
|
|
|
|
int startAngle = 0;
|
|
|
|
int spanAngle = 360;
|
|
|
|
int r = 0;
|
|
|
|
int g = 0;
|
|
|
|
int b = 0;
|
|
|
|
int a = 255;
|
|
|
|
|
|
|
|
bool argsOK = false;
|
|
|
|
|
|
|
|
if ( argCount == 9 && PyArg_ParseTuple(args, "iiiiiiiii", ¢erX, ¢erY, &radius, &startAngle, &spanAngle, &r, &g, &b, &a) )
|
|
|
|
{
|
|
|
|
argsOK = true;
|
|
|
|
}
|
|
|
|
if ( argCount == 8 && PyArg_ParseTuple(args, "iiiiiiii", ¢erX, ¢erY, &radius, &startAngle, &spanAngle, &r, &g, &b) )
|
|
|
|
{
|
|
|
|
argsOK = true;
|
|
|
|
}
|
|
|
|
if ( argCount == 7 && PyArg_ParseTuple(args, "iiiiisO", ¢erX, ¢erY, &radius, &startAngle, &spanAngle, &brush, &bytearray) )
|
|
|
|
{
|
|
|
|
argsOK = true;
|
|
|
|
}
|
|
|
|
if ( argCount == 5 && PyArg_ParseTuple(args, "iiisO", ¢erX, ¢erY, &radius, &brush, &bytearray) )
|
|
|
|
{
|
|
|
|
argsOK = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argsOK)
|
|
|
|
{
|
|
|
|
QPainter * painter = effect->_painter;
|
2017-08-04 12:01:45 +02:00
|
|
|
startAngle = qMax(qMin(startAngle,360),0);
|
|
|
|
spanAngle = qMax(qMin(spanAngle,360),-360);
|
2017-07-30 14:36:23 +02:00
|
|
|
|
|
|
|
if( argCount == 7 || argCount == 5 )
|
|
|
|
{
|
|
|
|
a = 0;
|
|
|
|
if (PyByteArray_Check(bytearray))
|
|
|
|
{
|
|
|
|
int length = PyByteArray_Size(bytearray);
|
|
|
|
if (length % 5 == 0)
|
|
|
|
{
|
|
|
|
|
|
|
|
QConicalGradient gradient(QPoint(centerX,centerY), startAngle);
|
|
|
|
|
|
|
|
|
|
|
|
char * data = PyByteArray_AS_STRING(bytearray);
|
|
|
|
|
|
|
|
for (int idx=0; idx<length; idx+=5)
|
|
|
|
{
|
|
|
|
gradient.setColorAt(
|
|
|
|
((uint8_t)data[idx])/255.0,
|
|
|
|
QColor(
|
|
|
|
(uint8_t)(data[idx+1]),
|
|
|
|
(uint8_t)(data[idx+2]),
|
|
|
|
(uint8_t)(data[idx+3]),
|
|
|
|
(uint8_t)(data[idx+4])
|
|
|
|
));
|
|
|
|
}
|
|
|
|
painter->setBrush(gradient);
|
2017-10-12 11:55:03 +02:00
|
|
|
|
2017-07-30 14:36:23 +02:00
|
|
|
return Py_BuildValue("");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PyErr_SetString(PyExc_RuntimeError, "Length of bytearray argument should multiple of 5");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PyErr_SetString(PyExc_RuntimeError, "Last argument is not a bytearray");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
painter->setBrush(QBrush(QColor(r,g,b,a), Qt::SolidPattern));
|
|
|
|
}
|
|
|
|
QPen oldPen = painter->pen();
|
|
|
|
QPen newPen(QColor(r,g,b,a));
|
|
|
|
painter->setPen(newPen);
|
|
|
|
painter->drawPie(centerX - radius, centerY - radius, centerX + radius, centerY + radius, startAngle * 16, spanAngle * 16);
|
|
|
|
painter->setPen(oldPen);
|
|
|
|
return Py_BuildValue("");
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-10-01 21:34:30 +02:00
|
|
|
PyObject* Effect::wrapImageSolidFill(PyObject *self, PyObject *args)
|
|
|
|
{
|
|
|
|
Effect * effect = getEffect();
|
|
|
|
|
|
|
|
int argCount = PyTuple_Size(args);
|
|
|
|
int r, g, b;
|
|
|
|
int a = 255;
|
|
|
|
int startX = 0;
|
|
|
|
int startY = 0;
|
|
|
|
int width = effect->_imageSize.width();
|
|
|
|
int height = effect->_imageSize.height();
|
|
|
|
|
|
|
|
bool argsOK = false;
|
|
|
|
|
|
|
|
if ( argCount == 8 && PyArg_ParseTuple(args, "iiiiiiii", &startX, &startY, &width, &height, &r, &g, &b, &a) )
|
|
|
|
{
|
2017-02-16 07:33:58 +01:00
|
|
|
argsOK = true;
|
2016-10-01 21:34:30 +02:00
|
|
|
}
|
|
|
|
if ( argCount == 7 && PyArg_ParseTuple(args, "iiiiiii", &startX, &startY, &width, &height, &r, &g, &b) )
|
|
|
|
{
|
2017-02-16 07:33:58 +01:00
|
|
|
argsOK = true;
|
2016-10-01 21:34:30 +02:00
|
|
|
}
|
|
|
|
if ( argCount == 4 && PyArg_ParseTuple(args, "iiii",&r, &g, &b, &a) )
|
|
|
|
{
|
2017-02-16 07:33:58 +01:00
|
|
|
argsOK = true;
|
2016-10-01 21:34:30 +02:00
|
|
|
}
|
|
|
|
if ( argCount == 3 && PyArg_ParseTuple(args, "iii",&r, &g, &b) )
|
|
|
|
{
|
2017-02-16 07:33:58 +01:00
|
|
|
argsOK = true;
|
2016-10-01 21:34:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (argsOK)
|
|
|
|
{
|
|
|
|
QRect myQRect(startX,startY,width,height);
|
|
|
|
effect->_painter->fillRect(myQRect, QColor(r,g,b,a));
|
|
|
|
return Py_BuildValue("");
|
|
|
|
}
|
2017-04-14 07:58:34 +02:00
|
|
|
return nullptr;
|
2016-10-01 21:34:30 +02:00
|
|
|
}
|
|
|
|
|
2016-09-21 22:01:50 +02:00
|
|
|
|
2017-02-16 07:33:58 +01:00
|
|
|
PyObject* Effect::wrapImageDrawLine(PyObject *self, PyObject *args)
|
|
|
|
{
|
|
|
|
Effect * effect = getEffect();
|
|
|
|
|
|
|
|
int argCount = PyTuple_Size(args);
|
|
|
|
int r, g, b;
|
|
|
|
int a = 255;
|
|
|
|
int startX = 0;
|
|
|
|
int startY = 0;
|
|
|
|
int thick = 1;
|
|
|
|
int endX = effect->_imageSize.width();
|
|
|
|
int endY = effect->_imageSize.height();
|
|
|
|
|
|
|
|
bool argsOK = false;
|
|
|
|
|
|
|
|
if ( argCount == 9 && PyArg_ParseTuple(args, "iiiiiiiii", &startX, &startY, &endX, &endY, &thick, &r, &g, &b, &a) )
|
|
|
|
{
|
|
|
|
argsOK = true;
|
|
|
|
}
|
|
|
|
if ( argCount == 8 && PyArg_ParseTuple(args, "iiiiiiii", &startX, &startY, &endX, &endY, &thick, &r, &g, &b) )
|
|
|
|
{
|
|
|
|
argsOK = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argsOK)
|
|
|
|
{
|
2017-04-14 07:58:34 +02:00
|
|
|
QPainter * painter = effect->_painter;
|
2017-02-16 07:33:58 +01:00
|
|
|
QRect myQRect(startX, startY, endX, endY);
|
2017-04-14 07:58:34 +02:00
|
|
|
QPen oldPen = painter->pen();
|
2017-02-16 07:33:58 +01:00
|
|
|
QPen newPen(QColor(r,g,b,a));
|
|
|
|
newPen.setWidth(thick);
|
2017-04-14 07:58:34 +02:00
|
|
|
painter->setPen(newPen);
|
|
|
|
painter->drawLine(startX, startY, endX, endY);
|
|
|
|
painter->setPen(oldPen);
|
2017-10-12 11:55:03 +02:00
|
|
|
|
2017-02-16 07:33:58 +01:00
|
|
|
return Py_BuildValue("");
|
|
|
|
}
|
2017-04-14 07:58:34 +02:00
|
|
|
return nullptr;
|
2017-02-16 07:33:58 +01:00
|
|
|
}
|
|
|
|
|
2017-07-30 14:36:23 +02:00
|
|
|
PyObject* Effect::wrapImageDrawPoint(PyObject *self, PyObject *args)
|
|
|
|
{
|
|
|
|
Effect * effect = getEffect();
|
|
|
|
|
|
|
|
int argCount = PyTuple_Size(args);
|
|
|
|
int r, g, b, x, y;
|
|
|
|
int a = 255;
|
|
|
|
int thick = 1;
|
|
|
|
|
|
|
|
bool argsOK = false;
|
|
|
|
|
|
|
|
if ( argCount == 7 && PyArg_ParseTuple(args, "iiiiiii", &x, &y, &thick, &r, &g, &b, &a) )
|
|
|
|
{
|
|
|
|
argsOK = true;
|
|
|
|
}
|
|
|
|
if ( argCount == 6 && PyArg_ParseTuple(args, "iiiiii", &x, &y, &thick, &r, &g, &b) )
|
|
|
|
{
|
|
|
|
argsOK = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argsOK)
|
|
|
|
{
|
|
|
|
QPainter * painter = effect->_painter;
|
|
|
|
QPen oldPen = painter->pen();
|
|
|
|
QPen newPen(QColor(r,g,b,a));
|
|
|
|
newPen.setWidth(thick);
|
|
|
|
painter->setPen(newPen);
|
|
|
|
painter->drawPoint(x, y);
|
|
|
|
painter->setPen(oldPen);
|
2017-10-12 11:55:03 +02:00
|
|
|
|
2017-07-30 14:36:23 +02:00
|
|
|
return Py_BuildValue("");
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
2017-02-16 07:33:58 +01:00
|
|
|
|
|
|
|
PyObject* Effect::wrapImageDrawRect(PyObject *self, PyObject *args)
|
|
|
|
{
|
|
|
|
Effect * effect = getEffect();
|
|
|
|
|
|
|
|
int argCount = PyTuple_Size(args);
|
|
|
|
int r, g, b;
|
|
|
|
int a = 255;
|
|
|
|
int startX = 0;
|
|
|
|
int startY = 0;
|
|
|
|
int thick = 1;
|
|
|
|
int width = effect->_imageSize.width();
|
|
|
|
int height = effect->_imageSize.height();
|
|
|
|
|
|
|
|
bool argsOK = false;
|
|
|
|
|
|
|
|
if ( argCount == 9 && PyArg_ParseTuple(args, "iiiiiiiii", &startX, &startY, &width, &height, &thick, &r, &g, &b, &a) )
|
|
|
|
{
|
|
|
|
argsOK = true;
|
|
|
|
}
|
|
|
|
if ( argCount == 8 && PyArg_ParseTuple(args, "iiiiiiii", &startX, &startY, &width, &height, &thick, &r, &g, &b) )
|
|
|
|
{
|
|
|
|
argsOK = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argsOK)
|
|
|
|
{
|
2017-04-14 07:58:34 +02:00
|
|
|
QPainter * painter = effect->_painter;
|
2017-02-16 07:33:58 +01:00
|
|
|
QRect myQRect(startX,startY,width,height);
|
2017-04-14 07:58:34 +02:00
|
|
|
QPen oldPen = painter->pen();
|
2017-02-16 07:33:58 +01:00
|
|
|
QPen newPen(QColor(r,g,b,a));
|
|
|
|
newPen.setWidth(thick);
|
2017-04-14 07:58:34 +02:00
|
|
|
painter->setPen(newPen);
|
|
|
|
painter->drawRect(startX, startY, width, height);
|
|
|
|
painter->setPen(oldPen);
|
2017-10-12 11:55:03 +02:00
|
|
|
|
2017-02-16 07:33:58 +01:00
|
|
|
return Py_BuildValue("");
|
|
|
|
}
|
2017-04-14 07:58:34 +02:00
|
|
|
return nullptr;
|
2017-02-16 07:33:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PyObject* Effect::wrapImageSetPixel(PyObject *self, PyObject *args)
|
|
|
|
{
|
|
|
|
Effect * effect = getEffect();
|
|
|
|
|
|
|
|
int argCount = PyTuple_Size(args);
|
|
|
|
int r, g, b, x, y;
|
|
|
|
|
|
|
|
if ( argCount == 5 && PyArg_ParseTuple(args, "iiiii", &x, &y, &r, &g, &b ) )
|
|
|
|
{
|
2017-04-14 07:58:34 +02:00
|
|
|
effect->_image.setPixel(x,y,qRgb(r,g,b));
|
2017-02-16 07:33:58 +01:00
|
|
|
return Py_BuildValue("");
|
|
|
|
}
|
2017-04-14 07:58:34 +02:00
|
|
|
|
|
|
|
return nullptr;
|
2017-02-16 07:33:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PyObject* Effect::wrapImageGetPixel(PyObject *self, PyObject *args)
|
|
|
|
{
|
|
|
|
Effect * effect = getEffect();
|
|
|
|
|
|
|
|
int argCount = PyTuple_Size(args);
|
|
|
|
int x, y;
|
|
|
|
|
|
|
|
if ( argCount == 2 && PyArg_ParseTuple(args, "ii", &x, &y) )
|
|
|
|
{
|
2017-04-14 07:58:34 +02:00
|
|
|
QRgb rgb = effect->_image.pixel(x,y);
|
2017-02-16 07:33:58 +01:00
|
|
|
return Py_BuildValue("iii",qRed(rgb),qGreen(rgb),qBlue(rgb));
|
|
|
|
}
|
2017-04-14 07:58:34 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
PyObject* Effect::wrapImageSave(PyObject *self, PyObject *args)
|
|
|
|
{
|
|
|
|
Effect * effect = getEffect();
|
|
|
|
QImage img(effect->_image.copy());
|
|
|
|
effect->_imageStack.append(img);
|
|
|
|
|
2017-10-12 11:55:03 +02:00
|
|
|
return Py_BuildValue("i", effect->_imageStack.size()-1);
|
2017-04-14 07:58:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
PyObject* Effect::wrapImageMinSize(PyObject *self, PyObject *args)
|
|
|
|
{
|
|
|
|
Effect * effect = getEffect();
|
|
|
|
|
|
|
|
int argCount = PyTuple_Size(args);
|
|
|
|
int w, h;
|
|
|
|
int width = effect->_imageSize.width();
|
|
|
|
int height = effect->_imageSize.height();
|
|
|
|
|
|
|
|
if ( argCount == 2 && PyArg_ParseTuple(args, "ii", &w, &h) )
|
2017-02-16 07:33:58 +01:00
|
|
|
{
|
2017-04-14 07:58:34 +02:00
|
|
|
if (width<w || height<h)
|
|
|
|
{
|
|
|
|
delete effect->_painter;
|
2017-10-12 11:55:03 +02:00
|
|
|
|
2017-08-04 12:01:45 +02:00
|
|
|
effect->_image = effect->_image.scaled(qMax(width,w),qMax(height,h), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
|
2017-04-14 07:58:34 +02:00
|
|
|
effect->_imageSize = effect->_image.size();
|
|
|
|
effect->_painter = new QPainter(&(effect->_image));
|
|
|
|
}
|
|
|
|
return Py_BuildValue("ii", effect->_image.width(), effect->_image.height());
|
2017-02-16 07:33:58 +01:00
|
|
|
}
|
2017-04-14 07:58:34 +02:00
|
|
|
return nullptr;
|
2017-02-16 07:33:58 +01:00
|
|
|
}
|
|
|
|
|
2017-04-14 07:58:34 +02:00
|
|
|
PyObject* Effect::wrapImageWidth(PyObject *self, PyObject *args)
|
|
|
|
{
|
|
|
|
Effect * effect = getEffect();
|
|
|
|
return Py_BuildValue("i", effect->_imageSize.width());
|
|
|
|
}
|
|
|
|
|
|
|
|
PyObject* Effect::wrapImageHeight(PyObject *self, PyObject *args)
|
|
|
|
{
|
|
|
|
Effect * effect = getEffect();
|
|
|
|
return Py_BuildValue("i", effect->_imageSize.height());
|
|
|
|
}
|
2017-02-16 07:33:58 +01:00
|
|
|
|
2017-07-30 14:36:23 +02:00
|
|
|
PyObject* Effect::wrapImageCRotate(PyObject *self, PyObject *args)
|
|
|
|
{
|
|
|
|
Effect * effect = getEffect();
|
2017-10-12 11:55:03 +02:00
|
|
|
|
2017-07-30 14:36:23 +02:00
|
|
|
int argCount = PyTuple_Size(args);
|
|
|
|
int angle;
|
2017-10-12 11:55:03 +02:00
|
|
|
|
2017-07-30 14:36:23 +02:00
|
|
|
if ( argCount == 1 && PyArg_ParseTuple(args, "i", &angle ) )
|
|
|
|
{
|
2017-08-04 12:01:45 +02:00
|
|
|
angle = qMax(qMin(angle,360),0);
|
2017-07-30 14:36:23 +02:00
|
|
|
effect->_painter->rotate(angle);
|
|
|
|
return Py_BuildValue("");
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
PyObject* Effect::wrapImageCOffset(PyObject *self, PyObject *args)
|
|
|
|
{
|
|
|
|
Effect * effect = getEffect();
|
2017-10-12 11:55:03 +02:00
|
|
|
|
2017-07-30 14:36:23 +02:00
|
|
|
int offsetX = 0;
|
|
|
|
int offsetY = 0;
|
|
|
|
int argCount = PyTuple_Size(args);
|
2017-10-12 11:55:03 +02:00
|
|
|
|
2017-07-30 14:36:23 +02:00
|
|
|
if ( argCount == 2 )
|
|
|
|
{
|
|
|
|
PyArg_ParseTuple(args, "ii", &offsetX, &offsetY );
|
|
|
|
}
|
2017-10-12 11:55:03 +02:00
|
|
|
|
2017-07-30 14:36:23 +02:00
|
|
|
effect->_painter->translate(QPoint(offsetX,offsetY));
|
|
|
|
return Py_BuildValue("");
|
|
|
|
}
|
|
|
|
|
|
|
|
PyObject* Effect::wrapImageCShear(PyObject *self, PyObject *args)
|
|
|
|
{
|
|
|
|
Effect * effect = getEffect();
|
2017-10-12 11:55:03 +02:00
|
|
|
|
2017-07-30 14:36:23 +02:00
|
|
|
int sh,sv;
|
|
|
|
int argCount = PyTuple_Size(args);
|
2017-10-12 11:55:03 +02:00
|
|
|
|
2017-07-30 14:36:23 +02:00
|
|
|
if ( argCount == 2 && PyArg_ParseTuple(args, "ii", &sh, &sv ))
|
|
|
|
{
|
|
|
|
effect->_painter->shear(sh,sv);
|
|
|
|
return Py_BuildValue("");
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
PyObject* Effect::wrapImageResetT(PyObject *self, PyObject *args)
|
|
|
|
{
|
|
|
|
Effect * effect = getEffect();
|
|
|
|
|
|
|
|
effect->_painter->resetTransform();
|
|
|
|
return Py_BuildValue("");
|
|
|
|
}
|
|
|
|
|
2014-02-26 18:10:17 +01:00
|
|
|
Effect * Effect::getEffect()
|
2013-12-08 12:46:33 +01:00
|
|
|
{
|
2014-03-01 19:28:57 +01:00
|
|
|
// extract the module from the runtime
|
|
|
|
PyObject * module = PyObject_GetAttrString(PyImport_AddModule("__main__"), "hyperion");
|
|
|
|
|
|
|
|
if (!PyModule_Check(module))
|
|
|
|
{
|
|
|
|
// something is wrong
|
|
|
|
Py_XDECREF(module);
|
2016-06-23 13:48:49 +02:00
|
|
|
Error(Logger::getInstance("EFFECTENGINE"), "Unable to retrieve the effect object from the Python runtime");
|
2014-03-01 19:28:57 +01:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// retrieve the capsule with the effect
|
|
|
|
PyObject * effectCapsule = PyObject_GetAttrString(module, "__effectObj");
|
|
|
|
Py_XDECREF(module);
|
|
|
|
|
|
|
|
if (!PyCapsule_CheckExact(effectCapsule))
|
|
|
|
{
|
|
|
|
// something is wrong
|
|
|
|
Py_XDECREF(effectCapsule);
|
2016-06-23 13:48:49 +02:00
|
|
|
Error(Logger::getInstance("EFFECTENGINE"), "Unable to retrieve the effect object from the Python runtime");
|
2014-03-01 19:28:57 +01:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the effect from the capsule
|
|
|
|
Effect * effect = reinterpret_cast<Effect *>(PyCapsule_GetPointer(effectCapsule, nullptr));
|
|
|
|
Py_XDECREF(effectCapsule);
|
|
|
|
return effect;
|
2013-11-28 14:29:31 +01:00
|
|
|
}
|