高效读取XBMC渲染的屏幕内容的平均颜色

高效读取XBMC渲染的屏幕内容的平均颜色

本文介绍了高效读取XBMC渲染的屏幕内容的平均颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在运行XBMC来更改电视环境光的颜色时获得屏幕内容的平均颜色. XBMC运行在带有OpenGL ES 2.0硬件(树莓派)的小型HTPC上,该硬件运行Debian衍生的发行版.我想我必须从屏幕上读取帧缓冲区,在该屏幕上XBMC使用OpenGL进行绘制. (至少,我认为并希望XBMC使用OpenGL渲染所有内容.)

I want to get the average color of the screen content when running XBMC to change the color of a TV ambient light. XBMC is running on a small HTPC with OpenGL ES 2.0 hardware (Raspberry Pi) running a Debian-derived distribution. I guess I have to read from the screen frame buffer in which XBMC draws using OpenGL. (At least, I think and hope that XBMC renders everything using OpenGL.)

是否可以读取表示整个屏幕输出的OpenGL帧缓冲区?我需要访问什么?我还需要一个自己的渲染上下文来访问屏幕的帧缓冲区吗? (我自己没有在屏幕上渲染任何东西,我只想 read ).

Is it possible to read the OpenGL frame buffer representing the whole screen output? What am I going to need to access it? Do I also need an own render context to access the frame buffer of the screen? (I don't render anything by myself to the screen, I only want to read).

下一个任务是有效计算平均颜色.我正在考虑读取每行/列的第8或16个像素(就足够了,我们正在谈论1080p高清电影),然后计算CPU的平均值.欢迎提供更好解决方案的任何想法.

Efficiently calculating the average color is the next task. I'm thinking about reading every 8th or 16th pixel per row/column (would be enough, we are talking about 1080p HD movies) and then calculating the average on the CPU. Any ideas for a better solution are welcome.

推荐答案

您应该看看 Boblight的源代码.

扩展Boblight似乎是一个可行的选择(如果它不支持您已经需要的东西!).

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

如果没有,请查看src/clients/文件夹. boblight-getpixel.c(对于MS Windows)和boblight-X11.c是像素抓取器";独立程序,可以完全满足您的需要,然后将抓取的颜色传达给boblight服务器.

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.

boblight-X11.c中,您有使用XShmGetImage或更慢的XGetImage来使用X11/extensions/XShm.h读取屏幕部分的示例,该代码的一部分可以做到:

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

[...]

这篇关于高效读取XBMC渲染的屏幕内容的平均颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 15:23