Corrupted XImage retrieved from a Window area

Carsten Haitzler (The Rasterman) raster at rasterman.com
Sun Jul 31 22:49:59 UTC 2016


On Sun, 31 Jul 2016 07:51:08 +0000 Fabien Lelaquais
<Fabien.Lelaquais at roguewave.com> said:

> Thanks a lot for your answer.
> Unfortunately I may not be able to rely of the Composite extension (app would
> be deployed in environments I don't control).
> 
> Regarding the XGetImage documentation, that I've read ten times:
> My drawable (mainWindow) is indeed a viewable window.
> It has no inferior, and an overlapping window on its center. The specified
> rectangle that I provide, which is the center part of the source window, is
> both fully visible on the screen and wholly contained in mainWindow. I have
> no X error. And that's why I'm calling for help.

you won't get an x error unless the region ends up being out of screen bounds.

if pixels of a window are clipped by the screen, a parent window, a shape
rectangle list, or are covered by another window... they "do not exist" by
default in x11. that is how it works. that is why thomas suggested pixmap
redirection to ensure that pixels DO exist and force them to live in a pixmap
irrespective of windows overlapping or the window being offscreen. without this
you are in regular old x11 mode and if your source is a window... if at the
time you grab, you cannot SEE the pixels on a screen... they do not exist.
irrespective of if someone drew to them just before. you can never get them.
you can "deal with it" and get pixels by setting includeinferiors in your gc
subwindowmode before you grab. this will ignore clipping of overlapping windows
and just grab whatever is there in the framebuffer as long as your resulting
rectangle at the time x performs the grab is still within screen limits. this
will get you the content including overlapping window content. this is
effectively how you do screenshots in x11.

if the region is within screen limits of course... if it is not - problems. if
you are managed by a window manager there is always then a race condition where
the wm may have moved you off screen but you have not seen the event yet. you
can xgrabserver first, then get geometry of your window and translate relative
to root to ensure you have the correct clipping coordinates, getimage, then
xungrab server to work around the race (and please at least xflush or xsync
after the xungrabserver.

note. i'm totally ignoring multiple visuals and depths here. :) if your screen
consists of lots of windows with differing visuals and depths life gets
complex. xv also creates problems if it is using overlays and colorkeys. :)

> Thanks again,
> 
> Cheers,
> Fabien
> 
> -----Original Message-----
> From: Thomas L├╝bking [mailto:thomas.luebking at gmx.de] 
> Sent: samedi 30 juillet 2016 16:03
> To: Fabien Lelaquais <Fabien.Lelaquais at roguewave.com>
> Cc: xorg at freedesktop.org
> Subject: Re: Corrupted XImage retrieved from a Window area
> 
> On Sat, Jul 30, 2016 at 08:34:20AM +0000, Fabien Lelaquais wrote:
> >Hi all,
> >I'm trying to create an XImage that represents a rectangular portion of a
> >Window (because I need to be able to access the actual pixel values). My
> >experimentations show that if the source window has an hidden region
> >(overlapping window) and if the origin of the rectangle I query is not (0,
> >0), then the data is corrupted, resulting in pixels set to 0 in the image
> >data (and a black area in the XImage).
> >
> >I use a raw XGetImage.
> 
> You want to use XCompositeRedirectWindow. This redirects the window into a
> pixmap. (What compositors like xcompmgr do)
> 
> 
> From man XGetImage:
> -------------------
> If the drawable is a window, the window must be viewable, and it must be the
> case that if there were no inferiors or overlapping windows, the specified
> rectangle of the window would be fully visible on the screen and wholly
> contained within the outside edges of the window, or a BadMatch error results.
> 
> Cheers,
> Thomas
> _______________________________________________
> xorg at 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

-- 
------------- Codito, ergo sum - "I code, therefore I am" --------------
The Rasterman (Carsten Haitzler)    raster at rasterman.com



More information about the xorg mailing list