mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Changed RgbImage to template based Image (with template for pixel type)
Former-commit-id: ef02f164eaf3c2f9dd552c1c17b525cf6eed499c
This commit is contained in:
parent
90f1f282e2
commit
dd16af0df5
@ -5,8 +5,9 @@
|
||||
#include <QTimer>
|
||||
|
||||
// Utils includes
|
||||
#include <utils/RgbColor.h>
|
||||
#include <utils/RgbImage.h>
|
||||
#include <utils/Image.h>
|
||||
#include <utils/ColorRgb.h>
|
||||
#include <utils/ColorRgba.h>
|
||||
#include <utils/GrabbingMode.h>
|
||||
|
||||
// Forward class declaration
|
||||
@ -15,8 +16,8 @@ class Hyperion;
|
||||
class ImageProcessor;
|
||||
|
||||
///
|
||||
/// The DispmanxWrapper uses an instance of the DispmanxFrameGrabber to obtain RgbImage's from the
|
||||
/// displayed content. This RgbImage is processed to a RgbColor for each led and commmited to the
|
||||
/// The DispmanxWrapper uses an instance of the DispmanxFrameGrabber to obtain ImageRgb's from the
|
||||
/// displayed content. This ImageRgb is processed to a ColorRgb for each led and commmited to the
|
||||
/// attached Hyperion.
|
||||
///
|
||||
class DispmanxWrapper: public QObject
|
||||
@ -72,14 +73,14 @@ private:
|
||||
QTimer _timer;
|
||||
|
||||
/// The image used for grabbing frames
|
||||
RgbImage _image;
|
||||
Image<ColorRgba> _image;
|
||||
/// The actual grabber
|
||||
DispmanxFrameGrabber * _frameGrabber;
|
||||
/// The processor for transforming images to led colors
|
||||
ImageProcessor * _processor;
|
||||
|
||||
/// The list with computed led colors
|
||||
std::vector<RgbColor> _ledColors;
|
||||
std::vector<ColorRgb> _ledColors;
|
||||
|
||||
/// Pointer to Hyperion for writing led values
|
||||
Hyperion * _hyperion;
|
||||
|
@ -2,7 +2,7 @@
|
||||
#pragma once
|
||||
|
||||
// Utils includes
|
||||
#include <utils/RgbImage.h>
|
||||
#include <utils/Image.h>
|
||||
|
||||
namespace hyperion
|
||||
{
|
||||
@ -58,7 +58,59 @@ namespace hyperion
|
||||
///
|
||||
/// @return The detected (or not detected) black border info
|
||||
///
|
||||
BlackBorder process(const RgbImage& image);
|
||||
template <typename Pixel_T>
|
||||
BlackBorder process(const Image<Pixel_T> & image)
|
||||
{
|
||||
// only test the topleft third of the image
|
||||
int width = image.width() /3;
|
||||
int height = image.height() / 3;
|
||||
int maxSize = std::max(width, height);
|
||||
|
||||
int firstNonBlackXPixelIndex = -1;
|
||||
int firstNonBlackYPixelIndex = -1;
|
||||
|
||||
// find some pixel of the image
|
||||
for (int i = 0; i < maxSize; ++i)
|
||||
{
|
||||
int x = std::min(i, width);
|
||||
int y = std::min(i, height);
|
||||
|
||||
const Pixel_T & color = image(x, y);
|
||||
if (!isBlack(color))
|
||||
{
|
||||
firstNonBlackXPixelIndex = x;
|
||||
firstNonBlackYPixelIndex = y;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// expand image to the left
|
||||
for(; firstNonBlackXPixelIndex > 0; --firstNonBlackXPixelIndex)
|
||||
{
|
||||
const Pixel_T & color = image(firstNonBlackXPixelIndex-1, firstNonBlackYPixelIndex);
|
||||
if (isBlack(color))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// expand image to the top
|
||||
for(; firstNonBlackYPixelIndex > 0; --firstNonBlackYPixelIndex)
|
||||
{
|
||||
const Pixel_T & color = image(firstNonBlackXPixelIndex, firstNonBlackYPixelIndex-1);
|
||||
if (isBlack(color))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Construct result
|
||||
BlackBorder detectedBorder;
|
||||
detectedBorder.unknown = firstNonBlackXPixelIndex == -1 || firstNonBlackYPixelIndex == -1;
|
||||
detectedBorder.horizontalSize = firstNonBlackYPixelIndex;
|
||||
detectedBorder.verticalSize = firstNonBlackXPixelIndex;
|
||||
return detectedBorder;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@ -69,11 +121,11 @@ namespace hyperion
|
||||
///
|
||||
/// @return True if the color is considered black else false
|
||||
///
|
||||
inline bool isBlack(const RgbColor& color)
|
||||
template <typename Pixel_T>
|
||||
inline bool isBlack(const Pixel_T & color)
|
||||
{
|
||||
// Return the simple compare of the color against black
|
||||
return RgbColor::BLACK == color;
|
||||
// TODO[TvdZ]: We could add a threshold to check that the color is close to black
|
||||
return color.red+color.green+color.green == 0;
|
||||
}
|
||||
};
|
||||
} // end namespace hyperion
|
@ -42,9 +42,35 @@ namespace hyperion
|
||||
///
|
||||
/// @return True if a different border was detected than the current else false
|
||||
///
|
||||
bool process(const RgbImage& image);
|
||||
template <typename Pixel_T>
|
||||
bool process(const Image<Pixel_T> & image)
|
||||
{
|
||||
// get the border for the single image
|
||||
BlackBorder imageBorder = _detector.process(image);
|
||||
// add blur to the border
|
||||
if (imageBorder.horizontalSize > 0)
|
||||
{
|
||||
imageBorder.horizontalSize += _blurRemoveCnt;
|
||||
}
|
||||
if (imageBorder.verticalSize > 0)
|
||||
{
|
||||
imageBorder.verticalSize += _blurRemoveCnt;
|
||||
}
|
||||
|
||||
const bool borderUpdated = updateBorder(imageBorder);
|
||||
return borderUpdated;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
///
|
||||
/// Updates the current border based on the newly detected border. Returns true if the
|
||||
/// current border has changed.
|
||||
///
|
||||
/// @param newDetectedBorder The newly detected border
|
||||
/// @return True if the current border changed else false
|
||||
///
|
||||
bool updateBorder(const BlackBorder & newDetectedBorder);
|
||||
|
||||
/// The number of unknown-borders detected before it becomes the current border
|
||||
const unsigned _unknownSwitchCnt;
|
@ -8,7 +8,7 @@
|
||||
#include <QTimer>
|
||||
|
||||
// hyperion-utils includes
|
||||
#include <utils/RgbImage.h>
|
||||
#include <utils/Image.h>
|
||||
|
||||
// Hyperion includes
|
||||
#include <hyperion/LedString.h>
|
||||
@ -76,7 +76,7 @@ public:
|
||||
/// @param[in] ledColor The color to write to the leds
|
||||
/// @param[in] timeout_ms The time the leds are set to the given color [ms]
|
||||
///
|
||||
void setColor(int priority, const RgbColor &ledColor, const int timeout_ms);
|
||||
void setColor(int priority, const ColorRgb &ledColor, const int timeout_ms);
|
||||
|
||||
///
|
||||
/// Writes the given colors to all leds for the given time and priority
|
||||
@ -85,7 +85,7 @@ public:
|
||||
/// @param[in] ledColors The colors to write to the leds
|
||||
/// @param[in] timeout_ms The time the leds are set to the given colors [ms]
|
||||
///
|
||||
void setColors(int priority, const std::vector<RgbColor> &ledColors, const int timeout_ms);
|
||||
void setColors(int priority, const std::vector<ColorRgb> &ledColors, const int timeout_ms);
|
||||
|
||||
///
|
||||
/// Sets/Updates a part of the color transformation.
|
||||
@ -162,7 +162,7 @@ private:
|
||||
///
|
||||
/// @param colors The colors to be transformed
|
||||
///
|
||||
void applyTransform(std::vector<RgbColor>& colors) const;
|
||||
void applyTransform(std::vector<ColorRgb>& colors) const;
|
||||
|
||||
/// The specifiation of the led frame construction and picture integration
|
||||
LedString _ledString;
|
||||
|
@ -2,17 +2,13 @@
|
||||
#pragma once
|
||||
|
||||
// Utils includes
|
||||
#include <utils/RgbImage.h>
|
||||
#include <utils/Image.h>
|
||||
|
||||
// Hyperion includes
|
||||
#include <hyperion/ImageProcessorFactory.h>
|
||||
#include <hyperion/LedString.h>
|
||||
|
||||
// Forward class declaration
|
||||
namespace hyperion {
|
||||
class ImageToLedsMap;
|
||||
class BlackBorderProcessor;
|
||||
}
|
||||
#include <hyperion/ImageToLedsMap.h>
|
||||
#include <hyperion/BlackBorderProcessor.h>
|
||||
|
||||
///
|
||||
/// The ImageProcessor translates an RGB-image to RGB-values for the leds. The processing is
|
||||
@ -42,7 +38,21 @@ public:
|
||||
///
|
||||
/// @return The color value per led
|
||||
///
|
||||
std::vector<RgbColor> process(const RgbImage& image);
|
||||
template <typename Pixel_T>
|
||||
std::vector<ColorRgb> process(const Image<Pixel_T>& image)
|
||||
{
|
||||
// Ensure that the buffer-image is the proper size
|
||||
setSize(image.width(), image.height());
|
||||
|
||||
// Check black border detection
|
||||
verifyBorder(image);
|
||||
|
||||
// Create a result vector and call the 'in place' functionl
|
||||
std::vector<ColorRgb> colors = mImageToLeds->getMeanLedColor(image);
|
||||
|
||||
// return the computed colors
|
||||
return colors;
|
||||
}
|
||||
|
||||
///
|
||||
/// Determines the led colors of the image in the buffer.
|
||||
@ -50,7 +60,18 @@ public:
|
||||
/// @param[in] image The image to translate to led values
|
||||
/// @param[out] ledColors The color value per led
|
||||
///
|
||||
void process(const RgbImage& image, std::vector<RgbColor>& ledColors);
|
||||
template <typename Pixel_T>
|
||||
void process(const Image<Pixel_T>& image, std::vector<ColorRgb>& ledColors)
|
||||
{
|
||||
// Ensure that the buffer-image is the proper size
|
||||
setSize(image.width(), image.height());
|
||||
|
||||
// Check black border detection
|
||||
verifyBorder(image);
|
||||
|
||||
// Determine the mean-colors of each led (using the existing mapping)
|
||||
mImageToLeds->getMeanLedColor(image, ledColors);
|
||||
}
|
||||
|
||||
///
|
||||
/// Get the hscan and vscan parameters for a single led
|
||||
@ -80,7 +101,33 @@ private:
|
||||
///
|
||||
/// @param[in] image The image to perform black-border detection on
|
||||
///
|
||||
void verifyBorder(const RgbImage& image);
|
||||
template <typename Pixel_T>
|
||||
void verifyBorder(const Image<Pixel_T> & image)
|
||||
{
|
||||
if(_enableBlackBorderRemoval && _borderProcessor->process(image))
|
||||
{
|
||||
std::cout << "BORDER SWITCH REQUIRED!!" << std::endl;
|
||||
|
||||
const hyperion::BlackBorder border = _borderProcessor->getCurrentBorder();
|
||||
|
||||
// Clean up the old mapping
|
||||
delete mImageToLeds;
|
||||
|
||||
if (border.unknown)
|
||||
{
|
||||
// Construct a new buffer and mapping
|
||||
mImageToLeds = new hyperion::ImageToLedsMap(image.width(), image.height(), 0, 0, mLedString.leds());
|
||||
}
|
||||
else
|
||||
{
|
||||
// Construct a new buffer and mapping
|
||||
mImageToLeds = new hyperion::ImageToLedsMap(image.width(), image.height(), border.horizontalSize, border.verticalSize, mLedString.leds());
|
||||
}
|
||||
|
||||
std::cout << "CURRENT BORDER TYPE: unknown=" << border.unknown << " hor.size=" << border.horizontalSize << " vert.size=" << border.verticalSize << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
/// The Led-string specification
|
||||
const LedString mLedString;
|
||||
|
@ -2,10 +2,11 @@
|
||||
#pragma once
|
||||
|
||||
// STL includes
|
||||
#include <cassert>
|
||||
#include <sstream>
|
||||
|
||||
// hyperion-utils includes
|
||||
#include <utils/RgbImage.h>
|
||||
#include <utils/Image.h>
|
||||
|
||||
// hyperion includes
|
||||
#include <hyperion/LedString.h>
|
||||
@ -63,7 +64,13 @@ namespace hyperion
|
||||
///
|
||||
/// @return ledColors The vector containing the output
|
||||
///
|
||||
std::vector<RgbColor> getMeanLedColor(const RgbImage & image) const;
|
||||
template <typename Pixel_T>
|
||||
std::vector<ColorRgb> getMeanLedColor(const Image<Pixel_T> & image) const
|
||||
{
|
||||
std::vector<ColorRgb> colors(mColorsMap.size(), ColorRgb{0,0,0});
|
||||
getMeanLedColor(image, colors);
|
||||
return colors;
|
||||
}
|
||||
|
||||
///
|
||||
/// Determines the mean color for each led using the mapping the image given
|
||||
@ -72,7 +79,20 @@ namespace hyperion
|
||||
/// @param[in] image The image from which to extract the led colors
|
||||
/// @param[out] ledColors The vector containing the output
|
||||
///
|
||||
void getMeanLedColor(const RgbImage & image, std::vector<RgbColor> & ledColors) const;
|
||||
template <typename Pixel_T>
|
||||
void getMeanLedColor(const Image<Pixel_T> & image, std::vector<ColorRgb> & ledColors) const
|
||||
{
|
||||
// Sanity check for the number of leds
|
||||
assert(mColorsMap.size() == ledColors.size());
|
||||
|
||||
// Iterate each led and compute the mean
|
||||
auto led = ledColors.begin();
|
||||
for (auto ledColors = mColorsMap.begin(); ledColors != mColorsMap.end(); ++ledColors, ++led)
|
||||
{
|
||||
const ColorRgb color = calcMeanColor(image, *ledColors);
|
||||
*led = color;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
/// The width of the indexed image
|
||||
@ -91,7 +111,34 @@ namespace hyperion
|
||||
///
|
||||
/// @return The mean of the given list of colors (or black when empty)
|
||||
///
|
||||
RgbColor calcMeanColor(const RgbImage & image, const std::vector<unsigned> & colors) const;
|
||||
template <typename Pixel_T>
|
||||
ColorRgb calcMeanColor(const Image<Pixel_T> & image, const std::vector<unsigned> & colors) const
|
||||
{
|
||||
if (colors.size() == 0)
|
||||
{
|
||||
return ColorRgb::BLACK;
|
||||
}
|
||||
|
||||
// Accumulate the sum of each seperate color channel
|
||||
uint_fast16_t cummRed = 0;
|
||||
uint_fast16_t cummGreen = 0;
|
||||
uint_fast16_t cummBlue = 0;
|
||||
for (const unsigned colorOffset : colors)
|
||||
{
|
||||
const Pixel_T& pixel = image.memptr()[colorOffset];
|
||||
cummRed += pixel.red;
|
||||
cummGreen += pixel.green;
|
||||
cummBlue += pixel.blue;
|
||||
}
|
||||
|
||||
// Compute the average of each color channel
|
||||
const uint8_t avgRed = uint8_t(cummRed/colors.size());
|
||||
const uint8_t avgGreen = uint8_t(cummGreen/colors.size());
|
||||
const uint8_t avgBlue = uint8_t(cummBlue/colors.size());
|
||||
|
||||
// Return the computed color
|
||||
return {avgRed, avgGreen, avgBlue};
|
||||
}
|
||||
};
|
||||
|
||||
} // end namespace hyperion
|
@ -4,7 +4,7 @@
|
||||
#include <vector>
|
||||
|
||||
// Utility includes
|
||||
#include <utils/RgbColor.h>
|
||||
#include <utils/ColorRgb.h>
|
||||
|
||||
///
|
||||
/// Interface (pure virtual base class) for LedDevices.
|
||||
@ -28,7 +28,7 @@ public:
|
||||
///
|
||||
/// @return Zero on success else negative
|
||||
///
|
||||
virtual int write(const std::vector<RgbColor>& ledValues) = 0;
|
||||
virtual int write(const std::vector<ColorRgb>& ledValues) = 0;
|
||||
|
||||
/// Switch the leds off
|
||||
virtual int switchOff() = 0;
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include <vector>
|
||||
|
||||
// Local includes
|
||||
#include <utils/RgbColor.h>
|
||||
#include <utils/ColorRgb.h>
|
||||
|
||||
// Forward class declarations
|
||||
namespace Json { class Value; }
|
||||
|
@ -10,7 +10,7 @@
|
||||
#include <QMap>
|
||||
|
||||
// Utils includes
|
||||
#include <utils/RgbColor.h>
|
||||
#include <utils/ColorRgb.h>
|
||||
|
||||
// Hyperion includes
|
||||
#include <hyperion/LedDevice.h>
|
||||
@ -34,7 +34,7 @@ public:
|
||||
/// The absolute timeout of the channel
|
||||
int64_t timeoutTime_ms;
|
||||
/// The colors for each led of the channel
|
||||
std::vector<RgbColor> ledColors;
|
||||
std::vector<ColorRgb> ledColors;
|
||||
};
|
||||
|
||||
///
|
||||
@ -89,7 +89,7 @@ public:
|
||||
/// @param[in] ledColors The led colors of the priority channel
|
||||
/// @param[in] timeoutTime_ms The absolute timeout time of the channel
|
||||
///
|
||||
void setInput(const int priority, const std::vector<RgbColor>& ledColors, const int64_t timeoutTime_ms=-1);
|
||||
void setInput(const int priority, const std::vector<ColorRgb>& ledColors, const int64_t timeoutTime_ms=-1);
|
||||
|
||||
///
|
||||
/// Clears the specified priority channel
|
||||
|
52
include/utils/ColorArgb.h
Normal file
52
include/utils/ColorArgb.h
Normal file
@ -0,0 +1,52 @@
|
||||
#pragma once
|
||||
|
||||
// STL includes
|
||||
#include <cstdint>
|
||||
#include <ostream>
|
||||
|
||||
struct ColorArgb;
|
||||
|
||||
struct ColorArgb
|
||||
{
|
||||
|
||||
/// The alpha mask channel
|
||||
uint8_t alpha;
|
||||
|
||||
/// The red color channel
|
||||
uint8_t red;
|
||||
/// The green color channel
|
||||
uint8_t green;
|
||||
/// The blue color channel
|
||||
uint8_t blue;
|
||||
|
||||
/// 'Black' RgbColor (255, 0, 0, 0)
|
||||
static ColorArgb BLACK;
|
||||
/// 'Red' RgbColor (255, 255, 0, 0)
|
||||
static ColorArgb RED;
|
||||
/// 'Green' RgbColor (255, 0, 255, 0)
|
||||
static ColorArgb GREEN;
|
||||
/// 'Blue' RgbColor (255, 0, 0, 255)
|
||||
static ColorArgb BLUE;
|
||||
/// 'Yellow' RgbColor (255, 255, 255, 0)
|
||||
static ColorArgb YELLOW;
|
||||
/// 'White' RgbColor (255, 255, 255, 255)
|
||||
static ColorArgb WHITE;
|
||||
};
|
||||
|
||||
|
||||
/// Assert to ensure that the size of the structure is 'only' 3 bytes
|
||||
static_assert(sizeof(ColorArgb) == 4, "Incorrect size of ColorARGB");
|
||||
|
||||
///
|
||||
/// Stream operator to write ColorRgb to an outputstream (format "'{'[alpha]', '[red]','[green]','[blue]'}'")
|
||||
///
|
||||
/// @param os The output stream
|
||||
/// @param color The color to write
|
||||
/// @return The output stream (with the color written to it)
|
||||
///
|
||||
inline std::ostream& operator<<(std::ostream& os, const ColorArgb& color)
|
||||
{
|
||||
os << "{" << unsigned(color.alpha) << "," << unsigned(color.red) << "," << unsigned(color.green) << "," << unsigned(color.blue) << "}";
|
||||
return os;
|
||||
}
|
||||
|
@ -1,18 +1,16 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
// STL includes
|
||||
#include <stdint.h>
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
|
||||
// Forward class declaration
|
||||
struct RgbColor;
|
||||
struct ColorRgb;
|
||||
|
||||
///
|
||||
/// Plain-Old-Data structure containing the red-green-blue color specification. Size of the
|
||||
/// structure is exactly 3-bytes for easy writing to led-device
|
||||
///
|
||||
struct RgbColor
|
||||
struct ColorRgb
|
||||
{
|
||||
/// The red color channel
|
||||
uint8_t red;
|
||||
@ -22,42 +20,30 @@ struct RgbColor
|
||||
uint8_t blue;
|
||||
|
||||
/// 'Black' RgbColor (0, 0, 0)
|
||||
static RgbColor BLACK;
|
||||
static ColorRgb BLACK;
|
||||
/// 'Red' RgbColor (255, 0, 0)
|
||||
static RgbColor RED;
|
||||
static ColorRgb RED;
|
||||
/// 'Green' RgbColor (0, 255, 0)
|
||||
static RgbColor GREEN;
|
||||
static ColorRgb GREEN;
|
||||
/// 'Blue' RgbColor (0, 0, 255)
|
||||
static RgbColor BLUE;
|
||||
static ColorRgb BLUE;
|
||||
/// 'Yellow' RgbColor (255, 255, 0)
|
||||
static RgbColor YELLOW;
|
||||
static ColorRgb YELLOW;
|
||||
/// 'White' RgbColor (255, 255, 255)
|
||||
static RgbColor WHITE;
|
||||
|
||||
///
|
||||
/// Checks is this exactly matches another color
|
||||
///
|
||||
/// @param other The other color
|
||||
///
|
||||
/// @return True if the colors are identical
|
||||
///
|
||||
inline bool operator==(const RgbColor& other) const
|
||||
{
|
||||
return red == other.red && green == other.green && blue == other.blue;
|
||||
}
|
||||
static ColorRgb WHITE;
|
||||
};
|
||||
|
||||
/// Assert to ensure that the size of the structure is 'only' 3 bytes
|
||||
static_assert(sizeof(RgbColor) == 3, "Incorrect size of RgbColor");
|
||||
static_assert(sizeof(ColorRgb) == 3, "Incorrect size of ColorRgb");
|
||||
|
||||
///
|
||||
/// Stream operator to write RgbColor to an outputstream (format "'{'[red]','[green]','[blue]'}'")
|
||||
/// Stream operator to write ColorRgb to an outputstream (format "'{'[red]','[green]','[blue]'}'")
|
||||
///
|
||||
/// @param os The output stream
|
||||
/// @param color The color to write
|
||||
/// @return The output stream (with the color written to it)
|
||||
///
|
||||
inline std::ostream& operator<<(std::ostream& os, const RgbColor& color)
|
||||
inline std::ostream& operator<<(std::ostream& os, const ColorRgb& color)
|
||||
{
|
||||
os << "{" << unsigned(color.red) << "," << unsigned(color.green) << "," << unsigned(color.blue) << "}";
|
||||
return os;
|
52
include/utils/ColorRgba.h
Normal file
52
include/utils/ColorRgba.h
Normal file
@ -0,0 +1,52 @@
|
||||
#pragma once
|
||||
|
||||
// STL includes
|
||||
#include <cstdint>
|
||||
#include <ostream>
|
||||
|
||||
struct ColorRgba;
|
||||
|
||||
struct ColorRgba
|
||||
{
|
||||
|
||||
/// The red color channel
|
||||
uint8_t red;
|
||||
/// The green color channel
|
||||
uint8_t green;
|
||||
/// The blue color channel
|
||||
uint8_t blue;
|
||||
|
||||
/// The alpha mask channel
|
||||
uint8_t alpha;
|
||||
|
||||
/// 'Black' RgbColor (0, 0, 0, 255)
|
||||
static ColorRgba BLACK;
|
||||
/// 'Red' RgbColor (255, 0, 0, 255)
|
||||
static ColorRgba RED;
|
||||
/// 'Green' RgbColor (0, 255, 0, 255)
|
||||
static ColorRgba GREEN;
|
||||
/// 'Blue' RgbColor (0, 0, 255, 255)
|
||||
static ColorRgba BLUE;
|
||||
/// 'Yellow' RgbColor (255, 255, 0, 255)
|
||||
static ColorRgba YELLOW;
|
||||
/// 'White' RgbColor (255, 255, 255, 255
|
||||
static ColorRgba WHITE;
|
||||
};
|
||||
|
||||
|
||||
/// Assert to ensure that the size of the structure is 'only' 3 bytes
|
||||
static_assert(sizeof(ColorRgba) == 4, "Incorrect size of ColorARGB");
|
||||
|
||||
///
|
||||
/// Stream operator to write ColorRgb to an outputstream (format "'{'[alpha]', '[red]','[green]','[blue]'}'")
|
||||
///
|
||||
/// @param os The output stream
|
||||
/// @param color The color to write
|
||||
/// @return The output stream (with the color written to it)
|
||||
///
|
||||
inline std::ostream& operator<<(std::ostream& os, const ColorRgba& color)
|
||||
{
|
||||
os << "{" << unsigned(color.alpha) << "," << unsigned(color.red) << "," << unsigned(color.green) << "," << unsigned(color.blue) << "}";
|
||||
return os;
|
||||
}
|
||||
|
@ -1,34 +1,56 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
// STL includes
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
|
||||
// Local includes
|
||||
#include "RgbColor.h"
|
||||
|
||||
///
|
||||
/// The RgbImage holds a 2D matrix of RgbColors's (or image). Width and height of the image are
|
||||
/// fixed at construction.
|
||||
///
|
||||
class RgbImage
|
||||
template <typename Pixel_T>
|
||||
class Image
|
||||
{
|
||||
public:
|
||||
|
||||
typedef Pixel_T pixel_type;
|
||||
|
||||
///
|
||||
/// Constructor for an image with specified width and height
|
||||
///
|
||||
/// @param width The width of the image
|
||||
/// @param height The height of the image
|
||||
/// @param background The color of the image (default = BLACK)
|
||||
///
|
||||
RgbImage(const unsigned width, const unsigned height, const RgbColor background = RgbColor::BLACK);
|
||||
Image(const unsigned width, const unsigned height) :
|
||||
_width(width),
|
||||
_height(height),
|
||||
_pixels(new Pixel_T[width*height + 1]),
|
||||
_endOfPixels(_pixels + width*height)
|
||||
{
|
||||
memset(_pixels, 0, (_width*_height+1)*sizeof(Pixel_T));
|
||||
}
|
||||
|
||||
///
|
||||
/// Constructor for an image with specified width and height
|
||||
///
|
||||
/// @param width The width of the image
|
||||
/// @param height The height of the image
|
||||
/// @param background The color of the image
|
||||
///
|
||||
Image(const unsigned width, const unsigned height, const Pixel_T background) :
|
||||
_width(width),
|
||||
_height(height),
|
||||
_pixels(new Pixel_T[width*height + 1]),
|
||||
_endOfPixels(_pixels + width*height)
|
||||
{
|
||||
std::fill(_pixels, _endOfPixels, background);
|
||||
}
|
||||
|
||||
///
|
||||
/// Destructor
|
||||
///
|
||||
~RgbImage();
|
||||
~Image()
|
||||
{
|
||||
delete[] _pixels;
|
||||
}
|
||||
|
||||
///
|
||||
/// Returns the width of the image
|
||||
@ -50,14 +72,25 @@ public:
|
||||
return _height;
|
||||
}
|
||||
|
||||
///
|
||||
/// Sets the color of a specific pixel in the image
|
||||
///
|
||||
/// @param x The x index
|
||||
/// @param y The y index
|
||||
/// @param color The new color
|
||||
///
|
||||
void setPixel(const unsigned x, const unsigned y, const RgbColor color);
|
||||
uint8_t alpha(const unsigned pixel) const
|
||||
{
|
||||
return (_pixels + pixel)->red;
|
||||
}
|
||||
|
||||
uint8_t red(const unsigned pixel) const
|
||||
{
|
||||
return (_pixels + pixel)->red;
|
||||
}
|
||||
|
||||
uint8_t green(const unsigned pixel) const
|
||||
{
|
||||
return (_pixels + pixel)->green;
|
||||
}
|
||||
|
||||
uint8_t blue(const unsigned pixel) const
|
||||
{
|
||||
return (_pixels + pixel)->blue;
|
||||
}
|
||||
|
||||
///
|
||||
/// Returns a const reference to a specified pixel in the image
|
||||
@ -67,7 +100,10 @@ public:
|
||||
///
|
||||
/// @return const reference to specified pixel
|
||||
///
|
||||
const RgbColor& operator()(const unsigned x, const unsigned y) const;
|
||||
const Pixel_T& operator()(const unsigned x, const unsigned y) const
|
||||
{
|
||||
return _pixels[toIndex(x,y)];
|
||||
}
|
||||
|
||||
///
|
||||
/// Returns a reference to a specified pixel in the image
|
||||
@ -77,37 +113,40 @@ public:
|
||||
///
|
||||
/// @return reference to specified pixel
|
||||
///
|
||||
RgbColor& operator()(const unsigned x, const unsigned y);
|
||||
Pixel_T& operator()(const unsigned x, const unsigned y)
|
||||
{
|
||||
return _pixels[toIndex(x,y)];
|
||||
}
|
||||
|
||||
///
|
||||
/// Copies another image into this image. The images should have exactly the same size.
|
||||
///
|
||||
/// @param other The image to copy into this
|
||||
///
|
||||
inline void copy(const RgbImage& other)
|
||||
void copy(const Image<Pixel_T>& other)
|
||||
{
|
||||
assert(other._width == _width);
|
||||
assert(other._height == _height);
|
||||
|
||||
memcpy(mColors, other.mColors, _width*_height*sizeof(RgbColor));
|
||||
memcpy(_pixels, other._pixels, _width*_height*sizeof(Pixel_T));
|
||||
}
|
||||
|
||||
///
|
||||
/// Returns a memory pointer to the first pixel in the image
|
||||
/// @return The memory pointer to the first pixel
|
||||
///
|
||||
RgbColor* memptr()
|
||||
Pixel_T* memptr()
|
||||
{
|
||||
return mColors;
|
||||
return _pixels;
|
||||
}
|
||||
|
||||
///
|
||||
/// Returns a const memory pointer to the first pixel in the image
|
||||
/// @return The const memory pointer to the first pixel
|
||||
///
|
||||
const RgbColor* memptr() const
|
||||
const Pixel_T* memptr() const
|
||||
{
|
||||
return mColors;
|
||||
return _pixels;
|
||||
}
|
||||
private:
|
||||
|
||||
@ -130,6 +169,9 @@ private:
|
||||
/// The height of the image
|
||||
const unsigned _height;
|
||||
|
||||
/** The colors of the image */
|
||||
RgbColor* mColors;
|
||||
/// The pixels of the image
|
||||
Pixel_T* _pixels;
|
||||
|
||||
/// Pointer to the last(extra) pixel
|
||||
Pixel_T* _endOfPixels;
|
||||
};
|
@ -16,7 +16,7 @@
|
||||
// hyperion util includes
|
||||
#include "hyperion/ImageProcessorFactory.h"
|
||||
#include "hyperion/ImageProcessor.h"
|
||||
#include "utils/RgbColor.h"
|
||||
#include "utils/ColorRgb.h"
|
||||
|
||||
// project includes
|
||||
#include "BoblightClientConnection.h"
|
||||
@ -29,7 +29,7 @@ BoblightClientConnection::BoblightClientConnection(QTcpSocket *socket, Hyperion
|
||||
_hyperion(hyperion),
|
||||
_receiveBuffer(),
|
||||
_priority(255),
|
||||
_ledColors(hyperion->getLedCount(), RgbColor::BLACK)
|
||||
_ledColors(hyperion->getLedCount(), ColorRgb::BLACK)
|
||||
{
|
||||
// initalize the locale. Start with the default C-locale
|
||||
_locale.setNumberOptions(QLocale::OmitGroupSeparator | QLocale::RejectGroupSeparator);
|
||||
@ -149,7 +149,7 @@ void BoblightClientConnection::handleMessage(const QString & message)
|
||||
|
||||
if (rc1 && rc2 && rc3)
|
||||
{
|
||||
RgbColor & rgb = _ledColors[ledIndex];
|
||||
ColorRgb & rgb = _ledColors[ledIndex];
|
||||
rgb.red = red;
|
||||
rgb.green = green;
|
||||
rgb.blue = blue;
|
||||
|
@ -99,5 +99,5 @@ private:
|
||||
int _priority;
|
||||
|
||||
/// The latest led color data
|
||||
std::vector<RgbColor> _ledColors;
|
||||
std::vector<ColorRgb> _ledColors;
|
||||
};
|
||||
|
@ -26,7 +26,7 @@ void AbstractBootSequence::update()
|
||||
}
|
||||
|
||||
// Obtain the next led-colors from the child-class
|
||||
const std::vector<RgbColor>& colors = nextColors();
|
||||
const std::vector<ColorRgb>& colors = nextColors();
|
||||
// Write the colors to hyperion
|
||||
_hyperion->setColors(_priority, colors, -1);
|
||||
|
||||
|
@ -45,7 +45,7 @@ protected:
|
||||
///
|
||||
/// @return The next led colors in the boot sequence
|
||||
///
|
||||
virtual const std::vector<RgbColor>& nextColors() = 0;
|
||||
virtual const std::vector<ColorRgb>& nextColors() = 0;
|
||||
|
||||
private:
|
||||
/// The timer used to generate an 'update' signal every interval
|
||||
|
@ -8,8 +8,8 @@
|
||||
KittBootSequence::KittBootSequence(Hyperion * hyperion, const unsigned duration_ms) :
|
||||
AbstractBootSequence(hyperion, 100, duration_ms/100),
|
||||
_processor(ImageProcessorFactory::getInstance().newImageProcessor()),
|
||||
_image(9, 1),
|
||||
_ledColors(hyperion->getLedCount(), RgbColor::BLACK),
|
||||
_image(9, 1, ColorRgb{0,0,0}),
|
||||
_ledColors(hyperion->getLedCount(), ColorRgb{0,0,0}),
|
||||
_forwardMove(false),
|
||||
_currentLight(0)
|
||||
{
|
||||
@ -21,17 +21,17 @@ KittBootSequence::~KittBootSequence()
|
||||
delete _processor;
|
||||
}
|
||||
|
||||
const std::vector<RgbColor>& KittBootSequence::nextColors()
|
||||
const std::vector<ColorRgb>& KittBootSequence::nextColors()
|
||||
{
|
||||
|
||||
// Switch the previous light 'off'
|
||||
_image(_currentLight, 0) = RgbColor::BLACK;
|
||||
_image(_currentLight, 0) = ColorRgb{0,0,0};
|
||||
|
||||
// Move the current to the next light
|
||||
moveNextLight();
|
||||
|
||||
// Switch the current light 'on'
|
||||
_image(_currentLight, 0) = RgbColor::RED;
|
||||
_image(_currentLight, 0) = ColorRgb{255,0,0};
|
||||
|
||||
|
||||
// Translate the 'image' to led colors
|
||||
|
@ -33,17 +33,17 @@ public:
|
||||
///
|
||||
/// @return The next colors for the leds
|
||||
///
|
||||
virtual const std::vector<RgbColor>& nextColors();
|
||||
virtual const std::vector<ColorRgb>& nextColors();
|
||||
|
||||
private:
|
||||
/// Image processor to compute led-colors from the image
|
||||
ImageProcessor * _processor;
|
||||
|
||||
/// 1D-Image of the KITT-grill contains a single red pixel and the rest black
|
||||
RgbImage _image;
|
||||
Image<ColorRgb> _image;
|
||||
|
||||
/// The vector with led-colors
|
||||
std::vector<RgbColor> _ledColors;
|
||||
std::vector<ColorRgb> _ledColors;
|
||||
|
||||
/// Direction the red-light is currently moving
|
||||
bool _forwardMove = true;
|
||||
|
@ -11,15 +11,15 @@ RainbowBootSequence::RainbowBootSequence(Hyperion * hyperion, const unsigned dur
|
||||
{
|
||||
for (unsigned iLed=0; iLed<hyperion->getLedCount(); ++iLed)
|
||||
{
|
||||
RgbColor& color = _ledColors[iLed];
|
||||
ColorRgb& color = _ledColors[iLed];
|
||||
HsvTransform::hsv2rgb(iLed*360/hyperion->getLedCount(), 255, 255, color.red, color.green, color.blue);
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<RgbColor>& RainbowBootSequence::nextColors()
|
||||
const std::vector<ColorRgb>& RainbowBootSequence::nextColors()
|
||||
{
|
||||
// Rotate the colors left
|
||||
const RgbColor headColor = _ledColors.front();
|
||||
const ColorRgb headColor = _ledColors.front();
|
||||
for (unsigned i=1; i<_ledColors.size(); ++i)
|
||||
{
|
||||
_ledColors[i-1] = _ledColors[i];
|
||||
|
@ -27,11 +27,11 @@ protected:
|
||||
///
|
||||
/// Moves the rainbow one led further
|
||||
///
|
||||
const std::vector<RgbColor>& nextColors();
|
||||
const std::vector<ColorRgb>& nextColors();
|
||||
|
||||
private:
|
||||
/// The current color of the boot sequence (the rainbow)
|
||||
std::vector<RgbColor> _ledColors;
|
||||
std::vector<ColorRgb> _ledColors;
|
||||
/// The counter of the number of iterations left
|
||||
int _iterationCounter;
|
||||
};
|
||||
|
@ -1,4 +1,9 @@
|
||||
|
||||
// STL includes
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
|
||||
// Local includes
|
||||
#include "DispmanxFrameGrabber.h"
|
||||
|
||||
DispmanxFrameGrabber::DispmanxFrameGrabber(const unsigned width, const unsigned height) :
|
||||
@ -32,7 +37,7 @@ DispmanxFrameGrabber::DispmanxFrameGrabber(const unsigned width, const unsigned
|
||||
// Create the resources for capturing image
|
||||
uint32_t vc_nativeImageHandle;
|
||||
_vc_resource = vc_dispmanx_resource_create(
|
||||
VC_IMAGE_RGB888,
|
||||
VC_IMAGE_RGBA32,
|
||||
width,
|
||||
height,
|
||||
&vc_nativeImageHandle);
|
||||
@ -56,7 +61,7 @@ void DispmanxFrameGrabber::setFlags(const int vc_flags)
|
||||
_vc_flags = vc_flags;
|
||||
}
|
||||
|
||||
void DispmanxFrameGrabber::grabFrame(RgbImage& image)
|
||||
void DispmanxFrameGrabber::grabFrame(Image<ColorRgba> & image)
|
||||
{
|
||||
// Sanity check of the given image size
|
||||
assert(image.width() == _width && image.height() == _height);
|
||||
@ -69,7 +74,7 @@ void DispmanxFrameGrabber::grabFrame(RgbImage& image)
|
||||
|
||||
// Read the snapshot into the memory
|
||||
void* image_ptr = image.memptr();
|
||||
const unsigned destPitch = _width * 3;
|
||||
const unsigned destPitch = _width * sizeof(ColorRgba);
|
||||
vc_dispmanx_resource_read_data(_vc_resource, &_rectangle, image_ptr, destPitch);
|
||||
|
||||
// Close the displaye
|
||||
|
@ -8,7 +8,8 @@
|
||||
#include <cstdint>
|
||||
|
||||
// Utils includes
|
||||
#include <utils/RgbImage.h>
|
||||
#include <utils/Image.h>
|
||||
#include <utils/ColorRgba.h>
|
||||
|
||||
///
|
||||
/// The DispmanxFrameGrabber is used for creating snapshots of the display (screenshots) with a
|
||||
@ -41,7 +42,7 @@ public:
|
||||
/// @param[out] image The snapped screenshot (should be initialized with correct width and
|
||||
/// height)
|
||||
///
|
||||
void grabFrame(RgbImage& image);
|
||||
void grabFrame(Image<ColorRgba> & image);
|
||||
|
||||
private:
|
||||
/// Handle to the display that is being captured
|
||||
|
@ -20,7 +20,7 @@ DispmanxWrapper::DispmanxWrapper(const unsigned grabWidth, const unsigned grabHe
|
||||
_image(grabWidth, grabHeight),
|
||||
_frameGrabber(new DispmanxFrameGrabber(grabWidth, grabHeight)),
|
||||
_processor(ImageProcessorFactory::getInstance().newImageProcessor()),
|
||||
_ledColors(hyperion->getLedCount(), RgbColor::BLACK),
|
||||
_ledColors(hyperion->getLedCount(), ColorRgb{0,0,0}),
|
||||
_hyperion(hyperion)
|
||||
{
|
||||
// Configure the timer to generate events every n milliseconds
|
||||
|
@ -1,6 +1,6 @@
|
||||
|
||||
// Local-Hyperion includes
|
||||
#include "BlackBorderDetector.h"
|
||||
#include <hyperion/BlackBorderDetector.h>
|
||||
|
||||
using namespace hyperion;
|
||||
|
||||
@ -8,56 +8,3 @@ BlackBorderDetector::BlackBorderDetector()
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
BlackBorder BlackBorderDetector::process(const RgbImage& image)
|
||||
{
|
||||
// only test the topleft third of the image
|
||||
int width = image.width() /3;
|
||||
int height = image.height() / 3;
|
||||
int maxSize = std::max(width, height);
|
||||
|
||||
int firstNonBlackXPixelIndex = -1;
|
||||
int firstNonBlackYPixelIndex = -1;
|
||||
|
||||
// find some pixel of the image
|
||||
for (int i = 0; i < maxSize; ++i)
|
||||
{
|
||||
int x = std::min(i, width);
|
||||
int y = std::min(i, height);
|
||||
|
||||
const RgbColor& color = image(x, y);
|
||||
if (!isBlack(color))
|
||||
{
|
||||
firstNonBlackXPixelIndex = x;
|
||||
firstNonBlackYPixelIndex = y;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// expand image to the left
|
||||
for(; firstNonBlackXPixelIndex > 0; --firstNonBlackXPixelIndex)
|
||||
{
|
||||
const RgbColor& color = image(firstNonBlackXPixelIndex-1, firstNonBlackYPixelIndex);
|
||||
if (isBlack(color))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// expand image to the top
|
||||
for(; firstNonBlackYPixelIndex > 0; --firstNonBlackYPixelIndex)
|
||||
{
|
||||
const RgbColor& color = image(firstNonBlackXPixelIndex, firstNonBlackYPixelIndex-1);
|
||||
if (isBlack(color))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Construct result
|
||||
BlackBorder detectedBorder;
|
||||
detectedBorder.unknown = firstNonBlackXPixelIndex == -1 || firstNonBlackYPixelIndex == -1;
|
||||
detectedBorder.horizontalSize = firstNonBlackYPixelIndex;
|
||||
detectedBorder.verticalSize = firstNonBlackXPixelIndex;
|
||||
return detectedBorder;
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
|
||||
// Local-Hyperion includes
|
||||
#include "BlackBorderProcessor.h"
|
||||
#include <hyperion/BlackBorderProcessor.h>
|
||||
|
||||
using namespace hyperion;
|
||||
|
||||
@ -16,6 +16,7 @@ BlackBorderProcessor::BlackBorderProcessor(
|
||||
_previousDetectedBorder({true, -1, -1}),
|
||||
_consistentCnt(0)
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
BlackBorder BlackBorderProcessor::getCurrentBorder() const
|
||||
@ -23,46 +24,33 @@ BlackBorder BlackBorderProcessor::getCurrentBorder() const
|
||||
return _currentBorder;
|
||||
}
|
||||
|
||||
bool BlackBorderProcessor::process(const RgbImage& image)
|
||||
bool BlackBorderProcessor::updateBorder(const BlackBorder & newDetectedBorder)
|
||||
{
|
||||
// get the border for the single image
|
||||
BlackBorder imageBorder = _detector.process(image);
|
||||
|
||||
// add blur to the border
|
||||
if (imageBorder.horizontalSize > 0)
|
||||
{
|
||||
imageBorder.horizontalSize += _blurRemoveCnt;
|
||||
}
|
||||
if (imageBorder.verticalSize > 0)
|
||||
{
|
||||
imageBorder.verticalSize += _blurRemoveCnt;
|
||||
}
|
||||
|
||||
// set the consistency counter
|
||||
if (imageBorder == _previousDetectedBorder)
|
||||
if (newDetectedBorder == _previousDetectedBorder)
|
||||
{
|
||||
++_consistentCnt;
|
||||
}
|
||||
else
|
||||
{
|
||||
_previousDetectedBorder = imageBorder;
|
||||
_previousDetectedBorder = newDetectedBorder;
|
||||
_consistentCnt = 0;
|
||||
}
|
||||
|
||||
// check if there is a change
|
||||
if (_currentBorder == imageBorder)
|
||||
if (_currentBorder == newDetectedBorder)
|
||||
{
|
||||
// No change required
|
||||
return false;
|
||||
}
|
||||
|
||||
bool borderChanged = false;
|
||||
if (imageBorder.unknown)
|
||||
if (newDetectedBorder.unknown)
|
||||
{
|
||||
// apply the unknown border if we consistently can't determine a border
|
||||
if (_consistentCnt == _unknownSwitchCnt)
|
||||
{
|
||||
_currentBorder = imageBorder;
|
||||
_currentBorder = newDetectedBorder;
|
||||
borderChanged = true;
|
||||
}
|
||||
}
|
||||
@ -71,21 +59,21 @@ bool BlackBorderProcessor::process(const RgbImage& image)
|
||||
// apply the detected border if it has been detected consistently
|
||||
if (_currentBorder.unknown || _consistentCnt == _borderSwitchCnt)
|
||||
{
|
||||
_currentBorder = imageBorder;
|
||||
_currentBorder = newDetectedBorder;
|
||||
borderChanged = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// apply smaller borders immediately
|
||||
if (imageBorder.verticalSize < _currentBorder.verticalSize)
|
||||
if (newDetectedBorder.verticalSize < _currentBorder.verticalSize)
|
||||
{
|
||||
_currentBorder.verticalSize = imageBorder.verticalSize;
|
||||
_currentBorder.verticalSize = newDetectedBorder.verticalSize;
|
||||
borderChanged = true;
|
||||
}
|
||||
|
||||
if (imageBorder.horizontalSize < _currentBorder.horizontalSize)
|
||||
if (newDetectedBorder.horizontalSize < _currentBorder.horizontalSize)
|
||||
{
|
||||
_currentBorder.horizontalSize = imageBorder.horizontalSize;
|
||||
_currentBorder.horizontalSize = newDetectedBorder.horizontalSize;
|
||||
borderChanged = true;
|
||||
}
|
||||
}
|
||||
|
@ -13,13 +13,13 @@ SET(Hyperion_QT_HEADERS
|
||||
SET(Hyperion_HEADERS
|
||||
${CURRENT_HEADER_DIR}/ImageProcessor.h
|
||||
${CURRENT_HEADER_DIR}/ImageProcessorFactory.h
|
||||
${CURRENT_HEADER_DIR}/ImageToLedsMap.h
|
||||
${CURRENT_HEADER_DIR}/LedDevice.h
|
||||
${CURRENT_HEADER_DIR}/LedString.h
|
||||
${CURRENT_HEADER_DIR}/PriorityMuxer.h
|
||||
|
||||
${CURRENT_SOURCE_DIR}/BlackBorderDetector.h
|
||||
${CURRENT_SOURCE_DIR}/BlackBorderProcessor.h
|
||||
${CURRENT_SOURCE_DIR}/ImageToLedsMap.h
|
||||
${CURRENT_HEADER_DIR}/BlackBorderDetector.h
|
||||
${CURRENT_HEADER_DIR}/BlackBorderProcessor.h
|
||||
|
||||
${CURRENT_SOURCE_DIR}/device/LedSpiDevice.h
|
||||
${CURRENT_SOURCE_DIR}/device/LedRs232Device.h
|
||||
|
@ -1,4 +1,7 @@
|
||||
|
||||
// STL includes
|
||||
#include <cassert>
|
||||
|
||||
// QT includes
|
||||
#include <QDateTime>
|
||||
|
||||
@ -249,16 +252,16 @@ unsigned Hyperion::getLedCount() const
|
||||
return _ledString.leds().size();
|
||||
}
|
||||
|
||||
void Hyperion::setColor(int priority, const RgbColor &color, const int timeout_ms)
|
||||
void Hyperion::setColor(int priority, const ColorRgb &color, const int timeout_ms)
|
||||
{
|
||||
// create led output
|
||||
std::vector<RgbColor> ledColors(_ledString.leds().size(), color);
|
||||
std::vector<ColorRgb> ledColors(_ledString.leds().size(), color);
|
||||
|
||||
// set colors
|
||||
setColors(priority, ledColors, timeout_ms);
|
||||
}
|
||||
|
||||
void Hyperion::setColors(int priority, const std::vector<RgbColor>& ledColors, const int timeout_ms)
|
||||
void Hyperion::setColors(int priority, const std::vector<ColorRgb>& ledColors, const int timeout_ms)
|
||||
{
|
||||
if (timeout_ms > 0)
|
||||
{
|
||||
@ -415,8 +418,8 @@ void Hyperion::update()
|
||||
const PriorityMuxer::InputInfo & priorityInfo = _muxer.getInputInfo(priority);
|
||||
|
||||
// Apply the transform to each led and color-channel
|
||||
std::vector<RgbColor> ledColors(priorityInfo.ledColors);
|
||||
for (RgbColor& color : ledColors)
|
||||
std::vector<ColorRgb> ledColors(priorityInfo.ledColors);
|
||||
for (ColorRgb& color : ledColors)
|
||||
{
|
||||
_hsvTransform->transform(color.red, color.green, color.blue);
|
||||
color.red = _redTransform->transform(color.red);
|
||||
|
@ -1,13 +1,11 @@
|
||||
|
||||
// Hyperion includes
|
||||
#include <hyperion/ImageProcessor.h>
|
||||
#include <hyperion/ImageToLedsMap.h>
|
||||
#include <hyperion/BlackBorderProcessor.h>
|
||||
|
||||
#include <utils/ColorTransform.h>
|
||||
|
||||
// Local-Hyperion includes
|
||||
#include "BlackBorderProcessor.h"
|
||||
#include "ImageToLedsMap.h"
|
||||
|
||||
using namespace hyperion;
|
||||
|
||||
ImageProcessor::ImageProcessor(const LedString& ledString, bool enableBlackBorderDetector) :
|
||||
@ -40,33 +38,6 @@ void ImageProcessor::setSize(const unsigned width, const unsigned height)
|
||||
mImageToLeds = new ImageToLedsMap(width, height, 0, 0, mLedString.leds());
|
||||
}
|
||||
|
||||
std::vector<RgbColor> ImageProcessor::process(const RgbImage& image)
|
||||
{
|
||||
// Ensure that the buffer-image is the proper size
|
||||
setSize(image.width(), image.height());
|
||||
|
||||
// Check black border detection
|
||||
verifyBorder(image);
|
||||
|
||||
// Create a result vector and call the 'in place' functionl
|
||||
std::vector<RgbColor> colors = mImageToLeds->getMeanLedColor(image);
|
||||
|
||||
// return the computed colors
|
||||
return colors;
|
||||
}
|
||||
|
||||
void ImageProcessor::process(const RgbImage& image, std::vector<RgbColor>& ledColors)
|
||||
{
|
||||
// Ensure that the buffer-image is the proper size
|
||||
setSize(image.width(), image.height());
|
||||
|
||||
// Check black border detection
|
||||
verifyBorder(image);
|
||||
|
||||
// Determine the mean-colors of each led (using the existing mapping)
|
||||
mImageToLeds->getMeanLedColor(image, ledColors);
|
||||
}
|
||||
|
||||
bool ImageProcessor::getScanParameters(size_t led, double &hscanBegin, double &hscanEnd, double &vscanBegin, double &vscanEnd) const
|
||||
{
|
||||
if (led < mLedString.leds().size())
|
||||
@ -81,29 +52,3 @@ bool ImageProcessor::getScanParameters(size_t led, double &hscanBegin, double &h
|
||||
return false;
|
||||
}
|
||||
|
||||
void ImageProcessor::verifyBorder(const RgbImage& image)
|
||||
{
|
||||
if(_enableBlackBorderRemoval && _borderProcessor->process(image))
|
||||
{
|
||||
std::cout << "BORDER SWITCH REQUIRED!!" << std::endl;
|
||||
|
||||
const BlackBorder border = _borderProcessor->getCurrentBorder();
|
||||
|
||||
// Clean up the old mapping
|
||||
delete mImageToLeds;
|
||||
|
||||
if (border.unknown)
|
||||
{
|
||||
// Construct a new buffer and mapping
|
||||
mImageToLeds = new ImageToLedsMap(image.width(), image.height(), 0, 0, mLedString.leds());
|
||||
}
|
||||
else
|
||||
{
|
||||
// Construct a new buffer and mapping
|
||||
mImageToLeds = new ImageToLedsMap(image.width(), image.height(), border.horizontalSize, border.verticalSize, mLedString.leds());
|
||||
}
|
||||
|
||||
std::cout << "CURRENT BORDER TYPE: unknown=" << border.unknown << " hor.size=" << border.horizontalSize << " vert.size=" << border.verticalSize << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,9 +1,10 @@
|
||||
|
||||
// STL includes
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
|
||||
// hyperion includes
|
||||
#include "ImageToLedsMap.h"
|
||||
#include <hyperion/ImageToLedsMap.h>
|
||||
|
||||
using namespace hyperion;
|
||||
|
||||
@ -61,52 +62,3 @@ unsigned ImageToLedsMap::height() const
|
||||
{
|
||||
return _height;
|
||||
}
|
||||
|
||||
std::vector<RgbColor> ImageToLedsMap::getMeanLedColor(const RgbImage & image) const
|
||||
{
|
||||
std::vector<RgbColor> colors(mColorsMap.size(), RgbColor::BLACK);
|
||||
getMeanLedColor(image, colors);
|
||||
return colors;
|
||||
}
|
||||
|
||||
void ImageToLedsMap::getMeanLedColor(const RgbImage & image, std::vector<RgbColor> & ledColors) const
|
||||
{
|
||||
// Sanity check for the number of leds
|
||||
assert(mColorsMap.size() == ledColors.size());
|
||||
|
||||
// Iterate each led and compute the mean
|
||||
auto led = ledColors.begin();
|
||||
for (auto ledColors = mColorsMap.begin(); ledColors != mColorsMap.end(); ++ledColors, ++led)
|
||||
{
|
||||
const RgbColor color = calcMeanColor(image, *ledColors);
|
||||
*led = color;
|
||||
}
|
||||
}
|
||||
|
||||
RgbColor ImageToLedsMap::calcMeanColor(const RgbImage & image, const std::vector<unsigned> & colors) const
|
||||
{
|
||||
if (colors.size() == 0)
|
||||
{
|
||||
return RgbColor::BLACK;
|
||||
}
|
||||
|
||||
// Accumulate the sum of each seperate color channel
|
||||
uint_fast16_t cummRed = 0;
|
||||
uint_fast16_t cummGreen = 0;
|
||||
uint_fast16_t cummBlue = 0;
|
||||
for (const unsigned colorOffset : colors)
|
||||
{
|
||||
const RgbColor& color = image.memptr()[colorOffset];
|
||||
cummRed += color.red;
|
||||
cummGreen += color.green;
|
||||
cummBlue += color.blue;
|
||||
}
|
||||
|
||||
// Compute the average of each color channel
|
||||
const uint8_t avgRed = uint8_t(cummRed/colors.size());
|
||||
const uint8_t avgGreen = uint8_t(cummGreen/colors.size());
|
||||
const uint8_t avgBlue = uint8_t(cummBlue/colors.size());
|
||||
|
||||
// Return the computed color
|
||||
return {avgRed, avgGreen, avgBlue};
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ LinearColorSmoothing::~LinearColorSmoothing()
|
||||
delete _ledDevice;
|
||||
}
|
||||
|
||||
int LinearColorSmoothing::write(const std::vector<RgbColor> &ledValues)
|
||||
int LinearColorSmoothing::write(const std::vector<ColorRgb> &ledValues)
|
||||
{
|
||||
// received a new target color
|
||||
if (_previousValues.size() == 0)
|
||||
@ -38,7 +38,7 @@ int LinearColorSmoothing::write(const std::vector<RgbColor> &ledValues)
|
||||
else
|
||||
{
|
||||
_targetTime = QDateTime::currentMSecsSinceEpoch() + _settlingTime;
|
||||
memcpy(_targetValues.data(), ledValues.data(), ledValues.size() * sizeof(RgbColor));
|
||||
memcpy(_targetValues.data(), ledValues.data(), ledValues.size() * sizeof(ColorRgb));
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -66,7 +66,7 @@ void LinearColorSmoothing::updateLeds()
|
||||
|
||||
if (deltaTime < 0)
|
||||
{
|
||||
memcpy(_previousValues.data(), _targetValues.data(), _targetValues.size() * sizeof(RgbColor));
|
||||
memcpy(_previousValues.data(), _targetValues.data(), _targetValues.size() * sizeof(ColorRgb));
|
||||
_previousTime = now;
|
||||
|
||||
_ledDevice->write(_previousValues);
|
||||
@ -77,8 +77,8 @@ void LinearColorSmoothing::updateLeds()
|
||||
|
||||
for (size_t i = 0; i < _previousValues.size(); ++i)
|
||||
{
|
||||
RgbColor & prev = _previousValues[i];
|
||||
RgbColor & target = _targetValues[i];
|
||||
ColorRgb & prev = _previousValues[i];
|
||||
ColorRgb & target = _targetValues[i];
|
||||
|
||||
prev.red += k * (target.red - prev.red);
|
||||
prev.green += k * (target.green - prev.green);
|
||||
|
@ -36,7 +36,7 @@ public:
|
||||
/// @param ledValues The color-value per led
|
||||
/// @return Zero on succes else negative
|
||||
///
|
||||
virtual int write(const std::vector<RgbColor> &ledValues);
|
||||
virtual int write(const std::vector<ColorRgb> &ledValues);
|
||||
|
||||
/// Switch the leds off
|
||||
virtual int switchOff();
|
||||
@ -62,11 +62,11 @@ private:
|
||||
int64_t _targetTime;
|
||||
|
||||
/// The target led data
|
||||
std::vector<RgbColor> _targetValues;
|
||||
std::vector<ColorRgb> _targetValues;
|
||||
|
||||
/// The timestamp of the previously written led data
|
||||
int64_t _previousTime;
|
||||
|
||||
/// The previously written led data
|
||||
std::vector<RgbColor> _previousValues;
|
||||
std::vector<ColorRgb> _previousValues;
|
||||
};
|
||||
|
@ -13,7 +13,7 @@ PriorityMuxer::PriorityMuxer(int ledCount) :
|
||||
{
|
||||
_lowestPriorityInfo.priority = LOWEST_PRIORITY;
|
||||
_lowestPriorityInfo.timeoutTime_ms = -1;
|
||||
_lowestPriorityInfo.ledColors = std::vector<RgbColor>(ledCount, {0, 0, 0});
|
||||
_lowestPriorityInfo.ledColors = std::vector<ColorRgb>(ledCount, {0, 0, 0});
|
||||
}
|
||||
|
||||
PriorityMuxer::~PriorityMuxer()
|
||||
@ -51,7 +51,7 @@ const PriorityMuxer::InputInfo& PriorityMuxer::getInputInfo(const int priority)
|
||||
return elemIt.value();
|
||||
}
|
||||
|
||||
void PriorityMuxer::setInput(const int priority, const std::vector<RgbColor>& ledColors, const int64_t timeoutTime_ms)
|
||||
void PriorityMuxer::setInput(const int priority, const std::vector<ColorRgb>& ledColors, const int64_t timeoutTime_ms)
|
||||
{
|
||||
InputInfo& input = _activeInputs[priority];
|
||||
input.priority = priority;
|
||||
|
@ -17,7 +17,7 @@ LedDeviceLdp6803::LedDeviceLdp6803(const std::string& outputDevice, const unsign
|
||||
// empty
|
||||
}
|
||||
|
||||
int LedDeviceLdp6803::write(const std::vector<RgbColor> &ledValues)
|
||||
int LedDeviceLdp6803::write(const std::vector<ColorRgb> &ledValues)
|
||||
{
|
||||
// Reconfigure if the current connfiguration does not match the required configuration
|
||||
if (4 + 2*ledValues.size() != _ledBuffer.size())
|
||||
@ -26,10 +26,10 @@ int LedDeviceLdp6803::write(const std::vector<RgbColor> &ledValues)
|
||||
_ledBuffer.resize(4 + 2*ledValues.size(), 0x00);
|
||||
}
|
||||
|
||||
// Copy the colors from the RgbColor vector to the Ldp6803 data vector
|
||||
// Copy the colors from the ColorRgb vector to the Ldp6803 data vector
|
||||
for (unsigned iLed=0; iLed<ledValues.size(); ++iLed)
|
||||
{
|
||||
const RgbColor& rgb = ledValues[iLed];
|
||||
const ColorRgb& rgb = ledValues[iLed];
|
||||
|
||||
_ledBuffer[4 + 2 * iLed] = 0x80 | ((rgb.red & 0xf8) >> 1) | (rgb.green >> 6);
|
||||
_ledBuffer[5 + 2 * iLed] = ((rgb.green & 0x38) << 2) | (rgb.blue >> 3);
|
||||
@ -45,5 +45,5 @@ int LedDeviceLdp6803::write(const std::vector<RgbColor> &ledValues)
|
||||
|
||||
int LedDeviceLdp6803::switchOff()
|
||||
{
|
||||
return write(std::vector<RgbColor>(_ledBuffer.size(), RgbColor::BLACK));
|
||||
return write(std::vector<ColorRgb>(_ledBuffer.size(), ColorRgb{0,0,0}));
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ public:
|
||||
/// @param ledValues The color-value per led
|
||||
/// @return Zero on succes else negative
|
||||
///
|
||||
virtual int write(const std::vector<RgbColor> &ledValues);
|
||||
virtual int write(const std::vector<ColorRgb> &ledValues);
|
||||
|
||||
/// Switch the leds off
|
||||
virtual int switchOff();
|
||||
|
@ -24,13 +24,13 @@ LedDeviceSedu::LedDeviceSedu(const std::string& outputDevice, const unsigned bau
|
||||
// empty
|
||||
}
|
||||
|
||||
int LedDeviceSedu::write(const std::vector<RgbColor> &ledValues)
|
||||
int LedDeviceSedu::write(const std::vector<ColorRgb> &ledValues)
|
||||
{
|
||||
if (_ledBuffer.size() == 0)
|
||||
{
|
||||
std::vector<FrameSpec> frameSpecs{{0xA0, 96}, {0xA1, 256}, {0xA2, 512}, {0xB0, 768}, {0xB1, 1536}, {0xB2, 3072} };
|
||||
|
||||
const unsigned reqColorChannels = ledValues.size() * sizeof(RgbColor);
|
||||
const unsigned reqColorChannels = ledValues.size() * sizeof(ColorRgb);
|
||||
|
||||
for (const FrameSpec& frameSpec : frameSpecs)
|
||||
{
|
||||
@ -52,7 +52,7 @@ int LedDeviceSedu::write(const std::vector<RgbColor> &ledValues)
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(_ledBuffer.data()+2, ledValues.data(), ledValues.size() * sizeof(RgbColor));
|
||||
memcpy(_ledBuffer.data()+2, ledValues.data(), ledValues.size() * sizeof(ColorRgb));
|
||||
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,7 @@ public:
|
||||
/// @param ledValues The color-value per led
|
||||
/// @return Zero on succes else negative
|
||||
///
|
||||
virtual int write(const std::vector<RgbColor> &ledValues);
|
||||
virtual int write(const std::vector<ColorRgb> &ledValues);
|
||||
|
||||
/// Switch the leds off
|
||||
virtual int switchOff();
|
||||
|
@ -13,10 +13,10 @@ LedDeviceTest::~LedDeviceTest()
|
||||
// empty
|
||||
}
|
||||
|
||||
int LedDeviceTest::write(const std::vector<RgbColor> & ledValues)
|
||||
int LedDeviceTest::write(const std::vector<ColorRgb> & ledValues)
|
||||
{
|
||||
_ofs << "[";
|
||||
for (const RgbColor& color : ledValues)
|
||||
for (const ColorRgb& color : ledValues)
|
||||
{
|
||||
_ofs << color;
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ public:
|
||||
///
|
||||
/// @return Zero on success else negative
|
||||
///
|
||||
virtual int write(const std::vector<RgbColor> & ledValues);
|
||||
virtual int write(const std::vector<ColorRgb> & ledValues);
|
||||
|
||||
/// Switch the leds off
|
||||
virtual int switchOff();
|
||||
|
@ -18,11 +18,11 @@ LedDeviceWs2801::LedDeviceWs2801(const std::string& outputDevice, const unsigned
|
||||
// empty
|
||||
}
|
||||
|
||||
int LedDeviceWs2801::write(const std::vector<RgbColor> &ledValues)
|
||||
int LedDeviceWs2801::write(const std::vector<ColorRgb> &ledValues)
|
||||
{
|
||||
mLedCount = ledValues.size();
|
||||
|
||||
const unsigned dataLen = ledValues.size() * sizeof(RgbColor);
|
||||
const unsigned dataLen = ledValues.size() * sizeof(ColorRgb);
|
||||
const uint8_t * dataPtr = reinterpret_cast<const uint8_t *>(ledValues.data());
|
||||
|
||||
return writeBytes(dataLen, dataPtr);
|
||||
@ -30,5 +30,5 @@ int LedDeviceWs2801::write(const std::vector<RgbColor> &ledValues)
|
||||
|
||||
int LedDeviceWs2801::switchOff()
|
||||
{
|
||||
return write(std::vector<RgbColor>(mLedCount, RgbColor::BLACK));
|
||||
return write(std::vector<ColorRgb>(mLedCount, ColorRgb{0,0,0}));
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ public:
|
||||
/// @param ledValues The color-value per led
|
||||
/// @return Zero on succes else negative
|
||||
///
|
||||
virtual int write(const std::vector<RgbColor> &ledValues);
|
||||
virtual int write(const std::vector<ColorRgb> &ledValues);
|
||||
|
||||
/// Switch the leds off
|
||||
virtual int switchOff();
|
||||
|
@ -14,7 +14,7 @@
|
||||
// hyperion util includes
|
||||
#include "hyperion/ImageProcessorFactory.h"
|
||||
#include "hyperion/ImageProcessor.h"
|
||||
#include "utils/RgbColor.h"
|
||||
#include "utils/ColorRgb.h"
|
||||
|
||||
// project includes
|
||||
#include "JsonClientConnection.h"
|
||||
@ -111,7 +111,7 @@ void JsonClientConnection::handleColorCommand(const Json::Value &message)
|
||||
// extract parameters
|
||||
int priority = message["priority"].asInt();
|
||||
int duration = message.get("duration", -1).asInt();
|
||||
RgbColor color = {uint8_t(message["color"][0u].asInt()), uint8_t(message["color"][1u].asInt()), uint8_t(message["color"][2u].asInt())};
|
||||
ColorRgb color = {uint8_t(message["color"][0u].asInt()), uint8_t(message["color"][1u].asInt()), uint8_t(message["color"][2u].asInt())};
|
||||
|
||||
// set output
|
||||
_hyperion->setColor(priority, color, duration);
|
||||
@ -139,12 +139,12 @@ void JsonClientConnection::handleImageCommand(const Json::Value &message)
|
||||
// set width and height of the image processor
|
||||
_imageProcessor->setSize(width, height);
|
||||
|
||||
// create RgbImage
|
||||
RgbImage image(width, height);
|
||||
// create ImageRgb
|
||||
Image<ColorRgb> image(width, height);
|
||||
memcpy(image.memptr(), data.data(), data.size());
|
||||
|
||||
// process the image
|
||||
std::vector<RgbColor> ledColors = _imageProcessor->process(image);
|
||||
std::vector<ColorRgb> ledColors = _imageProcessor->process(image);
|
||||
_hyperion->setColors(priority, ledColors, duration);
|
||||
|
||||
// send reply
|
||||
|
@ -15,7 +15,7 @@
|
||||
// hyperion util includes
|
||||
#include "hyperion/ImageProcessorFactory.h"
|
||||
#include "hyperion/ImageProcessor.h"
|
||||
#include "utils/RgbColor.h"
|
||||
#include "utils/ColorRgb.h"
|
||||
|
||||
// project includes
|
||||
#include "ProtoClientConnection.h"
|
||||
@ -120,7 +120,7 @@ void ProtoClientConnection::handleColorCommand(const proto::ColorRequest &messag
|
||||
// extract parameters
|
||||
int priority = message.priority();
|
||||
int duration = message.has_duration() ? message.duration() : -1;
|
||||
RgbColor color;
|
||||
ColorRgb color;
|
||||
color.red = qRed(message.rgbcolor());
|
||||
color.green = qGreen(message.rgbcolor());
|
||||
color.blue = qBlue(message.rgbcolor());
|
||||
@ -151,12 +151,12 @@ void ProtoClientConnection::handleImageCommand(const proto::ImageRequest &messag
|
||||
// set width and height of the image processor
|
||||
_imageProcessor->setSize(width, height);
|
||||
|
||||
// create RgbImage
|
||||
RgbImage image(width, height);
|
||||
// create ImageRgb
|
||||
Image<ColorRgb> image(width, height);
|
||||
memcpy(image.memptr(), imageData.c_str(), imageData.size());
|
||||
|
||||
// process the image
|
||||
std::vector<RgbColor> ledColors = _imageProcessor->process(image);
|
||||
std::vector<ColorRgb> ledColors = _imageProcessor->process(image);
|
||||
_hyperion->setColors(priority, ledColors, duration);
|
||||
|
||||
// send reply
|
||||
|
@ -24,7 +24,7 @@ message ColorRequest {
|
||||
required int32 priority = 1;
|
||||
|
||||
// integer value containing the rgb color (0x00RRGGBB)
|
||||
required int32 rgbColor = 2;
|
||||
required int32 RgbColor = 2;
|
||||
|
||||
// duration of the request (negative results in infinite)
|
||||
optional int32 duration = 3;
|
||||
|
@ -4,13 +4,16 @@ SET(CURRENT_HEADER_DIR ${CMAKE_SOURCE_DIR}/include/utils)
|
||||
SET(CURRENT_SOURCE_DIR ${CMAKE_SOURCE_DIR}/libsrc/utils)
|
||||
|
||||
add_library(hyperion-utils
|
||||
${CURRENT_HEADER_DIR}/RgbColor.h
|
||||
${CURRENT_HEADER_DIR}/RgbImage.h
|
||||
${CURRENT_HEADER_DIR}/ColorArgb.h
|
||||
${CURRENT_SOURCE_DIR}/ColorArgb.cpp
|
||||
${CURRENT_HEADER_DIR}/ColorRgb.h
|
||||
${CURRENT_SOURCE_DIR}/ColorRgb.cpp
|
||||
${CURRENT_HEADER_DIR}/ColorRgba.h
|
||||
${CURRENT_SOURCE_DIR}/ColorRgba.cpp
|
||||
${CURRENT_HEADER_DIR}/Image.h
|
||||
${CURRENT_HEADER_DIR}/ColorTransform.h
|
||||
${CURRENT_HEADER_DIR}/HsvTransform.h
|
||||
|
||||
${CURRENT_SOURCE_DIR}/RgbColor.cpp
|
||||
${CURRENT_SOURCE_DIR}/RgbImage.cpp
|
||||
${CURRENT_SOURCE_DIR}/ColorTransform.cpp
|
||||
${CURRENT_SOURCE_DIR}/HsvTransform.cpp
|
||||
|
||||
|
10
libsrc/utils/ColorArgb.cpp
Normal file
10
libsrc/utils/ColorArgb.cpp
Normal file
@ -0,0 +1,10 @@
|
||||
|
||||
// Utils includes
|
||||
#include <utils/ColorArgb.h>
|
||||
|
||||
ColorArgb ColorArgb::BLACK = { 255, 0, 0, 0 };
|
||||
ColorArgb ColorArgb::RED = { 255, 255, 0, 0 };
|
||||
ColorArgb ColorArgb::GREEN = { 255, 0, 255, 0 };
|
||||
ColorArgb ColorArgb::BLUE = { 255, 0, 0, 255 };
|
||||
ColorArgb ColorArgb::YELLOW= { 255, 255, 255, 0 };
|
||||
ColorArgb ColorArgb::WHITE = { 255, 255, 255, 255 };
|
10
libsrc/utils/ColorRgb.cpp
Normal file
10
libsrc/utils/ColorRgb.cpp
Normal file
@ -0,0 +1,10 @@
|
||||
|
||||
// Local includes
|
||||
#include <utils/ColorRgb.h>
|
||||
|
||||
ColorRgb ColorRgb::BLACK = { 0, 0, 0 };
|
||||
ColorRgb ColorRgb::RED = { 255, 0, 0 };
|
||||
ColorRgb ColorRgb::GREEN = { 0, 255, 0 };
|
||||
ColorRgb ColorRgb::BLUE = { 0, 0, 255 };
|
||||
ColorRgb ColorRgb::YELLOW= { 255, 255, 0 };
|
||||
ColorRgb ColorRgb::WHITE = { 255, 255, 255 };
|
10
libsrc/utils/ColorRgba.cpp
Normal file
10
libsrc/utils/ColorRgba.cpp
Normal file
@ -0,0 +1,10 @@
|
||||
|
||||
// Utils includes
|
||||
#include <utils/ColorRgba.h>
|
||||
|
||||
ColorRgba ColorRgba::BLACK = { 0, 0, 0, 255 };
|
||||
ColorRgba ColorRgba::RED = { 255, 0, 0, 255 };
|
||||
ColorRgba ColorRgba::GREEN = { 0, 255, 0, 255 };
|
||||
ColorRgba ColorRgba::BLUE = { 0, 0, 255, 255 };
|
||||
ColorRgba ColorRgba::YELLOW= { 255, 255, 0, 255 };
|
||||
ColorRgba ColorRgba::WHITE = { 255, 255, 255, 255 };
|
@ -1,10 +0,0 @@
|
||||
|
||||
// Local includes
|
||||
#include <utils/RgbColor.h>
|
||||
|
||||
RgbColor RgbColor::BLACK = { 0, 0, 0 };
|
||||
RgbColor RgbColor::RED = { 255, 0, 0 };
|
||||
RgbColor RgbColor::GREEN = { 0, 255, 0 };
|
||||
RgbColor RgbColor::BLUE = { 0, 0, 255 };
|
||||
RgbColor RgbColor::YELLOW= { 255, 255, 0 };
|
||||
RgbColor RgbColor::WHITE = { 255, 255, 255 };
|
@ -1,50 +0,0 @@
|
||||
|
||||
// STL includes
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
|
||||
// hyperion Utils includes
|
||||
#include <utils/RgbImage.h>
|
||||
|
||||
|
||||
RgbImage::RgbImage(const unsigned width, const unsigned height, const RgbColor background) :
|
||||
_width(width),
|
||||
_height(height),
|
||||
mColors(new RgbColor[width*height])
|
||||
{
|
||||
for (unsigned i=0; i<width*height; ++i)
|
||||
{
|
||||
mColors[i] = background;
|
||||
}
|
||||
}
|
||||
|
||||
RgbImage::~RgbImage()
|
||||
{
|
||||
delete[] mColors;
|
||||
}
|
||||
|
||||
void RgbImage::setPixel(const unsigned x, const unsigned y, const RgbColor color)
|
||||
{
|
||||
// Debug-mode sanity check on given index
|
||||
(*this)(x,y) = color;
|
||||
}
|
||||
|
||||
const RgbColor& RgbImage::operator()(const unsigned x, const unsigned y) const
|
||||
{
|
||||
// Debug-mode sanity check on given index
|
||||
assert(x < _width);
|
||||
assert(y < _height);
|
||||
|
||||
const unsigned index = toIndex(x, y);
|
||||
return mColors[index];
|
||||
}
|
||||
|
||||
RgbColor& RgbImage::operator()(const unsigned x, const unsigned y)
|
||||
{
|
||||
// Debug-mode sanity check on given index
|
||||
assert(x < _width);
|
||||
assert(y < _height);
|
||||
|
||||
const unsigned index = toIndex(x, y);
|
||||
return mColors[index];
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
// C++ includes
|
||||
#include <cassert>
|
||||
#include <csignal>
|
||||
|
||||
// QT includes
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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));
|
||||
|
Loading…
Reference in New Issue
Block a user