Flatbuffer/Protobuf now able to receive rgba data (#1399)

* Flatbuffer/Protobuf now able to receive rgba data

* Proto/Flat schema comment added

* Prevent diveded by zero

* Address LGTM findings

* Fix EncoderThread & cleanup

Co-authored-by: LordGrey <lordgrey.emmel@gmail.com>
This commit is contained in:
Markus
2022-01-09 17:23:50 +01:00
committed by GitHub
parent 2f573a117f
commit 98654e48f6
11 changed files with 97 additions and 34 deletions

View File

@@ -168,18 +168,36 @@ void ProtoClientConnection::handleImageCommand(const proto::ImageRequest &messag
_priority = priority;
}
if (width <= 0 || height <= 0)
{
sendErrorReply("Size of image data does not match with the width and height");
return;
}
// check consistency of the size of the received data
if ((int) imageData.size() != width*height*3)
int channelCount = (int)imageData.size()/(width*height);
if (channelCount != 3 && channelCount != 4)
{
sendErrorReply("Size of image data does not match with the width and height");
return;
}
// create ImageRgb
Image<ColorRgb> image(width, height);
memcpy(image.memptr(), imageData.c_str(), imageData.size());
Image<ColorRgb> imageRGB(width, height);
if (channelCount == 3)
{
memmove(imageRGB.memptr(), imageData.c_str(), imageData.size());
}
emit setGlobalInputImage(_priority, image, duration);
if (channelCount == 4)
{
for (int source=0, destination=0; source < width * height * static_cast<int>(sizeof(ColorRgb)); source+=sizeof(ColorRgb), destination+=sizeof(ColorRgba))
{
memmove((uint8_t*)imageRGB.memptr() + source, imageData.c_str() + destination, sizeof(ColorRgb));
}
}
emit setGlobalInputImage(_priority, imageRGB, duration);
// send reply
sendSuccessReply();

View File

@@ -9,6 +9,7 @@
#include <utils/Logger.h>
#include <utils/Image.h>
#include <utils/ColorRgb.h>
#include <utils/ColorRgba.h>
#include <utils/Components.h>
class QTcpSocket;

View File

@@ -45,7 +45,7 @@ message ImageRequest {
// height of the image
required int32 imageheight = 3;
// image data
// image data (either RGB or RGBA data can be transferred)
required bytes imagedata = 4;
// duration of the request (negative results in infinite)