framebuffer应用程序测试 (一)
- 格式:doc
- 大小:63.50 KB
- 文档页数:4
framebuffer应用程序测试(一)
本文的copyright归yuweixian4230@ 所有,使用GPL发布,可以自由拷贝,转载。但转载请保持文档的完整性,注明原作者及原链接,严禁用于任何商业用途。
作者:yuweixian4230@
博客:
程序源代码是:Enabling the Linux Framebuffer 实例访问framebuffer 中提到的代码
首先对这个程序进行测试,看看效果,然后对它进行分析。
再次贴出代码如下;
Testing: Here's a short program that opens the frame buffer and draws
a gradient-filled red square.
画一个红色的矩形框
1.#include
2. #include
3. #include
4. #include
5. #include
6.
7.int main()
8.{
9.int fbfd = 0;
10. struct fb_var_screeninfo vinfo;
11. struct fb_fix_screeninfo finfo;
12. long int screensize = 0;
13. char *fbp = 0;
14.int x = 0, y = 0;
15. long int location= 0;
16.
17.// Open the file for reading and writing
18. fbfd = open("/dev/fb0", O_RDWR);
19.if(!fbfd){
20. printf("Error: cannot open framebuffer device.\n");
21.exit(1);
22.}
23. printf("The framebuffer device was opened
successfully.\n");
24.
25.//Get fixed screen information
26.if(ioctl(fbfd, FBIOGET_FSCREENINFO,&finfo)){
27. printf("Error reading fixed information.\n");
28.exit(2);
29.}
30.
31.//Get variable screen information
32.if(ioctl(fbfd, FBIOGET_VSCREENINFO,&vinfo)){
33. printf("Error reading variable information.\n");
34.exit(3);
35.}
36.
37. printf("%dx%d, %dbpp\n", vinfo.xres, vinfo.yres,
vinfo.bits_per_pixel );
38.
39.// Figure out the size of the screen in bytes
40. screensize = vinfo.xres * vinfo.yres *
vinfo.bits_per_pixel / 8;
41.
42.// Map the device to memory
43. fbp =(char *)mmap(0,screensize,PROT_READ |PROT_WRITE,
MAP_SHARED,
44. fbfd, 0);
45.if((int)fbp ==-1){
46. printf("Error: failed to map framebuffer device to
memory.\n");
47.exit(4);
48.}
49. printf("The framebuffer device was mapped to memory
successfully.\n");
50.
51. x = 100; y = 100;// Where we are going to put the pixel
52.
53.// Figure out where in memory to put the pixel
54.for( y = 100; y < 300; y++)
55.for( x = 100; x < 300; x++){
56.
57.location=(x+vinfo.xoffset)*
(vinfo.bits_per_pixel/8)+
58.(y+vinfo.yoffset)*
finfo.line_length;
59.
60.if( vinfo.bits_per_pixel == 32 ){
61.*(fbp +location)= 100;// Some blue
62.*(fbp +location+ 1)= 15+(x-100)/2;// A
little green
63.*(fbp +location+2)=200-(y-100)/5;//A lot
of red
64.*(fbp +location+ 3)= 0;// No transparency
65.}else{//assume 16bpp
66.int b = 10;
67.int g =(x-100)/6;// A little green
68.int r = 31-(y-100)/16;// A lot of red
69. unsigned short int t = r<<11 | g << 5 | b;
70.*((unsigned short int*)(fbp +location))=t;
71.}
72.
73.}
74. munmap(fbp, screensize);
75. close(fbfd);
76. return 0;
77.}
然后通过 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 565LCD 使用的模式
16. g( 5, 6)