From 9fe2fcfdd0bd47b8ce8ac4a65d79a11767a41051 Mon Sep 17 00:00:00 2001 From: johan Date: Thu, 22 Aug 2013 20:31:57 +0200 Subject: [PATCH] Changed hue in HsvTransform from uint_8 to uint16_t --- libsrc/hyperion/HsvTransform.cpp | 17 +++++++++-------- libsrc/hyperion/HsvTransform.h | 8 +++++--- libsrc/hyperion/Hyperion.cpp | 2 ++ libsrc/jsonserver/CMakeLists.txt | 2 +- .../{resource.qrc => JsonSchemas.qrc} | 0 libsrc/jsonserver/JsonServer.cpp | 2 +- 6 files changed, 18 insertions(+), 13 deletions(-) rename libsrc/jsonserver/{resource.qrc => JsonSchemas.qrc} (100%) diff --git a/libsrc/hyperion/HsvTransform.cpp b/libsrc/hyperion/HsvTransform.cpp index 650b8699..b446b4a3 100644 --- a/libsrc/hyperion/HsvTransform.cpp +++ b/libsrc/hyperion/HsvTransform.cpp @@ -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; diff --git a/libsrc/hyperion/HsvTransform.h b/libsrc/hyperion/HsvTransform.h index 5f67b7fe..47284f65 100644 --- a/libsrc/hyperion/HsvTransform.h +++ b/libsrc/hyperion/HsvTransform.h @@ -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; diff --git a/libsrc/hyperion/Hyperion.cpp b/libsrc/hyperion/Hyperion.cpp index d40746cb..2aaa9b10 100644 --- a/libsrc/hyperion/Hyperion.cpp +++ b/libsrc/hyperion/Hyperion.cpp @@ -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()); diff --git a/libsrc/jsonserver/CMakeLists.txt b/libsrc/jsonserver/CMakeLists.txt index 3fed8c6e..f0ff1378 100644 --- a/libsrc/jsonserver/CMakeLists.txt +++ b/libsrc/jsonserver/CMakeLists.txt @@ -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}) diff --git a/libsrc/jsonserver/resource.qrc b/libsrc/jsonserver/JsonSchemas.qrc similarity index 100% rename from libsrc/jsonserver/resource.qrc rename to libsrc/jsonserver/JsonSchemas.qrc diff --git a/libsrc/jsonserver/JsonServer.cpp b/libsrc/jsonserver/JsonServer.cpp index 06a56221..4efe855c 100644 --- a/libsrc/jsonserver/JsonServer.cpp +++ b/libsrc/jsonserver/JsonServer.cpp @@ -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()