mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Changed hue in HsvTransform from uint_8 to uint16_t
This commit is contained in:
parent
51506cdeb9
commit
9fe2fcfdd0
@ -42,7 +42,8 @@ void HsvTransform::transform(uint8_t & red, uint8_t & green, uint8_t & blue) con
|
|||||||
{
|
{
|
||||||
if (_saturationGain != 1.0 || _valueGain != 1.0)
|
if (_saturationGain != 1.0 || _valueGain != 1.0)
|
||||||
{
|
{
|
||||||
uint8_t hue, saturation, value;
|
uint16_t hue;
|
||||||
|
uint8_t saturation, value;
|
||||||
rgb2hsv(red, green, blue, hue, saturation, value);
|
rgb2hsv(red, green, blue, hue, saturation, value);
|
||||||
|
|
||||||
int s = saturation * _saturationGain;
|
int s = saturation * _saturationGain;
|
||||||
@ -61,7 +62,7 @@ void HsvTransform::transform(uint8_t & red, uint8_t & green, uint8_t & blue) con
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HsvTransform::rgb2hsv(uint8_t red, uint8_t green, uint8_t blue, uint8_t & hue, uint8_t & saturation, uint8_t & value)
|
void HsvTransform::rgb2hsv(uint8_t red, uint8_t green, uint8_t blue, uint16_t & hue, uint8_t & saturation, uint8_t & value)
|
||||||
{
|
{
|
||||||
uint8_t rgbMin, rgbMax;
|
uint8_t rgbMin, rgbMax;
|
||||||
|
|
||||||
@ -84,14 +85,14 @@ void HsvTransform::rgb2hsv(uint8_t red, uint8_t green, uint8_t blue, uint8_t & h
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (rgbMax == red)
|
if (rgbMax == red)
|
||||||
hue = 0 + 43 * (green - blue) / (rgbMax - rgbMin);
|
hue = 0 + 60 * (green - blue) / (rgbMax - rgbMin);
|
||||||
else if (rgbMax == green)
|
else if (rgbMax == green)
|
||||||
hue = 85 + 43 * (blue - red) / (rgbMax - rgbMin);
|
hue = 120 + 60 * (blue - red) / (rgbMax - rgbMin);
|
||||||
else
|
else
|
||||||
hue = 171 + 43 * (red - green) / (rgbMax - rgbMin);
|
hue = 240 + 60 * (red - green) / (rgbMax - rgbMin);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HsvTransform::hsv2rgb(uint8_t hue, uint8_t saturation, uint8_t value, uint8_t & red, uint8_t & green, uint8_t & blue)
|
void HsvTransform::hsv2rgb(uint16_t hue, uint8_t saturation, uint8_t value, uint8_t & red, uint8_t & green, uint8_t & blue)
|
||||||
{
|
{
|
||||||
uint8_t region, remainder, p, q, t;
|
uint8_t region, remainder, p, q, t;
|
||||||
|
|
||||||
@ -103,8 +104,8 @@ void HsvTransform::hsv2rgb(uint8_t hue, uint8_t saturation, uint8_t value, uint8
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
region = hue / 43;
|
region = hue / 60;
|
||||||
remainder = (hue - (region * 43)) * 6;
|
remainder = (hue - (region * 60)) * 6;
|
||||||
|
|
||||||
p = (value * (255 - saturation)) >> 8;
|
p = (value * (255 - saturation)) >> 8;
|
||||||
q = (value * (255 - ((saturation * remainder) >> 8))) >> 8;
|
q = (value * (255 - ((saturation * remainder) >> 8))) >> 8;
|
||||||
|
@ -21,9 +21,11 @@ namespace hyperion
|
|||||||
void transform(uint8_t & red, uint8_t & green, uint8_t & blue) const;
|
void transform(uint8_t & red, uint8_t & green, uint8_t & blue) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// integer version of the conversion are faster, but a little less accurate
|
/// integer version of the conversion are faster, but a little less accurate
|
||||||
static void rgb2hsv(uint8_t red, uint8_t green, uint8_t blue, uint8_t & hue, uint8_t & saturation, uint8_t & value);
|
/// all values are unsigned 8 bit values and scaled between 0 and 255 except
|
||||||
static void hsv2rgb(uint8_t hue, uint8_t saturation, uint8_t value, uint8_t & red, uint8_t & green, uint8_t & blue);
|
/// 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:
|
private:
|
||||||
double _saturationGain;
|
double _saturationGain;
|
||||||
|
@ -82,6 +82,8 @@ LedString Hyperion::createLedString(const Json::Value& ledsConfig)
|
|||||||
|
|
||||||
Json::Value Hyperion::loadConfig(const std::string& configFile)
|
Json::Value Hyperion::loadConfig(const std::string& configFile)
|
||||||
{
|
{
|
||||||
|
Q_INIT_RESOURCE(resource);
|
||||||
|
|
||||||
// read the json schema from the resource
|
// read the json schema from the resource
|
||||||
QResource schemaData(":/hyperion.schema.json");
|
QResource schemaData(":/hyperion.schema.json");
|
||||||
assert(schemaData.isValid());
|
assert(schemaData.isValid());
|
||||||
|
@ -18,7 +18,7 @@ set(JsonServer_SOURCES
|
|||||||
)
|
)
|
||||||
|
|
||||||
set(JsonServer_RESOURCES
|
set(JsonServer_RESOURCES
|
||||||
${CURRENT_SOURCE_DIR}/resource.qrc
|
${CURRENT_SOURCE_DIR}/JsonSchemas.qrc
|
||||||
)
|
)
|
||||||
|
|
||||||
qt4_wrap_cpp(JsonServer_HEADERS_MOC ${JsonServer_QT_HEADERS})
|
qt4_wrap_cpp(JsonServer_HEADERS_MOC ${JsonServer_QT_HEADERS})
|
||||||
|
@ -20,7 +20,7 @@ JsonServer::JsonServer(Hyperion *hyperion, uint16_t port) :
|
|||||||
connect(&_server, SIGNAL(newConnection()), this, SLOT(newConnection()));
|
connect(&_server, SIGNAL(newConnection()), this, SLOT(newConnection()));
|
||||||
|
|
||||||
// make sure the resources are loaded (they may be left out after static linking
|
// make sure the resources are loaded (they may be left out after static linking
|
||||||
Q_INIT_RESOURCE(resource);
|
Q_INIT_RESOURCE(JsonSchemas);
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonServer::~JsonServer()
|
JsonServer::~JsonServer()
|
||||||
|
Loading…
Reference in New Issue
Block a user