diff --git a/config/hyperion.config.json b/config/hyperion.config.json index 68d24c70..61b84770 100644 --- a/config/hyperion.config.json +++ b/config/hyperion.config.json @@ -16,7 +16,7 @@ "type" : "ws2801", "output" : "/dev/spidev0.0", "rate" : 1000000, - "bgr-output" : false + "colorOrder" : "rgb" }, /// Color manipulation configuration used to tune the output colors to specific surroundings. Contains the following fields: diff --git a/deploy/HyperCon.jar.REMOVED.git-id b/deploy/HyperCon.jar.REMOVED.git-id index 43f8e851..6d5cc6e1 100644 --- a/deploy/HyperCon.jar.REMOVED.git-id +++ b/deploy/HyperCon.jar.REMOVED.git-id @@ -1 +1 @@ -56543287f8f9c84993d0578339da66f81efe6bdb \ No newline at end of file +2c2798b7a2ab68721c345158caaba28670dee0ae \ No newline at end of file diff --git a/deploy/hyperion-remote b/deploy/hyperion-remote index ad1653d6..1d39d89b 100755 Binary files a/deploy/hyperion-remote and b/deploy/hyperion-remote differ diff --git a/deploy/hyperiond.REMOVED.git-id b/deploy/hyperiond.REMOVED.git-id index 03a45695..96866a37 100644 --- a/deploy/hyperiond.REMOVED.git-id +++ b/deploy/hyperiond.REMOVED.git-id @@ -1 +1 @@ -26d94964cc23d092b4504771bb1c0940e4d6d66e \ No newline at end of file +632c368d0a5ce42aff067c6ba5f63dbe108dddc9 \ No newline at end of file diff --git a/include/hyperion/Hyperion.h b/include/hyperion/Hyperion.h index 7718f205..42ce51df 100644 --- a/include/hyperion/Hyperion.h +++ b/include/hyperion/Hyperion.h @@ -46,6 +46,12 @@ public: SATURATION_GAIN, VALUE_GAIN, THRESHOLD, GAMMA, BLACKLEVEL, WHITELEVEL }; + /// Enumeration containing the possible orders of device color byte data + enum ColorOrder + { + ORDER_RGB, ORDER_RBG, ORDER_GRB, ORDER_BRG, ORDER_GBR, ORDER_BGR + }; + /// /// Constructs the Hyperion instance based on the given Json configuration /// @@ -136,6 +142,7 @@ public: const InputInfo& getPriorityInfo(const int priority) const; static LedDevice * createDevice(const Json::Value & deviceConfig); + static ColorOrder createColorOrder(const Json::Value & deviceConfig); static LedString createLedString(const Json::Value & ledsConfig); static HsvTransform * createHsvTransform(const Json::Value & hsvConfig); static ColorTransform * createColorTransform(const Json::Value & colorConfig); @@ -172,8 +179,8 @@ private: /// The BLUE-Channel (RGB) transform ColorTransform * _blueTransform; - /// Flag indicating if the output should be BGR (red and blue reversed) - bool _haveBgrOutput; + /// Value with the desired color byte order + ColorOrder _colorOrder; /// The actual LedDevice LedDevice * _device; diff --git a/libsrc/hyperion/Hyperion.cpp b/libsrc/hyperion/Hyperion.cpp index bb26103b..4c3aa840 100644 --- a/libsrc/hyperion/Hyperion.cpp +++ b/libsrc/hyperion/Hyperion.cpp @@ -60,6 +60,47 @@ LedDevice* Hyperion::createDevice(const Json::Value& deviceConfig) return device; } +Hyperion::ColorOrder Hyperion::createColorOrder(const Json::Value &deviceConfig) +{ + // deprecated: force BGR when the deprecated flag is present and set to true + if (deviceConfig.get("bgr-output", false).asBool()) + { + return ORDER_BGR; + } + + std::string order = deviceConfig.get("colorOrder", "rgb").asString(); + if (order == "rgb") + { + return ORDER_RGB; + } + else if (order == "bgr") + { + return ORDER_BGR; + } + else if (order == "rbg") + { + return ORDER_RBG; + } + else if (order == "brg") + { + return ORDER_BRG; + } + else if (order == "gbr") + { + return ORDER_GBR; + } + else if (order == "grb") + { + return ORDER_GRB; + } + else + { + std::cout << "Unknown color order defined (" << order << "). Using RGB." << std::endl; + } + + return ORDER_RGB; +} + HsvTransform * Hyperion::createHsvTransform(const Json::Value & hsvConfig) { const double saturationGain = hsvConfig.get("saturationGain", 1.0).asDouble(); @@ -143,6 +184,7 @@ LedDevice * Hyperion::createColorSmoothing(const Json::Value & smoothingConfig, return ledDevice; } + Hyperion::Hyperion(const Json::Value &jsonConfig) : _ledString(createLedString(jsonConfig["leds"])), _muxer(_ledString.leds().size()), @@ -150,7 +192,7 @@ Hyperion::Hyperion(const Json::Value &jsonConfig) : _redTransform(createColorTransform(jsonConfig["color"]["red"])), _greenTransform(createColorTransform(jsonConfig["color"]["green"])), _blueTransform(createColorTransform(jsonConfig["color"]["blue"])), - _haveBgrOutput(jsonConfig["device"].get("bgr-output", false).asBool()), + _colorOrder(createColorOrder(jsonConfig["device"])), _device(createDevice(jsonConfig["device"])), _timer() { @@ -366,9 +408,37 @@ void Hyperion::update() color.green = _greenTransform->transform(color.green); color.blue = _blueTransform->transform(color.blue); - if (_haveBgrOutput) + // correct the color byte order + switch (_colorOrder) { + case ORDER_RGB: + // leave as it is + break; + case ORDER_BGR: std::swap(color.red, color.blue); + break; + case ORDER_RBG: + std::swap(color.green, color.blue); + break; + case ORDER_GRB: + std::swap(color.red, color.green); + break; + case ORDER_GBR: + { + uint8_t temp = color.red; + color.red = color.green; + color.green = color.blue; + color.blue = temp; + break; + } + case ORDER_BRG: + { + uint8_t temp = color.red; + color.red = color.blue; + color.blue = color.green; + color.green = temp; + break; + } } } diff --git a/libsrc/hyperion/hyperion.schema.json b/libsrc/hyperion/hyperion.schema.json index 31683d5d..7cd24ef7 100644 --- a/libsrc/hyperion/hyperion.schema.json +++ b/libsrc/hyperion/hyperion.schema.json @@ -23,7 +23,11 @@ "required" : true, "minimum" : 0 }, - "bgr-output" : { + "colorOrder" : { + "type" : "string", + "required" : false + }, + "bgr-output" : { // deprecated "type" : "boolean", "required" : false } diff --git a/src/config-tool/ConfigTool/src/org/hyperion/hypercon/spec/ColorByteOrder.java b/src/config-tool/ConfigTool/src/org/hyperion/hypercon/spec/ColorByteOrder.java new file mode 100644 index 00000000..c301ffc9 --- /dev/null +++ b/src/config-tool/ConfigTool/src/org/hyperion/hypercon/spec/ColorByteOrder.java @@ -0,0 +1,5 @@ +package org.hyperion.hypercon.spec; + +public enum ColorByteOrder { + RGB, RBG, BRG, BGR, GRB, GBR +} diff --git a/src/config-tool/ConfigTool/src/org/hyperion/hypercon/spec/DeviceConfig.java b/src/config-tool/ConfigTool/src/org/hyperion/hypercon/spec/DeviceConfig.java index 970d1913..a6ac3856 100644 --- a/src/config-tool/ConfigTool/src/org/hyperion/hypercon/spec/DeviceConfig.java +++ b/src/config-tool/ConfigTool/src/org/hyperion/hypercon/spec/DeviceConfig.java @@ -15,8 +15,8 @@ public class DeviceConfig extends Observable { public String mOutput = "/dev/spidev0.0"; /** The baudrate of the device */ public int mBaudrate = 1000000; - /** Flag indicating if the red and blue should be reversed */ - public boolean mBgrOutput = false; + /** The order of the color bytes */ + public ColorByteOrder mColorByteOrder = ColorByteOrder.RGB; /** * Creates the JSON string of the configuration as used in the Hyperion daemon configfile @@ -33,7 +33,7 @@ public class DeviceConfig extends Observable { strBuf.append("\t/// - 'ws2801' this is the device (eg '/dev/spidev0.0')\n"); strBuf.append("\t/// - 'test' this is the file used to write test output (eg '/home/pi/hyperion.out')\n"); strBuf.append("\t/// * 'rate' : The baudrate of the output to the device (only applicable for 'ws2801')\n"); - strBuf.append("\t/// * 'bgr-output' : Use BGR output instead of RGB (reverse red and blue).\n"); + strBuf.append("\t/// * 'colorOrder' : The order of the color bytes ('rgb', 'rbg', 'bgr', etc.).\n"); strBuf.append("\t\"device\" :\n"); strBuf.append("\t{\n"); @@ -42,7 +42,7 @@ public class DeviceConfig extends Observable { strBuf.append("\t\t\"type\" : \"").append(mType.name()).append("\",\n"); strBuf.append("\t\t\"output\" : \"").append(mOutput).append("\",\n"); strBuf.append("\t\t\"rate\" : ").append(mBaudrate).append(",\n"); - strBuf.append("\t\t\"bgr-output\" : ").append(mBgrOutput).append("\n"); + strBuf.append("\t\t\"colorOrder\" : ").append(mColorByteOrder.name().toLowerCase()).append("\n"); strBuf.append("\t}");