<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<p>I think I found the problem and sent a patch:</p>
<p><a class="moz-txt-link-freetext" href="https://lists.x.org/archives/xorg-devel/2016-August/050544.html">https://lists.x.org/archives/xorg-devel/2016-August/050544.html</a></p>
<p><a class="moz-txt-link-freetext" href="https://patchwork.freedesktop.org/patch/102574/">https://patchwork.freedesktop.org/patch/102574/</a><br>
</p>
<br>
<div class="moz-cite-prefix">On 08/01/2016 07:44 AM, Fabien
Lelaquais wrote:<br>
</div>
<blockquote
cite="mid:BY1PR0201MB10806EAF3532C22E15ABAA9288040@BY1PR0201MB1080.namprd02.prod.outlook.com"
type="cite">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Exchange Server">
<!-- converted from rtf -->
<style><!-- .EmailQuote { margin-left: 1pt; padding-left: 4pt; border-left: #800000 2px solid; } --></style>
<font face="Calibri" size="2"><span style="font-size:11pt;">
<div>Thansk again to you, Thomas, and Carsten.</div>
<div> </div>
<div>I suspect I still was not clear enough. My problem is not
the hidden pixels. I know they will be undefined (or I can
use an XCopyArea and process the GraphicsExpose events).</div>
<div> </div>
<div>My problem is that visible pixels (well defined, and in
this case, white) are retrieved as black pixels.</div>
<div> </div>
<div>To make things more clear, if you cannot reproduce my
problem.</div>
<div>I have two top windows A and B.</div>
<div>B is smaller than A, and located on top of it.</div>
<div>A is entirely on my screen (and B obviously is as well).</div>
<div> </div>
<div>Here what it looks like: (sorry guys, you'll need a
monospaced font to see this properly)</div>
<div><font face="Courier New">+------------+</font></div>
<div><font face="Courier New">| A |</font></div>
<div><font face="Courier New">| +-----+ |</font></div>
<div><font face="Courier New">| | B | |</font></div>
<div><font face="Courier New">| +-----+ |</font></div>
<div><font face="Courier New">+------------+</font></div>
<div> </div>
<div>If I XGetImage() from A a rectangle that contains the
area covered by B (but still inside A), what I expect is:</div>
<div><font face="Courier New">+------------+</font></div>
<div><font face="Courier New">| |</font></div>
<div><font face="Courier New">| ####### |</font></div>
<div><font face="Courier New">| ####### |</font></div>
<div><font face="Courier New">| ####### |</font></div>
<div><font face="Courier New">+------------+</font></div>
<div>Where the # signs indicate an undefined value: all the
pixels covered by B. Makes sense.</div>
<div> </div>
<div>But what I really get is:</div>
<div><font face="Courier New">+------------+</font></div>
<div><font face="Courier New">| |</font></div>
<div><font face="Courier New">| ######### |</font></div>
<div><font face="Courier New">| ######### |</font></div>
<div><font face="Courier New">| ######### |</font></div>
<div><font face="Courier New">+------------+</font></div>
<div>That is, more pixels are reported as undefined, to the
right of the expected 'undefined' region (the one covered by
B).</div>
<div>My experiments show that the more I translate the capture
rectangle to the right (limited to the surface of A), the
more undefined pixels I will get.<br>
If the capture rectangle has its left edge at 0 (on the A
left-hand border), the image is perfect. This makes no sense
at all.</div>
<div> </div>
<div>Unfortunately, I cannot rely on the BackingStore or other
properties: I may not be the one that created the Window
(I'm working on a library that sits on top of X).</div>
<div> </div>
<div>And yes, I suspect a bug in the server but honestly I
don't believe it.</div>
<div> </div>
<div>I tried this today: I can work the problem around by
creating a temporary Pixmap (the size of my capture area),
XCopyArea the window A into it, then XGetImage on that
Pixmap.</div>
<div>Then my image is fine, at the cost of an additional
Pixmap (potentially large) and a GC (where I dropped the
generation of GraphicsExpose events that I don't care
about).</div>
<div>All my pixels are correct, except the covered ones, which
is fair.</div>
<div> </div>
<div>Thanks!</div>
<div>Fabien</div>
<div> </div>
<div> </div>
<a moz-do-not-send="true" name="_MailEndCompose"></a>
<div> </div>
<div>-----Original Message-----<br>
From: Carsten Haitzler [<a moz-do-not-send="true"
href="mailto:raster@rasterman.com">mailto:raster@rasterman.com</a>]
<br>
Sent: lundi 1 août 2016 00:50<br>
To: Fabien Lelaquais <a class="moz-txt-link-rfc2396E" href="mailto:Fabien.Lelaquais@roguewave.com"><Fabien.Lelaquais@roguewave.com></a><br>
Cc: <a class="moz-txt-link-abbreviated" href="mailto:xorg@freedesktop.org">xorg@freedesktop.org</a><br>
Subject: Re: Corrupted XImage retrieved from a Window area</div>
<div> </div>
<div>On Sun, 31 Jul 2016 07:51:08 +0000 Fabien Lelaquais <<a
moz-do-not-send="true"
href="mailto:Fabien.Lelaquais@roguewave.com">Fabien.Lelaquais@roguewave.com</a>>
said:</div>
<div> </div>
<div>> Thanks a lot for your answer.</div>
<div>> Unfortunately I may not be able to rely of the
Composite extension </div>
<div>> (app would be deployed in environments I don't
control).</div>
<div>> </div>
<div>> Regarding the XGetImage documentation, that I've
read ten times:</div>
<div>> My drawable (mainWindow) is indeed a viewable
window.</div>
<div>> It has no inferior, and an overlapping window on its
center. The </div>
<div>> specified rectangle that I provide, which is the
center part of the </div>
<div>> source window, is both fully visible on the screen
and wholly </div>
<div>> contained in mainWindow. I have no X error. And
that's why I'm calling for help.</div>
<div> </div>
<div>you won't get an x error unless the region ends up being
out of screen bounds.</div>
<div> </div>
<div>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.</div>
<div>irrespective of if someone drew to them just before. you
can never get them.</div>
<div>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.</div>
<div> </div>
<div>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.</div>
<div> </div>
<div>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. :)</div>
<div> </div>
<div>> Thanks again,</div>
<div>> </div>
<div>> Cheers,</div>
<div>> Fabien</div>
<div>> </div>
<div>> -----Original Message-----</div>
<div>> From: Thomas Lübking [<a moz-do-not-send="true"
href="mailto:thomas.luebking@gmx.de">mailto:thomas.luebking@gmx.de</a>]</div>
<div>> Sent: samedi 30 juillet 2016 16:03</div>
<div>> To: Fabien Lelaquais <<a moz-do-not-send="true"
href="mailto:Fabien.Lelaquais@roguewave.com">Fabien.Lelaquais@roguewave.com</a>></div>
<div>> Cc: <a moz-do-not-send="true"
href="mailto:xorg@freedesktop.org">xorg@freedesktop.org</a></div>
<div>> Subject: Re: Corrupted XImage retrieved from a
Window area</div>
<div>> </div>
<div>> On Sat, Jul 30, 2016 at 08:34:20AM +0000, Fabien
Lelaquais wrote:</div>
<div>> >Hi all,</div>
<div>> >I'm trying to create an XImage that represents a
rectangular portion </div>
<div>> >of a Window (because I need to be able to access
the actual pixel </div>
<div>> >values). My experimentations show that if the
source window has an </div>
<div>> >hidden region (overlapping window) and if the
origin of the rectangle </div>
<div>> >I query is not (0, 0), then the data is
corrupted, resulting in </div>
<div>> >pixels set to 0 in the image data (and a black
area in the XImage).</div>
<div>> ></div>
<div>> >I use a raw XGetImage.</div>
<div>> </div>
<div>> You want to use XCompositeRedirectWindow. This
redirects the window </div>
<div>> into a pixmap. (What compositors like xcompmgr do)</div>
<div>> </div>
<div>> </div>
<div>> From man XGetImage:</div>
<div>> -------------------</div>
<div>> If the drawable is a window, the window must be
viewable, and it must </div>
<div>> be the case that if there were no inferiors or
overlapping windows, </div>
<div>> the specified rectangle of the window would be fully
visible on the </div>
<div>> screen and wholly contained within the outside edges
of the window, or a BadMatch error results.</div>
<div>> </div>
<div>> Cheers,</div>
<div>> Thomas</div>
<div>> _______________________________________________</div>
<div>> <a moz-do-not-send="true"
href="mailto:xorg@lists.x.org">xorg@lists.x.org</a>: X.Org
support</div>
<div>> Archives: <a moz-do-not-send="true"
href="http://lists.freedesktop.org/archives/xorg">http://lists.freedesktop.org/archives/xorg</a></div>
<div>> Info: <a moz-do-not-send="true"
href="https://lists.x.org/mailman/listinfo/xorg">https://lists.x.org/mailman/listinfo/xorg</a></div>
<div>> Your subscription address: %(user_address)s</div>
<div> </div>
<div>--</div>
<div>------------- Codito, ergo sum - "I code, therefore I am"
--------------</div>
<div>The Rasterman (Carsten Haitzler) <a
moz-do-not-send="true" href="mailto:raster@rasterman.com">raster@rasterman.com</a></div>
<div> </div>
<div> </div>
</span></font>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
<a class="moz-txt-link-abbreviated" href="mailto:xorg@lists.x.org">xorg@lists.x.org</a>: X.Org support
Archives: <a class="moz-txt-link-freetext" href="http://lists.freedesktop.org/archives/xorg">http://lists.freedesktop.org/archives/xorg</a>
Info: <a class="moz-txt-link-freetext" href="https://lists.x.org/mailman/listinfo/xorg">https://lists.x.org/mailman/listinfo/xorg</a>
Your subscription address: %(user_address)s</pre>
</blockquote>
nvpublic<br>
</body>
</html>