mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
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:
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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;
|
||||
|
Reference in New Issue
Block a user