Commits from @MartB and more ...

- Commit: 1d9165f403
- New default QT capture implementation
- UploadHandler added to Effects Configurator to allow uploading GIF files
- Docker compile script and instruction
- Travis Fix
This commit is contained in:
Paulchen-Panther
2019-01-06 19:49:56 +01:00
parent 7352ff4d42
commit 2dca1c93e6
57 changed files with 1134 additions and 341 deletions

View File

@@ -114,7 +114,7 @@ private:
///
/// @param message the incoming message
///
void handleEffectCommand(const QJsonObject & message, const QString &command, const int tan);
void handleEffectCommand(const QJsonObject &message, const QString &command, const int tan);
///
/// Handle an incoming JSON Effect message (Write JSON Effect)

View File

@@ -89,10 +89,9 @@ namespace hyperion
// find first X pixel of the image
for (int x = 0; x < width33percent; ++x)
{
const Pixel_T & color1 = image( (width - x), yCenter); // right side center line check
const Pixel_T & color2 = image(x, height33percent);
const Pixel_T & color3 = image(x, height66percent);
if (!isBlack(color1) || !isBlack(color2) || !isBlack(color3))
if (!isBlack(image((width - x), yCenter))
|| !isBlack(image(x, height33percent))
|| !isBlack(image(x, height66percent)))
{
firstNonBlackXPixelIndex = x;
break;
@@ -102,10 +101,9 @@ namespace hyperion
// find first Y pixel of the image
for (int y = 0; y < height33percent; ++y)
{
const Pixel_T & color1 = image(xCenter, (height - y)); // bottom center line check
const Pixel_T & color2 = image(width33percent, y );
const Pixel_T & color3 = image(width66percent, y);
if (!isBlack(color1) || !isBlack(color2) || !isBlack(color3))
if (!isBlack(image(xCenter, (height - y)))
|| !isBlack(image(width33percent, y))
|| !isBlack(image(width66percent, y)))
{
firstNonBlackYPixelIndex = y;
break;
@@ -203,10 +201,9 @@ namespace hyperion
int x;
for (x = 0; x < width33percent; ++x)
{
const Pixel_T & color1 = image( (width - x), yCenter); // right side center line check
const Pixel_T & color2 = image(x, height33percent);
const Pixel_T & color3 = image(x, height66percent);
if (!isBlack(color1) || !isBlack(color2) || !isBlack(color3))
if (!isBlack(image((width - x), yCenter))
|| !isBlack(image(x, height33percent))
|| !isBlack(image(x, height66percent)))
{
firstNonBlackXPixelIndex = x;
break;
@@ -216,13 +213,13 @@ namespace hyperion
// find first Y pixel of the image
for (int y = 0; y < height33percent; ++y)
{
const Pixel_T & color1 = image(x, y );// left side top check
const Pixel_T & color2 = image(x, (height - y)); // left side bottom check
const Pixel_T & color3 = image( (width - x), y); // right side top check
const Pixel_T & color4 = image( (width - x), (height - y)); // right side bottom check
if (!isBlack(color1) || !isBlack(color2) || !isBlack(color3) || !isBlack(color4))
// left side top + left side bottom + right side top + right side bottom
if (!isBlack(image(x, y))
|| !isBlack(image(x, (height - y)))
|| !isBlack(image((width - x), y))
|| !isBlack(image((width - x), (height - y))))
{
// std::cout << "y " << y << " lt " << int(isBlack(color1)) << " lb " << int(isBlack(color2)) << " rt " << int(isBlack(color3)) << " rb " << int(isBlack(color4)) << std::endl;
// std::cout << "y " << y << " lt " << int(isBlack(color1)) << " lb " << int(isBlack(color2)) << " rt " << int(isBlack(color3)) << " rb " << int(isBlack(color4)) << std::endl;
firstNonBlackYPixelIndex = y;
break;
}

View File

@@ -28,7 +28,14 @@ class Effect : public QThread
public:
friend class EffectModule;
Effect(Hyperion* hyperion, int priority, int timeout, const QString & script, const QString & name, const QJsonObject & args = QJsonObject());
Effect(Hyperion *hyperion
, int priority
, int timeout
, const QString &script
, const QString &name
, const QJsonObject &args = QJsonObject()
, const QString &imageData = ""
);
virtual ~Effect();
virtual void run();
@@ -55,14 +62,14 @@ public:
QJsonObject getArgs() const { return _args; }
signals:
void setInput(const int priority, const std::vector<ColorRgb>& ledColors, const int timeout_ms, const bool& clearEffect);
void setInputImage(const int priority, const Image<ColorRgb>& image, const int timeout_ms, const bool& clearEffect);
void setInput(const int priority, const std::vector<ColorRgb> &ledColors, const int timeout_ms, const bool &clearEffect);
void setInputImage(const int priority, const Image<ColorRgb> &image, const int timeout_ms, const bool &clearEffect);
private:
void addImage();
Hyperion* _hyperion;
Hyperion *_hyperion;
const int _priority;
@@ -72,18 +79,19 @@ private:
const QString _name;
const QJsonObject _args;
const QString _imageData;
int64_t _endTime;
/// Buffer for colorData
QVector<ColorRgb> _colors;
Logger* _log;
Logger *_log;
// Reflects whenever this effects should interupt (timeout or external request)
bool _interupt = false;
QSize _imageSize;
QImage _image;
QPainter* _painter;
QPainter *_painter;
QVector<QImage> _imageStack;
};

View File

@@ -74,7 +74,15 @@ public slots:
int runEffect(const QString &effectName, int priority, int timeout = -1, const QString &origin="System");
/// Run the specified effect on the given priority channel and optionally specify a timeout
int runEffect(const QString &effectName, const QJsonObject & args, int priority, int timeout = -1, const QString &pythonScript = "", const QString &origin = "System", unsigned smoothCfg=0);
int runEffect(const QString &effectName
, const QJsonObject &args
, int priority
, int timeout = -1
, const QString &pythonScript = ""
, const QString &origin = "System"
, unsigned smoothCfg=0
, const QString &imageData = ""
);
/// Clear any effect running on the provided channel
void channelCleared(int priority);
@@ -92,7 +100,15 @@ private slots:
private:
/// Run the specified effect on the given priority channel and optionally specify a timeout
int runEffectScript(const QString &script, const QString &name, const QJsonObject & args, int priority, int timeout = -1, const QString & origin="System", unsigned smoothCfg=0);
int runEffectScript(const QString &script
,const QString &name
, const QJsonObject &args
, int priority
, int timeout = -1
, const QString &origin="System"
, unsigned smoothCfg=0
, const QString &imageData = ""
);
private:
Hyperion * _hyperion;

View File

@@ -0,0 +1,96 @@
#pragma once
#include <QObject>
// Hyperion-utils includes
#include <utils/ColorRgb.h>
#include <hyperion/Grabber.h>
class QScreen;
///
/// @brief The platform capture implementation based on QT API
///
class QtGrabber : public Grabber
{
public:
QtGrabber(int cropLeft, int cropRight, int cropTop, int cropBottom, int pixelDecimation, int display);
virtual ~QtGrabber();
///
/// Captures a single snapshot of the display and writes the data to the given image. The
/// provided image should have the same dimensions as the configured values (_width and
/// _height)
///
/// @param[out] image The snapped screenshot (should be initialized with correct width and
/// height)
///
virtual int grabFrame(Image<ColorRgb> & image);
///
/// @brief Set a new video mode
///
virtual void setVideoMode(VideoMode mode);
///
/// @brief Apply new width/height values, overwrite Grabber.h implementation as qt doesn't use width/height, just pixelDecimation to calc dimensions
///
virtual bool setWidthHeight(int width, int height) { return true; };
///
/// @brief Apply new pixelDecimation
///
virtual void setPixelDecimation(int pixelDecimation);
///
/// Set the crop values
/// @param cropLeft Left pixel crop
/// @param cropRight Right pixel crop
/// @param cropTop Top pixel crop
/// @param cropBottom Bottom pixel crop
///
virtual void setCropping(unsigned cropLeft, unsigned cropRight, unsigned cropTop, unsigned cropBottom);
///
/// @brief Apply display index
///
virtual void setDisplayIndex(int index);
private slots:
///
/// @brief is called whenever the current _screen changes it's geometry
/// @param geo The new geometry
///
void geometryChanged(const QRect &geo);
private:
///
/// @brief Setup a new capture display, will free the previous one
/// @return True on success, false if no display is found
///
const bool setupDisplay();
///
/// @brief Is called whenever we need new screen dimension calculations based on window geometry
///
int updateScreenDimensions(const bool& force);
///
/// @brief free the _screen pointer
///
void freeResources();
private:
unsigned _display;
int _pixelDecimation;
unsigned _screenWidth;
unsigned _screenHeight;
unsigned _src_x;
unsigned _src_y;
unsigned _src_x_max;
unsigned _src_y_max;
QScreen* _screen;
};

View File

@@ -0,0 +1,38 @@
#pragma once
#include <hyperion/GrabberWrapper.h>
#include <grabber/QtGrabber.h>
///
/// The QtWrapper uses QtFramework API's to get a picture from system
///
class QtWrapper: public GrabberWrapper
{
public:
///
/// Constructs the framebuffer frame grabber with a specified grab size and update rate.
///
/// @param[in] cropLeft Remove from left [pixels]
/// @param[in] cropRight Remove from right [pixels]
/// @param[in] cropTop Remove from top [pixels]
/// @param[in] cropBottom Remove from bottom [pixels]
/// @param[in] pixelDecimation Decimation factor for image [pixels]
/// @param[in] updateRate_Hz The image grab rate [Hz]
///
QtWrapper(int cropLeft, int cropRight, int cropTop, int cropBottom, int pixelDecimation, int display, const unsigned updateRate_Hz);
///
/// Destructor of this qt frame grabber. Releases any claimed resources.
///
virtual ~QtWrapper() {};
public slots:
///
/// Performs a single frame grab and computes the led-colors
///
virtual void action();
private:
/// The actual grabber
QtGrabber _grabber;
};

View File

@@ -39,7 +39,7 @@ public:
virtual bool setWidthHeight(int width, int height);
///
/// @brief Apply new pixelDecimation (used from x11)
/// @brief Apply new pixelDecimation (used from x11 and qt)
///
virtual void setPixelDecimation(int pixelDecimation) {};
@@ -71,7 +71,7 @@ public:
virtual void setDeviceVideoStandard(QString device, VideoStandard videoStandard) {};
///
/// @brief Apply display index (used from x11)
/// @brief Apply display index (used from qt)
///
virtual void setDisplayIndex(int index) {};

View File

@@ -360,8 +360,14 @@ public slots:
/// @param args arguments of the effect script
/// @param priority The priority channel of the effect
/// @param timeout The timeout of the effect (after the timout, the effect will be cleared)
int setEffect(const QString & effectName, const QJsonObject & args, int priority,
int timeout = -1, const QString & pythonScript = "", const QString & origin="System");
int setEffect(const QString &effectName
, const QJsonObject &args
, int priority
, int timeout = -1
, const QString &pythonScript = ""
, const QString &origin="System"
, const QString &imageData = ""
);
/// sets the methode how image is maped to leds at ImageProcessor
void setLedMappingType(const int& mappingType);

View File

@@ -168,7 +168,9 @@ namespace hyperion
template <typename Pixel_T>
ColorRgb calcMeanColor(const Image<Pixel_T> & image, const std::vector<unsigned> & colors) const
{
if (colors.size() == 0)
const auto colorVecSize = colors.size();
if (colorVecSize == 0)
{
return ColorRgb::BLACK;
}
@@ -177,18 +179,20 @@ namespace hyperion
uint_fast16_t cummRed = 0;
uint_fast16_t cummGreen = 0;
uint_fast16_t cummBlue = 0;
const auto& imgData = image.memptr();
for (const unsigned colorOffset : colors)
{
const Pixel_T& pixel = image.memptr()[colorOffset];
const auto& pixel = imgData[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());
const uint8_t avgRed = uint8_t(cummRed/colorVecSize);
const uint8_t avgGreen = uint8_t(cummGreen/colorVecSize);
const uint8_t avgBlue = uint8_t(cummBlue/colorVecSize);
// Return the computed color
return {avgRed, avgGreen, avgBlue};
@@ -211,9 +215,11 @@ namespace hyperion
uint_fast16_t cummBlue = 0;
const unsigned imageSize = image.width() * image.height();
const auto& imgData = image.memptr();
for (unsigned idx=0; idx<imageSize; idx++)
{
const Pixel_T& pixel = image.memptr()[idx];
const auto& pixel = imgData[idx];
cummRed += pixel.red;
cummGreen += pixel.green;
cummBlue += pixel.blue;