Added the option to specify the color byte order

Former-commit-id: f911d0f26c25345bbe5e9014fbc31568b7386f08
This commit is contained in:
johan 2013-11-04 20:52:57 +01:00
parent 8d8c4bdfad
commit fc1e4bc6c8
9 changed files with 98 additions and 12 deletions

View File

@ -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:

View File

@ -1 +1 @@
56543287f8f9c84993d0578339da66f81efe6bdb
2c2798b7a2ab68721c345158caaba28670dee0ae

Binary file not shown.

View File

@ -1 +1 @@
26d94964cc23d092b4504771bb1c0940e4d6d66e
632c368d0a5ce42aff067c6ba5f63dbe108dddc9

View File

@ -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;

View File

@ -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;
}
}
}

View File

@ -23,7 +23,11 @@
"required" : true,
"minimum" : 0
},
"bgr-output" : {
"colorOrder" : {
"type" : "string",
"required" : false
},
"bgr-output" : { // deprecated
"type" : "boolean",
"required" : false
}

View File

@ -0,0 +1,5 @@
package org.hyperion.hypercon.spec;
public enum ColorByteOrder {
RGB, RBG, BRG, BGR, GRB, GBR
}

View File

@ -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}");