Changed RgbImage to template based Image (with template for pixel type)

Former-commit-id: ef02f164eaf3c2f9dd552c1c17b525cf6eed499c
This commit is contained in:
T. van der Zwan
2013-11-11 09:00:37 +00:00
parent 90f1f282e2
commit dd16af0df5
58 changed files with 593 additions and 464 deletions

View File

@@ -12,9 +12,9 @@ add_executable(test_configfile
target_link_libraries(test_configfile
hyperion)
add_executable(test_rgbimage
add_executable(test_ImageRgb
TestRgbImage.cpp)
target_link_libraries(test_rgbimage
target_link_libraries(test_ImageRgb
hyperion-utils)
add_executable(test_colortransform

View File

@@ -3,11 +3,12 @@
#include <random>
// Hyperion includes
#include "hyperion/BlackBorderDetector.h"
#include <hyperion/BlackBorderDetector.h>
#include <utils/ColorRgb.h>
using namespace hyperion;
RgbColor randomColor()
ColorRgb randomColor()
{
const uint8_t randomRedValue = uint8_t(rand() % (std::numeric_limits<uint8_t>::max() + 1));
const uint8_t randomGreenValue = uint8_t(rand() % (std::numeric_limits<uint8_t>::max() + 1));
@@ -16,16 +17,16 @@ RgbColor randomColor()
return {randomRedValue, randomGreenValue, randomBlueValue};
}
RgbImage createImage(unsigned width, unsigned height, unsigned topBorder, unsigned leftBorder)
Image<ColorRgb> createImage(unsigned width, unsigned height, unsigned topBorder, unsigned leftBorder)
{
RgbImage image(width, height);
Image<ColorRgb> image(width, height);
for (unsigned x=0; x<image.width(); ++x)
{
for (unsigned y=0; y<image.height(); ++y)
{
if (y < topBorder || x < leftBorder)
{
image(x,y) = RgbColor::BLACK;
image(x,y) = ColorRgb::BLACK;
}
else
{
@@ -43,7 +44,7 @@ int TC_NO_BORDER()
BlackBorderDetector detector;
{
RgbImage image = createImage(64, 64, 0, 0);
Image<ColorRgb> image = createImage(64, 64, 0, 0);
BlackBorder border = detector.process(image);
if (border.unknown != false && border.horizontalSize != 0 && border.verticalSize != 0)
{
@@ -62,7 +63,7 @@ int TC_TOP_BORDER()
BlackBorderDetector detector;
{
RgbImage image = createImage(64, 64, 12, 0);
Image<ColorRgb> image = createImage(64, 64, 12, 0);
BlackBorder border = detector.process(image);
if (border.unknown != false && border.horizontalSize != 12 && border.verticalSize != 0)
{
@@ -81,7 +82,7 @@ int TC_LEFT_BORDER()
BlackBorderDetector detector;
{
RgbImage image = createImage(64, 64, 0, 12);
Image<ColorRgb> image = createImage(64, 64, 0, 12);
BlackBorder border = detector.process(image);
if (border.unknown != false && border.horizontalSize != 0 && border.verticalSize != 12)
{
@@ -100,7 +101,7 @@ int TC_DUAL_BORDER()
BlackBorderDetector detector;
{
RgbImage image = createImage(64, 64, 12, 12);
Image<ColorRgb> image = createImage(64, 64, 12, 12);
BlackBorder border = detector.process(image);
if (border.unknown != false && border.horizontalSize != 12 && border.verticalSize != 12)
{
@@ -118,7 +119,7 @@ int TC_UNKNOWN_BORDER()
BlackBorderDetector detector;
{
RgbImage image = createImage(64, 64, 30, 30);
Image<ColorRgb> image = createImage(64, 64, 30, 30);
BlackBorder border = detector.process(image);
if (border.unknown != true)
{

View File

@@ -1,16 +1,19 @@
// STL includes
#include <cassert>
#include <random>
#include <iostream>
// Utils includes
#include <utils/RgbImage.h>
#include <utils/Image.h>
#include <utils/ColorRgb.h>
// Local-Hyperion includes
#include "hyperion/BlackBorderProcessor.h"
using namespace hyperion;
RgbColor randomColor()
ColorRgb randomColor()
{
const uint8_t randomRedValue = uint8_t(rand() % (std::numeric_limits<uint8_t>::max() + 1));
const uint8_t randomGreenValue = uint8_t(rand() % (std::numeric_limits<uint8_t>::max() + 1));
@@ -19,16 +22,16 @@ RgbColor randomColor()
return {randomRedValue, randomGreenValue, randomBlueValue};
}
RgbImage createImage(unsigned width, unsigned height, unsigned topBorder, unsigned leftBorder)
Image<ColorRgb> createImage(unsigned width, unsigned height, unsigned topBorder, unsigned leftBorder)
{
RgbImage image(width, height);
Image<ColorRgb> image(width, height);
for (unsigned x=0; x<image.width(); ++x)
{
for (unsigned y=0; y<image.height(); ++y)
{
if (y < topBorder || x < leftBorder)
{
image(x,y) = RgbColor::BLACK;
image(x,y) = ColorRgb::BLACK;
}
else
{
@@ -48,7 +51,7 @@ int main()
BlackBorderProcessor processor(unknownCnt, borderCnt, blurCnt);
// Start with 'no border' detection
RgbImage noBorderImage = createImage(64, 64, 0, 0);
Image<ColorRgb> noBorderImage = createImage(64, 64, 0, 0);
for (unsigned i=0; i<10; ++i)
{
bool newBorder = processor.process(noBorderImage);
@@ -79,7 +82,7 @@ int main()
}
int borderSize = 12;
RgbImage horzImage = createImage(64, 64, borderSize, 0);
Image<ColorRgb> horzImage = createImage(64, 64, borderSize, 0);
for (unsigned i=0; i<borderCnt*2; ++i)
{
bool newBorder = processor.process(horzImage);
@@ -115,7 +118,7 @@ int main()
exit(EXIT_FAILURE);
}
RgbImage vertImage = createImage(64, 64, 0, borderSize);
Image<ColorRgb> vertImage = createImage(64, 64, 0, borderSize);
for (unsigned i=0; i<borderCnt*2; ++i)
{
bool newBorder = processor.process(vertImage);

View File

@@ -1,6 +1,6 @@
// Utils includes
#include <utils/RgbImage.h>
#include <utils/Image.h>
#include <utils/jsonschema/JsonFactory.h>
// Hyperion includes
@@ -25,16 +25,16 @@ int main()
const LedString ledString = Hyperion::createLedString(config["leds"]);
const RgbColor testColor = {64, 123, 12};
const ColorRgb testColor = {64, 123, 12};
RgbImage image(64, 64, testColor);
Image<ColorRgb> image(64, 64, testColor);
ImageToLedsMap map(64, 64, 0, 0, ledString.leds());
std::vector<RgbColor> ledColors(ledString.leds().size());
std::vector<ColorRgb> ledColors(ledString.leds().size());
map.getMeanLedColor(image, ledColors);
std::cout << "[";
for (const RgbColor & color : ledColors)
for (const ColorRgb & color : ledColors)
{
std::cout << color;
}

View File

@@ -1,18 +1,22 @@
// STL includes
#include <iostream>
// Utils includes
#include <utils/RgbImage.h>
#include <utils/Image.h>
#include <utils/ColorRgb.h>
int main()
{
std::cout << "Constructing image" << std::endl;
RgbImage image(64, 64, RgbColor::BLACK);
Image<ColorRgb> image(64, 64, ColorRgb::BLACK);
std::cout << "Writing image" << std::endl;
for (unsigned y=0; y<64; ++y)
{
for (unsigned x=0; x<64; ++x)
{
image(x,y) = RgbColor::RED;
image(x,y) = ColorRgb::RED;
}
}

View File

@@ -8,28 +8,28 @@
#include <iostream>
// Local includes
#include <utils/RgbColor.h>
#include <utils/ColorRgb.h>
#include "../libsrc/hyperion/device/LedDeviceWs2801.h"
void setColor(char* colorStr)
{
RgbColor color = RgbColor::BLACK;
ColorRgb color = ColorRgb::BLACK;
std::cout << "Switching all leds to: ";
if (strncmp("red", colorStr, 3) == 0)
{
std::cout << "red";
color = RgbColor::RED;
color = ColorRgb::RED;
}
else if (strncmp("green", colorStr, 5) == 0)
{
std::cout << "green";
color = RgbColor::GREEN;
color = ColorRgb::GREEN;
}
else if (strncmp("blue", colorStr, 5) == 0)
{
std::cout << "blue";
color = RgbColor::BLUE;
color = ColorRgb::BLUE;
}
else if (strncmp("cyan", colorStr, 5) == 0)
{
@@ -42,17 +42,17 @@ void setColor(char* colorStr)
else if (strncmp("white", colorStr, 5) == 0)
{
std::cout << "white";
color = RgbColor::WHITE;
color = ColorRgb::WHITE;
}
else if (strncmp("black", colorStr, 5) == 0)
{
std::cout << "black";
color = RgbColor::BLACK;
color = ColorRgb::BLACK;
}
std::cout << std::endl;
unsigned ledCnt = 50;
std::vector<RgbColor> buff(ledCnt, color);
std::vector<ColorRgb> buff(ledCnt, color);
LedDeviceWs2801 ledDevice("/dev/spidev0.0", 40000);
ledDevice.open();
@@ -62,11 +62,11 @@ void setColor(char* colorStr)
bool _running = true;
void doCircle()
{
RgbColor color_1 = RgbColor::RED;
RgbColor color_2 = RgbColor::YELLOW;
ColorRgb color_1 = ColorRgb::RED;
ColorRgb color_2 = ColorRgb::YELLOW;
unsigned ledCnt = 50;
std::vector<RgbColor> data(ledCnt, RgbColor::BLACK);
std::vector<ColorRgb> data(ledCnt, ColorRgb::BLACK);
LedDeviceWs2801 ledDevice("/dev/spidev0.0", 40000);
ledDevice.open();
@@ -84,8 +84,8 @@ void doCircle()
while (_running)
{
data[curLed_1] = RgbColor::BLACK;
data[curLed_2] = RgbColor::BLACK;
data[curLed_1] = ColorRgb::BLACK;
data[curLed_2] = ColorRgb::BLACK;
// Move the current and the next pointer
curLed_1 = nextLed_1;
@@ -111,8 +111,8 @@ void doCircle()
}
// Switch the current leds off
data[curLed_1] = RgbColor::BLACK;
data[curLed_2] = RgbColor::BLACK;
data[curLed_1] = ColorRgb::BLACK;
data[curLed_2] = ColorRgb::BLACK;
ledDevice.write(data);
}
@@ -126,9 +126,9 @@ void signal_handler(int signum)
int main(int argc, char** argv)
{
if (sizeof(RgbColor) != 3)
if (sizeof(ColorRgb) != 3)
{
std::cout << "sizeof(RgbColor) = " << sizeof(RgbColor) << std::endl;
std::cout << "sizeof(ColorRgb) = " << sizeof(ColorRgb) << std::endl;
return -1;
}

View File

@@ -22,19 +22,20 @@ int main()
signal(SIGINT, signal_handler);
DispmanxFrameGrabber frameGrabber(64, 64);
frameGrabber.setFlags(DISPMANX_SNAPSHOT_NO_RGB|DISPMANX_SNAPSHOT_FILL);
unsigned iFrame = 0;
QImage qImage(64, 64, QImage::Format_RGB888);
RgbImage rgbImage(64, 64);
QImage qImage(64, 64, QImage::Format_ARGB32);
Image<ColorRgba> imageRgba(64, 64);
while(running)
{
frameGrabber.grabFrame(rgbImage);
frameGrabber.grabFrame(imageRgba);
for (int iScanline=0; iScanline<qImage.height(); ++iScanline)
{
unsigned char* scanLinePtr = qImage.scanLine(iScanline);
memcpy(scanLinePtr, rgbImage.memptr()+rgbImage.width()*iScanline, rgbImage.width()*sizeof(RgbColor));
memcpy(scanLinePtr, imageRgba.memptr()+imageRgba.width()*iScanline, imageRgba.width()*sizeof(ColorRgba));
}
qImage.save(QString("HYPERION_%3.png").arg(iFrame));