In as3, is there a utility or function to convert an RGB color (e.g. 0xFF0000) and an alpha value (e.g. .5) into a A 32-bit ARGB value?
And from ARGB to RGB + alpha?
Some explanation: a bitmapdata can take an ARGB value in its constructor, but filling shapes in sprites usually takes RGB values. I would like the aforementioned utilities to ensure colors match up.
var argb : int = (alpha<<24)|rgb;
var rgb : int = 0xFFFFFF & argb;
var alpha : int = (argb>>24)&0xFF;
A,R,G,B is a common format used by video cards to allow for "texture blending" and transparency in a texture. Most systems only use 8bits for R,G,and B so that leaves another 8bits free out of a 32bit word size which is common in PCs.
The mapping is:
For Bits:
33222222 22221111 11111100 00000000
10987654 32109876 54321098 76543210
AAAAAAAA RRRRRRRR GGGGGGGG BBBBBBBB
00000000 RRRRRRRR GGGGGGGG BBBBBBBB
Something like this:
private function toARGB(rgb:uint, newAlpha:uint):uint{
var argb:uint = 0;
argb = (rgb);
argb += (newAlpha<<24);
return argb;
}
private function toRGB(argb:uint):uint{
var rgb:uint = 0;
argb = (argb & 0xFFFFFF);
return rgb;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With