If you change desktop background to a lighter color, Windows autometically changes icon font color to black. If you change it to a darker color, it changes the font color to white.

How it detects which color is lighter and which color is darker ?