Get Average Colour From Texture?

Hello,

Is it possible to get grab every pixel colour from a texture within the scene (applied to a quad), and find the average colour that is being used?

I ask because I want to know how ‘bright’ the texture is, which will in turn will affect the intensity of a spotlight. Eg: if the texture is fairly bright, and over exposed on average, then the spotlight intensity will be pretty bright and strong. And vise versa.

Thanks

To calculate the brightness of a color you could try this method and then calculate the average brightness of all returned values (not tested):

private int Brightness(Color c)
{
    return (int)Mathf.Sqrt(
       c.R * c.R * .241 + 
       c.G * c.G * .691 + 
       c.B * c.B * .068);
}

@Edit

To get the pixels of a Texture2D just call GetPixels() or GetPixels32()

Texture2D destTex = new Texture2D(width, height);
Color[] pixels = destTex.GetPixels();

sources:
http://www.nbdtech.com/Blog/archive/2008/04/27/Calculating-the-Perceived-Brightness-of-a-Color.aspx
http://docs.unity3d.com/Documentation/ScriptReference/Texture2D.GetPixels.html