mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
add more drawing func to effect engine (#400)
* - add more drawing func to effect engine - make provider rs232 less noisy - json checks: remove utf8 conversion temporarly and make it compat with py3 again * fix compile prob
This commit is contained in:
parent
53406e4290
commit
cab3c2fdc9
@ -52,5 +52,5 @@ elseif (DEFAULT_USE_AVAHI_LIBS)
|
|||||||
libavahi-client.a
|
libavahi-client.a
|
||||||
libavahi-common.a
|
libavahi-common.a
|
||||||
libavahi-core.a
|
libavahi-core.a
|
||||||
libdbus-1.a)
|
dbus-1)
|
||||||
endif()
|
endif()
|
||||||
|
@ -22,15 +22,17 @@
|
|||||||
|
|
||||||
// Python method table
|
// Python method table
|
||||||
PyMethodDef Effect::effectMethods[] = {
|
PyMethodDef Effect::effectMethods[] = {
|
||||||
{"setColor", Effect::wrapSetColor, METH_VARARGS, "Set a new color for the leds."},
|
{"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."},
|
{"setImage" , Effect::wrapSetImage , METH_VARARGS, "Set a new image to process and determine new led colors."},
|
||||||
{"abort", Effect::wrapAbort, METH_NOARGS, "Check if the effect should abort execution."},
|
{"abort" , Effect::wrapAbort , METH_NOARGS, "Check if the effect should abort execution."},
|
||||||
{"imageShow", Effect::wrapImageShow, METH_NOARGS, "set current effect image to hyperion core."},
|
{"imageShow" , Effect::wrapImageShow , METH_NOARGS, "set current effect image to hyperion core."},
|
||||||
{"imageCanonicalGradient", Effect::wrapImageCanonicalGradient, METH_VARARGS, ""},
|
{"imageCanonicalGradient", Effect::wrapImageCanonicalGradient, METH_VARARGS, ""},
|
||||||
{"imageRadialGradient" , Effect::wrapImageRadialGradient, METH_VARARGS, ""},
|
{"imageRadialGradient" , Effect::wrapImageRadialGradient , METH_VARARGS, ""},
|
||||||
{"imageSolidFill" , Effect::wrapImageSolidFill, METH_VARARGS, ""},
|
{"imageSolidFill" , Effect::wrapImageSolidFill , METH_VARARGS, ""},
|
||||||
// {"imageSetPixel",Effect::wrapImageShow, METH_VARARGS, "set pixel color of image"},
|
{"imageDrawLine" , Effect::wrapImageDrawLine , METH_VARARGS, ""},
|
||||||
// {"imageGetPixel",Effect::wrapImageShow, METH_VARARGS, "get pixel color of image"},
|
{"imageDrawRect" , Effect::wrapImageDrawRect , METH_VARARGS, ""},
|
||||||
|
{"imageSetPixel" , Effect::wrapImageSetPixel , METH_VARARGS, "set pixel color of image"},
|
||||||
|
{"imageGetPixel" , Effect::wrapImageGetPixel , METH_VARARGS, "get pixel color of image"},
|
||||||
{NULL, NULL, 0, NULL}
|
{NULL, NULL, 0, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -637,6 +639,146 @@ PyObject* Effect::wrapImageSolidFill(PyObject *self, PyObject *args)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
QRect myQRect(startX, startY, endX, endY);
|
||||||
|
QPen oldPen = effect->_painter->pen();
|
||||||
|
QPen newPen(QColor(r,g,b,a));
|
||||||
|
newPen.setWidth(thick);
|
||||||
|
effect->_painter->setPen(newPen);
|
||||||
|
effect->_painter->drawLine(startX, startY, endX, endY);
|
||||||
|
effect->_painter->setPen(oldPen);
|
||||||
|
|
||||||
|
return Py_BuildValue("");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
QRect myQRect(startX,startY,width,height);
|
||||||
|
QPen oldPen = effect->_painter->pen();
|
||||||
|
QPen newPen(QColor(r,g,b,a));
|
||||||
|
newPen.setWidth(thick);
|
||||||
|
effect->_painter->setPen(newPen);
|
||||||
|
effect->_painter->drawRect(startX, startY, width, height);
|
||||||
|
effect->_painter->setPen(oldPen);
|
||||||
|
|
||||||
|
return Py_BuildValue("");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PyObject* Effect::wrapImageSetPixel(PyObject *self, PyObject *args)
|
||||||
|
{
|
||||||
|
Effect * effect = getEffect();
|
||||||
|
|
||||||
|
int argCount = PyTuple_Size(args);
|
||||||
|
int r, g, b, x, y;
|
||||||
|
|
||||||
|
bool argsOK = false;
|
||||||
|
|
||||||
|
if ( argCount == 5 && PyArg_ParseTuple(args, "iiiii", &x, &y, &r, &g, &b ) )
|
||||||
|
{
|
||||||
|
argsOK = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (argsOK)
|
||||||
|
{
|
||||||
|
effect->_image->setPixel(x,y,qRgb(r,g,b));
|
||||||
|
|
||||||
|
return Py_BuildValue("");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PyObject* Effect::wrapImageGetPixel(PyObject *self, PyObject *args)
|
||||||
|
{
|
||||||
|
Effect * effect = getEffect();
|
||||||
|
|
||||||
|
int argCount = PyTuple_Size(args);
|
||||||
|
int x, y;
|
||||||
|
|
||||||
|
bool argsOK = false;
|
||||||
|
|
||||||
|
if ( argCount == 2 && PyArg_ParseTuple(args, "ii", &x, &y) )
|
||||||
|
{
|
||||||
|
argsOK = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (argsOK)
|
||||||
|
{
|
||||||
|
QRgb rgb = effect->_image->pixel(x,y);
|
||||||
|
|
||||||
|
return Py_BuildValue("iii",qRed(rgb),qGreen(rgb),qBlue(rgb));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Effect * Effect::getEffect()
|
Effect * Effect::getEffect()
|
||||||
{
|
{
|
||||||
// extract the module from the runtime
|
// extract the module from the runtime
|
||||||
|
@ -53,13 +53,17 @@ private:
|
|||||||
|
|
||||||
// Wrapper methods for Python interpreter extra buildin methods
|
// Wrapper methods for Python interpreter extra buildin methods
|
||||||
static PyMethodDef effectMethods[];
|
static PyMethodDef effectMethods[];
|
||||||
static PyObject* wrapSetColor(PyObject *self, PyObject *args);
|
static PyObject* wrapSetColor (PyObject *self, PyObject *args);
|
||||||
static PyObject* wrapSetImage(PyObject *self, PyObject *args);
|
static PyObject* wrapSetImage (PyObject *self, PyObject *args);
|
||||||
static PyObject* wrapAbort(PyObject *self, PyObject *args);
|
static PyObject* wrapAbort (PyObject *self, PyObject *args);
|
||||||
static PyObject* wrapImageShow(PyObject *self, PyObject *args);
|
static PyObject* wrapImageShow (PyObject *self, PyObject *args);
|
||||||
static PyObject* wrapImageCanonicalGradient(PyObject *self, PyObject *args);
|
static PyObject* wrapImageCanonicalGradient(PyObject *self, PyObject *args);
|
||||||
static PyObject* wrapImageRadialGradient(PyObject *self, PyObject *args);
|
static PyObject* wrapImageRadialGradient (PyObject *self, PyObject *args);
|
||||||
static PyObject* wrapImageSolidFill(PyObject *self, PyObject *args);
|
static PyObject* wrapImageSolidFill (PyObject *self, PyObject *args);
|
||||||
|
static PyObject* wrapImageDrawLine (PyObject *self, PyObject *args);
|
||||||
|
static PyObject* wrapImageDrawRect (PyObject *self, PyObject *args);
|
||||||
|
static PyObject* wrapImageSetPixel (PyObject *self, PyObject *args);
|
||||||
|
static PyObject* wrapImageGetPixel (PyObject *self, PyObject *args);
|
||||||
|
|
||||||
static Effect * getEffect();
|
static Effect * getEffect();
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ void ProviderRs232::bytesWritten(qint64 bytes)
|
|||||||
void ProviderRs232::readyRead()
|
void ProviderRs232::readyRead()
|
||||||
{
|
{
|
||||||
emit receivedData(_rs232Port.readAll());
|
emit receivedData(_rs232Port.readAll());
|
||||||
Debug(_log, "received data");
|
//Debug(_log, "received data");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,14 +12,14 @@ retval = 0
|
|||||||
total = 0
|
total = 0
|
||||||
errors = 0
|
errors = 0
|
||||||
with open("libsrc/effectengine/EffectDefinition.schema.json") as baseSchemaFile:
|
with open("libsrc/effectengine/EffectDefinition.schema.json") as baseSchemaFile:
|
||||||
baseSchema = json.loads(baseSchemaFile.read().decode('utf-8-sig'))
|
baseSchema = json.loads(baseSchemaFile.read())
|
||||||
baseValidator = Draft3Validator(baseSchema)
|
baseValidator = Draft3Validator(baseSchema)
|
||||||
for filename in glob.glob(jsonFiles+'/*.json'):
|
for filename in glob.glob(jsonFiles+'/*.json'):
|
||||||
with open(filename) as f:
|
with open(filename) as f:
|
||||||
total += 1
|
total += 1
|
||||||
msg = " check effect %s ... " % filename
|
msg = " check effect %s ... " % filename
|
||||||
try:
|
try:
|
||||||
effect = json.loads(f.read().decode('utf-8-sig'))
|
effect = json.loads(f.read())
|
||||||
script = path.basename(effect['script'])
|
script = path.basename(effect['script'])
|
||||||
if not path.exists(jsonFiles+'/'+script):
|
if not path.exists(jsonFiles+'/'+script):
|
||||||
raise ValueError('script file: '+script+' not found.')
|
raise ValueError('script file: '+script+' not found.')
|
||||||
@ -31,7 +31,7 @@ with open("libsrc/effectengine/EffectDefinition.schema.json") as baseSchemaFile:
|
|||||||
|
|
||||||
# validate against schema
|
# validate against schema
|
||||||
with open(schema) as s:
|
with open(schema) as s:
|
||||||
effectSchema = json.loads(s.read().decode('utf-8-sig'))
|
effectSchema = json.loads(s.read())
|
||||||
Draft3Validator.check_schema(effectSchema)
|
Draft3Validator.check_schema(effectSchema)
|
||||||
validator = Draft3Validator(effectSchema)
|
validator = Draft3Validator(effectSchema)
|
||||||
baseValidator.validate(effect)
|
baseValidator.validate(effect)
|
||||||
|
@ -11,7 +11,8 @@ for filename in sys.argv[1:]:
|
|||||||
total += 1
|
total += 1
|
||||||
msg = " check json %s ... " % filename
|
msg = " check json %s ... " % filename
|
||||||
try:
|
try:
|
||||||
json.loads(f.read().decode('utf-8-sig'))
|
data = f.read()
|
||||||
|
json.loads(data)
|
||||||
#print(msg + "ok")
|
#print(msg + "ok")
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
print(msg + 'invalid ('+str(e)+')')
|
print(msg + 'invalid ('+str(e)+')')
|
||||||
|
@ -11,8 +11,8 @@ schemaFileName = sys.argv[2]
|
|||||||
try:
|
try:
|
||||||
with open(schemaFileName) as schemaFile:
|
with open(schemaFileName) as schemaFile:
|
||||||
with open(jsonFileName) as jsonFile:
|
with open(jsonFileName) as jsonFile:
|
||||||
j = json.loads(jsonFile.read().decode('utf-8-sig'))
|
j = json.loads(jsonFile.read())
|
||||||
validator = Draft3Validator(json.loads(schemaFile.read().decode('utf-8-sig')))
|
validator = Draft3Validator(json.loads(schemaFile.read()))
|
||||||
validator.validate(j)
|
validator.validate(j)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print('validation error: '+jsonFileName + ' '+schemaFileName+' ('+str(e)+')')
|
print('validation error: '+jsonFileName + ' '+schemaFileName+' ('+str(e)+')')
|
||||||
|
Loading…
Reference in New Issue
Block a user