Last active
January 31, 2018 20:20
-
-
Save vbalexr/7f7cc54ddbda5b07dcbd1fa06c9d78cd to your computer and use it in GitHub Desktop.
rgb to color tone
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uint8_t rgb2H(uint8_t red, uint8_t green, uint8_t blue){ | |
float r = red/255. , g=green/255. , b=blue/255.; | |
float cMax = max(max(r, g), b); | |
float cMin = min(min(r, g), b); | |
float delta = cMax - cMin; | |
float h = 0; | |
if(delta > 0) { | |
if(cMax == r) { | |
h = 60 * (fmod(((g - b) / delta), 6)); | |
} else if(cMax == g) { | |
h = 60 * (((b - r) / delta) + 2); | |
} else if(cMax == b) { | |
h = 60 * (((r - g) / delta) + 4); | |
} | |
if(h < 0) { | |
h = 360 + h; | |
} | |
} | |
return (uint8_t)h; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment