[prev in list] [next in list] [prev in thread] [next in thread] 

List:       freedesktop-xcb
Subject:    Re: [Xcb] BitBlt like method?
From:       Nadeem Syed <nadeem0319 () hotmail ! com>
Date:       2009-11-26 2:18:04
Message-ID: BLU106-W20DDDE90AF94EB46D75F50C29B0 () phx ! gbl
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


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.



[CODE]



/**

 * Author: Nadeem Syed

 * Desc: Gets a color from the specified point(x, y) from the window id provided

 * 

 * @see http://lists.freedesktop.org/archives/xcb/2009-November/005343.html

 */



// Standard

#include <iostream>

#include <sys/time.h>



// Xlib's

#include <X11/Xlib.h>



// XCB's

#include <xcb/xcb.h>

#include <xcb/xproto.h>

#include <xcb/xcb_image.h>



#define WINDOW_ID_TO_USE 65011716



typedef struct BOUNDS {

    uint16_t x;

    uint16_t y;

    uint16_t width;

    uint16_t height;

} BOUNDS;



void GetColor(unsigned int color, bool useXCB);



XImage* Xlib_GetImage(Window screen, BOUNDS &bounds);

unsigned int Xlib_GetColor(int x, int y, XImage *img);

int Xlib_CountColors(void);



xcb_image_t* XCB_GetImage(xcb_window_t window, BOUNDS &bounds, uint8_t* &data);

unsigned int XCB_GetColor(int x, int y, xcb_image_t *img, uint8_t *data);

int XCB_CountColors(void);





/* 

    return interval of time (uses time.h) 

*/

double get_time (void) {

    struct timeval timev;           

    gettimeofday(&timev, NULL);

    return (double)timev.tv_sec + (((double)timev.tv_usec) / 1000000);

}



int main() {

    double start, xcbt, xlibt;

    

    start = get_time();

    GetColor(0, true);

    xcbt = get_time() - start;

    start = get_time();

    GetColor(0, false);

    xlibt = get_time() - start;

    std::cout << "XCB GetColor Time = " << xcbt << std::endl;

    std::cout << "Xlib GetColor Time = " << xlibt << std::endl;

    

    std::cout << "--- Counting Colors ---" << std::endl;

    start = get_time();

    int xcb_count = 0;

    for (int i = 0; i <= 19; i++)

        xcb_count = XCB_CountColors();

    xcbt = (get_time() - start) / 19;

    std::cout << "XCB Colors Counted = " << xcb_count << std::endl;

    std::cout << "XCB Time Took AVG  = " << xcbt << std::endl;

    start = get_time();

    int xlib_count;

    for (int i = 0; i <= 19; i++)

        xlib_count = Xlib_CountColors();

    xlibt = (get_time() - start) / 19;

    std::cout << "Xlib Colors Counted = " << xlib_count << std::endl;

    std::cout << "Xlib Time Took AVG  = " << xlibt << std::endl;

    

    return 0;

}



/**

 * Gets color using the specified library. (true = XCB, false = Xlib)

 */

void GetColor(unsigned int color, bool useXCB) {

    if (!useXCB) {

        BOUNDS bounds;

        XImage *img = Xlib_GetImage(WINDOW_ID_TO_USE, bounds);

        unsigned int c = Xlib_GetColor(39, 39, img);

        std::cout << "Xlib Get Color = " << c << std::endl;

    } else {

        uint8_t *data;

        BOUNDS bounds;

        xcb_image_t *img = XCB_GetImage(WINDOW_ID_TO_USE, bounds, data);

        unsigned int c = XCB_GetColor(39, 39, img, data);

        std::cout << "XCB Get Color = " << c << std::endl;

    }

}



/**

 * Xlib - Get Image

 */

XImage* Xlib_GetImage(Window screen, BOUNDS &bounds) {

    XImage* bitmap;

    Display *display = XOpenDisplay(NULL);

    XWindowAttributes attr;

    XGetWindowAttributes(display, screen, &attr);

    bounds.x = attr.x;

    bounds.y = attr.y;

    bounds.width = attr.width - bounds.x;

    bounds.height = attr.height - bounds.y;

    bitmap = XGetImage(display, screen, bounds.x, bounds.y, 

                       bounds.width, bounds.height, AllPlanes, ZPixmap);

    return bitmap;

}



/**

 * Xlib - Get Color

 */

unsigned int Xlib_GetColor(int x, int y, XImage *img) {

    unsigned char* data = (unsigned char*)img->data;

    int bpp = img->bits_per_pixel / 8;

    int loc = (y * bpp * img->width) + (bpp * x);

    return (data[loc] << 16) | (data[loc+1] << 8) | (data[loc+2]);

}



/**

 * Xlib - Count Colors

 */

int Xlib_CountColors(void) {

    BOUNDS bounds;

    XImage *img = Xlib_GetImage(WINDOW_ID_TO_USE, bounds);

    int color_count = 0;//bounds.width * bounds.height - 2;

    for (int w = 0; w < bounds.width; w++) {

        for (int h = 0; h < bounds.height; h++) {

            //std::cout << 

            Xlib_GetColor(w, h, img);

            color_count++;

        }

    }

    return color_count;

}



/**

 * XCB - Get image

 */

xcb_image_t* XCB_GetImage(xcb_window_t window, BOUNDS &bounds, uint8_t* &data) {

    xcb_connection_t *c = xcb_connect(NULL, NULL);

    xcb_image_format_t format = XCB_IMAGE_FORMAT_Z_PIXMAP;    

    xcb_get_geometry_cookie_t gcookie = xcb_get_geometry(c, window);

    xcb_get_geometry_reply_t *greply = xcb_get_geometry_reply(c, gcookie, NULL);

    bounds.x = greply->x;

    bounds.y = greply->y;

    bounds.width = greply->width - bounds.x;

    bounds.height = greply->height - bounds.y;

    xcb_get_image_cookie_t cookie = xcb_get_image(c, format, window, 

                                                  bounds.x, bounds.y, 

                                                  bounds.width, bounds.height, 

                                                  ~0);

    xcb_get_image_reply_t *reply = xcb_get_image_reply(c, cookie, NULL);

    data = xcb_get_image_data(reply);

    return xcb_image_create_native(c, greply->width, greply->height, format, 

                                   reply->depth, NULL, ~0, data);

}



/**

 * XCB - Get Color

 */

unsigned int XCB_GetColor(int x, int y, xcb_image_t *img, uint8_t *data) {

    int bpp = img->bpp / 8;

    int loc = (y * bpp * img->width) + (bpp * x);

    return (data[loc] << 16) | (data[loc+1] << 8) | data[loc+2];

}



/**

 * XCB - Count Colors

 */

int XCB_CountColors(void) {

    uint8_t *data;

    BOUNDS bounds;

    xcb_image_t *img = XCB_GetImage(WINDOW_ID_TO_USE, bounds, data);

    int color_count = 0;//bounds.width * bounds.height - 2;

    for (int w = 0; w < bounds.width; w++) {

        for (int h = 0; h < bounds.height; h++) {

            //std::cout << 

            XCB_GetColor(w, h, img, data);

            color_count++;

        }

    }

    return color_count;

}



[/CODE]


-- Some of my results

XCB Get Color = 2829099
Xlib Get Color = 2829099
XCB GetColor Time = 0.0155019
Xlib GetColor Time = 0.0166171
--- Counting Colors ---
XCB Colors Counted = 160321
XCB Time Took AVG  = 0.0175713
Xlib Colors Counted = 160321
Xlib Time Took AVG  = 0.0190249

XCB Get Color = 2829099
Xlib Get Color = 2829099
XCB GetColor Time = 0.0114239
Xlib GetColor Time = 0.0141051
--- Counting Colors ---
XCB Colors Counted = 160321
XCB Time Took AVG  = 0.0172025
Xlib Colors Counted = 160321
Xlib Time Took AVG  = 0.020595

XCB Get Color = 2829099
Xlib Get Color = 2829099
XCB GetColor Time = 0.0126981
Xlib GetColor Time = 0.013911
--- Counting Colors ---
XCB Colors Counted = 160321
XCB Time Took AVG  = 0.0174001
Xlib Colors Counted = 160321
Xlib Time Took AVG  = 0.0196311





~ Thanks

 		 	   		  
_________________________________________________________________
Ready. Set. Get a great deal on Windows 7. See fantastic deals on Windows 7 now
http://go.microsoft.com/?linkid=9691818
[Attachment #5 (text/html)]

<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>



_______________________________________________
Xcb mailing list
Xcb@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/xcb

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic