Skip to content

Commit

Permalink
update hex parsing to be more cpu arch portable
Browse files Browse the repository at this point in the history
  • Loading branch information
ktgeek committed Jul 1, 2020
1 parent 3321703 commit 6332907
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions blinkstick-userspace-led-daemon/src/RGBColor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,11 @@ void RGBColor::releaseFriendlyColors() noexcept

RGBColorPtr RGBColor::parseHexString(std::string hexString)
{
uint32_t all_colors;
all_colors = std::stoi(hexString.substr(1), nullptr, 16);
uint8_t *colors = (uint8_t*) &all_colors;
uint32_t color = std::stoi(hexString.substr(1), nullptr, 16);

return RGBColorPtr(new RGBColor(colors[2], colors[1], colors[0]));
uint8_t red = (color >> 16) & 0xFF;
uint8_t green = (color >> 8) & 0xFF;
uint8_t blue = color & 0xFF;

return RGBColorPtr(new RGBColor(red, green, blue));
}

0 comments on commit 6332907

Please sign in to comment.