My (untested) solution: I split the foreground and background colors to (red + blue) and (green) components and multiply them with a 6bit alpha value. Enjoy! (Only if it works :)
// rrrrrggggggbbbbb
#define MASK_RB 63519 // 0b1111100000011111
#define MASK_G 2016 // 0b0000011111100000
#define MASK_MUL_RB 4065216 // 0b1111100000011111000000
#define MASK_MUL_G 129024 // 0b0000011111100000000000
#define MAX_ALPHA 64 // 6bits+1 with rounding
uint16 alphablend( uint16 fg, uint16 bg, uint8 alpha ){
// alpha for foreground multiplication
// convert from 8bit to (6bit+1) with rounding
// will be in [0..64] inclusive
alpha = ( alpha + 2 ) >> 2;
// "beta" for background multiplication; (6bit+1);
// will be in [0..64] inclusive
uint8 beta = MAX_ALPHA - alpha;
// so (0..64)*alpha + (0..64)*beta always in 0..64
return (uint16)((
( ( alpha * (uint32)( fg & MASK_RB )
+ beta * (uint32)( bg & MASK_RB )
) & MASK_MUL_RB )
|
( ( alpha * ( fg & MASK_G )
+ beta * ( bg & MASK_G )
) & MASK_MUL_G )
) >> 6 );
}
/*
result masks of multiplications
uppercase: usable bits of multiplications
RRRRRrrrrrrBBBBBbbbbbb // 5-5 bits of red+blue
1111100000011111 // from MASK_RB * 1
1111100000011111000000 // to MASK_RB * MAX_ALPHA // 22 bits!
-----GGGGGGgggggg----- // 6 bits of green
0000011111100000 // from MASK_G * 1
0000011111100000000000 // to MASK_G * MAX_ALPHA
*/