[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"> * Author: Nadeem \
Syed</font><font style="font-size: 8pt;" size="1"><br> </font><font style="font-size: \
8pt;" size="1"> * 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"> * </font><font style="font-size: 8pt;" \
size="1"><br> </font><font style="font-size: 8pt;" size="1"> * @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"> */</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 <iostream></font><font \
style="font-size: 8pt;" size="1"><br> </font><font style="font-size: 8pt;" \
size="1">#include <sys/time.h></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 \
<X11/Xlib.h></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 <xcb/xcb.h></font><font \
style="font-size: 8pt;" size="1"><br> </font><font style="font-size: 8pt;" \
size="1">#include <xcb/xproto.h></font><font style="font-size: 8pt;" \
size="1"><br> </font><font style="font-size: 8pt;" size="1">#include \
<xcb/xcb_image.h></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"> uint16_t x;</font><font style="font-size: 8pt;" \
size="1"><br> </font><font style="font-size: 8pt;" size="1"> \
uint16_t y;</font><font style="font-size: 8pt;" size="1"><br> </font><font \
style="font-size: 8pt;" size="1"> uint16_t width;</font><font \
style="font-size: 8pt;" size="1"><br> </font><font style="font-size: 8pt;" \
size="1"> 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 &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 &bounds, uint8_t* &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"> 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"> struct timeval \
timev; </font><font \
style="font-size: 8pt;" size="1"><br> </font><font style="font-size: 8pt;" \
size="1"> gettimeofday(&timev, NULL);</font><font \
style="font-size: 8pt;" size="1"><br> </font><font style="font-size: 8pt;" \
size="1"> 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"> double start, xcbt, \
xlibt;</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"> \
start = get_time();</font><font style="font-size: 8pt;" size="1"><br> </font><font \
style="font-size: 8pt;" size="1"> GetColor(0, true);</font><font \
style="font-size: 8pt;" size="1"><br> </font><font style="font-size: 8pt;" \
size="1"> xcbt = get_time() - start;</font><font style="font-size: \
8pt;" size="1"><br> </font><font style="font-size: 8pt;" size="1"> \
start = get_time();</font><font style="font-size: 8pt;" size="1"><br> </font><font \
style="font-size: 8pt;" size="1"> GetColor(0, false);</font><font \
style="font-size: 8pt;" size="1"><br> </font><font style="font-size: 8pt;" \
size="1"> xlibt = get_time() - start;</font><font style="font-size: \
8pt;" size="1"><br> </font><font style="font-size: 8pt;" size="1"> \
std::cout << "XCB GetColor Time = " << xcbt << \
std::endl;</font><font style="font-size: 8pt;" size="1"><br> </font><font \
style="font-size: 8pt;" size="1"> std::cout << "Xlib GetColor \
Time = " << xlibt << std::endl;</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"> std::cout << "--- Counting Colors ---" \
<< std::endl;</font><font style="font-size: 8pt;" size="1"><br> </font><font \
style="font-size: 8pt;" size="1"> start = get_time();</font><font \
style="font-size: 8pt;" size="1"><br> </font><font style="font-size: 8pt;" \
size="1"> int xcb_count = 0;</font><font style="font-size: 8pt;" \
size="1"><br> </font><font style="font-size: 8pt;" size="1"> for \
(int i = 0; i <= 19; i++)</font><font style="font-size: 8pt;" size="1"><br> \
</font><font style="font-size: 8pt;" size="1"> \
xcb_count = XCB_CountColors();</font><font style="font-size: 8pt;" size="1"><br> \
</font><font style="font-size: 8pt;" size="1"> xcbt = (get_time() - \
start) / 19;</font><font style="font-size: 8pt;" size="1"><br> </font><font \
style="font-size: 8pt;" size="1"> std::cout << "XCB Colors \
Counted = " << xcb_count << std::endl;</font><font style="font-size: \
8pt;" size="1"><br> </font><font style="font-size: 8pt;" size="1"> \
std::cout << "XCB Time Took AVG = " << xcbt << \
std::endl;</font><font style="font-size: 8pt;" size="1"><br> </font><font \
style="font-size: 8pt;" size="1"> start = get_time();</font><font \
style="font-size: 8pt;" size="1"><br> </font><font style="font-size: 8pt;" \
size="1"> int xlib_count;</font><font style="font-size: 8pt;" \
size="1"><br> </font><font style="font-size: 8pt;" size="1"> for \
(int i = 0; i <= 19; i++)</font><font style="font-size: 8pt;" size="1"><br> \
</font><font style="font-size: 8pt;" size="1"> \
xlib_count = Xlib_CountColors();</font><font style="font-size: 8pt;" size="1"><br> \
</font><font style="font-size: 8pt;" size="1"> xlibt = (get_time() \
- start) / 19;</font><font style="font-size: 8pt;" size="1"><br> </font><font \
style="font-size: 8pt;" size="1"> std::cout << "Xlib Colors \
Counted = " << xlib_count << std::endl;</font><font style="font-size: \
8pt;" size="1"><br> </font><font style="font-size: 8pt;" size="1"> \
std::cout << "Xlib Time Took AVG = " << xlibt << \
std::endl;</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"> \
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"> * 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"> */</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"> if \
(!useXCB) {</font><font style="font-size: 8pt;" size="1"><br> </font><font \
style="font-size: 8pt;" size="1"> BOUNDS \
bounds;</font><font style="font-size: 8pt;" size="1"><br> </font><font \
style="font-size: 8pt;" size="1"> 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"> \
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"> std::cout << "Xlib Get Color = " \
<< c << std::endl;</font><font style="font-size: 8pt;" size="1"><br> \
</font><font style="font-size: 8pt;" size="1"> } else {</font><font \
style="font-size: 8pt;" size="1"><br> </font><font style="font-size: 8pt;" \
size="1"> uint8_t *data;</font><font \
style="font-size: 8pt;" size="1"><br> </font><font style="font-size: 8pt;" \
size="1"> BOUNDS bounds;</font><font \
style="font-size: 8pt;" size="1"><br> </font><font style="font-size: 8pt;" \
size="1"> 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"> \
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"> std::cout << "XCB Get Color = " \
<< c << std::endl;</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">}</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"> * Xlib - Get Image</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">XImage* Xlib_GetImage(Window screen, BOUNDS \
&bounds) {</font><font style="font-size: 8pt;" size="1"><br> </font><font \
style="font-size: 8pt;" size="1"> XImage* bitmap;</font><font \
style="font-size: 8pt;" size="1"><br> </font><font style="font-size: 8pt;" \
size="1"> Display *display = XOpenDisplay(NULL);</font><font \
style="font-size: 8pt;" size="1"><br> </font><font style="font-size: 8pt;" \
size="1"> XWindowAttributes attr;</font><font style="font-size: \
8pt;" size="1"><br> </font><font style="font-size: 8pt;" size="1"> \
XGetWindowAttributes(display, screen, &attr);</font><font style="font-size: 8pt;" \
size="1"><br> </font><font style="font-size: 8pt;" size="1"> \
bounds.x = attr.x;</font><font style="font-size: 8pt;" size="1"><br> </font><font \
style="font-size: 8pt;" size="1"> bounds.y = attr.y;</font><font \
style="font-size: 8pt;" size="1"><br> </font><font style="font-size: 8pt;" \
size="1"> bounds.width = attr.width - bounds.x;</font><font \
style="font-size: 8pt;" size="1"><br> </font><font style="font-size: 8pt;" \
size="1"> bounds.height = attr.height - bounds.y;</font><font \
style="font-size: 8pt;" size="1"><br> </font><font style="font-size: 8pt;" \
size="1"> 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"> \
bounds.width, bounds.height, \
AllPlanes, ZPixmap);</font><font style="font-size: 8pt;" size="1"><br> </font><font \
style="font-size: 8pt;" size="1"> 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"> * Xlib - Get Color</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">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"> unsigned char* data = (unsigned \
char*)img->data;</font><font style="font-size: 8pt;" size="1"><br> </font><font \
style="font-size: 8pt;" size="1"> int bpp = img->bits_per_pixel \
/ 8;</font><font style="font-size: 8pt;" size="1"><br> </font><font style="font-size: \
8pt;" size="1"> int loc = (y * bpp * img->width) + (bpp * \
x);</font><font style="font-size: 8pt;" size="1"><br> </font><font style="font-size: \
8pt;" size="1"> return (data[loc] << 16) | (data[loc+1] \
<< 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"> * Xlib - Count \
Colors</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">int \
Xlib_CountColors(void) {</font><font style="font-size: 8pt;" size="1"><br> \
</font><font style="font-size: 8pt;" size="1"> BOUNDS \
bounds;</font><font style="font-size: 8pt;" size="1"><br> </font><font \
style="font-size: 8pt;" size="1"> 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"> 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"> \
for (int w = 0; w < bounds.width; w++) {</font><font style="font-size: 8pt;" \
size="1"><br> </font><font style="font-size: 8pt;" size="1"> \
for (int h = 0; h < bounds.height; h++) {</font><font \
style="font-size: 8pt;" size="1"><br> </font><font style="font-size: 8pt;" \
size="1"> //std::cout \
<< </font><font style="font-size: 8pt;" size="1"><br> </font><font \
style="font-size: 8pt;" size="1"> \
Xlib_GetColor(w, h, img);</font><font style="font-size: 8pt;" \
size="1"><br> </font><font style="font-size: 8pt;" size="1"> \
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"> }</font><font style="font-size: \
8pt;" size="1"><br> </font><font style="font-size: 8pt;" size="1"> \
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"> * XCB - Get image</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">xcb_image_t* XCB_GetImage(xcb_window_t window, \
BOUNDS &bounds, uint8_t* &data) {</font><font style="font-size: 8pt;" \
size="1"><br> </font><font style="font-size: 8pt;" size="1"> \
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"> \
xcb_image_format_t format = XCB_IMAGE_FORMAT_Z_PIXMAP; </font><font \
style="font-size: 8pt;" size="1"><br> </font><font style="font-size: 8pt;" \
size="1"> 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"> 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"> \
bounds.x = greply->x;</font><font style="font-size: 8pt;" size="1"><br> \
</font><font style="font-size: 8pt;" size="1"> bounds.y = \
greply->y;</font><font style="font-size: 8pt;" size="1"><br> </font><font \
style="font-size: 8pt;" size="1"> bounds.width = greply->width - \
bounds.x;</font><font style="font-size: 8pt;" size="1"><br> </font><font \
style="font-size: 8pt;" size="1"> bounds.height = greply->height \
- bounds.y;</font><font style="font-size: 8pt;" size="1"><br> </font><font \
style="font-size: 8pt;" size="1"> 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"> \
\
\
bounds.x, bounds.y, </font><font \
style="font-size: 8pt;" size="1"><br> </font><font style="font-size: 8pt;" \
size="1"> \
\
\
bounds.width, bounds.height, </font><font style="font-size: 8pt;" size="1"><br> \
</font><font style="font-size: 8pt;" size="1"> \
\
\
~0);</font><font style="font-size: 8pt;" \
size="1"><br> </font><font style="font-size: 8pt;" size="1"> \
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"> data = xcb_get_image_data(reply);</font><font \
style="font-size: 8pt;" size="1"><br> </font><font style="font-size: 8pt;" \
size="1"> return xcb_image_create_native(c, greply->width, \
greply->height, format, </font><font style="font-size: 8pt;" size="1"><br> \
</font><font style="font-size: 8pt;" size="1"> \
\
reply->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"> * XCB - Get Color</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">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 bpp = img->bpp / \
8;</font><font style="font-size: 8pt;" size="1"><br> </font><font style="font-size: \
8pt;" size="1"> int loc = (y * bpp * img->width) + (bpp * \
x);</font><font style="font-size: 8pt;" size="1"><br> </font><font style="font-size: \
8pt;" size="1"> return (data[loc] << 16) | (data[loc+1] \
<< 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"> * XCB - Count \
Colors</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">int XCB_CountColors(void) \
{</font><font style="font-size: 8pt;" size="1"><br> </font><font style="font-size: \
8pt;" size="1"> uint8_t *data;</font><font style="font-size: 8pt;" \
size="1"><br> </font><font style="font-size: 8pt;" size="1"> BOUNDS \
bounds;</font><font style="font-size: 8pt;" size="1"><br> </font><font \
style="font-size: 8pt;" size="1"> 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"> 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"> \
for (int w = 0; w < bounds.width; w++) {</font><font style="font-size: 8pt;" \
size="1"><br> </font><font style="font-size: 8pt;" size="1"> \
for (int h = 0; h < bounds.height; h++) {</font><font \
style="font-size: 8pt;" size="1"><br> </font><font style="font-size: 8pt;" \
size="1"> //std::cout \
<< </font><font style="font-size: 8pt;" size="1"><br> </font><font \
style="font-size: 8pt;" size="1"> \
XCB_GetColor(w, h, img, data);</font><font style="font-size: 8pt;" \
size="1"><br> </font><font style="font-size: 8pt;" size="1"> \
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"> }</font><font style="font-size: \
8pt;" size="1"><br> </font><font style="font-size: 8pt;" size="1"> \
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 = \
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 = 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 = 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 = \
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 = \
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 = 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