#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#pragma pack(1)
typedef struct tag_bitmap_file_header
{
unsigned short file_type;
unsigned int file_size;
unsigned short reserved1;
unsigned short reserved2;
unsigned int offset_bits;
}bmp_file_header;
typedef struct tag_bitmap_info_header
{
unsigned int bitmap_info_size;
int bitmap_width;
int bitmap_height;
unsigned short planes;
unsigned short image_depth;
unsigned int compression;
unsigned int image_size;
int x_pels_permeter;
int y_pels_permeter;
unsigned int color_used;
unsigned int color_important;
}bmp_info_header;
#pragma pack()
int main()
{
FILE * bmp_fp = fopen("demo.bmp","rb");
if(NULL == bmp_fp)
{
printf("open bmp file faild\n");
return -1;
}
bmp_info_header headerinfo;
bmp_file_header newheaderinfo1;
bmp_info_header newheaderinfo;
fseek(bmp_fp,14,SEEK_SET);
fread(&headerinfo,1,40,bmp_fp);
printf("current bmp width = %d\ncurrent bmp height = %d\n",headerinfo.bitmap_width,headerinfo.bitmap_height);
int pxsize = headerinfo.bitmap_width*headerinfo.bitmap_height*headerinfo.image_depth/8;
printf("pxsize = %d\n",pxsize);
char bmp_buf[pxsize];
fread(bmp_buf,1,pxsize,bmp_fp);
fseek(bmp_fp,0,SEEK_SET);
fread(&newheaderinfo1,1,14,bmp_fp);
newheaderinfo1.file_size = 400*240*3;
fread(&newheaderinfo,1,40,bmp_fp);
newheaderinfo.bitmap_width = 400;
newheaderinfo.bitmap_height = 240;
fclose(bmp_fp);
char newbmp_buf[pxsize/4];
int cnt = 0;
for(int y = 0;y < 480; y+=2)
{
for(int x = 0; x < 800 ;x+=2)
{
for(int k=0; k<3; k++)
{
newbmp_buf[cnt] = bmp_buf[(y*800+x)*3+k];
cnt++;
}
}
}
FILE * newbmp_fp = fopen("newdemo.bmp","wb+");
if(NULL == newbmp_fp)
{
printf("open bmp file faild\n");
return -1;
}
int fp = fwrite(&newheaderinfo1,1,14,newbmp_fp);
if(fp != 14)
{
printf("write failed\n");
}
fwrite(&newheaderinfo,1,40,newbmp_fp);
fwrite(&newbmp_buf,1,400*240*3,newbmp_fp);
fseek(bmp_fp,54,SEEK_SET);
char Newbmp_buf[pxsize/4];
fread(Newbmp_buf,1,pxsize/4,newbmp_fp);
fclose(newbmp_fp);
int lcd_fd = open("/dev/fb0",O_RDWR);
int lcd_pxsize = 800*480*4;
int * lcd_mp = (int *)mmap(NULL,lcd_pxsize,PROT_READ|PROT_WRITE,MAP_SHARED,lcd_fd,0);
int i = 0;
int data = 0;
for (int y = 240-1; y >= 0; y--)
{
for (int x = 0; x < 400 ; ++x)
{
data |= Newbmp_buf[i];
data |= Newbmp_buf[i+1]<<8;
data |= Newbmp_buf[i+2]<<16;
lcd_mp[800*y + x] = data;
i+=3;
data = 0;
}
}
close(lcd_fd);
munmap(lcd_mp,lcd_pxsize);
return 0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)