C语言将raw转为bmp,RAW格式数据转BMP格式数据

1.BMP文件结构,注意字节对齐

__packed struct tagBITMAPFILEHEADER

{

T_U16 bfType;

T_U32 bfSize;

T_U16 bfReserved1;

T_U16 bfReserved2;

T_U32 bfOffBits;

} ;

数据结构填充,其中RawWidth、RawHeight是指RAW的图像宽高,小端格式

memcpy(&file_head_t.bfType,"BM",sizeof(file_head_t.bfType));

file_head_t.bfSize = 1078 + RawWidth*RawHeight;

file_head_t.bfOffBits = 1078;

2. BMP信息结构,注意字节对齐

__packed struct tagBITMAPINFOHEADER

{

T_U32 biSize;

T_U32 biWidth;

T_U32 biHeight;

T_U16 biPlanes;

T_U16 biBitCount;

T_U32 biCompression;

T_U32 biSizeImage;

T_U32 biXPelsePerMeter;

T_U32 biYPelsePerMeter;

T_U32 biClrUsed;

T_U32 biClrImportant;

} ;

数据结构填充,其中RawWidth、RawHeight是指RAW的图像宽高,小端格式

info_head_t.biSize = 40;

info_head_t.biWidth = RawWidth;

info_head_t.biHeight = RawHeight;

info_head_t.biPlanes = 1;

info_head_t.biBitCount = 8;

info_head_t.biCompression = 0;

info_head_t.biSizeImage = RawWidth*RawHeight;

info_head_t.biClrUsed = 256;

3.调色板数据结构

__packed typedef struct tagRGBQUAD

{

T_U8 rgbBlue;

T_U8 rgbGreen;

T_U8 rgbRed;

T_U8 rgbReserved;

} ;

其数据长度受info_head_t.biClrUsed(颜色索引数)值影响,每个索引表示一个像素的值,如果是灰度图像则rgbBlue=rgbGreen=rgbRed,每个索引占4字节256个索引占1024字节,

而图像数据的数值就是索引号

4.图像数据

直接复制RAW

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值