Hello There, Guest!
View New Posts  |  View Today's Posts
RGB to HUE (Philips Hue API)

  • 0 Vote(s) - 0 Average


02-27-2016, 08:06 PM #1
AceInfinity
Developer
*******
Administrators
Posts: 9,733 Threads:1,026 Joined: Jun 2011 Reputation: 76

RGB to HUE (Philips Hue API)
Here's a helper method in case anyone wants it to convert to a hue angle, and translate that to a 0-65535 value for the hue API:
Code:
uint16_t rgb_to_hue_value(uint8_t r, uint8_t g, uint8_t b)
{
   double angle = 0.0;
   double R = r / 255.0;
   double G = g / 255.0;
   double B = b / 255.0;

   if (r > g && r > b)
   { angle = (G - B) / (r - (g < b ? g : b)); }
   else if (g > r && g > b)
   { angle = 2.0 + (B - R) / (g - (r < b ? r : b)); }
   else if (b > r && b > g)
   { angle = 4.0 + (R - G) / (b - (r < g ? r : g)); }

   angle *= 60.0;
   if (angle < 0.0) angle += 360;
   return (int)angle * 65535 / 360;
}

If you only want this method to return the hue angle, just return *(int)angle* directly.


Microsoft MVP .NET Programming - (2012 - Present)
®Crestron DMC-T Certified Automation Programmer

Development Site: aceinfinity.net

 ▲
 ▲ ▲




Forum Jump:


Possibly Related Threads...
Thread Author Replies Views Last Post
   Philips Hue Control AceInfinity 9 8,472 01-28-2015, 10:26 PM
Last Post: AceInfinity


Users browsing this thread: 1 Guest(s)