《windows游戏编程大师技巧》中碰到的问题!
whbc1 2011-07-08 07:24:29 本人最近在学习《windows编程大师技巧》,在第七章遇到几个问题,向各位大侠求解!
1.书中有载入16位位图这个小节。他说把24位图像装载到你的BITMAP_FILE结构中,而后读取缓冲,用下面得算法是想把24位色彩转换为16位!
for (int index_y = 0; index_y < SCREEN_HEIGHT; index_y++)
{
for (int index_x = 0; index_x < SCREEN_WIDTH; index_x++)
{
// get BGR values, note the scaling down of the channels, so that they
// fit into the 5.6.5 format
UCHAR blue = (bitmap.buffer[index_y*SCREEN_WIDTH*3 + index_x*3 + 0]) >> 3,
green = (bitmap.buffer[index_y*SCREEN_WIDTH*3 + index_x*3 + 1]) >> 3,
red = (bitmap.buffer[index_y*SCREEN_WIDTH*3 + index_x*3 + 2]) >> 3;
// this builds a 16 bit color value in 5.6.5 format (green dominant mode)
USHORT pixel = _RGB16BIT565(red,green,blue);
首先他这里为什么先乘以3然后有分别有加0,加1,加2,最后又向右移3位?这里是不懂的地方!是变成相邻的三个字节吗?还是?
2.在载入24位位图的时候,书上说许多图像卡支持32位图像但不支持24位图像,因为他们不喜欢奇数(3的奇数)地址。这里为什么是奇数?