So I'm having a strange problem with xvfb. Basically I have an application running through xvfb like so:
Xvfb :1 -screen 0 1920x1080x24+32 -fbdir /var/tmp &
export DISPLAY=:1
gimp &
And then I read the pixel data from the file like this:
#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;
}
For some reason when I print out the first 1000 elements or so of the buffer it prints out a bunch of random data before it starts printing the actual visual on the screen.
Any help would be greatly appreciated!
As stated here, your file isn't just a pixel array, but in xwd format.
You can learn more about this format in your platform-specific xwdfile.h header and use e.g. xwud utility source to learn how it's been done before you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With