mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Added simple QT-based grabber.
Moved ImageToLedsMap from include to libsrc. Moved instantiation of objects to Hyperion (no JSON required outside this class).
This commit is contained in:
32
include/hyperion/DispmanxWrapper.h
Normal file
32
include/hyperion/DispmanxWrapper.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
// QT includes
|
||||
#include <QObject>
|
||||
#include <QTimer>
|
||||
|
||||
// Forward class declaration
|
||||
class ImageProcessor;
|
||||
class DispmanxFrameGrabber;
|
||||
|
||||
class DispmanxWrapper: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
DispmanxWrapper();
|
||||
|
||||
virtual ~DispmanxWrapper();
|
||||
|
||||
public slots:
|
||||
void start();
|
||||
|
||||
void action();
|
||||
|
||||
void stop();
|
||||
|
||||
private:
|
||||
QTimer _timer;
|
||||
|
||||
DispmanxFrameGrabber* _frameGrabber;
|
||||
ImageProcessor* _processor;
|
||||
};
|
||||
|
@@ -4,9 +4,14 @@
|
||||
// hyperion-utils includes
|
||||
#include <utils/RgbImage.h>
|
||||
|
||||
// Hyperion includes
|
||||
#include <hyperion/LedString.h>
|
||||
#include <hyperion/ImageToLedsMap.h>
|
||||
#include <hyperion/LedDevice.h>
|
||||
#include <hyperion/PriorityMuxer.h>
|
||||
|
||||
// Forward class declaration
|
||||
namespace hyperion { class ColorTransform; }
|
||||
|
||||
|
||||
class Hyperion
|
||||
{
|
||||
@@ -15,27 +20,18 @@ public:
|
||||
|
||||
~Hyperion();
|
||||
|
||||
void setInputSize(const unsigned width, const unsigned height);
|
||||
|
||||
RgbImage& image()
|
||||
{
|
||||
return *mImage;
|
||||
}
|
||||
|
||||
void commit();
|
||||
|
||||
void operator() (const RgbImage& inputImage);
|
||||
|
||||
void setColor(const RgbColor& color);
|
||||
void setValue(int priority, std::vector<RgbColor> &ledColors);
|
||||
|
||||
private:
|
||||
void applyTransform(std::vector<RgbColor>& colors) const;
|
||||
|
||||
LedString mLedString;
|
||||
|
||||
RgbImage* mImage;
|
||||
PriorityMuxer mMuxer;
|
||||
|
||||
ImageToLedsMap mLedsMap;
|
||||
hyperion::ColorTransform* mRedTransform;
|
||||
hyperion::ColorTransform* mGreenTransform;
|
||||
hyperion::ColorTransform* mBlueTransform;
|
||||
|
||||
LedDevice* mDevice;
|
||||
};
|
||||
|
72
include/hyperion/ImageProcessor.h
Normal file
72
include/hyperion/ImageProcessor.h
Normal file
@@ -0,0 +1,72 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
// Utils includes
|
||||
#include <utils/RgbImage.h>
|
||||
|
||||
#include <hyperion/LedString.h>
|
||||
#include <hyperion/ImageProcessorFactory.h>
|
||||
|
||||
// Forward class declaration
|
||||
namespace hyperion { class ImageToLedsMap;
|
||||
class ColorTransform; }
|
||||
|
||||
/**
|
||||
* The ImageProcessor translates an RGB-image to RGB-values for the leds. The processing is
|
||||
* performed in two steps. First the average color per led-region is computed. Second a
|
||||
* color-tranform is applied based on a gamma-correction.
|
||||
*/
|
||||
class ImageProcessor
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Processes the image to a list of led colors. This will update the size of the buffer-image
|
||||
* if required and call the image-to-leds mapping to determine the mean color per led.
|
||||
*
|
||||
* @param[in] image The image to translate to led values
|
||||
*
|
||||
* @return The color value per led
|
||||
*/
|
||||
std::vector<RgbColor> process(const RgbImage& image);
|
||||
|
||||
// 'IN PLACE' processing functions
|
||||
|
||||
/**
|
||||
* Specifies the width and height of 'incomming' images. This will resize the buffer-image to
|
||||
* match the given size.
|
||||
* NB All earlier obtained references will be invalid.
|
||||
*
|
||||
* @param[in] width The new width of the buffer-image
|
||||
* @param[in] height The new height of the buffer-image
|
||||
*/
|
||||
void setSize(const unsigned width, const unsigned height);
|
||||
|
||||
/**
|
||||
* Returns a reference of the underlying image-buffer. This can be used to write data directly
|
||||
* into the buffer, avoiding a copy inside the process method.
|
||||
*
|
||||
* @return The reference of the underlying image-buffer.
|
||||
*/
|
||||
RgbImage& image();
|
||||
|
||||
/**
|
||||
* Determines the led colors of the image in the buffer.
|
||||
*
|
||||
* @param[out] ledColors The color value per led
|
||||
*/
|
||||
void inplace_process(std::vector<RgbColor>& ledColors);
|
||||
|
||||
private:
|
||||
friend class ImageProcessorFactory;
|
||||
|
||||
ImageProcessor(const LedString &ledString);
|
||||
|
||||
~ImageProcessor();
|
||||
|
||||
private:
|
||||
const LedString mLedString;
|
||||
|
||||
RgbImage *mBuffer;
|
||||
hyperion::ImageToLedsMap* mImageToLeds;
|
||||
};
|
||||
|
26
include/hyperion/ImageProcessorFactory.h
Normal file
26
include/hyperion/ImageProcessorFactory.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
// STL includes
|
||||
#include <memory>
|
||||
|
||||
// Jsoncpp includes
|
||||
#include <json/json.h>
|
||||
|
||||
#include <hyperion/LedString.h>
|
||||
|
||||
// Forward class declaration
|
||||
class ImageProcessor;
|
||||
|
||||
class ImageProcessorFactory
|
||||
{
|
||||
public:
|
||||
static ImageProcessorFactory& getInstance();
|
||||
|
||||
public:
|
||||
void init(const LedString& ledString);
|
||||
|
||||
ImageProcessor* newImageProcessor() const;
|
||||
|
||||
private:
|
||||
LedString _ledString;
|
||||
};
|
@@ -1,27 +0,0 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
// hyperion-utils includes
|
||||
#include <utils/RgbImage.h>
|
||||
|
||||
// hyperion includes
|
||||
#include <hyperion/LedString.h>
|
||||
|
||||
class ImageToLedsMap
|
||||
{
|
||||
public:
|
||||
|
||||
ImageToLedsMap();
|
||||
|
||||
void createMapping(const RgbImage& image, const std::vector<Led>& leds);
|
||||
|
||||
std::vector<RgbColor> getMeanLedColor();
|
||||
|
||||
RgbColor findMeanColor(const std::vector<const RgbColor*>& colors);
|
||||
|
||||
std::vector<RgbColor> getMedianLedColor();
|
||||
|
||||
RgbColor findMedianColor(std::vector<const RgbColor*>& colors);
|
||||
private:
|
||||
std::vector<std::vector<const RgbColor*> > mColorsMap;
|
||||
};
|
@@ -45,28 +45,16 @@ struct Led
|
||||
class LedString
|
||||
{
|
||||
public:
|
||||
static LedString construct(const Json::Value& ledConfig, const Json::Value& colorConfig);
|
||||
static LedString construct(const Json::Value& ledConfig);
|
||||
|
||||
LedString();
|
||||
|
||||
~LedString();
|
||||
|
||||
std::vector<Led>& leds();
|
||||
|
||||
const std::vector<Led>& leds() const;
|
||||
|
||||
private:
|
||||
std::vector<Led> mLeds;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Color adjustements per color
|
||||
*/
|
||||
struct
|
||||
{
|
||||
/** The color gradient */
|
||||
double gamma;
|
||||
/** The color offset */
|
||||
double adjust;
|
||||
/** The minimum required level for the led to turn on */
|
||||
double blacklevel;
|
||||
} red, green, blue;
|
||||
};
|
||||
|
55
include/hyperion/PriorityMuxer.h
Normal file
55
include/hyperion/PriorityMuxer.h
Normal file
@@ -0,0 +1,55 @@
|
||||
#pragma once
|
||||
|
||||
// STL includes
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <cstdint>
|
||||
#include <limits>
|
||||
|
||||
// QT includes
|
||||
#include <QMap>
|
||||
|
||||
// Utils includes
|
||||
#include <utils/RgbColor.h>
|
||||
|
||||
// Hyperion includes
|
||||
#include <hyperion/LedDevice.h>
|
||||
|
||||
class PriorityMuxer
|
||||
{
|
||||
public:
|
||||
struct InputInfo
|
||||
{
|
||||
int priority;
|
||||
|
||||
int64_t timeoutTime_ms;
|
||||
std::vector<RgbColor> ledColors;
|
||||
};
|
||||
|
||||
PriorityMuxer();
|
||||
|
||||
~PriorityMuxer();
|
||||
|
||||
int getCurrentPriority() const;
|
||||
|
||||
bool hasPriority(const int priority) const;
|
||||
|
||||
QList<int> getPriorities() const;
|
||||
|
||||
const InputInfo& getInputInfo(const int priority) const;
|
||||
|
||||
void setInput(const int priority, const std::vector<RgbColor>& ledColors, const int64_t timeoutTime_ms=-1);
|
||||
|
||||
void clearInput(const int priority);
|
||||
|
||||
void clearAll();
|
||||
|
||||
void setCurrentTime(const int64_t& now);
|
||||
|
||||
private:
|
||||
int mCurrentPriority;
|
||||
|
||||
QMap<int, InputInfo> mActiveInputs;
|
||||
|
||||
const static int MAX_PRIORITY = std::numeric_limits<int>::max();
|
||||
};
|
@@ -5,7 +5,6 @@
|
||||
#include <stdint.h>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
// Forward class declaration
|
||||
struct RgbColor;
|
||||
|
||||
@@ -21,8 +20,12 @@ struct RgbColor
|
||||
static RgbColor BLUE;
|
||||
static RgbColor YELLOW;
|
||||
static RgbColor WHITE;
|
||||
|
||||
};
|
||||
|
||||
static_assert(sizeof(RgbColor) == 3, "Incorrect size of RgbColor");
|
||||
|
||||
|
||||
inline std::ostream& operator<<(std::ostream& os, const RgbColor& color)
|
||||
{
|
||||
os << "{" << unsigned(color.red) << "," << unsigned(color.green) << "," << unsigned(color.blue) << "}";
|
||||
|
Reference in New Issue
Block a user