struct xColor
{
BYTE b, g, r, a;
};
struct RGBColor
{
BYTE b, g, r;
};
//void operator <<(RGBColor& rgb, xColor& color)
//{
// rgb.r = color.a * 1.0 / 0xFF * color.r;
// rgb.g = color.a * 1.0 / 0xFF * color.g;
// rgb.b = color.a * 1.0 / 0xFF * color.b;
//}
void operator <<(RGBColor& rgb, xColor& color)
{
rgb.r = 0xFF;
rgb.g = 0x0;
rgb.b = 0x0;
}
void alphaRGB2RGB(unsigned char* src, unsigned char* dest, int sizePixel)
{
assert(src != NULL && dest != NULL);
xColor* pColor = (xColor*)src;
RGBColor* pRGBColor = (RGBColor*)dest;
while (--sizePixel >= 0)
{
*pRGBColor << *pColor;
//printf("pColor r[%d] g[%d] b[%d] a[%d]
", pColor->r, pColor->g, pColor->b, pColor->a);
//printf("prgbColor r[%d] g[%d] b[%d]
", pRGBColor->r, pRGBColor->g, pRGBColor->b);
++pRGBColor;
++pColor;
}
}
unsigned short
RGB888toRGB565(xColor& color)
{
unsigned short B = ( (color.a / 0xFF * color.b) >> 3) & 0x001F;
unsigned short G = (( (color.a / 0xFF * color.g) >> 2) << 5) & 0x07E0;
unsigned short R = (( (color.a / 0xFF * color.r) >> 3) << 11) & 0xF800;
return (unsigned short) (R | G | B);
}
void alphaRGB2RGB565(unsigned char* src, unsigned char* dest, int xWidth, int yHeight, int nLineWidthByte)
{
assert(src != NULL && dest != NULL);
printf("xWidth[%d] xHeight[%d] nLineWidthByte[%d]", xWidth, yHeight, nLineWidthByte);
xColor* pColor = (xColor*)src;
BYTE* pDstLineByte = (BYTE*)dest;
for(int y =0; y < yHeight; ++y)
{
unsigned short* pDstPixel = (unsigned short*)pDstLineByte;
for(int x = 0; x < xWidth; ++x)
{
*pDstPixel = RGB888toRGB565(*pColor);
++pDstPixel;
++pColor;
}
pDstLineByte += nLineWidthByte;
}
}
unsigned short
RGB888toRGB565(unsigned char red, unsigned char green, unsigned char blue)
{
unsigned short B = (blue >> 3) & 0x001F;
unsigned short G = ((green >> 2) << 5) & 0x07E0;
unsigned short R = ((red >> 3) << 11) & 0xF800;
return (unsigned short) (R | G | B);
}