mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
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:
parent
736d841567
commit
ec67caf24e
@ -28,6 +28,7 @@ public:
|
||||
void addJsonSlave(std::string slave);
|
||||
void addProtoSlave(std::string slave);
|
||||
|
||||
bool protoForwardingEnabled();
|
||||
QStringList getProtoSlaves();
|
||||
QList<MessageForwarder::JsonSlaveAddress> getJsonSlaves();
|
||||
|
||||
|
@ -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:
|
||||
|
||||
///
|
||||
|
@ -44,3 +44,8 @@ QList<MessageForwarder::JsonSlaveAddress> MessageForwarder::getJsonSlaves()
|
||||
{
|
||||
return _jsonSlaves;
|
||||
}
|
||||
|
||||
bool MessageForwarder::protoForwardingEnabled()
|
||||
{
|
||||
return ! _protoSlaves.empty();
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user