Skip to content

Instantly share code, notes, and snippets.

@vbalexr
Last active January 31, 2018 20:20
Show Gist options
  • Save vbalexr/7f7cc54ddbda5b07dcbd1fa06c9d78cd to your computer and use it in GitHub Desktop.
Save vbalexr/7f7cc54ddbda5b07dcbd1fa06c9d78cd to your computer and use it in GitHub Desktop.
rgb to color tone
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