• FrameBuffer编程二(简单程序下)


    1、开发平台sc6410,编译器arm-linux-gcc 4.3

    以下为源代码:

    #include <fcntl.h>
    #include <sys/ioctl.h>
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <sys/mman.h>
    #include <unistd.h>
    #include <string.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include <string.h>
    #include <linux/types.h>
    #include <linux/fb.h>
    #include <linux/videodev2.h>

    int main(int argc ,char *argv[])
    {
        int fbfd = 0;
        struct fb_var_screeninfo vinfo;
        struct fb_fix_screeninfo finfo;
        long int screensize = 0;
        char *fbp = NULL;
        int x = 0 , y = 0;
        long int location = 0 ;
        int sav = 0;

    //open framebuffer device
        fbfd = open("/dev/fb0",O_RDWR);
        if(!fbfd){
                printf("Error:cannot open the framebuffer device!\n");
                exit(1);
            }   
        printf("well you open the framebuffer sucessful!\n");
    //get the fixed screen information
        if(ioctl(fbfd,FBIOGET_FSCREENINFO,&finfo)){
                printf("Error reading fixed information\n");
                exit(2);
            }
    //get the variable screen information
        if(ioctl(fbfd,FBIOGET_VSCREENINFO,&vinfo)){
                printf("Error reading variable information\n");
                exit(3);
            }
    //show these information
        printf("vinfo.xres=%d\n",vinfo.xres);
        printf("vinfo.yres=%d\n",vinfo.yres);
        printf("vinfo.bit_per_bits=%d\n",vinfo.bits_per_pixel);
        printf("vinfo.xoffset=%d\n",vinfo.xoffset);
        printf("vinfo.yoffset=%d\n",vinfo.yoffset);
        printf("finfo.line_length=%d\n",finfo.line_length);   
        screensize = vinfo.xres*vinfo.yres*vinfo.bits_per_pixel/8;

    //map the device to memory
        fbp = (char *)mmap(0,screensize,PROT_READ|PROT_WRITE,MAP_SHARED,fbfd,0);
        if((int)fbp == -1){
            printf("Error:failed to map framebuffer device to memory\n");
            exit(4);
        }
        memset(fbp,0,screensize);
    //plot the screen the colour for black
        for(x=0;x<vinfo.xres;x++)
            for(y=0;y<vinfo.yres;y++){
                location =(x+vinfo.xoffset)*(vinfo.bits_per_pixel/8)+(y+vinfo.yoffset)*finfo.line_length;
                *(fbp+location)=0xFF;
                *(fbp+location+1)=0x00;
                }   
        sleep(10);
    //release the memory
        munmap(fbp,screensize);
        close(fbfd);
        return 0;
    }

    编译下载到开发板上运行的结果截图为(而你的开发板的显示屏会变蓝色):

    2011-8-19-20-43

  • 相关阅读:
    springmvc 拦截器
    springmvc 文件上传
    springmvc 数据验证 hibernate-validator --->对象验证
    springmvc 类型转换器 数据回显及提示信息
    springmvc框架自带的异常处理器SimpleMappingExceptionResolver的使用
    如何解决JSP页面顶端报错 The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path
    eval函数的使用之一
    【模板】负环判定
    【洛谷P1072】Hankson 的趣味题
    【洛谷P1463】反素数
  • 原文地址:https://www.cnblogs.com/xmphoenix/p/2146152.html
Copyright © 2020-2023  润新知