Color Conversation SOLVED
Hi, there's a problem with teh convert-part of my DirectDraw LoadPicture() function. I try to load a 24 BPP Bitmap and convert it to 16 BPP. But after the load all the colors are wrong on my screen.
Here's the code i use to load the bitmap and convert it:
========================================================
...
#define _RGB16BIT555(r,g,b) ((b & 31) + ((g & 31) << 5) + ((b & 31) << 10))
#define _RGB16BIT565(r,g,b) ((b & 31) + ((g & 63) << 5) + ((b & 31) << 11))
...
// lpbyImage - BYTE pointer to the 24 bpp image data
// lpwSurface - WORD pointer to the 16 bpp surface
DWORD dwRGBBitCount = ddsd.ddpfPixelFormat.dwRGBBitCount;
...
for(int cY=0; cY < nDDSHeight; cY++)
{
for(int cX=0; cX<nDDSWidth; cX++)
{
UCHAR blue = (lpbyImage[(cY*nDDSWidth*3 + cX*3) + 0]),
green = (lpbyImage[(cY*nDDSWidth*3 + cX*3) + 1]),
red = (lpbyImage[(cY*nDDSWidth*3 + cX*3) + 2]);
USHORT color;
if(dwRGBBitCount==15) // 5.5.5 Format
color=_RGB16BIT555(red, green, blue);
else // 5.6.5 Format
color=_RGB16BIT565(red, green, blue);
lpwSurface[cX + (cY*nDDSPitch)] = color;
}
}
========================================================
[Edited by - m4ster on June 14, 2006 12:51:06 PM]
You're using the five LSBs - aren't you supposted to go with the five MSBs, e.g. (b & 248) >> 5 etc?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement