/**** 位图信息头数据结构 ****/
typedef struct {
unsigned int size;
//位图信息头大小
int width;
//图像宽度
int height;
//图像高度
unsigned short planes;
//位面数
unsigned short bpp;
//像素深度
unsigned int compression; //压缩方式
unsigned int image_size;
//图像大小
int x_pels_per_meter;
//像素/米
int y_pels_per_meter;
//像素/米
unsigned int clr_used;
unsigned int clr_omportant;
} __attribute__ ((packed)) bmp_info_header;
/**** 静态全局变量 ****/
static int width;
//LCD X 分辨率
static int height;
//LCD Y 分辨率
static unsigned short *screen_base = NULL;
//映射后的显存基地址
static unsigned long line_length;
//LCD 一行的长度(字节为单位)
static int show_bmp_image(const char *path)
{
bmp_file_header file_h;
bmp_info_header info_h;
unsigned short *line_buf = NULL;
//行缓冲区
unsigned long line_bytes; //BMP 图像一行的字节的大小
unsigned int min_h, min_bytes;
int fd = -1;
int j;
/* 打开文件 */
if (0 > (fd = open(path, O_RDONLY))) {
perror("open error");
return -1;
}
/* 读取 BMP 文件头 */
if (sizeof(bmp_file_header) !=
read(fd, &file_h, sizeof(bmp_file_header))) {
perror("read error");
close(fd);
return -1;
}
if (0 != memcmp(file_h.type, "BM", 2)) {
fprintf(stderr, "it's not a BMP file\n");
close(fd);
return -1;
}