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

@@ -152,15 +152,36 @@ void FlatBufferClient::handleImageCommand(const hyperionnet::Image *image)
const int width = img->width();
const int height = img->height();
if ((int) imageData->size() != width*height*3)
if (width <= 0 || height <= 0)
{
sendErrorReply("Size of image data does not match with the width and height");
return;
}
Image<ColorRgb> imageDest(width, height);
memmove(imageDest.memptr(), imageData->data(), imageData->size());
emit setGlobalInputImage(_priority, imageDest, duration);
// check consistency of the size of the received data
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> imageRGB(width, height);
if (channelCount == 3)
{
memmove(imageRGB.memptr(), imageData->data(), imageData->size());
}
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->data() + destination, sizeof(ColorRgb));
}
}
emit setGlobalInputImage(_priority, imageRGB, duration);
}
// send reply

View File

@@ -4,6 +4,7 @@
#include <utils/Logger.h>
#include <utils/Image.h>
#include <utils/ColorRgb.h>
#include <utils/ColorRgba.h>
#include <utils/Components.h>
// flatbuffer FBS

View File

@@ -14,6 +14,7 @@ table RawImage {
union ImageType {RawImage}
// Either RGB or RGBA data can be transferred
table Image {
data:ImageType (required);
duration:int = -1;