Skip to content

Instantly share code, notes, and snippets.

@emiel
Created September 14, 2017 17:52
Show Gist options
  • Save emiel/416af1b5027ef52849cf8f72fb9e414d to your computer and use it in GitHub Desktop.
Save emiel/416af1b5027ef52849cf8f72fb9e414d to your computer and use it in GitHub Desktop.
RGBA color space (javascript)
decode_argb = function(argb_val)
{
/*
- https://en.wikipedia.org/wiki/RGBA_color_space
- ARGB (word-order)
- https://developer.mozilla.org/en-US/docs/Web/CSS/color_value
*/
return {
a: (argb_val & 0xff000000) >>> 24,
r: (argb_val & 0x00ff0000) >>> 16,
g: (argb_val & 0x0000ff00) >>> 8,
b: (argb_val & 0x000000ff)
}
}
encode_argb = function(a, r, g, b)
{
return (a << 24) + (r << 16) + (g << 8) + b;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment