<div dir="ltr"><div><br></div><div>I want to get the same values as got by using XGetImage for red_mask, blue_mask and green_mask in xcb.</div><div><br></div><div>Here is m C-go lang code. <br></div><div><br></div><div>I am iterating on the screen got from xcb_setup_roots_iterator .<br></div><div><br></div>for depthIter := C.xcb_screen_allowed_depths_iterator(cx.screen); depthIter.rem != 0; C.xcb_depth_next(&depthIter) {<br> d := depthIter.data<br> for visual_iter := C.xcb_depth_visuals_iterator(d); visual_iter.rem != 0; C.xcb_visualtype_next(&visual_iter) {<br> v := visual_iter.data<br> fmt.Printf("MASKS %x, %x, %x", v.red_mask, v.green_mask, v.blue_mask)<br> }<br> }<br><br>Which Depth and Visual Id should I select for getting correct masks ? </div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Aug 23, 2017 at 6:47 PM, Ilya Anfimov <span dir="ltr"><<a href="mailto:ilan@tzirechnoy.com" target="_blank">ilan@tzirechnoy.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Tue, Aug 22, 2017 at 11:39:26AM +0530, Sai Prasanna wrote:<br>
> I thought Zpixmap mapped directly to BGRA. But my assumption didn't turn<br>
> out to be correct in some older X versions.<br>
><br>
> I am using xcb_get_image and xcb_shm_get_image to grab screen pixels. I<br>
> used Zpixmap option for image format. In new-ish Xorg versions it works<br>
> perfectly.<br>
><br>
> But in some machines with older Xorg (1.15 and below) , I get discolored,<br>
> overlapped data, and it is less than 4 * width * height bytes. If I try to<br>
> read with bytes per pixel as 4 , overflow occurs.<br>
><br>
> Could this be some environment issue , or is there any other "proper" way<br>
> to convert Zpixmap to bgra/rgb formats?<br>
<br>
</div></div> 1) The best source of knowledge about core X11 functionality<br>
is the "X Window System Protocol" book, available e.g. here:<br>
<br>
<a href="https://www.x.org/docs/XProtocol/proto.pdf" rel="noreferrer" target="_blank">https://www.x.org/docs/<wbr>XProtocol/proto.pdf</a><br>
<br>
2) The general pixel storage of the Z pixmap format is described<br>
there in section 8 (Connection Setup), "Server information" and<br>
pixel contents -- in "Visual information".<br>
<br>
It does not need to be 4 bytes per pixel, or even integer bytes<br>
per pixel. Number of bits per pixel is specified in FORMAT: field<br>
of server connection setup response (and may be taken via<br>
xcb_get_setup in xcb library).<br>
Many X servers round pixel size up to integer number of bytes,<br>
as it allows some shortcuts and speedups in server implementa-<br>
tion, but not all do that.<br>
<br>
Pixels does not need to be in {pad,r,g,b} format. The masks for<br>
red, green and blue are specified in VISUALTYPE: field of server<br>
connection setup response. Fortunately, that masks are contigu-<br>
ous, but they don't need to lay on a byte boundary. However,<br>
modern processors don't care much about bit shift size, and it<br>
does not matter -- shift by 8 bits or 11.<br>
<br>
<br>
Also, pixels will be in different byte orders as specified by<br>
image-byte-order: field in server response. You should prepare to<br>
access individual bytes, not integers (or find some other solu-<br>
tion).<br>
<br>
It would be good to build you program for something like Debian<br>
mips architecture (not mips-el!) and check all combinations of<br>
your program and X server in something like qemu-system-mips.<br>
<br>
<br>
PS And yes, probably the most recommended ways to read image<br>
from X11 is to use some image manipulation library, like libgdk<br>
or imagemagick.<br>
The required transformations are fairly simple, though, and if<br>
you are messing with xcb, that it should be really simple to<br>
write a conversion code in like 30-50 lines.<br>
<br>
<br>
<br>
<br>
______________________________<wbr>_________________<br>
<a href="mailto:xorg@lists.x.org">xorg@lists.x.org</a>: X.Org support<br>
Archives: <a href="http://lists.freedesktop.org/archives/xorg" rel="noreferrer" target="_blank">http://lists.freedesktop.org/<wbr>archives/xorg</a><br>
Info: <a href="https://lists.x.org/mailman/listinfo/xorg" rel="noreferrer" target="_blank">https://lists.x.org/mailman/<wbr>listinfo/xorg</a><br>
Your subscription address: %(user_address)s</blockquote></div><br></div>