Set image implemented

This commit is contained in:
johan 2013-08-18 20:55:59 +02:00
parent 1766212b70
commit 0a9bbe86a4
2 changed files with 34 additions and 1 deletions

View File

@ -11,6 +11,8 @@
#include <QResource> #include <QResource>
// hyperion util includes // hyperion util includes
#include "hyperion/ImageProcessorFactory.h"
#include "hyperion/ImageProcessor.h"
#include "utils/RgbColor.h" #include "utils/RgbColor.h"
// project includes // project includes
@ -19,6 +21,7 @@
JsonClientConnection::JsonClientConnection(QTcpSocket *socket, Hyperion * hyperion) : JsonClientConnection::JsonClientConnection(QTcpSocket *socket, Hyperion * hyperion) :
QObject(), QObject(),
_socket(socket), _socket(socket),
_imageProcessor(ImageProcessorFactory::getInstance().newImageProcessor()),
_hyperion(hyperion), _hyperion(hyperion),
_receiveBuffer() _receiveBuffer()
{ {
@ -115,7 +118,33 @@ void JsonClientConnection::handleColorCommand(const Json::Value &message)
void JsonClientConnection::handleImageCommand(const Json::Value &message) void JsonClientConnection::handleImageCommand(const Json::Value &message)
{ {
handleNotImplemented(); // extract parameters
int priority = message["priority"].asInt();
int duration = message.get("duration", -1).asInt();
int width = message["imagewidth"].asInt();
int height = message["imageheight"].asInt();
QByteArray data = QByteArray::fromBase64(QByteArray(message["imagedata"].asCString()));
// check consistency of the size of the received data
if (data.size() != width*height*3)
{
sendErrorReply("Size of image data does not match with the width and height");
return;
}
// set width and height of the image processor
_imageProcessor->setSize(width, height);
// create RgbImage
RgbImage image(width, height);
memcpy(image.memptr(), data.data(), data.size());
// process the image
std::vector<RgbColor> ledColors = _imageProcessor->process(image);
_hyperion->setColors(priority, ledColors, duration);
// send reply
sendSuccessReply();
} }
void JsonClientConnection::handleServerInfoCommand(const Json::Value &message) void JsonClientConnection::handleServerInfoCommand(const Json::Value &message)

View File

@ -16,6 +16,8 @@
// util includes // util includes
#include <utils/jsonschema/JsonSchemaChecker.h> #include <utils/jsonschema/JsonSchemaChecker.h>
class ImageProcessor;
class JsonClientConnection : public QObject class JsonClientConnection : public QObject
{ {
Q_OBJECT Q_OBJECT
@ -51,6 +53,8 @@ private:
private: private:
QTcpSocket * _socket; QTcpSocket * _socket;
ImageProcessor * _imageProcessor;
Hyperion * _hyperion; Hyperion * _hyperion;
QByteArray _receiveBuffer; QByteArray _receiveBuffer;