Following code works for me:
Code:
CFbsBitmap* Convert16MUto16ML(CFbsBitmap &aBitmap)
{
TSize size = aBitmap.SizeInPixels();
TDisplayMode dMode = aBitmap.DisplayMode();
TBuf<512> buf;
// if(iFileLogger)
// {
// _LIT(KFmt1, "New Camera Image received in game, w=%d, h=%d, cm=%d");
// buf.Format(KFmt1, size.iWidth, size.iHeight, dMode);
// iFileLogger->WriteLineL(buf);
// }
if (dMode != EColor16MU)
return NULL;
if (bitmap == NULL)
{
bitmap = new (ELeave) CFbsBitmap();
bitmap->Create(size, EColor16M);
}
TInt sW = size.iWidth; //source width
TInt sH = size.iHeight; //source height
TInt dW = sW; //dest width
TInt dH = sH; //dest Height
TInt bpps = 4; //bytes per pixel on source
TInt bppd = 3; //bytes per pixel on dest
TInt l, c;
TUint8 *src = (TUint8*) aBitmap.DataAddress(); //We have 0x00BBGGRR in each 4 bytes of this data (EColor16MU)
TUint8 *dst = (TUint8*) bitmap->DataAddress(); //We want 0xRRGGBB here (EColor16M)
//copy the image pixel by piexel
l = 0;
while (l < sH && l < dH)
{
for (c = 0; c < sW; c++)
{
//in case the image is larger than the texture we stop at the last pixel that fits
if (c >= dW)
break;
//dst[l*dW*bppd + c*bppd] = src[l*sW*bpps + c*bpps + 2]; //B
//dst[l*dW*bppd + c*bppd + 1] = src[l*sW*bpps + c*bpps + 1]; //G
//dst[l*dW*bppd + c*bppd + 2] = src[l*sW*bpps + c*bpps]; //R
dst[l * dW * bppd + c * bppd] = src[l * sW * bpps + c * bpps]; //B
dst[l * dW * bppd + c * bppd + 1] = src[l * sW * bpps + c * bpps
+ 1]; //G
dst[l * dW * bppd + c * bppd + 2] = src[l * sW * bpps + c * bpps
+ 2]; //R
}
l++;
}
return bitmap;
}