<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Verdana
}
--></style>
</head>
<body class='hmmessage'>
<br>
Here is what I put together with the help of everyone =) I've also
added in it as a test code with Xlib to compare speeds and etc...
Posted the code at: http://pastebin.com/f34fa2d3f aswell for better
view.<br>
<br>
[CODE]<br>
<br>
<font style="font-size: 8pt;" size="1">/**</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;* Author: Nadeem Syed</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;* Desc: Gets a color from the specified point(x, y) from the window id provided</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;* </font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;* @see http://lists.freedesktop.org/archives/xcb/2009-November/005343.html</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;*/</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">// Standard</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">#include &lt;iostream&gt;</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">#include &lt;sys/time.h&gt;</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">// Xlib's</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">#include &lt;X11/Xlib.h&gt;</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">// XCB's</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">#include &lt;xcb/xcb.h&gt;</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">#include &lt;xcb/xproto.h&gt;</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">#include &lt;xcb/xcb_image.h&gt;</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">#define WINDOW_ID_TO_USE 65011716</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">typedef struct BOUNDS {</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; uint16_t x;</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; uint16_t y;</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; uint16_t width;</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; uint16_t height;</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">} BOUNDS;</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">void GetColor(unsigned int color, bool useXCB);</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">XImage* Xlib_GetImage(Window screen, BOUNDS &amp;bounds);</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">unsigned int Xlib_GetColor(int x, int y, XImage *img);</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">int Xlib_CountColors(void);</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">xcb_image_t* XCB_GetImage(xcb_window_t window, BOUNDS &amp;bounds, uint8_t* &amp;data);</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">unsigned int XCB_GetColor(int x, int y, xcb_image_t *img, uint8_t *data);</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">int XCB_CountColors(void);</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">/* </font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; return interval of time (uses time.h) </font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">*/</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">double get_time (void) {</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; struct timeval timev;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; gettimeofday(&amp;timev, NULL);</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; return (double)timev.tv_sec + (((double)timev.tv_usec) / 1000000);</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">}</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">int main() {</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; double start, xcbt, xlibt;</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; </font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; start = get_time();</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; GetColor(0, true);</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; xcbt = get_time() - start;</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; start = get_time();</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; GetColor(0, false);</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; xlibt = get_time() - start;</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; std::cout &lt;&lt; "XCB GetColor Time = " &lt;&lt; xcbt &lt;&lt; std::endl;</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; std::cout &lt;&lt; "Xlib GetColor Time = " &lt;&lt; xlibt &lt;&lt; std::endl;</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; </font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; std::cout &lt;&lt; "--- Counting Colors ---" &lt;&lt; std::endl;</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; start = get_time();</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; int xcb_count = 0;</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; for (int i = 0; i &lt;= 19; i++)</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; xcb_count = XCB_CountColors();</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; xcbt = (get_time() - start) / 19;</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; std::cout &lt;&lt; "XCB Colors Counted = " &lt;&lt; xcb_count &lt;&lt; std::endl;</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; std::cout &lt;&lt; "XCB Time Took AVG&nbsp; = " &lt;&lt; xcbt &lt;&lt; std::endl;</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; start = get_time();</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; int xlib_count;</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; for (int i = 0; i &lt;= 19; i++)</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; xlib_count = Xlib_CountColors();</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; xlibt = (get_time() - start) / 19;</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; std::cout &lt;&lt; "Xlib Colors Counted = " &lt;&lt; xlib_count &lt;&lt; std::endl;</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; std::cout &lt;&lt; "Xlib Time Took AVG&nbsp; = " &lt;&lt; xlibt &lt;&lt; std::endl;</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; </font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; return 0;</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">}</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">/**</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;* Gets color using the specified library. (true = XCB, false = Xlib)</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;*/</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">void GetColor(unsigned int color, bool useXCB) {</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; if (!useXCB) {</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; BOUNDS bounds;</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; XImage *img = Xlib_GetImage(WINDOW_ID_TO_USE, bounds);</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; unsigned int c = Xlib_GetColor(39, 39, img);</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; std::cout &lt;&lt; "Xlib Get Color = " &lt;&lt; c &lt;&lt; std::endl;</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; } else {</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; uint8_t *data;</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; BOUNDS bounds;</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; xcb_image_t *img = XCB_GetImage(WINDOW_ID_TO_USE, bounds, data);</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; unsigned int c = XCB_GetColor(39, 39, img, data);</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; std::cout &lt;&lt; "XCB Get Color = " &lt;&lt; c &lt;&lt; std::endl;</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; }</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">}</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">/**</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;* Xlib - Get Image</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;*/</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">XImage* Xlib_GetImage(Window screen, BOUNDS &amp;bounds) {</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; XImage* bitmap;</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; Display *display = XOpenDisplay(NULL);</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; XWindowAttributes attr;</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; XGetWindowAttributes(display, screen, &amp;attr);</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; bounds.x = attr.x;</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; bounds.y = attr.y;</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; bounds.width = attr.width - bounds.x;</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; bounds.height = attr.height - bounds.y;</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; bitmap = XGetImage(display, screen, bounds.x, bounds.y, </font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; bounds.width, bounds.height, AllPlanes, ZPixmap);</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; return bitmap;</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">}</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">/**</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;* Xlib - Get Color</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;*/</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">unsigned int Xlib_GetColor(int x, int y, XImage *img) {</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; unsigned char* data = (unsigned char*)img-&gt;data;</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; int bpp = img-&gt;bits_per_pixel / 8;</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; int loc = (y * bpp * img-&gt;width) + (bpp * x);</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; return (data[loc] &lt;&lt; 16) | (data[loc+1] &lt;&lt; 8) | (data[loc+2]);</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">}</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">/**</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;* Xlib - Count Colors</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;*/</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">int Xlib_CountColors(void) {</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; BOUNDS bounds;</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; XImage *img = Xlib_GetImage(WINDOW_ID_TO_USE, bounds);</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; int color_count = 0;//bounds.width * bounds.height - 2;</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; for (int w = 0; w &lt; bounds.width; w++) {</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for (int h = 0; h &lt; bounds.height; h++) {</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; //std::cout &lt;&lt; </font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Xlib_GetColor(w, h, img);</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; color_count++;</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; }</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; return color_count;</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">}</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">/**</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;* XCB - Get image</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;*/</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">xcb_image_t* XCB_GetImage(xcb_window_t window, BOUNDS &amp;bounds, uint8_t* &amp;data) {</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; xcb_connection_t *c = xcb_connect(NULL, NULL);</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; xcb_image_format_t format = XCB_IMAGE_FORMAT_Z_PIXMAP;&nbsp;&nbsp;&nbsp; </font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; xcb_get_geometry_cookie_t gcookie = xcb_get_geometry(c, window);</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; xcb_get_geometry_reply_t *greply = xcb_get_geometry_reply(c, gcookie, NULL);</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; bounds.x = greply-&gt;x;</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; bounds.y = greply-&gt;y;</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; bounds.width = greply-&gt;width - bounds.x;</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; bounds.height = greply-&gt;height - bounds.y;</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; xcb_get_image_cookie_t cookie = xcb_get_image(c, format, window, </font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; bounds.x, bounds.y, </font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; bounds.width, bounds.height, </font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; ~0);</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; xcb_get_image_reply_t *reply = xcb_get_image_reply(c, cookie, NULL);</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; data = xcb_get_image_data(reply);</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; return xcb_image_create_native(c, greply-&gt;width, greply-&gt;height, format, </font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; reply-&gt;depth, NULL, ~0, data);</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">}</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">/**</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;* XCB - Get Color</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;*/</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">unsigned int XCB_GetColor(int x, int y, xcb_image_t *img, uint8_t *data) {</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; int bpp = img-&gt;bpp / 8;</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; int loc = (y * bpp * img-&gt;width) + (bpp * x);</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; return (data[loc] &lt;&lt; 16) | (data[loc+1] &lt;&lt; 8) | data[loc+2];</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">}</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">/**</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;* XCB - Count Colors</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;*/</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">int XCB_CountColors(void) {</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; uint8_t *data;</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; BOUNDS bounds;</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; xcb_image_t *img = XCB_GetImage(WINDOW_ID_TO_USE, bounds, data);</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; int color_count = 0;//bounds.width * bounds.height - 2;</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; for (int w = 0; w &lt; bounds.width; w++) {</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for (int h = 0; h &lt; bounds.height; h++) {</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; //std::cout &lt;&lt; </font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; XCB_GetColor(w, h, img, data);</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; color_count++;</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; }</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">&nbsp;&nbsp;&nbsp; return color_count;</font><font style="font-size: 8pt;" size="1"><br>
</font><font style="font-size: 8pt;" size="1">}</font><br>
<br>
[/CODE]<br><br><br>-- Some of my results<br><font style="font-size: 8pt;" size="1"><br></font><font style="font-size: 8pt;" size="1">XCB Get Color = 2829099</font><font style="font-size: 8pt;" size="1"><br></font><font style="font-size: 8pt;" size="1">Xlib Get Color = 2829099</font><font style="font-size: 8pt;" size="1"><br></font><font style="font-size: 8pt;" size="1">XCB GetColor Time = 0.0155019</font><font style="font-size: 8pt;" size="1"><br></font><font style="font-size: 8pt;" size="1">Xlib GetColor Time = 0.0166171</font><font style="font-size: 8pt;" size="1"><br></font><font style="font-size: 8pt;" size="1">--- Counting Colors ---</font><font style="font-size: 8pt;" size="1"><br></font><font style="font-size: 8pt;" size="1">XCB Colors Counted = 160321</font><font style="font-size: 8pt;" size="1"><br></font><font style="font-size: 8pt;" size="1">XCB Time Took AVG&nbsp; = 0.0175713</font><font style="font-size: 8pt;" size="1"><br></font><font style="font-size: 8pt;" size="1">Xlib Colors Counted = 160321</font><font style="font-size: 8pt;" size="1"><br></font><font style="font-size: 8pt;" size="1">Xlib Time Took AVG&nbsp; = 0.0190249</font><font style="font-size: 8pt;" size="1"><br></font><font style="font-size: 8pt;" size="1"><br></font><font style="font-size: 8pt;" size="1">XCB Get Color = 2829099</font><font style="font-size: 8pt;" size="1"><br></font><font style="font-size: 8pt;" size="1">Xlib Get Color = 2829099</font><font style="font-size: 8pt;" size="1"><br></font><font style="font-size: 8pt;" size="1">XCB GetColor Time = 0.0114239</font><font style="font-size: 8pt;" size="1"><br></font><font style="font-size: 8pt;" size="1">Xlib GetColor Time = 0.0141051</font><font style="font-size: 8pt;" size="1"><br></font><font style="font-size: 8pt;" size="1">--- Counting Colors ---</font><font style="font-size: 8pt;" size="1"><br></font><font style="font-size: 8pt;" size="1">XCB Colors Counted = 160321</font><font style="font-size: 8pt;" size="1"><br></font><font style="font-size: 8pt;" size="1">XCB Time Took AVG&nbsp; = 0.0172025</font><font style="font-size: 8pt;" size="1"><br></font><font style="font-size: 8pt;" size="1">Xlib Colors Counted = 160321</font><font style="font-size: 8pt;" size="1"><br></font><font style="font-size: 8pt;" size="1">Xlib Time Took AVG&nbsp; = 0.020595</font><font style="font-size: 8pt;" size="1"><br></font><font style="font-size: 8pt;" size="1"><br></font><font style="font-size: 8pt;" size="1">XCB Get Color = 2829099</font><font style="font-size: 8pt;" size="1"><br></font><font style="font-size: 8pt;" size="1">Xlib Get Color = 2829099</font><font style="font-size: 8pt;" size="1"><br></font><font style="font-size: 8pt;" size="1">XCB GetColor Time = 0.0126981</font><font style="font-size: 8pt;" size="1"><br></font><font style="font-size: 8pt;" size="1">Xlib GetColor Time = 0.013911</font><font style="font-size: 8pt;" size="1"><br></font><font style="font-size: 8pt;" size="1">--- Counting Colors ---</font><font style="font-size: 8pt;" size="1"><br></font><font style="font-size: 8pt;" size="1">XCB Colors Counted = 160321</font><font style="font-size: 8pt;" size="1"><br></font><font style="font-size: 8pt;" size="1">XCB Time Took AVG&nbsp; = 0.0174001</font><font style="font-size: 8pt;" size="1"><br></font><font style="font-size: 8pt;" size="1">Xlib Colors Counted = 160321</font><font style="font-size: 8pt;" size="1"><br></font><font style="font-size: 8pt;" size="1">Xlib Time Took AVG&nbsp; = 0.0196311</font><font style="font-size: 8pt;" size="1"><br><br><br></font>
<br>
~ Thanks<br>
                                               <br /><hr />Get a great deal on Windows 7 and see how it works the way you want. <a href='http://go.microsoft.com/?linkid=9691813' target='_new'>See the Windows 7 offers now.</a></body>
</html>