How to convert ZPixMap to BGRA reliably?

Adam Jackson ajax at
Tue Aug 22 14:54:46 UTC 2017

On Tue, 2017-08-22 at 11:39 +0530, Sai Prasanna wrote:
> I thought Zpixmap mapped directly to BGRA. But my assumption didn't
> turn out to be correct in some older X versions.
> I am using xcb_get_image and xcb_shm_get_image to grab screen pixels.
> I used Zpixmap option for image format. In new-ish Xorg versions it
> works perfectly. 
> But in some machines with older Xorg (1.15 and below) , I get
> discolored, overlapped data, and it is less than 4 * width * height
> bytes. If I try to read with bytes per pixel as 4 , overflow occurs.

Which machines are these, specifically?

In particular, when you run xdpyinfo, you should see a line for the
depth-24 pixmap format, like this:

    depth 24, bits_per_pixel 32, scanline_pad 32

Some older servers may instead have bits_per_pixel == 24, in which case
the data is missing the "A" channel, which would explain the buffer
overrun you're seeing (which I bet happens at 3 * width * height).
Newer servers and drivers attempt to hide 24bpp formats from clients
for exactly this reason.

- ajax

More information about the xorg mailing list