Efficiently read the average color of the screen content rendered by XBMC Efficiently read the average color of the screen content rendered by XBMC linux linux

Efficiently read the average color of the screen content rendered by XBMC


You should take a look at the source code of Boblight.

Extending Boblight seems like a viable alternative (if it does not support what you need already!).

If not, look at src/clients/ folder. boblight-getpixel.c (for MS Windows) and boblight-X11.c are 'pixel grabbers'; standalone programs that do exactly what you need, and then communicate the grabbed color to the boblight server.

In boblight-X11.c you have examples of using XShmGetImage or the slower XGetImage to read portions of the screen using X11/extensions/XShm.h, a portion of that code does:

[...]if(!XShmGetImage(dpy, root_win, xim, 0, 0, AllPlanes)){   sleep(1);   pthread_mutex_unlock(&grabmutex);   return;}XSync(dpy, True);for (x = 0; x < width; x += xadd){    for (y = 0; y < height; y += yadd)    {       pixel = XGetPixel(xim, x, y);       RGB[0] = (pixel >> 16) & 0xff;       RGB[1] = (pixel >>  8) & 0xff;       RGB[2] = (pixel >>  0) & 0xff;       /*add it to the RGB array*/       boblight_add_pixel (&config, RGB, x, y);   }}[...]