#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#include <stdlib.h>
#pragma pack(1)
typedef struct
{
unsigned short bfType;
unsigned int bfSize;
unsigned short bfReserved1;
unsigned short bfReserved2;
unsigned int bfOffBits;
} BITMAPFILEHEADER;
typedef struct
{
unsigned int biSize;
int biWidth;
int biHeight;
unsigned short biPlanes;
unsigned short biBitCount;
unsigned int biCompression;
unsigned int biSizeImage;
int biXPelsPerMeter;
int biYPelsPerMeter;
unsigned int biClrUsed;
unsigned int biClrImportant;
} BITMAPINFOHEADER;
#pragma pack()
int main(int argc, char const *argv[])
{
FILE *bmp_fp = fopen(argv[1], "rb");
if (NULL == bmp_fp)
{
return -1;
}
BITMAPINFOHEADER pic;
fseek(bmp_fp, 14, SEEK_SET);
fread(&pic, 1, 40, bmp_fp);
printf("bmp width = %d,height = %d\n", pic.biWidth, pic.biHeight);
char *bmp_buf = (char *)calloc(pic.biWidth * pic.biHeight * 3, 1);
int offset = (4 - (pic.biWidth * 3) % 4) % 4;
for (int i = 0; i < pic.biHeight; i++)
{
fread(bmp_buf + i * pic.biWidth * 3, 1, pic.biWidth * 3, bmp_fp);
fseek(bmp_fp, offset, SEEK_CUR);
}
fclose(bmp_fp);
int lcd_fd = open("/dev/fb0", O_RDWR);
int *lcd_mp = (int *)mmap(NULL, 800 * 480 * 4, PROT_READ | PROT_WRITE, MAP_SHARED, lcd_fd, 0);
int i = 0;
int data = 0;
int X = 0, Y = 0;
printf("please input the picture's site:");
scanf("%d,%d", &X, &Y);
for (int y = Y + pic.biHeight - 1; y >= Y; y--)
{
for (int x = X; x < X + pic.biWidth; ++x)
{
data |= bmp_buf[i];
data |= bmp_buf[i + 1] << 8;
data |= bmp_buf[i + 2] << 16;
lcd_mp[800 * y + x] = data;
i += 3;
data = 0;
}
}
close(lcd_fd);
munmap(lcd_mp, 800 * 480 * 4);
return 0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!