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

猜你喜欢

转载自www.cnblogs.com/xuyu-blogs/p/11290284.html