全部博文(237)
分类:
2010-08-16 11:11:48
24位色和1位色mask图合并为32位真彩色图片。
struct col //24位的像素点定义
{
TUint8 g;
TUint8 b;
TUint8 r;
};
struct cola //32位的像素点定义
{
TUint8 g;
TUint8 b;
TUint8 r;
TUint8 a; //透明度 alpha, 用于图像合成
};
/*
Note:The alpha channel is normally used as an opacity channel. If a pixel has a value of 0% in its alpha channel, it is fully transparent (and, thus, invisible), whereas a value of 100% in the alpha channel gives a fully opaque pixel (traditional digital images). Values between 0% and 100% make it possible for pixels to show through a background like a glass (translucency), an effect not possible with simple binary (transparent or opaque) transparency. It allows easy image compositing. Alpha channel values can be expressed as a percentage, integer, or real number between 0 and 1 like RGB parameters.
*/
bitmap;24C
|
True colour display mode (24 bpp) |
mask;1
|
Monochrome display mode (1 bpp) |
bitmap3->Create(bitmap->SizeInPixels(), EColor16MA);
/*
EColor16MA:Display mode with alpha (24bpp colour plus 8bpp alpha)
*/
bitmap->LockHeap();
bitmap3->LockHeap();
mask->LockHeap();
TSize s = bitmap->SizeInPixels();
TInt scan = CFbsBitmap::ScanLineLength(bitmap->SizeInPixels().iWidth, bitmap->DisplayMode());
TInt scan3 = CFbsBitmap::ScanLineLength(bitmap3->SizeInPixels().iWidth, bitmap3->DisplayMode());
TInt scanm = CFbsBitmap::ScanLineLength(mask->SizeInPixels().iWidth, mask->DisplayMode());
col* bit = (col*)bitmap->DataAddress();
cola* bita = (cola*)bitmap3->DataAddress();
TUint8* bitm = (TUint8*)mask->DataAddress();
for (TInt i = 0; i < s.iHeight; i++)
{
TUint8* temp = bitm;
for (TInt j = 0, m = 0; j < s.iWidth; j++, m++)
{
Mem::Copy((void*)&(bita[j]), &bit[j], sizeof(col));
bita[j].a = (((*temp)>>m) & 1) == 0 ? 255 : 0;
if (m == 7)
{
temp++;
m = -1;
}
}
bit = (col*)((TUint8*)(bit) + scan);
bita = (cola*)((TUint8*)(bita) + scan3);
bitm = bitm + scanm;
}
bitmap->UnlockHeap();
bitmap3->UnlockHeap();
mask->UnlockHeap();