Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/126.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 在Linux(Debian)中访问文本屏幕内存_C++_Linux_Gcc_Debian - Fatal编程技术网

C++ 在Linux(Debian)中访问文本屏幕内存

C++ 在Linux(Debian)中访问文本屏幕内存,c++,linux,gcc,debian,C++,Linux,Gcc,Debian,我在寻找如何读取文本屏幕上的屏幕内存。基本上,我正在编写一个linux应用程序,它使用扩展字符集(unicode)在屏幕上绘制一个“窗口”。我需要准备好我要写的屏幕区域,以便在“窗口”关闭时替换该区域 谢谢在控制台中,您可以保存的内容 它通常可以通过/dev/fb0访问,它不是加速的,而是可靠的 下面是一个具有清晰函数的小示例 #include <stdlib.h> #include <unistd.h> #include <stdio.h> #include

我在寻找如何读取文本屏幕上的屏幕内存。基本上,我正在编写一个linux应用程序,它使用扩展字符集(unicode)在屏幕上绘制一个“窗口”。我需要准备好我要写的屏幕区域,以便在“窗口”关闭时替换该区域


谢谢

在控制台中,您可以保存的内容

它通常可以通过
/dev/fb0
访问,它不是加速的,而是可靠的

下面是一个具有清晰函数的小示例

#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <string.h>

#include <sys/mman.h>
#include <sys/ioctl.h>

#include <linux/fb.h>

#define red pixel {0xFF,0,0,0}

typedef struct s_Pixel {
    char r;
    char g;
    char b;
    char a;
}pixel;

typedef struct s_Framebuffer {
    void*   ptr;
    int     hauteur;
    int     largeur;
    int linelength;
}Framebuffer;

void FB_close   ();
void FB_init    (Framebuffer *);
void FB_clear   (int);
void FB_setPixel(int,int,char,char,char,char);

char        *fbp;
int         fbfd;
long int    screensize;

struct  fb_var_screeninfo vinfo;
struct  fb_fix_screeninfo finfo;

void FB_setPixel(int x, int y, char r, char g, char b, char a)
{
    char * p = (char*)fbp + (x * 4) + (y * finfo.line_length); 
    p[0] = r;
    p[1] = g;
    p[2] = b;
    p[3] = a;
}

void FB_close()
{
    munmap(fbp, screensize);
    close(fbfd);
}

void FB_init(Framebuffer* fb)
{

    // Open the file for reading and writing
    fbfd = open("/dev/fb0", O_RDWR);

    if (fbfd == -1) {
        perror("Error: cannot open framebuffer device");
        exit(1);
    }

    // Get fixed screen information
    if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo) == -1) {
        perror("Error reading fixed information");
        exit(2);
    }

    // Get variable screen information
    if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo) == -1) {
        perror("Error reading variable information");
        exit(3);
    }

    // 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) {
        perror("Error: failed to map framebuffer device to memory");
        exit(4);
    }

    fb->ptr = fbp;
    fb->largeur = vinfo.xres;
    fb->hauteur = vinfo.yres;
    fb->linelength = finfo.line_length;

    FB_clear    ( 0x0 );

    //trace(T1,"%dx%d, %dbpp\n", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel);
}

void FB_clear(int color)
{
    unsigned int x,y;
    switch (vinfo.bits_per_pixel)
    {
        case 32:
            memset((int*)fbp,color,screensize);
            break;
        default:
            for (y=0;y<vinfo.yres;y++)
            {
                for (x=0;x<vinfo.xres;x++)
                {
                    fbp[x * 4 + y *finfo.line_length] = 0x0;
                    fbp[1 + x * 4 + y * finfo.line_length] = 0x0;
                    fbp[2 + x * 4 + y * finfo.line_length] = 0x0;
                }
            }
            break;
    }

}
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#定义红色像素{0xFF,0,0,0}
typedef结构s_像素{
字符r;
charg;
字符b;
字符a;
}像素;
typedef结构s_帧缓冲区{
无效*ptr;
内特豪尔;
国际大酒店;
int行长度;
}帧缓冲区;
void FB_close();
void FB_init(帧缓冲区*);
无效FB_清除(int);
void FB_setPixel(int,int,char,char,char,char,char);
char*fbp;
int-fbfd;
长整型屏幕尺寸;
结构fb_var_screenfo vinfo;
结构fb\u fix\u屏幕信息finfo;
void FB_setPixel(int x,int y,char r,char g,char b,char a)
{
char*p=(char*)fbp+(x*4)+(y*finfo.line_长度);
p[0]=r;
p[1]=g;
p[2]=b;
p[3]=a;
}
void FB_close()
{
munmap(fbp,屏幕大小);
关闭(fbfd);
}
void FB_init(帧缓冲区*FB)
{
//打开文件进行读写
fbfd=打开(“/dev/fb0”,O_RDWR);
如果(fbfd==-1){
perror(“错误:无法打开帧缓冲区设备”);
出口(1);
}
//获取固定屏幕信息
如果(ioctl(fbfd、FBIOGET_FSCREENINFO和finfo)=-1){
perror(“读取固定信息时出错”);
出口(2);
}
//获取可变屏幕信息
如果(ioctl(fbfd、FBIOGET\U VSCREENINFO和vinfo)=-1){
perror(“错误读取变量信息”);
出口(3);
}
//计算屏幕的大小(以字节为单位)
屏幕大小=vinfo.xres*vinfo.yres*vinfo.bits_/u像素/8;
//将设备映射到内存
fbp=(字符*)mmap(0,屏幕大小,保护读取,保护写入,地图共享,fbfd,0);
如果((int)fbp==-1){
perror(“错误:无法将帧缓冲区设备映射到内存”);
出口(4);
}
fb->ptr=fbp;
fb->largeur=vinfo.xres;
fb->hauteur=vinfo.yres;
fb->linelength=finfo.line\u长度;
FB_清除(0x0);
//跟踪(T1、%dx%d、%dbpp\n)、vinfo.xres、vinfo.yres、vinfo.bits_/u像素);
}
无效FB_清除(内部颜色)
{
无符号整数x,y;
开关(vinfo.位/像素)
{
案例32:
memset((int*)fbp、颜色、屏幕大小);
打破
违约:

对于(y=0;yThanks-将尝试此方法