Changed hue in HsvTransform from uint_8 to uint16_t

This commit is contained in:
johan 2013-08-22 20:31:57 +02:00
parent 51506cdeb9
commit 9fe2fcfdd0
6 changed files with 18 additions and 13 deletions

View File

@ -42,7 +42,8 @@ void HsvTransform::transform(uint8_t & red, uint8_t & green, uint8_t & blue) con
{
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);
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;
@ -84,14 +85,14 @@ void HsvTransform::rgb2hsv(uint8_t red, uint8_t green, uint8_t blue, uint8_t & h
}
if (rgbMax == red)
hue = 0 + 43 * (green - blue) / (rgbMax - rgbMin);
hue = 0 + 60 * (green - blue) / (rgbMax - rgbMin);
else if (rgbMax == green)
hue = 85 + 43 * (blue - red) / (rgbMax - rgbMin);
hue = 120 + 60 * (blue - red) / (rgbMax - rgbMin);
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;
@ -103,8 +104,8 @@ void HsvTransform::hsv2rgb(uint8_t hue, uint8_t saturation, uint8_t value, uint8
return;
}
region = hue / 43;
remainder = (hue - (region * 43)) * 6;
region = hue / 60;
remainder = (hue - (region * 60)) * 6;
p = (value * (255 - saturation)) >> 8;
q = (value * (255 - ((saturation * remainder) >> 8))) >> 8;

View File

@ -21,9 +21,11 @@ namespace hyperion
void transform(uint8_t & red, uint8_t & green, uint8_t & blue) const;
private:
// 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);
static void hsv2rgb(uint8_t hue, uint8_t saturation, uint8_t value, uint8_t & red, uint8_t & green, uint8_t & blue);
/// 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;

View File

@ -82,6 +82,8 @@ LedString Hyperion::createLedString(const Json::Value& ledsConfig)
Json::Value Hyperion::loadConfig(const std::string& configFile)
{
Q_INIT_RESOURCE(resource);
// read the json schema from the resource
QResource schemaData(":/hyperion.schema.json");
assert(schemaData.isValid());

View File

@ -18,7 +18,7 @@ set(JsonServer_SOURCES
)
set(JsonServer_RESOURCES
${CURRENT_SOURCE_DIR}/resource.qrc
${CURRENT_SOURCE_DIR}/JsonSchemas.qrc
)
qt4_wrap_cpp(JsonServer_HEADERS_MOC ${JsonServer_QT_HEADERS})

View File

@ -20,7 +20,7 @@ JsonServer::JsonServer(Hyperion *hyperion, uint16_t port) :
connect(&_server, SIGNAL(newConnection()), this, SLOT(newConnection()));
// make sure the resources are loaded (they may be left out after static linking
Q_INIT_RESOURCE(resource);
Q_INIT_RESOURCE(JsonSchemas);
}
JsonServer::~JsonServer()