Consider the screen content when calculating the ideal brightness.

I modified the code in 2 ways:
- calculate the brightness differently in order to get a result in the range 0-255 (I tested it and it looks like it works)
- take into account what is shown on the screen when calculating the ideal screen brightness. Dark contents require a brighter screen and the opposite holds for bright contents (at least that's the way I like it :) ) 

The changes look a lot more than they really are because I retabbed the file