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:
@@ -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();
|
||||
|
@@ -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;
|
||||
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user