Re: How to convert ZPixMap to BGRA reliably?

2017-08-25 Thread Ilya Anfimov
On Fri, Aug 25, 2017 at 06:25:41PM +0530, Sai Prasanna wrote:
>I want to get the same values as got by using XGetImage for red_mask,
>blue_mask and green_mask in xcb.
>Here is m C-go lang code.
>I am iterating on the screen got from xcb_setup_roots_iterator .
>for depthIter := C.xcb_screen_allowed_depths_iterator(cx.screen);
>depthIter.rem != 0; C.xcb_depth_next() {
>d := depthIter.data
>for visual_iter := C.xcb_depth_visuals_iterator(d);
>visual_iter.rem != 0; C.xcb_visualtype_next(_iter) {
>v := visual_iter.data
>fmt.Printf("MASKS %x, %x, %x", v.red_mask, v.green_mask,
>v.blue_mask)
>}
>}
> 
>Which Depth and Visual Id should I select for getting correct masks ?

 Generally,  VisualID  is inherited from a window you taking con-
tents of.
 I mean, if you are casting get_image on a window -- than  it  is
VisualID  of  that window, and if you do get_image on a pixmap --
than that pixmap is somehow filled with some data,  probably  via
XCopyArea,  and you should use VisualID of the window you used to
fill that pixmap.
 Also, you can fill the pixmap with drawing  functions  like  im-
age_text  or  poly_line or put_image requests -- than contents of
it's available planes is determined by your colors in  GC  and/or
your image data.


 The  Depth  should be the same that you used in XCreateWindow or
XCreatePixmap.

>On Wed, Aug 23, 2017 at 6:47 PM, Ilya Anfimov <[1]i...@tzirechnoy.com>
>wrote:
> 
>  On Tue, Aug 22, 2017 at 11:39:26AM +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.
>  >
>  >Could  this be some environment issue , or is there any other
>  "proper" way
>  >to convert Zpixmap to bgra/rgb formats?
> 
>   1) The best source of knowledge about core X11 functionality
>  is the "X Window System Protocol" book, available e.g. here:
> 
>[2]https://www.x.org/docs/XProtocol/proto.pdf
> 
>   2) The general pixel storage of the Z pixmap format is described
>  there in section 8 (Connection Setup), "Server  information"  and
>  pixel contents -- in "Visual information".
> 
>   It  does not need to be 4 bytes per pixel, or even integer bytes
>  per pixel. Number of bits per pixel is specified in FORMAT: field
>  of  server  connection  setup  response  (and  may  be  taken via
>  xcb_get_setup in xcb library).
>   Many X servers round pixel size up to integer number  of  bytes,
>  as  it  allows  some shortcuts and speedups in server implementa-
>  tion, but not all do that.
> 
>   Pixels does not need to be in {pad,r,g,b} format. The masks  for
>  red,  green and blue are specified in VISUALTYPE: field of server
>  connection setup response. Fortunately, that masks  are  contigu-
>  ous,  but  they  don't  need to lay on a byte boundary.  However,
>  modern processors don't care much about bit shift  size,  and  it
>  does not matter -- shift by 8 bits or 11.
> 
>   Also,  pixels  will  be in different byte orders as specified by
>  image-byte-order: field in server response. You should prepare to
>  access  individual  bytes, not integers (or find some other solu-
>  tion).
> 
>   It  would be good to build you program for something like Debian
>  mips architecture (not mips-el!) and check  all  combinations  of
>  your program and X server in something like qemu-system-mips.
> 
>   PS  And  yes,  probably  the most recommended ways to read image
>  from X11 is to use some image manipulation library,  like  libgdk
>  or imagemagick.
>   The  required  transformations are fairly simple, though, and if
>  you are messing with xcb, that it  should  be  really  simple  to
>  write a conversion code in like 30-50 lines.
> 
>  ___
>  [3]xorg@lists.x.org: X.Org support
>  Archives: [4]http://lists.freedesktop.org/archives/xorg
>  Info: [5]https://lists.x.org/mailman/listinfo/xorg
>  Your subscription address: %(user_address)s
> 
> References
> 
>Visible links
>1. mailto:i...@tzirechnoy.com
>2. https://www.x.org/docs/XProtocol/proto.pdf
>3. mailto:xorg@lists.x.org
>4. http://lists.freedesktop.org/archives/xorg
>5. https://lists.x.org/mailman/listinfo/xorg

> 

Re: How to convert ZPixMap to BGRA reliably?

2017-08-25 Thread Sai Prasanna
I want to get the same values as got by using XGetImage for red_mask,
blue_mask and green_mask in xcb.

Here is m C-go lang code.

I am iterating on the screen got from xcb_setup_roots_iterator .

for depthIter := C.xcb_screen_allowed_depths_iterator(cx.screen);
depthIter.rem != 0; C.xcb_depth_next() {
d := depthIter.data
for visual_iter := C.xcb_depth_visuals_iterator(d); visual_iter.rem
!= 0; C.xcb_visualtype_next(_iter) {
v := visual_iter.data
fmt.Printf("MASKS %x, %x, %x", v.red_mask, v.green_mask,
v.blue_mask)
}
}

Which Depth and Visual Id should I select for getting correct masks ?

On Wed, Aug 23, 2017 at 6:47 PM, Ilya Anfimov  wrote:

> On Tue, Aug 22, 2017 at 11:39:26AM +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.
> >
> >Could  this be some environment issue , or is there any other
> "proper" way
> >to convert Zpixmap to bgra/rgb formats?
>
>  1) The best source of knowledge about core X11 functionality
> is the "X Window System Protocol" book, available e.g. here:
>
>   https://www.x.org/docs/XProtocol/proto.pdf
>
>  2) The general pixel storage of the Z pixmap format is described
> there in section 8 (Connection Setup), "Server  information"  and
> pixel contents -- in "Visual information".
>
>  It  does not need to be 4 bytes per pixel, or even integer bytes
> per pixel. Number of bits per pixel is specified in FORMAT: field
> of  server  connection  setup  response  (and  may  be  taken via
> xcb_get_setup in xcb library).
>  Many X servers round pixel size up to integer number  of  bytes,
> as  it  allows  some shortcuts and speedups in server implementa-
> tion, but not all do that.
>
>  Pixels does not need to be in {pad,r,g,b} format. The masks  for
> red,  green and blue are specified in VISUALTYPE: field of server
> connection setup response. Fortunately, that masks  are  contigu-
> ous,  but  they  don't  need to lay on a byte boundary.  However,
> modern processors don't care much about bit shift  size,  and  it
> does not matter -- shift by 8 bits or 11.
>
>
>  Also,  pixels  will  be in different byte orders as specified by
> image-byte-order: field in server response. You should prepare to
> access  individual  bytes, not integers (or find some other solu-
> tion).
>
>  It  would be good to build you program for something like Debian
> mips architecture (not mips-el!) and check  all  combinations  of
> your program and X server in something like qemu-system-mips.
>
>
>  PS  And  yes,  probably  the most recommended ways to read image
> from X11 is to use some image manipulation library,  like  libgdk
> or imagemagick.
>  The  required  transformations are fairly simple, though, and if
> you are messing with xcb, that it  should  be  really  simple  to
> write a conversion code in like 30-50 lines.
>
>
>
>
> ___
> xorg@lists.x.org: X.Org support
> Archives: http://lists.freedesktop.org/archives/xorg
> Info: https://lists.x.org/mailman/listinfo/xorg
> Your subscription address: %(user_address)s
___
xorg@lists.x.org: X.Org support
Archives: http://lists.freedesktop.org/archives/xorg
Info: https://lists.x.org/mailman/listinfo/xorg
Your subscription address: %(user_address)s

Re: How to convert ZPixMap to BGRA reliably?

2017-08-22 Thread Adam Jackson
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
___
xorg@lists.x.org: X.Org support
Archives: http://lists.freedesktop.org/archives/xorg
Info: https://lists.x.org/mailman/listinfo/xorg
Your subscription address: %(user_address)s

How to convert ZPixMap to BGRA reliably?

2017-08-22 Thread Sai Prasanna
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.

Could  this be some environment issue , or is there any other "proper" way
to convert Zpixmap to bgra/rgb formats?
___
xorg@lists.x.org: X.Org support
Archives: http://lists.freedesktop.org/archives/xorg
Info: https://lists.x.org/mailman/listinfo/xorg
Your subscription address: %(user_address)s