Chinaunix首页 | 论坛 | 博客
  • 博客访问: 152765
  • 博文数量: 47
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 405
  • 用 户 组: 普通用户
  • 注册时间: 2014-11-23 14:38
文章分类

全部博文(47)

文章存档

2017年(7)

2016年(4)

2015年(19)

2014年(17)

我的朋友

分类: 嵌入式

2014-11-23 22:15:59

想要用帧缓存显示图片,必须要搞清楚两点:1是帧缓存的详细信息和具体功能以及相应的操作函数,2是你所要显示的图片格式的信息。对于不同的图片格式,信息存储的方式不同,那么读取显示的细节也就不相同。
对于帧缓存而言,我们知道了它的操作步骤,作为文件设备用open函数打开,用ioctl函数获取帧缓存的参数,主要是x轴和y轴的实际分辨率以及色深,这关系到精确对准到各个像素点。接下来就是映射,用mmap函数将帧缓存映射到用户空间的虚拟地址。
现在就可以将图片内容写进去了。用malloc函数分配一定长度的内存空间,用read函数将图片内容读取进去,因为BMP图片前部含有文件头,信息头,颜色表(视具体情况而定,如真彩图片就不存在),首先需要剔除它们。
接下来就是需要将图片内容一一对应到相应的像素点,这里要注意BMP图片信息是按从左到右从下到上的顺序存储的。
具体关于帧缓存和BMP图片格式的内容可以参考我的前两篇文章。
附上我写的小程序:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include


struct fb_fix_screeninfo fb_fix;
struct fb_var_screeninfo fb_var;
#define size 2359296
#define row 768
#define line 1024
char *map_address;
unsigned char* recbuf = NULL;


void showbmp(unsigned char* recvbuf) 
{
    int location = 0;
    int linex = 0, liney = 0;
    int count = 0;
    for (liney = row-1; liney >= 0; --liney) 
    {
        for (linex = 0; linex < line; ++linex) 
        {
            location = linex * fb_var.bits_per_pixel / 8 + liney * fb_var.xres *      fb_var.bits_per_pixel / 8;
            *((int*) (map_address + location + 0)) = *(recvbuf + count);
            count++;
            *((int*) (map_address + location + 1)) = *(recvbuf + count);
            count++;
            *((int*) (map_address + location + 2)) = *(recvbuf + count);
            count++;
        }
    }
}




int main()
{
    int fbfd;
    int fd;
    size_t fb_size;


    fbfd = open("/dev/fb0", O_RDWR );
    if(fbfd < 0)
    {
        printf("open fb failed!\n");
    }
     if( ioctl(fbfd, FBIOGET_FSCREENINFO, &fb_fix) == -1 )
    {
        printf("return fix failed\n");
    }
    if( ioctl(fbfd, FBIOGET_VSCREENINFO, &fb_var) == -1 )
    {
    printf("return var failed\n");
    }


    fb_size = fb_var.xres * fb_var.yres * fb_var.bits_per_pixel / 8;
    map_address = mmap(NULL, fb_size, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, 0);

    fd = open("/root/Bluestream.bmp", O_RDONLY);
    if(fd == -1)
    {
        printf("open failed\n");
        exit(1);
    }
    recbuf = malloc(size);
    memset(recbuf, 0, size);


    lseek(fd, 54, SEEK_SET);
    read(fd, recbuf, size);
    showbmp(recbuf);


    free(recbuf);
    munmap(map_address, fb_size);
    close(fbfd);
    close(fd);
    return 0;
}



阅读(2321) | 评论(0) | 转发(0) |
0

上一篇:Linux帧缓存

下一篇:关于API

给主人留下些什么吧!~~