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

喜欢而已 提交于 2019-12-03 12:30:18

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);
   }
}

[...]
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!