打开bmp文件- //打开.bmp文件
- FILE *fb = fopen(bmpname, "rb");
- if (fb == NULL)
- {
- printf("fopen bmp error\r\n");
- return -1;
- }
获取lcd参数
查看- struct fb_var_screeninfo {
- __u32 xres; /* visible resolution */
- __u32 yres;
- __u32 xres_virtual; /* virtual resolution */
- __u32 yres_virtual;
- __u32 xoffset; /* offset from virtual to visible */
- __u32 yoffset; /* resolution */
- __u32 bits_per_pixel; /* guess what */
- __u32 grayscale; /* 0 = color, 1 = grayscale, */
- /* >1 = FOURCC */
- struct fb_bitfield red; /* bitfield in fb mem if true color, */
- struct fb_bitfield green; /* else only length is significant */
- struct fb_bitfield blue;
- struct fb_bitfield transp; /* transparency */
- __u32 nonstd; /* != 0 Non standard pixel format */
- __u32 activate; /* see FB_ACTIVATE_* */
- __u32 height; /* height of picture in mm */
- __u32 width; /* width of picture in mm */
- __u32 accel_flags; /* (OBSOLETE) see fb_info.flags */
- /* Timing: All values in pixclocks, except pixclock (of course) */
- __u32 pixclock; /* pixel clock in ps (pico seconds) */
- __u32 left_margin; /* time from sync to picture */
- __u32 right_margin; /* time from picture to sync */
- __u32 upper_margin; /* time from sync to picture */
- __u32 lower_margin;
- __u32 hsync_len; /* length of horizontal sync */
- __u32 vsync_len; /* length of vertical sync */
- __u32 sync; /* see FB_SYNC_* */
- __u32 vmode; /* see FB_VMODE_* */
- __u32 rotate; /* angle we rotate counter clockwise */
- __u32 colorspace; /* colorspace for FOURCC-based modes */
- __u32 reserved[4]; /* Reserved for future compatibility */
- };
头文件中,用fb_var_screeninfo结构体定义屏幕参数基本信息,如分辨率,像素点位数及RGB分别用多少位表示。
获取结构体fb_var_screeninfo- //获取屏幕信息
- //若屏幕显示区域大小不合适,可用ioctl(dev_fd, FBIOPUT_VSCREENINFO, &scrinfo)设置
- if (ioctl(dev_fd, FBIOGET_VSCREENINFO, &scrinfo))
- {
- printf("get screen infomation error!\r\n");
- return -1;
- }
使用ioctl的参数,FBIOGET_VSCREENINFO来表示获得屏幕的可变信息。
映射framebuffer- //计算需要的映射内存大小
- screensize = scrinfo.xres_virtual * scrinfo.yres_virtual * scrinfo.bits_per_pixel / 8;
- // printf("screensize=%lu!\r\n", screensize);
- //内存映射
- fbp = (char *)mmap(NULL, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, dev_fd, 0);
- if (-1 == (int)fbp)
- {
- printf("mmap error!\r\n");
- return -1;
- }
首先计算需要的映射内存大小,计算公式为:映射内存大小 = 屏幕大小 = xres * yres * 每个像素位数 / 8。然后使用mmap映射内存,PROT_READ | PROT_WRITE表示该区域可读、可写;MAP_SHARED表示该区域是共享的,APP写入数据时,会直达驱动程序。到这一步之后就做好显示图片的准备了。
更多回帖