Chinaunix首页 | 论坛 | 博客
  • 博客访问: 492287
  • 博文数量: 130
  • 博客积分: 2111
  • 博客等级: 大尉
  • 技术积分: 1373
  • 用 户 组: 普通用户
  • 注册时间: 2009-08-28 09:55
个人简介

IT民工

文章分类

全部博文(130)

文章存档

2021年(1)

2019年(1)

2017年(3)

2014年(1)

2013年(3)

2012年(2)

2011年(3)

2010年(2)

2009年(114)

分类: LINUX

2009-09-01 12:38:07

framebuffer编程
2007-12-18 15:26:03
/*自己写的framebuffer 可以在yc的2440板子上显示真彩图片*/

#include
#include
#include
#include
#include

#include "image.h"
#include "image0.h"
#include "image1.h"


#define FB_NAME  "/dev/fb0"
#define TRUE 1
 struct FB_MSG
{
        int fb;
        struct fb_var_screeninfo vinfo;
        struct fb_fix_screeninfo finfo;
        long screensize;
        char *fbp;
};

typedef struct FB_MSG FB;


void open_fb(FB *fb_msg)
{
        int fb;
        fb=open(FB_NAME,O_RDWR);
        if (fb<0)
        {
                printf("Error: Can not open framebuffer device \n");
                exit(1);
        }
         fb_msg->fb=fb;
}
int get_fb_msg(FB *fb_msg)
{
        if (ioctl(fb_msg->fb,FBIOGET_FSCREENINFO,&fb_msg->finfo))
        {
                printf("Error: Reading fixed information \n");
                exit(2);
        }
        if (ioctl(fb_msg->fb,FBIOGET_VSCREENINFO,&fb_msg->vinfo))
        {
                printf("Error: Reading variable information \n");
                exit(3);
        }

        return TRUE;
}

int fb_mmap(FB *fb_msg)
{
        fb_msg->screensize=fb_msg->vinfo.xres * fb_msg->vinfo.yres * fb_msg->vinfo.bits_per_pixel / 8;
        fb_msg->fbp=(char *)mmap(0,fb_msg->screensize,PROT_READ | PROT_WRITE, MAP_SHARED,fb_msg->fb,0);
        if ((int)fb_msg->fbp == -1)
        {
                printf("Error : failed to map framebuffer device to memory. \n");
                exit(4);
        }
        return TRUE;
}

int fb_ummap(FB *fb_msg)
{
        munmap(fb_msg->fbp,fb_msg->screensize);
        close(fb_msg->fb);
}
void draw_picture(const unsigned int *image,FB *fb_msg)
{
        int x,y,count=0;
        long location=0;
        for(x=0;xvinfo.xres;x++)
                for(y=fb_msg->vinfo.yres-1;y>=0;y--)
                {
                        location = x*(fb_msg->vinfo.bits_per_pixel / 8) + y* fb_msg->finfo.line_length;
                        *(fb_msg->fbp+location)=image[count];
                        *(fb_msg->fbp+location+1)=image[count+1];
                        count=count+2;
                }
}

void clear_screen(int color,FB *fb_msg)
{
        int x,y;
        long location=0;
        for(x=0;xvinfo.xres;x++)
                for(y=fb_msg->vinfo.yres-1;y>=0;y--)
                {
                        location = x*(fb_msg->vinfo.bits_per_pixel / 8) + y* fb_msg->finfo.line_length;
                        *(fb_msg->fbp+location)=color;
                        *(fb_msg->fbp+location+1)=color;
                }

}
main()
{
        FB *fb;
        fb=(FB *)malloc(sizeof(FB));
        open_fb(fb);
        get_fb_msg(fb);
        fb_mmap(fb);
        clear_screen(0xff,fb);
//      draw_picture(image0,fb);
        draw_picture(image1,fb);
//      draw_picture(image,fb);
        fb_ummap(fb);
}

阅读(531) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~