Hi BillieJoe,
You have to split the values into their integer colour channels. Off the tope of my head:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
int blend( int bgcol, int fgcol ) { int bg_r = bgcol&0xff; int bg_g = bgcol&0xff00; int bg_b = bgcol&0xff0000;
int fg_r = fgcol&0xff; int fg_g = fgcol&0xff00; int fg_b = fgcol&0xff0000;
int alpha = fgcol >> 24;
|
Alpha blending operation is as follows:
Final = (FG - BG) * Alpha + BG;
When alpha = 0, Final = BG, when alpha = 1, Final = FG.
In code:
1 2 3 4 5 6 7 8 9 10 11
| bg_r += ( (fg_r - bg_r) * alpha)>>8; bg_g += ( (fg_g - bg_g) * alpha)>>8; bg_b += ( (fg_b - bg_b) * alpha)>>8; bg_r &= 0xff; bg_g &= 0xff00; bg_b &= 0xff0000; return ( 0xff000000 + bg_r + bg_g + bg_b); } |
This can be optimised as you can do the B and R parts simultaneously. Hope this helps,
- Dom