首页 > 代码库 > Linux Framebuffer编程简介
Linux Framebuffer编程简介
linux下,framebuffer设备文件名通常是/
dev/fb0,1,2等。
控制framebuffer设备的一般步骤如下:
1) 打开设备,映射framebuffer
2)依照硬件要求,准备好数据
3)把数据复制到framebuffer
例子程序如下:
1)打开设备,映射framebuffer
static void *fbbuf;
int openfb(char *devname)
{
int fd;
fd = open(devname, O_RDWR);
if (ioctl(fd, FBIOGET_VSCREENINFO, &fbvar) < 0)
return -1;
bpp = fbvar.bits_per_pixel;
screen_size = fbvar.xres * fbvar.yres * bpp / 8;
fbbuf = mmap(0, screen_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
return fd;
}
2)数据准备,假设lcd控制器被初始化为565,16bit格式的
static inline int make_pixel(unsigned int a, unsigned int r, unsigned int g, unsigned int b)
{
return (unsigned int)(((r>>3)<<11)|((g>>2)<<5|(b>>3)));
}
3) 把想要显示的数据复制到framebuffer,假设把framebuffer填充成一种颜色
static void fill_pixel(unsigned int pixel, int x0, int y0, int w, int h)
{
int i, j;
unsigned short *pbuf = (unsigned short *)fbbuf;
for (i = y0; i < h; i ++) {
for (j = x0; j < w; j ++) {
pbuf[i * screen_width + j] = pixel;
}
}
}
下面程序把lcd屏幕填充成蓝色
fill_pixel(make_pixel(0, 0, 0,0xff), 0, 0, screen_width, screen_height);
控制framebuffer设备的一般步骤如下:
1) 打开设备,映射framebuffer
2)依照硬件要求,准备好数据
3)把数据复制到framebuffer
例子程序如下:
1)打开设备,映射framebuffer
static void *fbbuf;
int openfb(char *devname)
{
int fd;
fd = open(devname, O_RDWR);
if (ioctl(fd, FBIOGET_VSCREENINFO, &fbvar) < 0)
return -1;
bpp = fbvar.bits_per_pixel;
screen_size = fbvar.xres * fbvar.yres * bpp / 8;
fbbuf = mmap(0, screen_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
return fd;
}
2)数据准备,假设lcd控制器被初始化为565,16bit格式的
static inline int make_pixel(unsigned int a, unsigned int r, unsigned int g, unsigned int b)
{
return (unsigned int)(((r>>3)<<11)|((g>>2)<<5|(b>>3)));
}
3) 把想要显示的数据复制到framebuffer,假设把framebuffer填充成一种颜色
static void fill_pixel(unsigned int pixel, int x0, int y0, int w, int h)
{
int i, j;
unsigned short *pbuf = (unsigned short *)fbbuf;
for (i = y0; i < h; i ++) {
for (j = x0; j < w; j ++) {
pbuf[i * screen_width + j] = pixel;
}
}
}
下面程序把lcd屏幕填充成蓝色
fill_pixel(make_pixel(0, 0, 0,0xff), 0, 0, screen_width, screen_height);
From:http://www.cnblogs.com/cornsea/archive/2009/12/08/1619760.html
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。