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:
redPanther 2017-02-16 07:33:58 +01:00 committed by GitHub
parent 53406e4290
commit cab3c2fdc9
7 changed files with 176 additions and 29 deletions

View File

@ -52,5 +52,5 @@ elseif (DEFAULT_USE_AVAHI_LIBS)
libavahi-client.a
libavahi-common.a
libavahi-core.a
libdbus-1.a)
dbus-1)
endif()

View File

@ -22,15 +22,17 @@
// Python method table
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."},
{"abort", Effect::wrapAbort, METH_NOARGS, "Check if the effect should abort execution."},
{"imageShow", Effect::wrapImageShow, METH_NOARGS, "set current effect image to hyperion core."},
{"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."},
{"abort" , Effect::wrapAbort , METH_NOARGS, "Check if the effect should abort execution."},
{"imageShow" , Effect::wrapImageShow , METH_NOARGS, "set current effect image to hyperion core."},
{"imageCanonicalGradient", Effect::wrapImageCanonicalGradient, METH_VARARGS, ""},
{"imageRadialGradient" , Effect::wrapImageRadialGradient, METH_VARARGS, ""},
{"imageSolidFill" , Effect::wrapImageSolidFill, METH_VARARGS, ""},
// {"imageSetPixel",Effect::wrapImageShow, METH_VARARGS, "set pixel color of image"},
// {"imageGetPixel",Effect::wrapImageShow, METH_VARARGS, "get pixel color of image"},
{"imageRadialGradient" , Effect::wrapImageRadialGradient , METH_VARARGS, ""},
{"imageSolidFill" , Effect::wrapImageSolidFill , METH_VARARGS, ""},
{"imageDrawLine" , Effect::wrapImageDrawLine , METH_VARARGS, ""},
{"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}
};
@ -452,11 +454,11 @@ PyObject* Effect::wrapImageCanonicalGradient(PyObject *self, PyObject *args)
if ( argCount == 8 && PyArg_ParseTuple(args, "iiiiiiiO", &startX, &startY, &width, &height, &centerX, &centerY, &angle, &bytearray) )
{
argsOK = true;
argsOK = true;
}
if ( argCount == 4 && PyArg_ParseTuple(args, "iiiO", &centerX, &centerY, &angle, &bytearray) )
{
argsOK = true;
argsOK = true;
}
angle = std::max(std::min(angle,360),0);
@ -536,7 +538,7 @@ PyObject* Effect::wrapImageRadialGradient(PyObject *self, PyObject *args)
}
if ( argCount == 7 && PyArg_ParseTuple(args, "iiiiiiO", &centerX, &centerY, &radius, &focalX, &focalY, &focalRadius, &bytearray) )
{
argsOK = true;
argsOK = true;
}
if ( argCount == 4 && PyArg_ParseTuple(args, "iiiO", &centerX, &centerY, &radius, &bytearray) )
{
@ -609,19 +611,19 @@ PyObject* Effect::wrapImageSolidFill(PyObject *self, PyObject *args)
if ( argCount == 8 && PyArg_ParseTuple(args, "iiiiiiii", &startX, &startY, &width, &height, &r, &g, &b, &a) )
{
argsOK = true;
argsOK = true;
}
if ( argCount == 7 && PyArg_ParseTuple(args, "iiiiiii", &startX, &startY, &width, &height, &r, &g, &b) )
{
argsOK = true;
argsOK = true;
}
if ( argCount == 4 && PyArg_ParseTuple(args, "iiii",&r, &g, &b, &a) )
{
argsOK = true;
argsOK = true;
}
if ( argCount == 3 && PyArg_ParseTuple(args, "iii",&r, &g, &b) )
{
argsOK = true;
argsOK = true;
}
if (argsOK)
@ -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()
{
// extract the module from the runtime

View File

@ -53,13 +53,17 @@ private:
// Wrapper methods for Python interpreter extra buildin methods
static PyMethodDef effectMethods[];
static PyObject* wrapSetColor(PyObject *self, PyObject *args);
static PyObject* wrapSetImage(PyObject *self, PyObject *args);
static PyObject* wrapAbort(PyObject *self, PyObject *args);
static PyObject* wrapImageShow(PyObject *self, PyObject *args);
static PyObject* wrapSetColor (PyObject *self, PyObject *args);
static PyObject* wrapSetImage (PyObject *self, PyObject *args);
static PyObject* wrapAbort (PyObject *self, PyObject *args);
static PyObject* wrapImageShow (PyObject *self, PyObject *args);
static PyObject* wrapImageCanonicalGradient(PyObject *self, PyObject *args);
static PyObject* wrapImageRadialGradient(PyObject *self, PyObject *args);
static PyObject* wrapImageSolidFill(PyObject *self, PyObject *args);
static PyObject* wrapImageRadialGradient (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();

View File

@ -73,7 +73,7 @@ void ProviderRs232::bytesWritten(qint64 bytes)
void ProviderRs232::readyRead()
{
emit receivedData(_rs232Port.readAll());
Debug(_log, "received data");
//Debug(_log, "received data");
}

View File

@ -12,14 +12,14 @@ retval = 0
total = 0
errors = 0
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)
for filename in glob.glob(jsonFiles+'/*.json'):
with open(filename) as f:
total += 1
msg = " check effect %s ... " % filename
try:
effect = json.loads(f.read().decode('utf-8-sig'))
effect = json.loads(f.read())
script = path.basename(effect['script'])
if not path.exists(jsonFiles+'/'+script):
raise ValueError('script file: '+script+' not found.')
@ -31,7 +31,7 @@ with open("libsrc/effectengine/EffectDefinition.schema.json") as baseSchemaFile:
# validate against schema
with open(schema) as s:
effectSchema = json.loads(s.read().decode('utf-8-sig'))
effectSchema = json.loads(s.read())
Draft3Validator.check_schema(effectSchema)
validator = Draft3Validator(effectSchema)
baseValidator.validate(effect)

View File

@ -11,7 +11,8 @@ for filename in sys.argv[1:]:
total += 1
msg = " check json %s ... " % filename
try:
json.loads(f.read().decode('utf-8-sig'))
data = f.read()
json.loads(data)
#print(msg + "ok")
except ValueError as e:
print(msg + 'invalid ('+str(e)+')')

View File

@ -11,8 +11,8 @@ schemaFileName = sys.argv[2]
try:
with open(schemaFileName) as schemaFile:
with open(jsonFileName) as jsonFile:
j = json.loads(jsonFile.read().decode('utf-8-sig'))
validator = Draft3Validator(json.loads(schemaFile.read().decode('utf-8-sig')))
j = json.loads(jsonFile.read())
validator = Draft3Validator(json.loads(schemaFile.read()))
validator.validate(j)
except Exception as e:
print('validation error: '+jsonFileName + ' '+schemaFileName+' ('+str(e)+')')