游戏开发论坛

 找回密码
 立即注册
搜索
查看: 1827|回复: 5

求救:16位模式如何载入24位位图

[复制链接]

6

主题

53

帖子

53

积分

注册会员

Rank: 2

积分
53
发表于 2005-3-14 19:19:00 | 显示全部楼层 |阅读模式
如题,哪位高手知道的话,请告诉一下,多谢!  [em7] [em3]

20

主题

398

帖子

398

积分

中级会员

Rank: 3Rank: 3

积分
398
发表于 2005-3-14 19:28:00 | 显示全部楼层

Re:求救:16位模式如何载入24位位图

很简单!载入图片的时候,编个转换函数转换一下就行了!

原理是:
Red(16)=Red(24)/ 256 * 31
Red(16)=Red(24)/ 256 * 31

20

主题

398

帖子

398

积分

中级会员

Rank: 3Rank: 3

积分
398
发表于 2005-3-14 19:29:00 | 显示全部楼层

Re:求救:16位模式如何载入24位位图

Red(16)=Red(24)/ 256 * 31
Red(16)=Red(24)/ 256 * 31

20

主题

398

帖子

398

积分

中级会员

Rank: 3Rank: 3

积分
398
发表于 2005-3-14 19:30:00 | 显示全部楼层

Re:求救:16位模式如何载入24位位图

不好意思,刚才不小心发出去了!

原理是这个:
r(16) = r(24) / 256 * 31
g(16) = g(24) / 256 * 63
b(16) = b(24) / 256 * 31

你自己优化一下吧!

6

主题

53

帖子

53

积分

注册会员

Rank: 2

积分
53
 楼主| 发表于 2005-3-14 19:41:00 | 显示全部楼层

Re:求救:16位模式如何载入24位位图

谢拉!!!!!!!!!!

6

主题

53

帖子

53

积分

注册会员

Rank: 2

积分
53
 楼主| 发表于 2005-3-14 19:59:00 | 显示全部楼层

Re:求救:16位模式如何载入24位位图

我的编码方式是:
#define _RGB16BIT565(r,g,b) ((b & 31) + ((g & 63) << 5) + ((r & 31) << 11))
24位图已载入到显存bitmap.buffer中
转化并写到主表面的方法是以下代码,但白色全变成了红色,请各位帮忙看一下
USHORT *primary_buffer = (USHORT *)ddsd.lpSurface;      

// process each line and copy it into the primary buffer
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);

        // write the pixel
        primary_buffer[index_x + (index_y*ddsd.lPitch >> 1)] = pixel;

        } // end for index_x

    } // end for index_y
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2025-12-24 20:13

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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