本文的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.
画一个红色的矩形框
- #include <unistd.h>
-
#include <stdio.h>
-
#include <fcntl.h>
-
#include <linux/fb.h>
-
#include <sys/mman.h>
-
-
int main()
-
{
-
int fbfd = 0;
-
struct fb_var_screeninfo vinfo;
-
struct fb_fix_screeninfo finfo;
-
long int screensize = 0;
-
char *fbp = 0;
-
int x = 0, y = 0;
-
long int location = 0;
-
-
// Open the file for reading and writing
-
fbfd = open("/dev/fb0", O_RDWR);
-
if (!fbfd) {
-
printf("Error: cannot open framebuffer device.\n");
-
exit(1);
-
}
-
printf("The framebuffer device was opened successfully.\n");
-
-
// Get fixed screen information
-
if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo)) {
-
printf("Error reading fixed information.\n");
-
exit(2);
-
}
-
-
// Get variable screen information
-
if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo)) {
-
printf("Error reading variable information.\n");
-
exit(3);
-
}
-
-
printf("%dx%d, %dbpp\n", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel );
-
-
// Figure out the size of the screen in bytes
-
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);
-
}
-
printf("The framebuffer device was mapped to memory successfully.\n");
-
-
x = 100; y = 100; // Where we are going to put the pixel
-
-
// Figure out where in memory to put the pixel
-
for ( y = 100; y < 300; y++ )
-
for ( x = 100; x < 300; x++ ) {
-
-
location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/8) +
-
(y+vinfo.yoffset) * finfo.line_length;
-
-
if ( vinfo.bits_per_pixel == 32 ) {
-
*(fbp + location) = 100; // Some blue
-
*(fbp + location + 1) = 15+(x-100)/2; // A little green
-
*(fbp + location + 2) = 200-(y-100)/5; // A lot of red
-
*(fbp + location + 3) = 0; // No transparency
-
} else { //assume 16bpp
-
int b = 10;
-
int g = (x-100)/6; // A little green
-
int r = 31-(y-100)/16; // A lot of red
-
unsigned short int t = r<<11 | g << 5 | b;
-
*((unsigned short int*)(fbp + location)) = t;
-
}
-
-
}
-
munmap(fbp, screensize);
-
close(fbfd);
-
return 0;
-
}
然后通过
gsnap 截图工具,gsnap framer.jpg /dev/fb0 获取图片信息
操作过程如下:
- [root@yuweixian yu]# ls
-
0.jpg beijing.avi framebuff test-mmap.jpg usb_camera
-
axu capture mmap.jpg ts_test
-
[root@yuweixian yu]# ./framebuff
-
The framebuffer device was opened successfully.
-
320x240, 16bpp
-
The framebuffer device was mapped to memory successfully.
-
Segmentation fault
-
[root@yuweixian yu]# gsnap frammer.jpg /dev/fb0
-
---------------framebuffer---------------
-
/dev/fb0:
-
width : 320
-
height: 240
-
bpp : 2
-
r(11, 5) R G B 565 LCD 使用的模式
-
g( 5, 6)
-
b( 0, 5)
-
-----------------------------------------
-
[root@yuweixian yu]# sz frammer.jpg
-
rz
-
Starting zmodem transfer. Press Ctrl+C to cancel.
-
Transferring frammer.jpg...
-
100% 19 KB 9 KB/s 00:00:02 0 Errors
-
-
奜Osz 3.48 01-27-98 finished.
-
[root@yuweixian yu]#
背景 “hello测试程序” 是qt程序,开机时就开启了。
然后执行测试测试程序,就在 覆盖了 hello 测试程序,在其上面显示了 红色矩形框
阅读(3795) | 评论(0) | 转发(0) |