#define _RGB16BIT555(r, g, b) ((b%32) + ((g%32) << 5) + ((r%32) << 10))
#define _RGB16BIT565(r, g, b) ((b%32) + ((g%64) << 6) + ((r%32) << 11))
void Bitmap24_To_Bitmap16(BITMAP_FILE_PTR bitmap,
LPDIRECTDRAWSURFACE7 lpdds)
{
DDPIXELFORMAT ddpixel; // store pixel format here
USHORT *dest_ptr;
int index;
memset(&ddpixel;,0,sizeof(ddpixel));
ddpixel.dwSize = sizeof(ddpixel);
// Get Pixel Format for Match
lpdds->GetPixelFormat(&ddpixel;);
switch(ddpixel.dwRGBBitCount)
{
case 15 : // 5.5.5 16 bit format
{
lpdds->Lock(NULL,&ddsd;,DDLOCK_WAIT|DDLOCK_SURFACEMEMORYPTR,NULL);
dest_ptr = (USHORT *)ddsd.lpSurface;
// change RGB format to BGR format and match bit
for(index=0; index < bitmap->bitmapinfoheader.biSizeImage; index++)
{
dest_ptr[index]=(USHORT)(_RGB16BIT555((bitmap->buffer[index*3 + 0]) >> 3,
(bitmap->buffer[index*3 + 1]) >> 3,
(bitmap->buffer[index*3 + 2]) >> 3));
}
lpdds->Unlock(NULL);
}
case 16 : // 5.6.6 16 bit format
{
lpdds->Lock(NULL,&ddsd;,DDLOCK_WAIT|DDLOCK_SURFACEMEMORYPTR,NULL);
dest_ptr = (USHORT *)ddsd.lpSurface;
// change RGB format to BGR format and match bit
for(index=0; index < bitmap->bitmapinfoheader.biSizeImage; index++)
{
dest_ptr[index]=(USHORT)(_RGB16BIT565((bitmap->buffer[index*3 + 0]) >> 3,
(bitmap->buffer[index*3 + 1]) >> 3,
(bitmap->buffer[index*3 + 2]) >>3));
}
lpdds->Unlock(NULL);
}
}
}