打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
framebuffer编程显示真彩图片
/*自己写的framebuffer 可以在yc的2440板子上显示真彩图片*/

#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <sys/mman.h>

#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;x<fb_msg->vinfo.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;x<fb_msg->vinfo.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);
}
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
framebuffer应用程序编写
FrameBuffer编程二(简单程序下)
对FrameBuffer的一夜hack。。。
framebuffer 和skia 结合搭建GUI
fb在启动后默认是TEXT模式,如何让fb启动默认为图形模式
直接写framebuffer
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服