游戏开发论坛

 找回密码
 立即注册
搜索
查看: 2716|回复: 2

blue = (bitmap.buffer[index_y*bitmap.bitmapinfoheader.biWidth*3 + index_x*

[复制链接]

37

主题

67

帖子

73

积分

注册会员

Rank: 2

积分
73
发表于 2006-11-2 15:37:00 | 显示全部楼层 |阅读模式
/////////////////////////////////////////////
//创建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]

37

主题

67

帖子

73

积分

注册会员

Rank: 2

积分
73
 楼主| 发表于 2006-11-2 15:54:00 | 显示全部楼层

Re:blue = (bitmap.buffer[index_y*bitmap.bitmapinfoheader.biWidth*3 + index

还有:
pic_buffer[index_x + (index_y*ddsd.lPitch >> 1)] = _RGB16BIT565(red,green,blue);

中的

index_x + (index_y*ddsd.lPitch >> 1) 得到的是什么呢?

为什么要 >>1

谢谢!

0

主题

51

帖子

51

积分

注册会员

Rank: 2

积分
51
发表于 2012-9-27 18:45:00 | 显示全部楼层

Re:blue = (bitmap.buffer[index_y*bitmap.bitmapinfoheader.biWidth*3 + index

顶!不错!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-2-27 16:30

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表