Skip to content

Commit ec67caf

Browse files
author
redpanther
committed
add ability to convert an image to RGB color order
forwarder: add flag to detect if forwarding is enabled Former-commit-id: c814651ec4973fe3b2bfca7c0370a0bac752f025
1 parent 736d841 commit ec67caf

File tree

4 files changed

+54
-7
lines changed

4 files changed

+54
-7
lines changed

include/hyperion/MessageForwarder.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ class MessageForwarder
2727

2828
void addJsonSlave(std::string slave);
2929
void addProtoSlave(std::string slave);
30-
30+
31+
bool protoForwardingEnabled();
3132
QStringList getProtoSlaves();
3233
QList<MessageForwarder::JsonSlaveAddress> getJsonSlaves();
3334

include/utils/Image.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include <cstdint>
66
#include <cstring>
77
#include <algorithm>
8+
#include <utils/ColorRgb.h>
9+
810

911
template <typename Pixel_T>
1012
class Image
@@ -183,6 +185,25 @@ class Image
183185
{
184186
return _pixels;
185187
}
188+
189+
190+
///
191+
/// Convert image of any color order to a RGB image.
192+
///
193+
/// @param[out] image The image that buffers the output
194+
///
195+
void toRgb(Image<ColorRgb>& image)
196+
{
197+
image.resize(_width, _height);
198+
const unsigned imageSize = _width * _height;
199+
200+
for (unsigned idx=0; idx<imageSize; idx++)
201+
{
202+
const Pixel_T color = memptr()[idx];
203+
image.memptr()[idx] = ColorRgb{color.red, color.green, color.blue};
204+
}
205+
}
206+
186207
private:
187208

188209
///

libsrc/hyperion/MessageForwarder.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,8 @@ QList<MessageForwarder::JsonSlaveAddress> MessageForwarder::getJsonSlaves()
4444
{
4545
return _jsonSlaves;
4646
}
47+
48+
bool MessageForwarder::protoForwardingEnabled()
49+
{
50+
return ! _protoSlaves.empty();
51+
}

test/TestRgbImage.cpp

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,42 @@
44

55
// Utils includes
66
#include <utils/Image.h>
7+
#include <utils/ColorRgba.h>
78
#include <utils/ColorRgb.h>
9+
#include <utils/ColorBgr.h>
10+
#include <hyperion/ImageProcessor.h>
811

912
int main()
1013
{
1114
std::cout << "Constructing image" << std::endl;
12-
Image<ColorRgb> image(64, 64, ColorRgb::BLACK);
15+
int width = 64;
16+
int height = 64;
17+
Image<ColorRgb> image_rgb(width, height, ColorRgb::BLACK);
18+
Image<ColorBgr> image_bgr(image_rgb.width(), image_rgb.height(), ColorBgr::BLACK);
1319

1420
std::cout << "Writing image" << std::endl;
15-
for (unsigned y=0; y<64; ++y)
21+
unsigned l = width * height;
22+
23+
// BGR
24+
for (unsigned i=0; i<l; ++i)
25+
image_bgr.memptr()[i] = ColorBgr{0,128,255};
26+
27+
28+
// to RGB
29+
image_bgr.toRgb(image_rgb);
30+
31+
// test
32+
for (unsigned i=0; i<l; ++i)
1633
{
17-
for (unsigned x=0; x<64; ++x)
18-
{
19-
image(x,y) = ColorRgb::RED;
20-
}
34+
const ColorRgb rgb = image_rgb.memptr()[i];
35+
if ( rgb.red != 255 || rgb.green != 128 || rgb.blue != 0 )
36+
std::cout << "RGB error idx " << i << " " << rgb << std::endl;
2137
}
2238

39+
40+
41+
42+
2343
std::cout << "Finished (destruction will be performed)" << std::endl;
2444

2545
return 0;

0 commit comments

Comments
 (0)