FrameBuffer操作
FrameBuffer是Linux下对于显存操作的抽象层,一般作为一个驱动文件,位置:/dev/fb0。
用C++封装了一下,便于使用:
- fbhelper.h
#ifndef FBHELPER_H
#define FBHELPER_H
//非线程安全
struct fb_var_screeninfo;
class FBHelper
{
public:FBHelper();~FBHelper();int setScreenPtr(int index);const unsigned char* getScreenPtr();
private:int _iFbFd;int _iFbMemSize;int _iFbPixelByte;void *_pFbMemAddr;struct fb_var_screeninfo* _pFbScreenInfo;
};
#endif // FBHELPER_H
- fbhelper.cpp
#include "fbhelper.h"
#include "guidef.h"
#include <linux/fb.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <unistd.h>
#include <iostream>
#include <string.h>
#define FB_NODE ("/dev/fb0")
FBHelper::FBHelper() : _iFbFd(-1), _iFbMemSize(0), _iFbPixelByte(1), _pFbMemAddr(NULL), _pFbScreenInfo(NULL)
{_pFbScreenInfo = new struct fb_var_screeninfo;_iFbFd = open(FB_NODE, O_RDWR);if ( _iFbFd < 0 || ioctl(_iFbFd, FBIOGET_VSCREENINFO, _pFbScreenInfo) != 0 ){std::cout << "[ERR] Fail to operate frame buffer.\n";}_pFbScreenInfo->yoffset = 0;_pFbScreenInfo->xres = BMPWIDTH;_pFbScreenInfo->yres = BMPHEIGHT * MAX_FB_BUFFER_NUM;_pFbScreenInfo->xres_virtual = _pFbScreenInfo->xres;_pFbScreenInfo->yres_virtual = _pFbScreenInfo->yres;if ( ioctl(_iFbFd, FBIOPUT_VSCREENINFO, _pFbScreenInfo) != 0 ){std::cout << "[ERR] Fail to set fb info.\n";}struct fb_fix_screeninfo fixInfo;if ( ioctl(_iFbFd, FBIOGET_FSCREENINFO, &fixInfo) != 0 ){std::cout << "[ERR] Fail to get fb fix info.\n";}
// else
// {
// int *p = (int *)(&fixInfo);
// for (int i = 0; i < sizeof(struct fb_fix_screeninfo)/sizeof(int); i++)
// {
// printf("%d==0x%x %d==\n", i, *p, *p);
// p++;
// }
// }_iFbPixelByte = _pFbScreenInfo->bits_per_pixel / 8;_iFbMemSize = _pFbScreenInfo->xres_virtual * _pFbScreenInfo->yres_virtual * _iFbPixelByte;_pFbMemAddr = mmap(0, _iFbMemSize, PROT_WRITE | PROT_READ, MAP_SHARED, _iFbFd, 0);if ( _pFbMemAddr == MAP_FAILED ){std::cout << "[ERR] Fail to mmap fb.\n";}
// printf("[fb vir-addr = 0x%x - 0x%x]\n", (int)_pFbMemAddr, (int)_pFbMemAddr + _iFbMemSize);memset(_pFbMemAddr, 255, _iFbMemSize);
}
FBHelper::~FBHelper()
{if (_pFbMemAddr && _iFbMemSize > 0){munmap(_pFbMemAddr, _iFbMemSize);}if (_iFbFd >= 0){close(_iFbFd);}if (_pFbScreenInfo){delete _pFbScreenInfo;}
}
int FBHelper::setScreenPtr(int index)
{if (!_pFbScreenInfo){return -1;}int iFrameBytes = BMPWIDTH* BMPHEIGHT * _iFbPixelByte;if ( (index + 1) * iFrameBytes > _iFbMemSize ){return -1;}_pFbScreenInfo->yoffset = index * BMPHEIGHT;if ( ioctl(_iFbFd, FBIOPUT_VSCREENINFO, _pFbScreenInfo) < 0 ){return -1;}return 0;
}
const unsigned char *FBHelper::getScreenPtr()
{if (!_pFbScreenInfo){return NULL;}//ioctl(_iFbFd, FBIO_WAITFORVSYNC, 0);return (unsigned char*)_pFbMemAddr + _pFbScreenInfo->yoffset * BMPWIDTH * _pFbScreenInfo->bits_per_pixel / 8;
}
FrameBuffer操作相关推荐
- 【Linux】FrameBuffer操作入门
所有的这些操作,都是在控制台界面下,root登录. 一,先变一个魔法 $ cat /dev/fb0 > sreensnap /*获取一屏的数据*/ $ clear ...
- Linux FrameBuffer操作(二十七)
所有的这些操作,都是在控制台界面下,root登录. 一.读屏与写屏操作 1.获取一屏的数据 # cat /dev/fb0 > 111.bmp2.将屏幕数据显示 # cat sreensnap & ...
- I.MX6 android 获取framebuffer信息
/********************************************************************************* I.MX6 android 获取f ...
- Framebuffer应用开发
Framebuffer应用开发 文章目录 Framebuffer应用开发 LCD Framebuffer操作原理 Framebuffer API接口 open系统调用 ioctl系统调用 mmap系统 ...
- Linux应用开发【第一章】Framebuffer应用开发
文章目录 1 Framebuffer应用开发 1.1 LCD Framebuffer操作原理 1.2 Framebuffer API接口 1.2.1 open系统调用 1.2.2 ioctl系统调用 ...
- Android 如何使用GPU硬件加速
转自:http://blog.csdn.net/myarrow/article/details/7164638 1.名词解释 GPU:Graphic Processing Unit (图形处理器) O ...
- 【嵌入式Linux】嵌入式项目实战之七步从零编写带GUI的应用之显示系统、输入系统、文字系统
文章目录 前言 1.显示系统 1.1.程序分层 1.2.几个重要的数据结构 1.3.程序分析 2.输入系统 2.1.程序分层 2.2.触摸屏输入 2.2.1.几个重要的数据结构 2.2.1.程序分析 ...
- 计算机图形学学习:GAMES101
渲染管线(Rendering Pipeline) 顶点处理Vertex Processing 顶点流Vertex Stream 三角形的处理Triangle Processing 三角形流Triang ...
- linux图像显示(五)使用freetype处理矢量字体
linux图像显示 linux图像显示(一)framebuffer操作 linux图像显示(二)bmp图片 linux图像显示(三)使用libjpg处理jpg图片 linux图像显示(四)使用libp ...
最新文章
- 技术图文:如何利用 Turtle 绘制一棵漂亮的樱花树
- SAP MM 不常用事务代码MIDO
- linux视频教程 iptables 跟踪,linux – 了解iptables中的连接跟踪
- 红帽虚拟化RHEV3.2创建虚拟机(图文Step by Step)
- c mysql存储过程实例_MySQL存储过程实例
- c语言中指针中 - 和 。的区别?
- officescan客户端迁移和升级
- js null加法的处理
- hiho1257 Snake Carpet
- 关于Xldown和Xlup的用法(Excel VBA)
- AlldayTest 产品使用--文件
- python统计列表中数字出现的次数_Python实现统计给定列表中指定数字出现次数的方法...
- 【java笔记】scanner类和匿名对象的使用
- 为什么每次开机第一次启动程序会很慢?
- dump文件_windows程序崩溃时生成dump文件方法
- AIX 7.1查看硬件配置信息 查看端口IBM POWER 750 P750
- BZOJ 1050 HAOI2006 旅行comf
- python画误差棒_Python数据处理从零开始----第四章(可视化)(3)散点图和误差棒...
- CT原理与技术(生物医学工程专业)
- 高斯图、高斯球、高斯映射