add ability to convert an image to RGB color order

forwarder: add flag to detect if forwarding is enabled

Former-commit-id: c814651ec4973fe3b2bfca7c0370a0bac752f025
This commit is contained in:
redpanther 2016-02-19 13:31:08 +01:00
parent 736d841567
commit ec67caf24e
4 changed files with 54 additions and 7 deletions

View File

@ -27,7 +27,8 @@ public:
void addJsonSlave(std::string slave);
void addProtoSlave(std::string slave);
bool protoForwardingEnabled();
QStringList getProtoSlaves();
QList<MessageForwarder::JsonSlaveAddress> getJsonSlaves();

View File

@ -5,6 +5,8 @@
#include <cstdint>
#include <cstring>
#include <algorithm>
#include <utils/ColorRgb.h>
template <typename Pixel_T>
class Image
@ -183,6 +185,25 @@ public:
{
return _pixels;
}
///
/// Convert image of any color order to a RGB image.
///
/// @param[out] image The image that buffers the output
///
void toRgb(Image<ColorRgb>& image)
{
image.resize(_width, _height);
const unsigned imageSize = _width * _height;
for (unsigned idx=0; idx<imageSize; idx++)
{
const Pixel_T color = memptr()[idx];
image.memptr()[idx] = ColorRgb{color.red, color.green, color.blue};
}
}
private:
///

View File

@ -44,3 +44,8 @@ QList<MessageForwarder::JsonSlaveAddress> MessageForwarder::getJsonSlaves()
{
return _jsonSlaves;
}
bool MessageForwarder::protoForwardingEnabled()
{
return ! _protoSlaves.empty();
}

View File

@ -4,22 +4,42 @@
// Utils includes
#include <utils/Image.h>
#include <utils/ColorRgba.h>
#include <utils/ColorRgb.h>
#include <utils/ColorBgr.h>
#include <hyperion/ImageProcessor.h>
int main()
{
std::cout << "Constructing image" << std::endl;
Image<ColorRgb> image(64, 64, ColorRgb::BLACK);
int width = 64;
int height = 64;
Image<ColorRgb> image_rgb(width, height, ColorRgb::BLACK);
Image<ColorBgr> image_bgr(image_rgb.width(), image_rgb.height(), ColorBgr::BLACK);
std::cout << "Writing image" << std::endl;
for (unsigned y=0; y<64; ++y)
unsigned l = width * height;
// BGR
for (unsigned i=0; i<l; ++i)
image_bgr.memptr()[i] = ColorBgr{0,128,255};
// to RGB
image_bgr.toRgb(image_rgb);
// test
for (unsigned i=0; i<l; ++i)
{
for (unsigned x=0; x<64; ++x)
{
image(x,y) = ColorRgb::RED;
}
const ColorRgb rgb = image_rgb.memptr()[i];
if ( rgb.red != 255 || rgb.green != 128 || rgb.blue != 0 )
std::cout << "RGB error idx " << i << " " << rgb << std::endl;
}
std::cout << "Finished (destruction will be performed)" << std::endl;
return 0;