[Xcb] Identifying format of image data returned by get_image

Josh Triplett josh at joshtriplett.org
Sat Dec 10 10:14:35 PST 2011

On Sat, Dec 10, 2011 at 12:39:28PM -0500, Jonathan Baldwin wrote:
> Hi! I'm trying to read and process image data from a drawable using
> xcb_get_image. To parse and encode the data, I need to match the
> format against a list of formats (RGBA32, BGRA15, monochrome, etc...)
> supported by the encoder. In Xlib, the XImage structure provides
> bits_per_pixel and colour masks which can be tested to identify the
> format, but the xcb_get_image_reply_t structure only contains a depth
> and visualid. How can I get the bpp and colour masks using xcb?

The visualid corresponds to an X "visual" which tells you all the
parameters you need.  The X server sends you a list of valid visuals
during connection setup.  Call xcb_get_setup to get the xcb_setup_t.
That has a list of roots (of type xcb_screent_t) which you can iterate
through, each of which has a list of depths (of type xcb_depth_t) you
can iterate through, each of which has a list of visuals (of type
xcb_visualtype_t) you can iterate through.  Each xcb_visualtype_t
contains the visual type, the color masks, and in the case of
pseudocolor visuals the colormap (palette).

Hope that helps,
Josh Triplett

More information about the Xcb mailing list