mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Fix bug in rgb2hsv transform
This commit is contained in:
parent
02fa8f5679
commit
82617dea51
@ -1,3 +1,4 @@
|
|||||||
|
#include <iostream>
|
||||||
#include <utils/HsvTransform.h>
|
#include <utils/HsvTransform.h>
|
||||||
|
|
||||||
HsvTransform::HsvTransform() :
|
HsvTransform::HsvTransform() :
|
||||||
@ -44,6 +45,8 @@ void HsvTransform::transform(uint8_t & red, uint8_t & green, uint8_t & blue) con
|
|||||||
uint8_t saturation, value;
|
uint8_t saturation, value;
|
||||||
rgb2hsv(red, green, blue, hue, saturation, value);
|
rgb2hsv(red, green, blue, hue, saturation, value);
|
||||||
|
|
||||||
|
std::cout << int(hue) << " " << int(saturation) << " " << int(value) << std::endl;
|
||||||
|
|
||||||
int s = saturation * _saturationGain;
|
int s = saturation * _saturationGain;
|
||||||
if (s > 255)
|
if (s > 255)
|
||||||
saturation = 255;
|
saturation = 255;
|
||||||
@ -83,12 +86,22 @@ void HsvTransform::rgb2hsv(uint8_t red, uint8_t green, uint8_t blue, uint16_t &
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (rgbMax == red)
|
if (rgbMax == red)
|
||||||
hue = 0 + 60 * (green - blue) / (rgbMax - rgbMin);
|
{
|
||||||
|
// start from 360 to be sure that we won't assign a negative number to the unsigned hue value
|
||||||
|
hue = 360 + 60 * (green - blue) / (rgbMax - rgbMin);
|
||||||
|
|
||||||
|
if (hue > 359)
|
||||||
|
hue -= 360;
|
||||||
|
}
|
||||||
else if (rgbMax == green)
|
else if (rgbMax == green)
|
||||||
|
{
|
||||||
hue = 120 + 60 * (blue - red) / (rgbMax - rgbMin);
|
hue = 120 + 60 * (blue - red) / (rgbMax - rgbMin);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
hue = 240 + 60 * (red - green) / (rgbMax - rgbMin);
|
hue = 240 + 60 * (red - green) / (rgbMax - rgbMin);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void HsvTransform::hsv2rgb(uint16_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)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user