|
/////////////////////////////////////////////
//创建BMP画面
/////////////////////////////////////////////
LPDIRECTDRAWSURFACE7 CreatePicSurface(char *filename , int mem_flags , int colorkey)
{
DDSURFACEDESC2 ddsd;
LPDIRECTDRAWSURFACE7 picsurface = NULL;
//读取BMP文件
if (!LoadBMPFile(&bitmap , filename))
{
MessageBox(NULL,TEXT("Load Bitmap File error!"),
TEXT("Wrong!"),MB_OK);
return(0);
}
//创建画面
memset(&ddsd,0,sizeof(ddsd));
ddsd.dwSize=sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CKSRCBLT;
ddsd.dwWidth = bitmap.bitmapinfoheader.biWidth;
ddsd.dwHeight= bitmap.bitmapinfoheader.biHeight;
ddsd.ddckCKSrcBlt.dwColorSpaceLowValue = _RGB16BIT565(0,0,0);
ddsd.ddckCKSrcBlt.dwColorSpaceHighValue = _RGB16BIT565(0,0,0);
if(mem_flags == 0)
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN |DDSCAPS_VIDEOMEMORY;
else
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN |DDSCAPS_SYSTEMMEMORY;
if(FAILED(lpDDraw7->CreateSurface(&ddsd,&picsurface,NULL)))
{
MessageBox(NULL,TEXT("DirectDraw Create Pic Surface error!"),
TEXT("Wrong!"),MB_OK);
return(NULL);
}
//设置色彩关键色
DDCOLORKEY color_key;
color_key.dwColorSpaceLowValue = _RGB16BIT565(0,0,255);
color_key.dwColorSpaceHighValue = _RGB16BIT565(0,0,255);
if(FAILED(picsurface->SetColorKey(DDCKEY_SRCBLT , &color_key)))
{
MessageBox(NULL,TEXT("DirectDraw SetColorKey error!"),
TEXT("Wrong!"),MB_OK);
return(NULL);
}
//写入BMP数据
if (FAILED(picsurface->Lock(NULL,&ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT,NULL)))
{
MessageBox(NULL,TEXT("DirectDraw picsurface lock error!"),
TEXT("Wrong!"),MB_OK);
return(NULL);
}
//得到指针
USHORT *pic_buffer = (USHORT *)ddsd.lpSurface;
//将位图写入画面
for (int index_y = 0; index_y < bitmap.bitmapinfoheader.biHeight; index_y++)
{
for (int index_x = 0; index_x < bitmap.bitmapinfoheader.biWidth; index_x++)
{
//读取色彩
UCHAR blue = (bitmap.buffer[index_y*bitmap.bitmapinfoheader.biWidth*3 + index_x*3]) >> 3,
green = (bitmap.buffer[index_y*bitmap.bitmapinfoheader.biWidth*3 + index_x*3 + 1]) >> 3,
red = (bitmap.buffer[index_y*bitmap.bitmapinfoheader.biWidth*3 + index_x*3 + 2]) >> 3;
pic_buffer[index_x + (index_y*ddsd.lPitch >> 1)] = _RGB16BIT565(red,green,blue);
}
}
if (FAILED(picsurface->Unlock(NULL)))
{
MessageBox(NULL,TEXT("DirectDraw picsurface Unlock error!"),
TEXT("Wrong!"),MB_OK);
return(NULL);
}
//释放BMP
UnloadBMPFile(&bitmap);
return (picsurface);
}
请教:
各位大哥
for (int index_x = 0; index_x < bitmap.bitmapinfoheader.biWidth; index_x++)
{
//读取色彩
UCHAR blue = (bitmap.buffer[index_y*bitmap.bitmapinfoheader.biWidth*3 + index_x*3]) >> 3,
green = (bitmap.buffer[index_y*bitmap.bitmapinfoheader.biWidth*3 + index_x*3 + 1]) >> 3,
red = (bitmap.buffer[index_y*bitmap.bitmapinfoheader.biWidth*3 + index_x*3 + 2]) >> 3;
pic_buffer[index_x + (index_y*ddsd.lPitch >> 1)] = _RGB16BIT565(red,green,blue);
}
中的
index_y*bitmap.bitmapinfoheader.biWidth*3 + index_x*3
是什么意思啊?
还有,为什么要 >> 3 呢?
谢谢!
[em20] [em17] [em3] [em21] |
|