Skip to content

Instantly share code, notes, and snippets.

@tcatm
Created March 15, 2016 11:17
Show Gist options
  • Save tcatm/d1563d2f274290d7d7b8 to your computer and use it in GitHub Desktop.
Save tcatm/d1563d2f274290d7d7b8 to your computer and use it in GitHub Desktop.
union {
uint32_t a;
uint8_t b[4];
} ret;
uint8_t Vi = float2uint8_t(myHsv->lightness);
uint8_t ti = float2uint8_t(t);
uint8_t pi = float2uint8_t(p);
uint8_t qi = float2uint8_t(q);
if (hi%6 == 0){
// V t p
ret.b[2] = Vi;
ret.b[1] = ti;
ret.b[0] = pi;
} else if (hi == 1){
// q V p
ret.b[2] = qi;
ret.b[1] = Vi;
ret.b[0] = pi;
} else if (hi == 2){
// p V t
ret.b[2] = pi;
ret.b[1] = Vi;
ret.b[0] = ti;
} else if (hi == 3){
// p q V
ret.b[2] = pi;
ret.b[1] = qi;
ret.b[0] = Vi;
} else if (hi == 4){
// tpV
ret.b[2] = ti;
ret.b[1] = pi;
ret.b[0] = Vi;
} else if (hi == 5){
// V p q
ret.b[2] = Vi;
ret.b[1] = pi;
ret.b[0] = qi;
}
return ret.a;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment