因为调用频繁,欧博所以采用宏或内联函数方式实现。
#define RGB565_ALPHA_CONVERSION( d, s, alpha) \ { \ unsigned int sr = (s) & 0xF800; \ unsigned int sg = (s) & 0x07E0; \ unsigned int sb = (s) & 0x001F; \ unsigned int dr = (d) & 0xF800; \ unsigned int dg = (d) & 0x07E0; \ unsigned int db = (d) & 0x001F; \ \ dr += ((sr - dr) * (alpha)) >> 8; \ dg += ((sg - dg) * (alpha)) >> 8; \ db += ((sb - db) * (alpha)) >> 8; \ dr &= 0xF800; \ dg &= 0x07E0; \ db &= 0x001F; \ d= dr | dg | db; \ }
根据实际应用测试,皇冠图片中点的alpha为0 或255居多,DG游戏所以先处理,欧博注册性能有显著提高:
#define RGB565_ALPHA_CONVERSION( d, s, alpha) \ { \ if(alpha==0) \ { \ \ }else if(alpha == 255) \ { \ d = s; \ }else \ { \ unsigned int sr = (s) & 0xF800; \ unsigned int sg = (s) & 0x07E0; \ unsigned int sb = (s) & 0x001F; \ unsigned int dr = (d) & 0xF800; \ unsigned int dg = (d) & 0x07E0; \ unsigned int db = (d) & 0x001F; \ \ dr += ((sr - dr) * (alpha)) >> 8; \ dg += ((sg - dg) * (alpha)) >> 8; \ db += ((sb - db) * (alpha)) >> 8; \ dr &= 0xF800; \ dg &= 0x07E0; \ db &= 0x001F; \ d= dr | dg | db; \ } \ }
再来:看以下代码:
TUint32 Fast_AlphaBlender(TUint32 x, TUint32 y, TUint32 Alpha) { x = ( x | ( x<<16 ) ) & 0x7E0F81F; y = ( y | ( x<<16 ) ) & 0x7E0F81F; TUint32 result = ( ((x - y) * Alpha) >> 5 + y ) & 0x7E0F81F; return (TUint32)(result&0xFFFF) | (result>>16); }
采用这个算法再加上用宏的形式并对0 255 单独处理,欧博代理性能肯定会提高,不过我还没来得及测试,参考以下文档: (责任编辑:)
|