Added 'rainbow' boot sequence

Moved color transform to utils lib
This commit is contained in:
T. van der Zwan
2013-08-23 16:24:10 +00:00
parent 6ee94409dc
commit 3d02fecc7a
20 changed files with 218 additions and 78 deletions

View 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];
};

View 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;
};