I'm trying to capture images with XGetImage. Everything fine but I need to send the data to a module which expects an array of RGB quads. Calling XGetPixel for every pixel in the image is very slow (0.5 seconds on a i5 for 1440x900 resolution). I've looked up the XGetPixel source code in xlib and the reason is obvious, a lot of computations are done for each pixel. Is there any efficient (or maybe completely different) way of doing this?
相关问题
- X11 forwarding affects Java Swing GUI dropdowns -
- X11 non-clipped child windows
- Using Python GTK GUI front end with C++ backend
- Saving xlib XImage to PNG
- JavaFX crashes X Server
相关文章
- Tracking XWindow Protocol
- How do I map an X11 keysym to a Unicode character?
- Sending Keystrokes to a X Window
- XLib Window Name Problems
- Desktop integrated application (desktop widget lik
- With X11, how can I get the user's time “away
- Programmatically launching standalone Adobe flashp
- Embedding QWidget into X11 Window
With the MIT Shared Memory Extension you can store an image in a shared memory area. This way you avoid going through the Xlib IPC channel when processing the image. You can get or set the contents of a drawable with XShmGetImage and XShmPutImage respectively. You can't resize the shared memory area, you have to destroy it and create a new one.
The next utility takes a screenshot, sets the alpha channel of all pixels to 0xFF and saves it to the specified file. It assumes the pixels are 32 bits BGRA, you should handle all packed pixel formats.
You can compile it like this:
You can capture and save a screenshot like this:
If you don't want to deal with the png library and you are not interested in taking a screenshot, delete initpngimage and savepng functions, plus the following lines:
And compile it like this: