gpt4 book ai didi

c++ - 从 xvfb 读取像素数据

转载 作者:搜寻专家 更新时间:2023-10-31 02:16:46 25 4
gpt4 key购买 nike

所以我在使用 xvfb 时遇到了一个奇怪的问题。基本上我有一个像这样通过 xvfb 运行的应用程序:

Xvfb :1 -screen 0 1920x1080x24+32 -fbdir /var/tmp &
export DISPLAY=:1
gimp &

然后我像这样从文件中读取像素数据:

#include <string>
#include <string.h>
#include <thread>
#include <math.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>

using namespace std;

char *fbp1 = 0;
int fbfd1;
long int screensize1;

int main() {
fbfd1 = 0;
screensize1 = 0;
fbfd1 = open("/var/tmp/Xvfb_screen0", O_RDWR);

screensize1 = 1920 * 1080 * 4;
fbp1 = (char*)mmap(0,
screensize1,
PROT_READ | PROT_WRITE,
MAP_SHARED,
fbfd1,
0);

for (int i = 0; i < 1000; i++) {
cout << ((int*)fbp1)[i] << endl;
}
return 0;
}

出于某种原因,当我打印出缓冲区的前 1000 个左右的元素时,它会在开始在屏幕上打印实际视觉效果之前打印出一堆随机数据。

如有任何帮助,我们将不胜感激!

最佳答案

如前所述here ,你的文件不仅仅是一个像素数组,而是在 xwd format .

您可以在特定于平台的 xwdfile.h header 中了解有关此格式的更多信息,并使用例如xwud实用程序源以了解您之前是如何完成的。

关于c++ - 从 xvfb 读取像素数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36587815/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com