Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,18 @@ Color getColor(const char* param, unsigned char maxval) {
if(strlen(color) == 4 || strlen(color) == 7) {
char flag = 0;
std::string hex(color);
unsigned int red = 0, green = 0, blue = 0;
unsigned int red = 0, green = 0, blue = 0, temp = 0;
if (strlen(color) == 4) {
// Try to parse the color as a shorthand 3-character color (e.g. '#FFF')
if (sscanf(hex.substr(1,1).c_str(), "%X", &red) +
sscanf(hex.substr(2,1).c_str(), "%X", &green) +
sscanf(hex.substr(3,1).c_str(), "%X", &blue) == 3) {
red = red << 4;
green = green << 4;
blue = blue << 4;
temp = red;
red = red << 4 + temp;
temp = green;
green = green << 4 + temp;
temp = blue;
blue = blue << 4 + temp;
flag++;
}
} else if (strlen(color) == 7) {
Expand Down