Example:
time gm import -verbose -window 0x02000016 /dev/shm/img.bmp
/dev/shm/img.bmp PS 484x316+0+0 DirectClass 8-bit 0.000u 0:01
/dev/shm/img.bmp BMP 484x316+0+0 DirectClass 8-bit 448.0K 0.000u 0:01
real 0m0.856s
user 0m0.007s
sys 0m0.020s
This is absolutely reproducable. The reason of clowness is that gm just sleepsfor 0.8 s. Here is the fix:
$ diff -u magick/xwindow.c_original magick/xwindow.c
--- magick/xwindow.c_original 2012-09-02 14:32:49.877801700 +0400
+++ magick/xwindow.c 2012-09-02 14:37:21.240979988 +0400
@@ -5017,7 +5017,6 @@
if (!ximage_info->frame && prior_target)
target=prior_target;
(void) XRaiseWindow(display,target);
- MagickXDelay(display,SuspendTime << 4);
}
}
if (ximage_info->screen)
It seems this this delay was introduced long tima ago, even before gm forked off imagemagick. In imagemagick it is laready fixed though http://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=16033
"(void) XRaiseWindow(display,target);" also seems unneeded. Probably it was added to enable importing of minimized windows, but it does not help. Importing minimized windows fails when redirection is turned off with XRaiseWindow as without it.
The raise request and the delay are there to support capturing windows which lack backing store (a pre-rendered image of the window cached in the X11 server) and/or need to be refreshed by Expose events. The import code was written in the early to mid '90s and it is likely that the behavior of X11 implementations and window managers has changed since then. Memory is much cheaper now and computers are a whole lot faster.
A Google search with the query "X11 backing store" reveals that backing store issues are still relevant. If the raise and delay are entirely removed then some data in the capture may be missing and this is X11 server, window manager, and application dependent.
I did a test with ImageMagick's import and was able to get it to fail in various ways (some pretty terrible) when capturing a partially-obscured window but GM worked every time. The program I used to test captures on is X11's 'xev' event tester program.
I agree that since X11 servers and programs run much faster now, it may be safe to lessen the delay, but X11 connections over a network (e.g. over the Internet) might still be impacted because they have more re-display delay.
A bad screen capture produced by ImageMagick
I do not plan to "fix" the screen capture delay issue since the delay is necessary in order to assure a correct capture.