refactor calculate_foreground_color()
refactor calculate_foreground_color()

split repeated code into separate function.

travisred/dunst,thomasf/dunst,LukeShu/dunst,LukeShu/dunst,travisred/dunst,thomasf/dunst,LukeShu/dunst