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

@ -29,8 +29,10 @@ PyMethodDef Effect::effectMethods[] = {
{"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"},
{"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}
};
@ -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

@ -60,6 +60,10 @@ private:
static PyObject* wrapImageCanonicalGradient(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)+')')