使用6位高彩模式

16位高彩模式:

Alpha.5.5.5---------用D15位存储一个Alpha分量(透明度),其余15位均匀分配给红色、绿色、蓝色。每种色彩产生的变化数位2^5,每个调色板有32*32*32 = 32768种色彩。

X.5.5.5-----这种模式同Alpha.5.5.5类似,只是没有用到MSB(最高位),共32768种色彩。

5.6.5---------这是16位色彩最常用的模式。分6位给绿色,是因为人的眼睛对绿色最为敏感。

 

算法表示的宏:

// this builds a 16 bit color value in 5.5.5 format (1-bit alpha mode)
#define _RGB16BIT555(r,g,b) ((b & 31) + ((g & 31) << 5) + ((r & 31) << 10))

// this builds a 16 bit color value in 5.6.5 format (green dominate mode)
#define _RGB16BIT565(r,g,b) ((b & 31) + ((g & 63) << 5) + ((r & 31) << 11))

 

···警告:在建立一个16位模式的演示程序之前,必须强调一个细节:如何检测视频编码格式是5.5.5还是5.6.5。这很重要,因为它不受你控制。

虽然你可以指示DirectDraw创建一个16位模式,但是具体的编码格式还是由硬件决定。(也就是说我们可以创建16位色彩模式,但是具体是5.5.5还是5.6.5是由硬件决定的)

 

获取像素格式(是5.5.5还是5.6.5捏?):

     使用 IDIRECTDRAWSURFACE7::GetPixelFormat()函数;

原型:

HRESULT GetPixelFormat(
  LPDDPIXELFORMAT lpDDPixelFormat
  );

Parameters

lpDDPixelFormat

Points to the DDPIXELFORMAT structure which will be filled in with a detailed description of the current pixel and color space format of the surface.

 

DDPIXELFORMAT为DDSURFACEDESC2结构中的一个数据项

************************************************************************

DDPIXELFORMAT结构中我们最长关心的数据域是:

DWORD  dwSize; //the  size of the structure  ,must be set by you

DOWRD dwFlags;flags describing the surface

DWORD  dwRGBBitCount;number of bit for  Red,Green ,Blue

目前来说最重要的标志:

DDPF_PALETTEINDEXED8-------说明表面采用8位调色板模式

DDPF_RGB-----说明表面采用RGB模式,其格式可以通过测试dwRGBBitCount值获取。

 

测试代码:

DDPIXELFORMAT  ddpixel; used to hold info

LPDIRECTDRAWSURFACE7  lpdds_primary;  //assume  this is  valid

 

//clear  our structure

memset(&ddpixel, 0 , sizeof(ddpixel));

set  length

ddpixel.dwSize = sizeof(ddpixel);

///make call off surface

lpdds_primary->GetPixelFormat(&ddpixel);

 

now  perform  tests ,check if   this  is  an  RGB mode  or  palettized

if(ddpixel.dwFlags & DDPF_RGB)   ///位与,同1异0

{

///RGB  mode

what's the  RGB mode

switch(ddpixel.dwRGBBitCount)

{

case 15:{}break;

case 16:{}break;

case 24:{} break;

case 32 :{}break;

}

}end if

else   if(ddpixel.dwlags & DDPF_PALETTEINDEXED8)

{

///256 color  palettized  mode

}

else

{

///

}

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值