mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Added 'rainbow' boot sequence
Moved color transform to utils lib
This commit is contained in:
32
include/bootsequence/RainbowBootSequence.h
Normal file
32
include/bootsequence/RainbowBootSequence.h
Normal file
@@ -0,0 +1,32 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
// QT includes
|
||||
#include <QTimer>
|
||||
|
||||
// Hyperion includes
|
||||
#include <hyperion/Hyperion.h>
|
||||
|
||||
class RainbowBootSequence : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
RainbowBootSequence(Hyperion * hyperion);
|
||||
|
||||
void start();
|
||||
|
||||
private slots:
|
||||
void update();
|
||||
|
||||
private:
|
||||
QTimer _timer;
|
||||
|
||||
Hyperion * _hyperion;
|
||||
|
||||
int _priority;
|
||||
|
||||
std::vector<RgbColor> _ledColors;
|
||||
int _iterationCounter;
|
||||
};
|
||||
|
@@ -16,10 +16,8 @@
|
||||
#include <hyperion/PriorityMuxer.h>
|
||||
|
||||
// Forward class declaration
|
||||
namespace hyperion {
|
||||
class HsvTransform;
|
||||
class ColorTransform;
|
||||
}
|
||||
class HsvTransform;
|
||||
class ColorTransform;
|
||||
|
||||
class Hyperion : public QObject
|
||||
{
|
||||
@@ -74,10 +72,10 @@ private:
|
||||
|
||||
PriorityMuxer _muxer;
|
||||
|
||||
hyperion::HsvTransform * _hsvTransform;
|
||||
hyperion::ColorTransform * _redTransform;
|
||||
hyperion::ColorTransform * _greenTransform;
|
||||
hyperion::ColorTransform * _blueTransform;
|
||||
HsvTransform * _hsvTransform;
|
||||
ColorTransform * _redTransform;
|
||||
ColorTransform * _greenTransform;
|
||||
ColorTransform * _blueTransform;
|
||||
|
||||
LedDevice* _device;
|
||||
|
||||
|
50
include/utils/ColorTransform.h
Normal file
50
include/utils/ColorTransform.h
Normal file
@@ -0,0 +1,50 @@
|
||||
#pragma once
|
||||
|
||||
// STL includes
|
||||
#include <cstdint>
|
||||
|
||||
/// Transform for a single color byte value
|
||||
///
|
||||
/// Transforms are applied in the following order:
|
||||
/// 1) a threshold is applied. All values below threshold will be set to zero
|
||||
/// 2) gamma color correction is applied
|
||||
/// 3) the output value is scaled from the [0:1] to [blacklevel:whitelevel]
|
||||
/// 4) finally, in case of a weird choice of parameters, the output is clamped between [0:1]
|
||||
///
|
||||
/// All configuration values are doubles and assume the color value to be between 0 and 1
|
||||
class ColorTransform
|
||||
{
|
||||
public:
|
||||
ColorTransform();
|
||||
ColorTransform(double threshold, double gamma, double blacklevel, double whitelevel);
|
||||
~ColorTransform();
|
||||
|
||||
double getThreshold() const;
|
||||
void setThreshold(double threshold);
|
||||
|
||||
double getGamma() const;
|
||||
void setGamma(double gamma);
|
||||
|
||||
double getBlacklevel() const;
|
||||
void setBlacklevel(double blacklevel);
|
||||
|
||||
double getWhitelevel() const;
|
||||
void setWhitelevel(double whitelevel);
|
||||
|
||||
/// get the transformed value for the given byte value
|
||||
uint8_t transform(uint8_t input) const
|
||||
{
|
||||
return _mapping[input];
|
||||
}
|
||||
|
||||
private:
|
||||
void initializeMapping();
|
||||
|
||||
private:
|
||||
double _threshold;
|
||||
double _gamma;
|
||||
double _blacklevel;
|
||||
double _whitelevel;
|
||||
|
||||
uint8_t _mapping[256];
|
||||
};
|
30
include/utils/HsvTransform.h
Normal file
30
include/utils/HsvTransform.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
// STL includes
|
||||
#include <cstdint>
|
||||
|
||||
class HsvTransform
|
||||
{
|
||||
public:
|
||||
HsvTransform();
|
||||
HsvTransform(double saturationGain, double valueGain);
|
||||
~HsvTransform();
|
||||
|
||||
void setSaturationGain(double saturationGain);
|
||||
double getSaturationGain() const;
|
||||
|
||||
void setValueGain(double valueGain);
|
||||
double getValueGain() const;
|
||||
|
||||
void transform(uint8_t & red, uint8_t & green, uint8_t & blue) const;
|
||||
|
||||
/// integer version of the conversion are faster, but a little less accurate
|
||||
/// all values are unsigned 8 bit values and scaled between 0 and 255 except
|
||||
/// for the hue which is a 16 bit number and scaled between 0 and 360
|
||||
static void rgb2hsv(uint8_t red, uint8_t green, uint8_t blue, uint16_t & hue, uint8_t & saturation, uint8_t & value);
|
||||
static void hsv2rgb(uint16_t hue, uint8_t saturation, uint8_t value, uint8_t & red, uint8_t & green, uint8_t & blue);
|
||||
|
||||
private:
|
||||
double _saturationGain;
|
||||
double _valueGain;
|
||||
};
|
Reference in New Issue
Block a user