hyperion.ng
ImageProcessor.h
1 #pragma once
2 
3 #include <QString>
4 
5 // Utils includes
6 #include <utils/Image.h>
7 
8 // Hyperion includes
9 #include <hyperion/LedString.h>
10 #include <hyperion/ImageToLedsMap.h>
11 #include <utils/Logger.h>
12 
13 // settings
14 #include <utils/settings.h>
15 
16 // Black border includes
17 #include <blackborder/BlackBorderProcessor.h>
18 
19 class Hyperion;
20 
26 class ImageProcessor : public QObject
27 {
28  Q_OBJECT
29 
30 public:
37  ImageProcessor(const LedString& ledString, Hyperion* hyperion);
38 
39  ~ImageProcessor();
40 
49  void setSize(const unsigned width, const unsigned height);
50 
54  void setLedString(const LedString& ledString);
55 
58 
60  const int & getUserLedMappingType() { return _userMappingType; };
61 
63  const int & ledMappingType() { return _mappingType; };
64 
65  static int mappingTypeToInt(QString mappingType);
66  static QString mappingTypeToStr(int mappingType);
67 
73  void setHardLedMappingType(int mapType);
74 
75 public slots:
77  void setBlackbarDetectDisable(bool enable);
78 
84  void setLedMappingType(int mapType);
85 
86 public:
94  template <typename Pixel_T>
95  void setSize(const Image<Pixel_T> &image)
96  {
97  setSize(image.width(), image.height());
98  }
99 
108  template <typename Pixel_T>
109  std::vector<ColorRgb> process(const Image<Pixel_T>& image)
110  {
111  std::vector<ColorRgb> colors;
112  if (image.width()>0 && image.height()>0)
113  {
114  // Ensure that the buffer-image is the proper size
115  setSize(image);
116 
117  // Check black border detection
118  verifyBorder(image);
119 
120  // Create a result vector and call the 'in place' functionl
121  switch (_mappingType)
122  {
123  case 1: colors = _imageToLeds->getUniLedColor(image); break;
124  default: colors = _imageToLeds->getMeanLedColor(image);
125  }
126  }
127  else
128  {
129  Warning(_log, "ImageProcessor::process called with image size 0");
130  }
131 
132  // return the computed colors
133  return colors;
134  }
135 
142  template <typename Pixel_T>
143  void process(const Image<Pixel_T>& image, std::vector<ColorRgb>& ledColors)
144  {
145  if ( image.width()>0 && image.height()>0)
146  {
147  // Ensure that the buffer-image is the proper size
148  setSize(image);
149 
150  // Check black border detection
151  verifyBorder(image);
152 
153  // Determine the mean or uni colors of each led (using the existing mapping)
154  switch (_mappingType)
155  {
156  case 1: _imageToLeds->getUniLedColor(image, ledColors); break;
157  default: _imageToLeds->getMeanLedColor(image, ledColors);
158  }
159  }
160  else
161  {
162  Warning(_log, "Called with image size 0");
163  }
164  }
165 
175  bool getScanParameters(size_t led, double & hscanBegin, double & hscanEnd, double & vscanBegin, double & vscanEnd) const;
176 
177 private:
183  template <typename Pixel_T>
184  void verifyBorder(const Image<Pixel_T> & image)
185  {
186  if (!_borderProcessor->enabled() && ( _imageToLeds->horizontalBorder()!=0 || _imageToLeds->verticalBorder()!=0 ))
187  {
188  Debug(_log, "Reset border");
189  _borderProcessor->process(image);
190  delete _imageToLeds;
191  _imageToLeds = new hyperion::ImageToLedsMap(image.width(), image.height(), 0, 0, _ledString.leds());
192  }
193 
194  if(_borderProcessor->enabled() && _borderProcessor->process(image))
195  {
196  const hyperion::BlackBorder border = _borderProcessor->getCurrentBorder();
197 
198  // Clean up the old mapping
199  delete _imageToLeds;
200 
201  if (border.unknown)
202  {
203  // Construct a new buffer and mapping
204  _imageToLeds = new hyperion::ImageToLedsMap(image.width(), image.height(), 0, 0, _ledString.leds());
205  }
206  else
207  {
208  // Construct a new buffer and mapping
209  _imageToLeds = new hyperion::ImageToLedsMap(image.width(), image.height(), border.horizontalSize, border.verticalSize, _ledString.leds());
210  }
211 
212  //Debug(Logger::getInstance("BLACKBORDER"), "CURRENT BORDER TYPE: unknown=%d hor.size=%d vert.size=%d",
213  // border.unknown, border.horizontalSize, border.verticalSize );
214  }
215  }
216 
217 private slots:
218  void handleSettingsUpdate(const settings::type& type, const QJsonDocument& config);
219 
220 private:
221  Logger * _log;
223  LedString _ledString;
224 
226  hyperion::BlackBorderProcessor * _borderProcessor;
227 
229  hyperion::ImageToLedsMap* _imageToLeds;
230 
232  int _mappingType;
234  int _userMappingType;
236  int _hardMappingType;
237 
239  Hyperion* _hyperion;
240 };
Definition: Logger.h:32
void setBlackbarDetectDisable(bool enable)
Enable or disable the black border detector based on component.
Definition: ImageProcessor.cpp:94
BlackBorder getCurrentBorder() const
Return the current (detected) border.
Definition: BlackBorderProcessor.cpp:107
bool getScanParameters(size_t led, double &hscanBegin, double &hscanEnd, double &vscanBegin, double &vscanEnd) const
Get the hscan and vscan parameters for a single led.
Definition: ImageProcessor.cpp:125
The main class of Hyperion.
Definition: Hyperion.h:57
Provide utility methods for Hyperion class.
Definition: BlackBorderDetector.h:7
The BlackBorder processor is a wrapper around the black-border detector for keeping track of detected...
Definition: BlackBorderProcessor.h:23
std::vector< ColorRgb > getMeanLedColor(const Image< Pixel_T > &image) const
Determines the mean color for each led using the mapping the image given at construction.
Definition: ImageToLedsMap.h:72
int verticalSize
The size of the detected vertical border.
Definition: BlackBorderDetector.h:21
unsigned height() const
Returns the height of the image.
Definition: Image.h:129
bool blackBorderDetectorEnabled()
Returns starte of black border detector.
Definition: ImageProcessor.cpp:99
Result structure of the detected blackborder.
Definition: BlackBorderDetector.h:12
std::vector< Led > & leds()
Returns the led specifications.
Definition: LedString.cpp:20
void setLedString(const LedString &ledString)
Update the led string (eg on settings change)
Definition: ImageProcessor.cpp:79
void process(const Image< Pixel_T > &image, std::vector< ColorRgb > &ledColors)
Determines the led colors of the image in the buffer.
Definition: ImageProcessor.h:143
bool enabled() const
Return activation state of black border detector.
Definition: BlackBorderProcessor.cpp:112
void setHardLedMappingType(int mapType)
Set the Hyperion::update() requestes led mapping type.
Definition: ImageProcessor.cpp:115
std::vector< ColorRgb > process(const Image< Pixel_T > &image)
Processes the image to a list of led colors.
Definition: ImageProcessor.h:109
unsigned width() const
Returns the width of the image.
Definition: Image.h:119
const int & ledMappingType()
Returns the current _mappingType.
Definition: ImageProcessor.h:63
bool process(const Image< Pixel_T > &image)
Processes the image.
Definition: BlackBorderProcessor.h:64
std::vector< ColorRgb > getUniLedColor(const Image< Pixel_T > &image) const
Determines the uni color for each led using the mapping the image given at construction.
Definition: ImageToLedsMap.h:115
bool unknown
Falg indicating if the border is unknown.
Definition: BlackBorderDetector.h:15
The ImageProcessor translates an RGB-image to RGB-values for the leds.
Definition: ImageProcessor.h:26
ImageProcessor(const LedString &ledString, Hyperion *hyperion)
Constructs an image-processor for translating an image to led-color values based on the given led-str...
Definition: ImageProcessor.cpp:29
const int & getUserLedMappingType()
Returns the current _userMappingType, this may not be the current applied type!
Definition: ImageProcessor.h:60
void setSize(const unsigned width, const unsigned height)
Specifies the width and height of &#39;incomming&#39; images.
Definition: ImageProcessor.cpp:64
void setLedMappingType(int mapType)
Set the user requested led mapping.
Definition: ImageProcessor.cpp:104
Definition: Image.h:13
The ImageToLedsMap holds a mapping of indices into an image to leds.
Definition: ImageToLedsMap.h:22
int horizontalSize
The size of the detected horizontal border.
Definition: BlackBorderDetector.h:18
The LedString contains the image integration information of the leds.
Definition: LedString.h:111
void setSize(const Image< Pixel_T > &image)
Specifies the width and height of &#39;incomming&#39; images.
Definition: ImageProcessor.h:95