Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4471424
  • 博文数量: 1148
  • 博客积分: 25453
  • 博客等级: 上将
  • 技术积分: 11949
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-06 21:14
文章分类

全部博文(1148)

文章存档

2012年(15)

2011年(1078)

2010年(58)

分类: 嵌入式

2011-05-03 08:08:01

 本文的copyright归yuweixian4230@163.com 所有,使用GPL发布,可以自由拷贝,转载。但转载请保持文档的完整性,注明原作者及原链接,严禁用于任何商业用途。
作者:yuweixian4230@163.com
博客:
yuweixian4230.blog.chinaunix.net 


  程序源代码是:
   中提到的代码
   首先对 这个程序进行测试,看看效果,然后对它进行分析。

再次贴出代码 如下;
    Testing: Here's a short program that opens the frame buffer and draws a gradient-filled red square.

    画一个红色的矩形框
  1. #include <unistd.h>
  2.     #include <stdio.h>
  3.     #include <fcntl.h>
  4.     #include <linux/fb.h>
  5.     #include <sys/mman.h>

  6.     int main()
  7.     {
  8.         int fbfd = 0;
  9.         struct fb_var_screeninfo vinfo;
  10.         struct fb_fix_screeninfo finfo;
  11.         long int screensize = 0;
  12.         char *fbp = 0;
  13.         int x = 0, y = 0;
  14.         long int location = 0;

  15.         // Open the file for reading and writing
  16.         fbfd = open("/dev/fb0", O_RDWR);
  17.         if (!fbfd) {
  18.             printf("Error: cannot open framebuffer device.\n");
  19.             exit(1);
  20.         }
  21.         printf("The framebuffer device was opened successfully.\n");

  22.         // Get fixed screen information
  23.         if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo)) {
  24.             printf("Error reading fixed information.\n");
  25.             exit(2);
  26.         }

  27.         // Get variable screen information
  28.         if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo)) {
  29.             printf("Error reading variable information.\n");
  30.             exit(3);
  31.         }

  32.         printf("%dx%d, %dbpp\n", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel );

  33.         // Figure out the size of the screen in bytes
  34.         screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;

  35.         // Map the device to memory
  36.         fbp = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED,
  37.                            fbfd, 0);
  38.         if ((int)fbp == -1) {
  39.             printf("Error: failed to map framebuffer device to memory.\n");
  40.             exit(4);
  41.         }
  42.         printf("The framebuffer device was mapped to memory successfully.\n");

  43.         x = 100; y = 100; // Where we are going to put the pixel

  44.         // Figure out where in memory to put the pixel
  45.         for ( y = 100; y < 300; y++ )
  46.             for ( x = 100; x < 300; x++ ) {

  47.                 location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/8) +
  48.                            (y+vinfo.yoffset) * finfo.line_length;

  49.                 if ( vinfo.bits_per_pixel == 32 ) {
  50.                     *(fbp + location) = 100; // Some blue
  51.                     *(fbp + location + 1) = 15+(x-100)/2; // A little green
  52.                     *(fbp + location + 2) = 200-(y-100)/5; // A lot of red
  53.                     *(fbp + location + 3) = 0; // No transparency
  54.                 } else { //assume 16bpp
  55.                     int b = 10;
  56.                     int g = (x-100)/6; // A little green
  57.                     int r = 31-(y-100)/16; // A lot of red
  58.                     unsigned short int t = r<<11 | g << 5 | b;
  59.                     *((unsigned short int*)(fbp + location)) = t;
  60.                 }

  61.             }
  62.         munmap(fbp, screensize);
  63.         close(fbfd);
  64.         return 0;
  65.     }
然后通过 gsnap 截图工具,gsnap framer.jpg /dev/fb0 获取图片信息


操作过程如下:

  1. [root@yuweixian yu]# ls
  2. 0.jpg beijing.avi framebuff test-mmap.jpg usb_camera
  3. axu capture mmap.jpg ts_test
  4. [root@yuweixian yu]# ./framebuff
  5. The framebuffer device was opened successfully.
  6. 320x240, 16bpp
  7. The framebuffer device was mapped to memory successfully.
  8. Segmentation fault
  9. [root@yuweixian yu]# gsnap frammer.jpg /dev/fb0
  10. ---------------framebuffer---------------
  11. /dev/fb0:
  12.   width : 320
  13.   height: 240
  14.   bpp : 2
  15.   r(11, 5)    R G B  565   LCD 使用的模式
  16.   g( 5, 6)
  17.   b( 0, 5)
  18. -----------------------------------------
  19. [root@yuweixian yu]# sz frammer.jpg
  20. rz
  21. Starting zmodem transfer. Press Ctrl+C to cancel.
  22. Transferring frammer.jpg...
  23.   100% 19 KB 9 KB/s 00:00:02 0 Errors

  24. 奜Osz 3.48 01-27-98 finished.
  25. [root@yuweixian yu]#



背景 “hello测试程序” 是qt程序,开机时就开启了。

然后执行测试测试程序,就在 覆盖了 hello 测试程序,在其上面显示了 红色矩形框

 


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