| |
| |
| |
| |
| |
| |
| |
| |
| #include <stdio.h> |
| #include <sys/types.h> |
| #include <sys/stat.h> |
| #include <fcntl.h> |
| #include <unistd.h> |
| #include <sys/mman.h> |
| #include <sys/ioctl.h> |
| #include <linux/fb.h> |
| #include <stdlib.h> |
| |
| #define MUL 2 |
| |
| #pragma pack(1) |
| typedef struct tagBITMAPFILEHEADER // bmp格式图片的文件信息头1 |
| { |
| unsigned short type; |
| unsigned int size; |
| unsigned short reserved1; |
| unsigned short reserved2; |
| unsigned int offBits; |
| } BMF_HEADER; |
| |
| typedef struct tagBITMAPINFOHEADER // bmp格式图片的文件信息头2 |
| { |
| unsigned int biSize; |
| int width; |
| int height; |
| unsigned short biPlanes; |
| unsigned short biBit_depth; |
| unsigned int biCompression; |
| unsigned int biSizeImage; |
| int biXPelsPerMeter; |
| int biYPelsPerMeter; |
| unsigned int biClrUsed; |
| unsigned int biClrImportant; |
| } BMFI_HEADER; |
| #pragma pack() |
| |
| int main(int argc, char *argv[]) |
| { |
| |
| BMF_HEADER S1; |
| BMFI_HEADER S2; |
| FILE *bmp_fp = fopen(argv[1], "rb+"); |
| if (argc != 3) |
| { |
| printf("Usage:%s <srcfile><dstfile>\n", argv[0]); |
| exit(1); |
| } |
| if (!bmp_fp) |
| { |
| perror("fopen()"); |
| exit(1); |
| } |
| fread(&S1, 1, 14, bmp_fp); |
| fread(&S2, 1, 40, bmp_fp); |
| |
| int bmp_size = S2.width * S2.height * S2.biBit_depth / 8; |
| char bmp_buf[bmp_size]; |
| fread(bmp_buf, 1, bmp_size, bmp_fp); |
| fclose(bmp_fp); |
| |
| |
| |
| |
| |
| |
| |
| char newbuf[bmp_size / MUL / MUL]; |
| int cnt = 0; |
| for (int y = 0; y < S2.height; y += MUL) |
| { |
| for (int x = 0; x < S2.width; x += MUL) |
| { |
| newbuf[cnt++] = bmp_buf[(y * S2.width + x) * 3]; |
| newbuf[cnt++] = bmp_buf[(y * S2.width + x) * 3 + 1]; |
| newbuf[cnt++] = bmp_buf[(y * S2.width + x) * 3 + 2]; |
| } |
| } |
| |
| |
| FILE *new_fp = fopen(argv[2], "wb+"); |
| if (!new_fp) |
| { |
| perror("fopen()"); |
| exit(1); |
| } |
| S2.width = S2.width / MUL; |
| S2.height = S2.height / MUL; |
| fwrite(&S1, 1, 14, new_fp); |
| fwrite(&S2, 1, 40, new_fp); |
| fwrite(&newbuf, 1, bmp_size / MUL / MUL, new_fp); |
| fclose(new_fp); |
| |
| |
| int lcd_fd = open("/dev/fb0", O_RDWR); |
| int *lcd_map = (int *)mmap(NULL, |
| 800 * 480 * 4, |
| PROT_READ | PROT_WRITE, |
| MAP_SHARED, |
| lcd_fd, |
| 0); |
| |
| int X, Y; |
| printf("Please enter the location(X Y):\n"); |
| scanf("%d %d", &X, &Y); |
| int i = 0; |
| int data = 0; |
| for (int y = S2.height / MUL - 1; y >= 0; y--) |
| { |
| for (int x = 0; x < S2.width / MUL; ++x) |
| { |
| |
| data |= newbuf[i]; |
| data |= newbuf[i + 1] << 8; |
| data |= newbuf[i + 2] << 16; |
| lcd_map[800 * (y + Y) + x + X] = data; |
| i += 3; |
| data = 0; |
| } |
| } |
| close(lcd_fd); |
| munmap(lcd_map, 800 * 480 * 4); |
| return 0; |
| } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步