Skip to content

Flatbuffer/Protobuf now able to receive rgba data #1399

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions libsrc/flatbufserver/FlatBufferClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,30 @@ void FlatBufferClient::handleImageCommand(const hyperionnet::Image *image)
const int width = img->width();
const int height = img->height();

if ((int) imageData->size() != width*height*3)
// 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;
}

Image<ColorRgb> imageDest(width, height);
memmove(imageDest.memptr(), imageData->data(), imageData->size());
emit setGlobalInputImage(_priority, imageDest, duration);
// 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 * 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
Expand Down
1 change: 1 addition & 0 deletions libsrc/flatbufserver/FlatBufferClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions libsrc/flatbufserver/hyperion_request.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 16 additions & 4 deletions libsrc/protoserver/ProtoClientConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,17 +169,29 @@ void ProtoClientConnection::handleImageCommand(const proto::ImageRequest &messag
}

// 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());
}

if (channelCount == 4)
{
for (int source=0, destination=0; source < width * height * sizeof(ColorRgb); source+=sizeof(ColorRgb), destination+=sizeof(ColorRgba))
{
memmove((uint8_t*)imageRGB.memptr() + source, imageData.c_str() + destination, sizeof(ColorRgb));
}
}

emit setGlobalInputImage(_priority, image, duration);
emit setGlobalInputImage(_priority, imageRGB, duration);

// send reply
sendSuccessReply();
Expand Down
1 change: 1 addition & 0 deletions libsrc/protoserver/ProtoClientConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion libsrc/protoserver/message.proto
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,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)
Expand Down